Introduce override filters while searching setting (#242)
* Introduced override filters while searching setting * update branch; change strings and method names * fix eslint issue * code review changes * moved search setting types into its own type --------- Co-authored-by: akxer <>
This commit is contained in:
31
src/util/searchSettings.ts
Normal file
31
src/util/searchSettings.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { useQuery } from 'util/client';
|
||||
import { getMetadataFrom } from 'util/metadata';
|
||||
import { IMetadata, ISearchSettings, MetadataKeyValuePair } from 'typings';
|
||||
|
||||
export const getDefaultSettings = () =>
|
||||
({
|
||||
ignoreFilters: false,
|
||||
} as ISearchSettings);
|
||||
|
||||
const getSearchSettingsWithDefaultValueFallback = (
|
||||
meta?: IMetadata,
|
||||
defaultSettings?: ISearchSettings,
|
||||
applyMetadataMigration: boolean = true,
|
||||
): ISearchSettings => ({
|
||||
...(getMetadataFrom(
|
||||
{ meta },
|
||||
Object.entries(defaultSettings ?? getDefaultSettings()) as MetadataKeyValuePair[],
|
||||
applyMetadataMigration,
|
||||
) as unknown as ISearchSettings),
|
||||
});
|
||||
|
||||
export const useSearchSettings = (): {
|
||||
metadata?: IMetadata;
|
||||
settings: ISearchSettings;
|
||||
loading: boolean;
|
||||
} => {
|
||||
const { data: meta, loading } = useQuery<IMetadata>('/api/v1/meta');
|
||||
const settings = getSearchSettingsWithDefaultValueFallback(meta);
|
||||
|
||||
return { metadata: meta, settings, loading };
|
||||
};
|
||||
Reference in New Issue
Block a user