diff --git a/gui/src/components/search/FilterRegistry.js b/gui/src/components/search/FilterRegistry.js index cfe9f46e9a459985458cdb846340574e8a890db0..946a412515195ae57d97e6390bb3444d92b31e59 100644 --- a/gui/src/components/search/FilterRegistry.js +++ b/gui/src/components/search/FilterRegistry.js @@ -740,26 +740,25 @@ export function getStaticSuggestions(quantities, filterData) { return suggestions } -// add a specific filter -export function addFilter(filterPath, def, repeats, filtersData, setFiltersData) { - if (filterPath in filtersData) { - return - } - const newFilters = {} - const pathDtype = filterPath.split(schemaSeparator).slice(-1)[0] - const dtype = dtypeMap[getDatatype(def)] || pathDtype - // TODO: For some Nexus quantities, the data types cannot be fetched. - if (!dtype) { - return - } +// Add a new filter to filterData on the fly: NOTE: this is a workaround for +// enabling the search of unregistered search quantities. +export function tryAddNewFilter(filterPath, def, repeats, filtersData, setFiltersData) { + if (filterPath in filtersData) return + const dtype = postFixMap[parseQuantityName(filterPath)?.dtype] + if (!dtype) return + const params = { name: filterPath, quantity: filterPath, aggregatable: new Set([DType.String, DType.Enum, DType.Boolean]).has(getDatatype(def)), - repeats: repeats + repeats: repeats, + dtype: dtype } - newFilters[filterPath] = new Filter(def, params) - setFiltersData((old) => ({...old, ...newFilters})) + setFiltersData((old) => { + const newFilters = {...old} + newFilters[filterPath] = new Filter(def, params) + return newFilters + }) } /** diff --git a/gui/src/components/search/SearchContext.js b/gui/src/components/search/SearchContext.js index dcffd4fce27f73e9c60bc4855d4acd53076ab65c..785b63db51490b938515664903199051f58ef3d6 100644 --- a/gui/src/components/search/SearchContext.js +++ b/gui/src/components/search/SearchContext.js @@ -72,7 +72,7 @@ import UploadStatusIcon from '../uploads/UploadStatusIcon' import { getWidgetsObject } from './widgets/Widget' import { inputSectionContext } from './input/InputNestedObject' import { SearchSuggestion } from './SearchSuggestion' -import { withSearchQuantities, addFilter } from './FilterRegistry' +import { withSearchQuantities, tryAddNewFilter } from './FilterRegistry' import { useUnitContext } from '../units/UnitContext' const useWidthConstrainedStyles = makeStyles(theme => ({ @@ -1096,9 +1096,7 @@ export const SearchContextRaw = React.memo(({ // trigger any required API calls that also return the aggregation // response that is returned by this hook. useEffect(() => { - if (!(name in filtersData)) { - addFilter(name, "", true, filtersData, setFiltersData) - } + tryAddNewFilter(name, "", true, filtersData, setFiltersData) const defaults = filtersData[name]?.aggs?.[config?.type] const finalConfig = { update: update, diff --git a/gui/src/components/search/input/InputHistogram.js b/gui/src/components/search/input/InputHistogram.js index 1a9fd25933bdbe74a5a73fefded8b07f69f59163..2e81a9f6a815f7ce0f111510ac784aaba571c32e 100644 --- a/gui/src/components/search/input/InputHistogram.js +++ b/gui/src/components/search/input/InputHistogram.js @@ -612,14 +612,13 @@ const InputHistogram = React.memo(({ const {units} = useUnitContext() const styles = useInputHistogramStyles() const [scaleState, setScaleState] = useState(y?.scale || filterData[x?.search_quantity].scale) - const dtype = filterData[x.search_quantity].dtype - const isTime = dtype === DType.Timestamp - const autorangeFinal = isNil(autorange) ? isTime : autorange showStatistics = isStatisticsEnabled && showStatistics // Create final axis configs for the histogram const xAxis = useMemo(() => getAxisConfig(x, filterData, units), [x, filterData, units]) const yAxis = useMemo(() => ({...y, scale: scaleState}), [scaleState, y]) + const isTime = xAxis.dtype === DType.Timestamp + const autorangeFinal = isNil(autorange) ? isTime : autorange // Determine the description and title const def = filterData[x.search_quantity]