diff --git a/src/components/custom/edit/dataset/AncestorIds.jsx b/src/components/custom/edit/dataset/AncestorIds.jsx index c2b7577f..42301266 100644 --- a/src/components/custom/edit/dataset/AncestorIds.jsx +++ b/src/components/custom/edit/dataset/AncestorIds.jsx @@ -1,4 +1,4 @@ -import React, {useContext, useEffect, useState} from 'react'; +import React, {useContext, useState} from 'react'; import {Form} from 'react-bootstrap'; import {Results, SearchBox} from "@elastic/react-search-ui"; import {Layout} from "@elastic/react-search-ui-views"; @@ -16,11 +16,13 @@ import {getUBKGFullName} from "../../js/functions"; import SenNetPopover from "../../../SenNetPopover"; import SearchUIContainer from 'search-ui/components/core/SearchUIContainer'; import FacetsContent from '../../search/FacetsContent'; -import SearchUIContext from 'search-ui/components/core/SearchUIContext'; import AppContext from "../../../../context/AppContext"; +import { useSearchUIContext } from "search-ui/components/core/SearchUIContext"; function BodyContent({ handleChangeAncestor, data }) { - const { wasSearched, filters } = useContext(SearchUIContext) + + const { wasSearched, filters } = useSearchUIContext(); + const {hasAuthenticationCookie, isUnauthorized } = useContext(AppContext) const addConditional = (key, entity) => { valid_dataset_ancestor_config['searchQuery']['conditionalFacets'][key] = ({filters}) => { diff --git a/src/components/custom/edit/sample/AncestorId.jsx b/src/components/custom/edit/sample/AncestorId.jsx index f0ad7157..d854d91b 100644 --- a/src/components/custom/edit/sample/AncestorId.jsx +++ b/src/components/custom/edit/sample/AncestorId.jsx @@ -13,13 +13,13 @@ import SelectedFilters from "../../layout/SelectedFilters"; import {getUBKGFullName} from "../../js/functions"; import SenNetPopover from "../../../SenNetPopover"; import SearchUIContainer from 'search-ui/components/core/SearchUIContainer'; -import SearchUIContext from 'search-ui/components/core/SearchUIContext'; import FacetsContent from '../../search/FacetsContent'; import AppContext from "../../../../context/AppContext"; +import { useSearchUIContext } from "search-ui/components/core/SearchUIContext"; function BodyContent({ handleChangeSource, data }) { const {hasAuthenticationCookie, isUnauthorized } = useContext(AppContext) - const { filters } = useContext(SearchUIContext) + const { filters } = useSearchUIContext(); const includedExclude = useRef(false) exclude_dataset_config['searchQuery']['conditionalFacets']['rui_location'] = ({filters}) => { @@ -51,6 +51,12 @@ function BodyContent({ handleChangeSource, data }) { } const AncestorId = ({fetchSource, onChange, source, data}) => { + const { + adminGroup, + authorized, + hasAuthenticationCookie + } = useContext(AppContext); + const [showHideModal, setShowHideModal] = useState(false) const handleSearchFormSubmit = (event, onSubmit) => { @@ -77,6 +83,12 @@ const AncestorId = ({fetchSource, onChange, source, data}) => { hideModal(); } + const authState = { + isAuthenticated: hasAuthenticationCookie() === true, + isAuthorized: authorized === true, + isAdmin: adminGroup === true + } + return ( <> Ancestor ID { keyboard={false} > - + diff --git a/src/components/custom/layout/CustomClearSearchBox.js b/src/components/custom/layout/CustomClearSearchBox.js index c5d62714..a3bec5e3 100644 --- a/src/components/custom/layout/CustomClearSearchBox.js +++ b/src/components/custom/layout/CustomClearSearchBox.js @@ -1,9 +1,9 @@ -import React, { useContext } from "react"; +import React from "react"; import {withSearch} from "@elastic/react-search-ui"; -import SearchUIContext from "search-ui/components/core/SearchUIContext"; +import { useSearchUIContext } from "search-ui/components/core/SearchUIContext"; function CustomClearSearchBox({shouldClearFilters = true}) { - const { clearSearchTerm, setPageSize, setPageNumber } = useContext(SearchUIContext) + const { clearSearchTerm, setPageSize, setPageNumber } = useSearchUIContext(); function handleClearFiltersClick() { setPageSize(20) diff --git a/src/components/custom/search/BodyContent.jsx b/src/components/custom/search/BodyContent.jsx index c43dff87..ca6f5b51 100644 --- a/src/components/custom/search/BodyContent.jsx +++ b/src/components/custom/search/BodyContent.jsx @@ -1,10 +1,9 @@ -import { useContext } from 'react' import { Results } from '@elastic/react-search-ui' -import SearchUIContext from 'search-ui/components/core/SearchUIContext' +import { useSearchUIContext } from "search-ui/components/core/SearchUIContext"; import Spinner from '../Spinner' function BodyContent({ view }) { - const { wasSearched, filters, rawResponse } = useContext(SearchUIContext) + const { wasSearched, filters, rawResponse } = useSearchUIContext() return (
{wasSearched && } } diff --git a/src/components/custom/search/SelectedFacets.jsx b/src/components/custom/search/SelectedFacets.jsx index deefbf29..54aea46b 100644 --- a/src/components/custom/search/SelectedFacets.jsx +++ b/src/components/custom/search/SelectedFacets.jsx @@ -1,10 +1,9 @@ -import { useContext } from 'react' import { Chip } from '@mui/material' import { getUBKGFullName } from '../js/functions' -import SearchUIContext from 'search-ui/components/core/SearchUIContext' +import { useSearchUIContext } from "search-ui/components/core/SearchUIContext"; function SelectedFacets() { - const { filters, setFilter, removeFilter } = useContext(SearchUIContext) + const { facetConfig, filters, setFilter, removeFilter } = useSearchUIContext() const getSelector = (pre, label, value) => { return `sui-${pre}--${formatVal(label)}-${formatVal(value)}` @@ -14,49 +13,55 @@ function SelectedFacets() { return `${id}`.replace(/\W+/g, '') } - const convertToDisplayLabel = (filter, key) => { - switch (filter.uiType) { + const convertToDisplayLabel = (facet, key) => { + switch (facet.facetType) { case 'daterange': const datePrefix = key === 'from' ? 'Start' : 'End' - return `${datePrefix} ${filter.label}` - case 'numrange': + return `${datePrefix} ${facet.label}` + case 'histogram': const numPrefix = key === 'from' ? 'Min' : 'Max' - return `${numPrefix} ${filter.label}` + return `${numPrefix} ${facet.label}` default: - return filter.label + return facet.label } } - const convertToDisplayValue = (filter, value) => { - switch (filter.uiType) { + const convertToDisplayValue = (facet, value) => { + switch (facet.facetType) { case 'daterange': return new Date(value).toLocaleDateString('en-US', { timeZone: 'UTC' }) - case 'numrange': + case 'histogram': return value default: return getUBKGFullName(value) } } - const handleDelete = (e, filter, value, key) => { + const handleDelete = (e, filter, facet, value, key) => { e.preventDefault() - if (filter.type === 'range') { - const newValue = { ...value } - delete newValue[key] - if (!newValue.from && !newValue.to) { - removeFilter(filter.field, value, 'SelectedFacets') - } else { - setFilter(filter.field, newValue, 'SelectedFacets') - } - } else { - removeFilter(filter.field, value, 'SelectedFacets') + switch (facet.facetType) { + case 'daterange': + case 'histogram': + const newValue = { ...value } + delete newValue[key] + if (!newValue.from && !newValue.to) { + removeFilter(filter.field, value) + } else { + setFilter(filter.field, newValue) + } + break; + default: + removeFilter(filter.field, value) + break; } } - const buildRangeFacetChip = (filter, value) => { + const buildRangeFacetChip = (filter, facet, value) => { const chips = [] Array('from', 'to').forEach((key) => { - if (!value[key]) return + if (!value[key]) + return + chips.push( {' '} - {convertToDisplayLabel(filter, key)}:{' '} - {convertToDisplayValue(filter, value[key])} + {convertToDisplayLabel(facet, key)}:{' '} + {convertToDisplayValue(facet, value[key])} } variant='outlined' - onDelete={(e) => handleDelete(e, filter, value, key)} + onDelete={(e) => handleDelete(e, filter, facet, value, key)} /> ) }) return chips } - const buildValueFacetChip = (filter, value) => { + const buildValueFacetChip = (filter, facet, value) => { return ( {' '} - {convertToDisplayLabel(filter)}:{' '} - {convertToDisplayValue(filter, value)} + {convertToDisplayLabel(facet)}:{' '} + {convertToDisplayValue(facet, value)} } variant='outlined' - onDelete={(e) => handleDelete(e, filter, value)} + onDelete={(e) => handleDelete(e, filter, facet, value)} /> ) } @@ -97,11 +102,16 @@ function SelectedFacets() { return (
{filters.reduce((acc, filter) => { + const facet = facetConfig[filter.field] for (const value of filter.values) { - if (filter.type === 'range') { - acc.push(...buildRangeFacetChip(filter, value)) - } else { - acc.push(buildValueFacetChip(filter, value)) + switch (facet.facetType) { + case 'daterange': + case 'histogram': + acc.push(...buildRangeFacetChip(filter, facet, value)) + break; + default: + acc.push(buildValueFacetChip(filter, facet, value)) + break; } } return acc diff --git a/src/config/config.js b/src/config/config.js index 1a494e74..c3f89d40 100644 --- a/src/config/config.js +++ b/src/config/config.js @@ -140,27 +140,58 @@ export let valid_dataset_ancestor_config = _.cloneDeep(ancestor_config) export let exclude_dataset_config = _.cloneDeep(ancestor_config); exclude_dataset_config['searchQuery']['excludeFilters'].push( { - keyword: "entity_type.keyword", - value: "Dataset" - }, - { - keyword: "entity_type.keyword", - value: "Upload" - }, - { - keyword: "entity_type.keyword", - value: "Collection" + type: 'term', + field: 'entity_type.keyword', + values: ['Collection', 'Dataset', 'Upload'] } -); +) export function FilterIsSelected(fieldName, value) { - return ({filters}) => { - return filters.some( - (f) => f.field === fieldName && (!value || f.values.includes(value)) - ); - }; + return ({filters, aggregations}) => { + for (const filter of filters) { + if (filter.field === fieldName && filter.values.includes(value)) { + return true + } + } + return false + } } export const STORAGE_KEY = (key = '') => `sn-portal.${key}` export const COLS_ORDER_KEY = (context = '') => `${context}.columnsOrder` + +export function doesTermFilterContainValues(name, values) { + return (filters, auth) => { + const filter = filters.find((f) => f.field === name) + return ( + filter != undefined && values.some((v) => filter.values.includes(v)) + ) + } +} + +export function doFiltersContainField(field) { + return (filters, auth) => { + return filters.some((f) => f.field === field) + } +} + +export function doesAggregationHaveBuckets(field) { + return (filters, aggregations, auth) => { + try { + return ( + aggregations[field] !== undefined && aggregations[field].buckets.length > 0 + ) + } catch { + return false + } + } +} + +export function doesTermOptionHaveDocCount(option, filters, aggregations, auth) { + return option.doc_count > 0 +} + +export function isDateFacetVisible(filters, aggregations, auth) { + return Object.keys(aggregations).length > 0 +} \ No newline at end of file diff --git a/src/config/search/entities.js b/src/config/search/entities.js index 29c78f94..81b3dae8 100644 --- a/src/config/search/entities.js +++ b/src/config/search/entities.js @@ -1,5 +1,12 @@ -import {FilterIsSelected, getAuth, getEntitiesIndex, getSearchEndPoint} from "../config"; -import SearchAPIConnector from "search-ui/packages/search-api-connector"; +import SearchAPIConnector from 'search-ui/packages/search-api-connector'; +import { + doesAggregationHaveBuckets, + doesTermFilterContainValues, + getAuth, + getEntitiesIndex, + getSearchEndPoint, + isDateFacetVisible +} from '../config'; const connector = new SearchAPIConnector({ indexName: getEntitiesIndex(), @@ -7,17 +14,25 @@ const connector = new SearchAPIConnector({ accessToken: getAuth(), }) +const lateralOrgans = ['Breast', 'Kidney', 'Lung', 'Mammary Gland', 'Ovary', 'Tonsil'] + export const SEARCH_ENTITIES = { alwaysSearchOnInitialLoad: true, searchQuery: { excludeFilters: [ { - keyword: "entity_type.keyword", - value: "Publication" + type: 'term', + field: 'entity_type.keyword', + values: ['Publication'] }, { - keyword: "dataset_category.keyword", - value: ["codcc-processed", "lab-processed"] + type: 'term', + field: 'dataset_category.keyword', + values: ['codcc-processed', 'lab-processed'] + }, + { + type: 'exists', + field: 'next_revision_uuid', } ], facets: { @@ -28,8 +43,11 @@ export const SEARCH_ENTITIES = { isExpanded: true, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: true, + isFacetVisible: doesAggregationHaveBuckets('entity_type') }, - // Used for when "Sample" is selected to show organs + // Used for when 'Sample' is selected to show organs source_type: { label: 'Source Type', type: 'value', @@ -37,6 +55,9 @@ export const SEARCH_ENTITIES = { filterType: 'any', isExpanded: false, isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('entity_type', ['Source']), + isFacetVisible: doesAggregationHaveBuckets('source_type') }, sample_category: { label: 'Sample Category', @@ -45,6 +66,9 @@ export const SEARCH_ENTITIES = { isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('entity_type', ['Sample']), + isFacetVisible: doesAggregationHaveBuckets('sample_category') }, has_qa_derived_dataset: { label: 'Has QA Derived Datasets', @@ -52,7 +76,16 @@ export const SEARCH_ENTITIES = { field: 'has_qa_derived_dataset.keyword', isExpanded: false, filterType: 'any', - isFilterable: false + isFilterable: false, + facetType: 'term', + isAggregationActive: (filters, authState) => { + if (authState.isAdmin) { + const isActiveFunc = doesTermFilterContainValues('entity_type', ['Dataset']) + return isActiveFunc(filters) + } + return false + }, + isFacetVisible: doesAggregationHaveBuckets('has_qa_derived_dataset') }, dataset_type: { label: 'Dataset Type', @@ -61,8 +94,10 @@ export const SEARCH_ENTITIES = { isExpanded: false, filterType: 'any', isFilterable: false, - groupBy: 'dataset_type_hierarchy.first_level.keyword', - groupAll: true, + facetType: 'hierarchy', + groupByField: 'dataset_type_hierarchy.first_level.keyword', + isAggregationActive: true, + isFacetVisible: doesAggregationHaveBuckets('dataset_type') }, 'sources.source_type': { label: 'Source Type', @@ -71,6 +106,9 @@ export const SEARCH_ENTITIES = { filterType: 'any', isExpanded: false, isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('entity_type', ['Dataset']), + isFacetVisible: doesAggregationHaveBuckets('sources.source_type') }, organ: { label: 'Organ', @@ -79,28 +117,44 @@ export const SEARCH_ENTITIES = { isExpanded: false, filterType: 'any', isFilterable: false, - groupBy: 'organ_hierarchy.keyword', - groupAll: false, + facetType: 'hierarchy', + groupByField: 'organ_hierarchy.keyword', + isHierarchyOption: (option) => { + return lateralOrgans.includes(option) + }, + isAggregationActive: doesTermFilterContainValues('entity_type', ['Sample']), + isFacetVisible: doesAggregationHaveBuckets('organ') }, - // Used for when "Dataset" or Sample Block/Section/Suspension is selected to show related organs - "origin_sample.organ": { + // Used for when 'Dataset' or Sample Block/Section/Suspension is selected to show related organs + 'origin_sample.organ': { label: 'Organ', type: 'value', field: 'origin_sample.organ.keyword', isExpanded: false, filterType: 'any', isFilterable: false, - groupBy: 'origin_sample.organ_hierarchy.keyword', - groupAll: false, + facetType: 'hierarchy', + groupByField: 'origin_sample.organ_hierarchy.keyword', + isHierarchyOption: (option) => { + return lateralOrgans.includes(option) + }, + isAggregationActive: [ + doesTermFilterContainValues('entity_type', ['Dataset']), + doesTermFilterContainValues('sample_category', ['Block', 'Section', 'Suspension']) + ], + isFacetVisible: doesAggregationHaveBuckets('origin_sample.organ') }, - // Used for when "Dataset/Sample" is selected to show related sources - "source.source_type": { + // Used for when 'Dataset/Sample' is selected to show related sources + 'source.source_type': { label: 'Source Type', type: 'value', field: 'source.source_type.keyword', filterType: 'any', isExpanded: false, isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('entity_type', ['Sample']), + isFacetVisible: doesAggregationHaveBuckets('source.source_type') }, has_rui_information: { label: 'Is Spatially Registered', @@ -109,6 +163,9 @@ export const SEARCH_ENTITIES = { isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: true, + isFacetVisible: doesAggregationHaveBuckets('has_rui_information') }, 'rui_location_anatomical_locations.label': { label: 'Anatomical Locations', @@ -117,22 +174,23 @@ export const SEARCH_ENTITIES = { isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('entity_type', ['Sample']), + isFacetVisible: doesAggregationHaveBuckets('rui_location_anatomical_locations.label') }, - 'metadata': { + 'has_metadata': { label: 'Has Metadata', type: 'exists', - field: 'metadata', - isExpanded: false, - filterType: 'any', - isFilterable: false, - }, - 'ingest_metadata.metadata': { - label: 'Has Metadata', - type: 'exists', - field: 'ingest_metadata.metadata', + field: 'has_metadata.keyword', isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: [ + doesTermFilterContainValues('entity_type', ['Source', 'Dataset', 'Collection', 'Publication']), + doesTermFilterContainValues('sample_category', ['Block', 'Section', 'Suspension']) + ], + isFacetVisible: doesAggregationHaveBuckets('has_metadata') }, has_all_published_datasets: { label: 'Has All Primary Published', @@ -141,6 +199,15 @@ export const SEARCH_ENTITIES = { isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: (filters, authState) => { + if (authState.isAdmin) { + const isActiveFunc = doesTermFilterContainValues('entity_type', ['Upload']) + return isActiveFunc(filters) + } + return false + }, + isFacetVisible: doesAggregationHaveBuckets('has_all_published_datasets') }, status: { label: 'Status', @@ -149,6 +216,9 @@ export const SEARCH_ENTITIES = { isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: true, + isFacetVisible: doesAggregationHaveBuckets('status') }, group_name: { label: 'Data Provider Group', @@ -157,6 +227,9 @@ export const SEARCH_ENTITIES = { isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: true, + isFacetVisible: doesAggregationHaveBuckets('group_name') }, created_by_user_displayname: { label: 'Registered By', @@ -165,6 +238,9 @@ export const SEARCH_ENTITIES = { isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: true, + isFacetVisible: doesAggregationHaveBuckets('created_by_user_displayname') }, created_timestamp: { label: 'Creation Date', @@ -173,7 +249,8 @@ export const SEARCH_ENTITIES = { isExpanded: false, filterType: 'any', isFilterable: true, - uiType: 'daterange', + facetType: 'daterange', + isFacetVisible: isDateFacetVisible }, last_modified_timestamp: { label: 'Modification Date', @@ -182,60 +259,19 @@ export const SEARCH_ENTITIES = { isExpanded: false, filterType: 'any', isFilterable: true, - uiType: 'daterange', + facetType: 'daterange', + isFacetVisible: isDateFacetVisible }, }, disjunctiveFacets: [], - conditionalFacets: { - // Show 'origin_sample.organ' facet if 'Dataset' or Sample Block/Section/Suspension is selected - "origin_sample.organ": ({filters}) => { - return filters.some( - (filter) => - (filter.field === 'entity_type' && filter.values.includes('Dataset')) || - (filter.field === 'sample_category' && (filter.values.includes('Block') || - filter.values.includes('Section') || filter.values.includes('Suspension'))) - ) - }, - // Show 'metadata' facet if 'Sample' or Sample Block/Section/Suspension is selected - 'metadata': ({filters}) => { - return filters.some( - (filter) => - (filter.field === 'entity_type' && filter.values.some(r=> ['Source', 'Collection', 'Publication'].includes(r)) ) || - (filter.field === 'sample_category' && (filter.values.includes('Block') || - filter.values.includes('Section') || filter.values.includes('Suspension'))) - ) - }, - 'ingest_metadata.metadata': ({filters}) => { - return filters.some( - (filter) => - (filter.field === 'entity_type' && filter.values.includes('Dataset')) - ) - }, - // Only show 'organ' facet if 'Sample' is selected from the entity type facet - organ: FilterIsSelected('entity_type', 'Sample'), - 'rui_location_anatomical_locations.label': FilterIsSelected('entity_type', 'Sample'), - - sample_category: FilterIsSelected('entity_type', 'Sample'), - - // Only show 'source.source_type' facet if 'Sample' is selected from the entity type facet - "source.source_type": ({filters}) => { - return filters.some( - (filter) => - filter.field === 'entity_type' && filter.values.includes('Sample') - ) - }, - // Only show 'source' facet if 'Source' is selected from the entity type facet - source_type: FilterIsSelected('entity_type', 'Source'), - // Only show 'sources' facet if 'Dataset' is selected from the entity type facet - 'sources.source_type': FilterIsSelected('entity_type', 'Dataset') - }, + conditionalFacets: {}, search_fields: { - "sennet_id^4": {type: 'value'}, - "group_name^3": {type: 'value'}, - "dataset_type^2": {type: 'value'}, - "sample_category^2": {type: 'value'}, - "entity_type^2": {type: 'value'}, - "status^2": {type: 'value'}, + 'sennet_id^4': {type: 'value'}, + 'group_name^3': {type: 'value'}, + 'dataset_type^2': {type: 'value'}, + 'sample_category^2': {type: 'value'}, + 'entity_type^2': {type: 'value'}, + 'status^2': {type: 'value'}, all_text: {type: 'value'}, }, source_fields: [ @@ -263,15 +299,17 @@ export const SEARCH_ENTITIES = { current: 1, resultsPerPage: 20, sortList: [{ - field: "last_modified_timestamp", - direction: "desc" + field: 'last_modified_timestamp', + direction: 'desc' }] }, + urlPushDebounceLength: 100, + trackTotalHits: true, trackUrlState: true, apiConnector: connector, hasA11yNotifications: true, a11yNotificationMessages: { searchResults: ({start, end, totalResults, searchTerm}) => - `Searching for "${searchTerm}". Showing ${start} to ${end} results out of ${totalResults}.`, + `Searching for '${searchTerm}'. Showing ${start} to ${end} results out of ${totalResults}.`, }, } diff --git a/src/config/search/files.js b/src/config/search/files.js index fdf7aa11..06242412 100644 --- a/src/config/search/files.js +++ b/src/config/search/files.js @@ -1,6 +1,11 @@ -import {getAuth, getFilesIndex, getSearchEndPoint} from "../config"; -import SearchAPIConnector from "search-ui/packages/search-api-connector"; - +import SearchAPIConnector from 'search-ui/packages/search-api-connector'; +import { + doesAggregationHaveBuckets, + getAuth, + getFilesIndex, + getSearchEndPoint, + isDateFacetVisible +} from '../config'; const connector = new SearchAPIConnector({ indexName: getFilesIndex(), @@ -27,8 +32,12 @@ const sourceItems = [ export const SEARCH_FILES = { alwaysSearchOnInitialLoad: true, searchQuery: { - groupBy: 'dataset_uuid.keyword', - excludeFilters: [], + excludeFilters: [ + { + type: 'exists', + field: 'next_revision_uuid', + } + ], facets: { file_extension: { label: 'File Type', @@ -36,6 +45,9 @@ export const SEARCH_FILES = { field: 'file_extension.keyword', filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: true, + isFacetVisible: doesAggregationHaveBuckets('file_extension') }, 'organs.type': { label: 'Organs', @@ -44,6 +56,9 @@ export const SEARCH_FILES = { isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: true, + isFacetVisible: doesAggregationHaveBuckets('organs.type') }, dataset_type: { label: 'Dataset Type', @@ -52,6 +67,9 @@ export const SEARCH_FILES = { isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: true, + isFacetVisible: doesAggregationHaveBuckets('dataset_type') }, file_info_refresh_timestamp: { label: 'Modification Date', @@ -60,12 +78,12 @@ export const SEARCH_FILES = { isExpanded: false, filterType: 'any', isFilterable: true, - uiType: 'daterange', + facetType: 'daterange', + isFacetVisible: isDateFacetVisible }, }, disjunctiveFacets: [], - conditionalFacets: { - }, + conditionalFacets: {}, search_fields: { rel_path: {type: 'value'}, file_extension: {type: 'value'}, @@ -80,10 +98,12 @@ export const SEARCH_FILES = { current: 1, resultsPerPage: 20, sortList: [{ - field: "source.file_info_refresh_timestamp", - direction: "desc" + field: 'source.file_info_refresh_timestamp', + direction: 'desc' }] }, + urlPushDebounceLength: 100, + trackTotalHits: true, trackUrlState: true, apiConnector: connector, hasA11yNotifications: true, diff --git a/src/config/search/metadata.js b/src/config/search/metadata.js index 414ae17a..605cf4a4 100644 --- a/src/config/search/metadata.js +++ b/src/config/search/metadata.js @@ -1,6 +1,13 @@ -import { searchUIQueryString } from "@/components/custom/js/functions"; -import SearchAPIConnector from "search-ui/packages/search-api-connector"; -import { FilterIsSelected, getAuth, getEntitiesIndex, getSearchEndPoint } from "../config"; +import { searchUIQueryString } from '@/components/custom/js/functions'; +import SearchAPIConnector from 'search-ui/packages/search-api-connector'; +import { + doFiltersContainField, + doesAggregationHaveBuckets, + doesTermFilterContainValues, + getAuth, + getEntitiesIndex, + getSearchEndPoint, +} from '../config'; const connector = new SearchAPIConnector({ indexName: getEntitiesIndex(), @@ -13,24 +20,23 @@ export const SEARCH_METADATA = { searchQuery: { excludeFilters: [ { - keyword: "entity_type.keyword", - value: "Collection" - }, - { - keyword: "entity_type.keyword", - value: "Publication" + type: 'term', + field: 'entity_type.keyword', + values: ['Collection', 'Publication', 'Upload'] }, { - keyword: "entity_type.keyword", - value: "Upload" + type: 'term', + field: 'sample_category.keyword', + values: ['Organ'], }, { - keyword: "sample_category.keyword", - value: "Organ", + type: 'term', + field: 'dataset_category.keyword', + values: ['codcc-processed', 'lab-processed'] }, { - keyword: "dataset_category.keyword", - value: ["codcc-processed", "lab-processed"] + type: 'exists', + field: 'next_revision_uuid', } ], facets: { @@ -41,6 +47,9 @@ export const SEARCH_METADATA = { isExpanded: true, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: true, + isFacetVisible: doesAggregationHaveBuckets('entity_type') }, source_type: { label: 'Source Type', @@ -49,6 +58,9 @@ export const SEARCH_METADATA = { isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('entity_type', ['Source']), + isFacetVisible: doesAggregationHaveBuckets('source_type') }, sample_category: { label: 'Sample Category', @@ -57,6 +69,9 @@ export const SEARCH_METADATA = { isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('entity_type', ['Sample']), + isFacetVisible: doesAggregationHaveBuckets('sample_category') }, dataset_type: { label: 'Dataset Type', @@ -65,159 +80,207 @@ export const SEARCH_METADATA = { isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: true, + isFacetVisible: doesAggregationHaveBuckets('dataset_type') }, // Source Human - "source_mapped_metadata.age.value": { + 'source_mapped_metadata.age.value': { label: 'Age', type: 'range', field: 'source_mapped_metadata.age.value', isExpanded: false, filterType: 'any', isFilterable: false, - uiType: 'numrange', - uiInterval: 1, + facetType: 'histogram', + aggregationInterval: 1, + isAggregationActive: doesTermFilterContainValues('source_type', ['Human']), + isFacetVisible: doesAggregationHaveBuckets('source_mapped_metadata.age.value') }, - "source_mapped_metadata.body_mass_index.value": { + 'source_mapped_metadata.body_mass_index.value': { label: 'Body Mass Index', type: 'range', field: 'source_mapped_metadata.body_mass_index.value', isExpanded: false, filterType: 'any', isFilterable: false, - uiType: 'numrange', - uiInterval: 1, + facetType: 'histogram', + aggregationInterval: 1, + isAggregationActive: doesTermFilterContainValues('source_type', ['Human']), + isFacetVisible: doesAggregationHaveBuckets('source_mapped_metadata.body_mass_index.value') }, - "source_mapped_metadata.race.value": { + 'source_mapped_metadata.race.value': { label: 'Race', type: 'value', field: 'source_mapped_metadata.race.value.keyword', isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('source_type', ['Human']), + isFacetVisible: doesAggregationHaveBuckets('source_mapped_metadata.race.value') }, - "source_mapped_metadata.sex.value": { + 'source_mapped_metadata.sex.value': { label: 'Sex', type: 'value', field: 'source_mapped_metadata.sex.value.keyword', isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('source_type', ['Human']), + isFacetVisible: doesAggregationHaveBuckets('source_mapped_metadata.sex.value') }, // Source Mouse - "metadata.euthanization_method": { + 'metadata.euthanization_method': { label: 'Euthanization Method', type: 'value', field: 'metadata.euthanization_method.keyword', isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('source_type', ['Mouse']), + isFacetVisible: doesAggregationHaveBuckets('metadata.euthanization_method') }, - "metadata.is_embryo": { + 'metadata.is_embryo': { label: 'Is Embryo', type: 'value', field: 'metadata.is_embryo.keyword', isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('source_type', ['Mouse']), + isFacetVisible: doesAggregationHaveBuckets('metadata.is_embryo') }, - "metadata.is_deceased": { + 'metadata.is_deceased': { label: 'Is Deceased', type: 'value', field: 'metadata.is_deceased.keyword', isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('source_type', ['Mouse']), + isFacetVisible: doesAggregationHaveBuckets('metadata.is_deceased') }, - "metadata.sex": { + 'metadata.sex': { label: 'Sex', type: 'value', field: 'metadata.sex.keyword', isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('source_type', ['Mouse']), + isFacetVisible: doesAggregationHaveBuckets('metadata.sex') }, - "metadata.strain": { + 'metadata.strain': { label: 'Strain', type: 'value', field: 'metadata.strain.keyword', isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('source_type', ['Mouse']), + isFacetVisible: doesAggregationHaveBuckets('metadata.strain') }, - // Sample Section - "metadata.area_value": { + 'metadata.area_value': { label: 'Area', type: 'range', field: 'metadata.area_value', isExpanded: false, filterType: 'any', isFilterable: false, - uiType: 'numrange', + facetType: 'histogram', + aggregationInterval: 1, + isAggregationActive: doFiltersContainField('metadata.area_unit'), + isFacetVisible: doesAggregationHaveBuckets('metadata.area_value') }, - "metadata.area_unit": { + 'metadata.area_unit': { label: 'Area Unit', type: 'value', field: 'metadata.area_unit.keyword', isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('sample_category', ['Section']), + isFacetVisible: doesAggregationHaveBuckets('metadata.area_unit') }, // Sample Shared - "metadata.preparation_condition": { + 'metadata.preparation_condition': { label: 'Preparation Condition', type: 'value', field: 'metadata.preparation_condition.keyword', isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('entity_type', ['Sample']), + isFacetVisible: doesAggregationHaveBuckets('metadata.preparation_condition') }, - "metadata.preparation_medium": { + 'metadata.preparation_medium': { label: 'Preparation Medium', type: 'value', field: 'metadata.preparation_medium.keyword', isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('entity_type', ['Sample']), + isFacetVisible: doesAggregationHaveBuckets('metadata.preparation_medium') }, - "metadata.storage_method": { + 'metadata.storage_method': { label: 'Preparation Method', type: 'value', field: 'metadata.storage_method.keyword', isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('entity_type', ['Sample']), + isFacetVisible: doesAggregationHaveBuckets('metadata.storage_method') }, - "metadata.processing_time_value": { + 'metadata.processing_time_value': { label: 'Processing Time', type: 'range', field: 'metadata.processing_time_value', isExpanded: false, filterType: 'any', isFilterable: false, - uiType: 'numrange', + facetType: 'histogram', + aggregationInterval: 1, + isAggregationActive: doFiltersContainField('metadata.processing_time_unit'), + isFacetVisible: doesAggregationHaveBuckets('metadata.processing_time_value') }, - "metadata.processing_time_unit": { + 'metadata.processing_time_unit': { label: 'Processing Time Unit', type: 'value', field: 'metadata.processing_time_unit.keyword', isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('entity_type', ['Sample']), + isFacetVisible: doesAggregationHaveBuckets('metadata.processing_time_unit') }, - "metadata.source_storage_duration_value": { + 'metadata.source_storage_duration_value': { label: 'Storage Duration', type: 'range', field: 'metadata.source_storage_duration_value', isExpanded: false, filterType: 'any', isFilterable: false, - uiType: 'numrange', - uiInterval: (filters) => { + facetType: 'histogram', + aggregationInterval: (filters) => { if (filters.some((filter) => filter.values.includes('day'))) { return 5 } @@ -226,237 +289,212 @@ export const SEARCH_METADATA = { } return 1 }, + isAggregationActive: doFiltersContainField('metadata.source_storage_duration_unit'), + isFacetVisible: doesAggregationHaveBuckets('metadata.source_storage_duration_value') }, - "metadata.source_storage_duration_unit": { + 'metadata.source_storage_duration_unit': { label: 'Storage Duration Unit', type: 'value', field: 'metadata.source_storage_duration_unit.keyword', isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('entity_type', ['Sample']), + isFacetVisible: doesAggregationHaveBuckets('metadata.source_storage_duration_unit') }, - "metadata.storage_medium": { + 'metadata.storage_medium': { label: 'Storage Medium', type: 'value', field: 'metadata.storage_medium.keyword', isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('entity_type', ['Sample']), + isFacetVisible: doesAggregationHaveBuckets('metadata.storage_medium') }, - //Sample Section - "metadata.thickness_value": { + // Sample Section + 'metadata.thickness_value': { label: 'Thickness', type: 'range', field: 'metadata.thickness_value', isExpanded: false, filterType: 'any', isFilterable: false, - uiType: 'numrange', - uiInterval: (filters) => { + facetType: 'histogram', + aggregationInterval: (filters) => { if (filters.some((filter) => filter.values.includes('um'))) { return 1 } return 0.1 }, + isAggregationActive: doFiltersContainField('metadata.thickness_unit'), + isFacetVisible: doesAggregationHaveBuckets('metadata.thickness_value') }, - "metadata.thickness_unit": { + 'metadata.thickness_unit': { label: 'Thickness Unit', type: 'value', field: 'metadata.thickness_unit.keyword', isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('sample_category', ['Section']), + isFacetVisible: doesAggregationHaveBuckets('metadata.thickness_unit') }, // Sample Block/Suspension Shared - "metadata.tissue_weight_value": { + 'metadata.tissue_weight_value': { label: 'Tissue Weight', type: 'range', field: 'metadata.tissue_weight_value', isExpanded: false, filterType: 'any', isFilterable: false, - uiType: 'numrange', - uiInterval: 5, + facetType: 'histogram', + aggregationInterval: 5, + isAggregationActive: doFiltersContainField('metadata.tissue_weight_unit'), + isFacetVisible: doesAggregationHaveBuckets('metadata.tissue_weight_value') }, - "metadata.tissue_weight_unit": { + 'metadata.tissue_weight_unit': { label: 'Tissue Weight Unit', type: 'value', field: 'metadata.tissue_weight_unit.keyword', isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('sample_category', ['Block', 'Suspension']), + isFacetVisible: doesAggregationHaveBuckets('metadata.tissue_weight_unit') }, // Sample Block - "metadata.volume_value": { + 'metadata.volume_value': { label: 'Volume', type: 'range', field: 'metadata.volume_value', isExpanded: false, filterType: 'any', isFilterable: false, - uiType: 'numrange', - uiInterval: (filters) => { + facetType: 'histogram', + aggregationInterval: (filters) => { if (filters.some((filter) => filter.values.includes('ml'))) { return 0.1 } return 1000 }, + isAggregationActive: doFiltersContainField('metadata.volume_unit'), + isFacetVisible: doesAggregationHaveBuckets('metadata.volume_value') }, - "metadata.volume_unit": { + 'metadata.volume_unit': { label: 'Volume Unit', type: 'value', field: 'metadata.volume_unit.keyword', isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('sample_category', ['Block']), + isFacetVisible: doesAggregationHaveBuckets('metadata.volume_unit') }, // Sample Suspension - "metadata.suspension_entity_type": { + 'metadata.suspension_entity_type': { label: 'Suspension Entity Type', type: 'value', field: 'metadata.suspension_entity_type.keyword', isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('sample_category', ['Suspension']), + isFacetVisible: doesAggregationHaveBuckets('metadata.suspension_entity_type') }, - "metadata.suspension_entity_count": { + 'metadata.suspension_entity_count': { label: 'Suspension Entity Number', type: 'range', field: 'metadata.suspension_entity_count', isExpanded: false, filterType: 'any', isFilterable: false, - uiType: 'numrange', - uiInterval: 100000, + facetType: 'histogram', + aggregationInterval: 100000, + isAggregationActive: doesTermFilterContainValues('sample_category', ['Suspension']), + isFacetVisible: doesAggregationHaveBuckets('metadata.suspension_entity_count') }, - "metadata.is_suspension_enriched": { + 'metadata.is_suspension_enriched': { label: 'Is Suspension Enriched', type: 'value', field: 'metadata.is_suspension_enriched.keyword', isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('sample_category', ['Suspension']), + isFacetVisible: doesAggregationHaveBuckets('metadata.is_suspension_enriched') }, // Dataset - "ingest_metadata.metadata.acquisition_instrument_model": { + 'ingest_metadata.metadata.acquisition_instrument_model': { label: 'Acquisition Instrument Model', type: 'value', field: 'ingest_metadata.metadata.acquisition_instrument_model.keyword', isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('entity_type', ['Dataset']), + isFacetVisible: doesAggregationHaveBuckets('ingest_metadata.metadata.acquisition_instrument_model') }, - "ingest_metadata.metadata.acquisition_instrument_vendor": { + 'ingest_metadata.metadata.acquisition_instrument_vendor': { label: 'Acquisition Instrument Vendor', type: 'value', field: 'ingest_metadata.metadata.acquisition_instrument_vendor.keyword', isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('entity_type', ['Dataset']), + isFacetVisible: doesAggregationHaveBuckets('ingest_metadata.metadata.acquisition_instrument_vendor') }, - "ingest_metadata.metadata.analyte_class": { + 'ingest_metadata.metadata.analyte_class': { label: 'Analyte Class', type: 'value', field: 'ingest_metadata.metadata.analyte_class.keyword', isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('entity_type', ['Dataset']), + isFacetVisible: doesAggregationHaveBuckets('ingest_metadata.metadata.analyte_class') }, - "ingest_metadata.metadata.assay_category": { + 'ingest_metadata.metadata.assay_category': { label: 'Assay Category', type: 'value', field: 'ingest_metadata.metadata.assay_category.keyword', isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('entity_type', ['Dataset']), + isFacetVisible: doesAggregationHaveBuckets('ingest_metadata.metadata.assay_category') }, - "ingest_metadata.metadata.operator": { + 'ingest_metadata.metadata.operator': { label: 'Operator', type: 'value', field: 'ingest_metadata.metadata.operator.keyword', isExpanded: false, filterType: 'any', isFilterable: false, + facetType: 'term', + isAggregationActive: doesTermFilterContainValues('entity_type', ['Dataset']), + isFacetVisible: doesAggregationHaveBuckets('ingest_metadata.metadata.operator') }, - }, disjunctiveFacets: [], - conditionalFacets: { - source_type: FilterIsSelected('entity_type', 'Source'), - sample_category: FilterIsSelected('entity_type', 'Sample'), - - // Source Human - "source_mapped_metadata.sex": FilterIsSelected('source_type', 'Human'), - "source_mapped_metadata.race": FilterIsSelected('source_type', 'Human'), - "source_mapped_metadata.age.value": FilterIsSelected('source_type', 'Human'), - "source_mapped_metadata.body_mass_index.value": FilterIsSelected('source_type', 'Human'), - - // Source Mouse - "metadata.strain": FilterIsSelected('source_type', 'Mouse'), - "metadata.sex": FilterIsSelected('source_type', 'Mouse'), - "metadata.is_embryo": FilterIsSelected('source_type', 'Mouse'), - "metadata.is_deceased": FilterIsSelected('source_type', 'Mouse'), - "metadata.euthanization_method": FilterIsSelected('source_type', 'Mouse'), - - // Sample Block - "metadata.volume_unit": FilterIsSelected('sample_category', 'Block'), - "metadata.volume_value": ({filters}) => { - return filters.some((filter) => filter.field === 'metadata.volume_unit') - }, - - // Sample Section - "metadata.thickness_unit": FilterIsSelected('sample_category', 'Section'), - "metadata.thickness_value": ({filters}) => { - return filters.some((filter) => filter.field === 'metadata.thickness_unit') - }, - "metadata.area_unit": FilterIsSelected('sample_category', 'Section'), - "metadata.area_value": ({filters}) => { - return filters.some((filter) => filter.field === 'metadata.area_unit') - }, - - // Sample Suspension - "metadata.suspension_entity_type": FilterIsSelected('sample_category', 'Suspension'), - "metadata.suspension_entity_count": FilterIsSelected('sample_category', 'Suspension'), - "metadata.is_suspension_enriched": FilterIsSelected('sample_category', 'Suspension'), - - // Sample Block/Suspension Shared - "metadata.tissue_weight_unit": ({filters}) => { - return filters.some( - (filter) => - filter.field === 'sample_category' && - (filter.values.includes('Block') || filter.values.includes('Suspension')) - ) - }, - "metadata.tissue_weight_value": ({filters}) => { - return filters.some((filter) => filter.field === 'metadata.tissue_weight_unit') - }, - - // Sample Shared - "metadata.source_storage_duration_unit": FilterIsSelected('entity_type', 'Sample'), - "metadata.source_storage_duration_value": ({filters}) => { - return filters.some((filter) => filter.field === 'metadata.source_storage_duration_unit') - }, - "metadata.preparation_medium": FilterIsSelected('entity_type', 'Sample'), - "metadata.preparation_condition": FilterIsSelected('entity_type', 'Sample'), - "metadata.storage_medium": FilterIsSelected('entity_type', 'Sample'), - "metadata.storage_method": FilterIsSelected('entity_type', 'Sample'), - "metadata.processing_time_unit": FilterIsSelected('entity_type', 'Sample'), - "metadata.processing_time_value": ({filters}) => { - return filters.some((filter) => filter.field === 'metadata.processing_time_unit') - }, - - // Dataset - "ingest_metadata.metadata.assay_category": FilterIsSelected('entity_type', 'Dataset'), - "ingest_metadata.metadata.analyte_class": FilterIsSelected('entity_type', 'Dataset'), - "ingest_metadata.metadata.operator": FilterIsSelected('entity_type', 'Dataset'), - "ingest_metadata.metadata.acquisition_instrument_model": FilterIsSelected('entity_type', 'Dataset'), - "ingest_metadata.metadata.acquisition_instrument_vendor": FilterIsSelected('entity_type', 'Dataset'), - }, + conditionalFacets: {}, search_fields: { all_text: {type: 'value'}, }, @@ -482,16 +520,18 @@ export const SEARCH_METADATA = { current: 1, resultsPerPage: 20, sortList: [{ - field: "last_modified_timestamp", - direction: "desc" + field: 'last_modified_timestamp', + direction: 'desc' }] }, + urlPushDebounceLength: 100, + trackTotalHits: true, trackUrlState: true, apiConnector: connector, hasA11yNotifications: true, a11yNotificationMessages: { searchResults: ({start, end, totalResults, searchTerm}) => - `Searching for "${searchTerm}". Showing ${start} to ${end} results out of ${totalResults}.`, + `Searching for '${searchTerm}'. Showing ${start} to ${end} results out of ${totalResults}.`, }, // Discover page configuration diff --git a/src/context/AppContext.jsx b/src/context/AppContext.jsx index 7fd3750b..0cb508c1 100644 --- a/src/context/AppContext.jsx +++ b/src/context/AppContext.jsx @@ -276,7 +276,7 @@ export const AppProvider = ({ cache, banners, children }) => { const getPreviewView = (data) => { return isUnauthorized(data) && data != null ? : } - + return ( { const {isLoggedIn} = useContext(AppContext) - const {isLoading, rawResponse, pageNumber, - setPageNumber, pageSize, setPageSize, setSort} = useContext(SearchUIContext) + const {isLoading, rawResponse, pageNumber, setPageNumber, pageSize, setPageSize, setSort} = useSearchUIContext() const sortedFields = useRef({}) const hasLoaded = useRef(false) diff --git a/src/pages/search/entities.js b/src/pages/search/entities.js index 3956a717..629a2cf9 100644 --- a/src/pages/search/entities.js +++ b/src/pages/search/entities.js @@ -34,6 +34,7 @@ function SearchEntities() { isRegisterHidden, hasInvalidToken, validatingToken, + authorized, isAuthorizing, isUnauthorized, hasAuthenticationCookie @@ -43,17 +44,6 @@ function SearchEntities() { onSubmit(event) } - // Define here because we need auth state from AppContext - SEARCH_ENTITIES['searchQuery']['conditionalFacets']['has_qa_derived_dataset'] = ({filters}) => { - return adminGroup === true && - filters.some((filter) => filter.field === "entity_type" && filter.values.includes("Dataset")) - } - - SEARCH_ENTITIES['searchQuery']['conditionalFacets']['has_all_published_datasets'] = ({filters}) => { - return adminGroup === true && - filters.some((filter) => filter.field === "entity_type" && filter.values.includes("Upload")) - } - if (validatingToken() || isAuthorizing()) { return } else if (hasInvalidToken()) { @@ -64,11 +54,18 @@ function SearchEntities() { logout() window.location.reload() } + + const authState = { + isAuthenticated: hasAuthenticationCookie() === true, + isAuthorized: authorized === true, + isAdmin: adminGroup === true + } + return ( <>
- +