diff --git a/client/src/routes/Search/Filters.tsx b/client/src/routes/Search/Filters.tsx
index 2977759..3491362 100644
--- a/client/src/routes/Search/Filters.tsx
+++ b/client/src/routes/Search/Filters.tsx
@@ -1,4 +1,5 @@
-import React, { PureComponent } from 'react'
+import React from 'react'
+import shortid from 'shortid'
import Button from '../../components/atoms/Button'
import styles from './Filters.module.scss'
import data from '../../data/form-publish.json'
@@ -11,89 +12,104 @@ const labelCategories =
steps[1].fields.categories &&
steps[1].fields.categories.label
-const optionsCategories =
- steps &&
- steps[1].fields &&
- steps[1].fields.categories &&
- steps[1].fields.categories.options
-
const labelLicense =
steps &&
steps[2].fields &&
steps[2].fields.license &&
steps[2].fields.license.label
-const optionsLicense =
- steps &&
- steps[2].fields &&
- steps[2].fields.license &&
- steps[2].fields.license.options
+function getFilterMetadata(results: any[]) {
+ const filterCategories: string[] = []
+ const filterLicenses: string[] = []
-const filters = [
- { label: labelCategories, items: optionsCategories },
- { label: labelLicense, items: optionsLicense }
-]
+ results.map(asset => {
+ const { metadata } = asset.findServiceByType('Metadata')
+ const { categories, license } = metadata.base
+ categories && filterCategories.push(categories[0])
+ license && filterLicenses.push(license)
+ return null
+ })
-export default class Filters extends PureComponent<{
+ return { filterCategories, filterLicenses }
+}
+
+export default function Filters({
+ category,
+ license,
+ results,
+ setCategory,
+ setLicense
+}: {
category: string
license: string
+ results: any[]
setCategory(category: string): void
setLicense(license: string): void
-}> {
- public render() {
- const { category, license, setCategory, setLicense } = this.props
+}) {
+ const { filterCategories, filterLicenses } = getFilterMetadata(results)
- return filters.map(filter => (
-
-
{filter.label}
-
- {filter.items &&
- filter.items
- .sort((a: string, b: string) => a.localeCompare(b)) // sort alphabetically
- .map((option: string) => {
- const isActive =
- category === option || license === option
+ const filters = [
+ { label: labelCategories, items: filterCategories },
+ { label: labelLicense, items: filterLicenses }
+ ]
- return (
- -
-
+ )
+ })}
+
+
+ ))}
+ >
+ )
}
diff --git a/client/src/routes/Search/Sidebar.tsx b/client/src/routes/Search/Sidebar.tsx
index 4b3d407..355d6a9 100644
--- a/client/src/routes/Search/Sidebar.tsx
+++ b/client/src/routes/Search/Sidebar.tsx
@@ -8,6 +8,7 @@ export default function Sidebar({
inputChange,
category,
license,
+ results,
setCategory,
setLicense
}: {
@@ -15,6 +16,7 @@ export default function Sidebar({
inputChange: any
category: string
license: string
+ results: any[]
setCategory(category: string): void
setLicense(license: string): void
}) {
@@ -37,6 +39,7 @@ export default function Sidebar({
diff --git a/client/src/routes/Search/index.tsx b/client/src/routes/Search/index.tsx
index 473a6b4..c368521 100644
--- a/client/src/routes/Search/index.tsx
+++ b/client/src/routes/Search/index.tsx
@@ -2,6 +2,7 @@ import React, { PureComponent, ChangeEvent } from 'react'
import { Link } from 'react-router-dom'
import queryString from 'query-string'
import { History, Location } from 'history'
+import shortid from 'shortid'
import { Logger } from '@oceanprotocol/squid'
import Spinner from '../../components/atoms/Spinner'
import Route from '../../components/templates/Route'
@@ -165,14 +166,20 @@ class Search extends PureComponent {
}
public renderResults = () =>
- this.state.isLoading ? (
-
- ) : this.state.results && this.state.results.length ? (
-
- {this.state.results.map((asset: any) => (
-
- ))}
-
+ this.state.results && this.state.results.length ? (
+ <>
+
+ {this.state.results.map((asset: any) => (
+
+ ))}
+
+
+
+ >
) : (
No Data Sets Found.
@@ -181,42 +188,45 @@ class Search extends PureComponent
{
)
public render() {
- const { totalResults, totalPages, currentPage } = this.state
+ const {
+ isLoading,
+ results,
+ totalResults,
+ search,
+ category,
+ license
+ } = this.state
return (
- {!this.state.isLoading && (
-
- {totalResults} results for{' '}
-
- {decodeURIComponent(
- this.state.search ||
- this.state.category
- )}
-
-
- )}
+ {isLoading ? (
+
+ ) : (
+ <>
+
+ {totalResults} results for{' '}
+
+ {decodeURIComponent(
+ search || category
+ )}
+
+
- {this.renderResults()}
-
- {!this.state.isLoading && (
-
+ {this.renderResults()}
+ >
)}