Skip to content

Commit

Permalink
Rename 'Catalog' related variables to 'Filter'
Browse files Browse the repository at this point in the history
  • Loading branch information
hanbyul-here committed Jun 28, 2024
1 parent f39d0f8 commit 7a08578
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 60 deletions.
6 changes: 3 additions & 3 deletions app/scripts/components/common/browse-controls/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { DropMenu, DropTitle } from '@devseed-ui/dropdown';

import { useFiltersWithQS } from '../catalog/controls/hooks/use-filters-with-query';
import { optionAll } from './constants';
import { CatalogActions } from '$components/common/catalog/utils';
import { FilterActions } from '$components/common/catalog/utils';

import DropdownScrollable from '$components/common/dropdown-scrollable';
import DropMenuItemButton from '$styles/drop-menu-item-button';
Expand Down Expand Up @@ -95,7 +95,7 @@ function BrowseControls(props: BrowseControlsProps) {
items={[optionAll].concat(values)}
currentId={(taxonomies[name]?.length ? taxonomies[name][0] as string : 'all')}
onChange={(v) => {
onAction(CatalogActions.TAXONOMY, { key: name, value: v });
onAction(FilterActions.TAXONOMY, { key: name, value: v });
}}
size={isLargeUp ? 'large' : 'medium'}
/>
Expand All @@ -110,7 +110,7 @@ function BrowseControls(props: BrowseControlsProps) {
placeholder='Title, description...'
keepOpen={isLargeUp}
value={search}
onChange={(v) => onAction(CatalogActions.SEARCH, v)}
onChange={(v) => onAction(FilterActions.SEARCH, v)}
/>
<FilterOptionsWrapper>
{createFilterList(taxonomiesOptions.slice(0, filterWrapConstant))}
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/components/common/card-sources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styled from 'styled-components';
import { TaxonomyItem } from 'veda';
import { Link } from 'react-router-dom';
import { listReset } from '@devseed-ui/theme-provider';
import { CatalogActions } from '$components/common//catalog/utils';
import { FilterActions } from '$components/common//catalog/utils';

const SourcesUl = styled.ul`
${listReset()}
Expand Down Expand Up @@ -51,7 +51,7 @@ export function CardSourcesList(props: SourcesListProps) {
{sources.map((source) => (
<li key={source.id}>
<Link
to={`${rootPath}?${CatalogActions.TAXONOMY}=${encodeURIComponent(
to={`${rootPath}?${FilterActions.TAXONOMY}=${encodeURIComponent(
JSON.stringify({
Source: source.id
})
Expand Down
12 changes: 6 additions & 6 deletions app/scripts/components/common/catalog/catalog-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import FiltersControl from './filters-control';
import { CatalogCard } from './catalog-card';
import CatalogTagsContainer from './catalog-tags';

import { CatalogActions } from './utils';
import { FilterActions } from './utils';
import { CardList } from '$components/common/card/styles';
import EmptyHub from '$components/common/empty-hub';

Expand All @@ -35,7 +35,7 @@ export interface CatalogContentProps {
emptyStateContent?: React.ReactNode;
search: string;
taxonomies: Record<string, string[]>;
onAction: (action: CatalogActions, value?: any) => void;
onAction: (action: FilterActions, value?: any) => void;
}

const DEFAULT_SORT_OPTION = 'asc';
Expand Down Expand Up @@ -82,7 +82,7 @@ function CatalogContent({
setSelectedFilters(selectedFilters.filter((selected) => selected.id !== item.id));
}

onAction(CatalogActions.TAXONOMY_MULTISELECT, { key: item.taxonomy, value: item.id });
onAction(FilterActions.TAXONOMY_MULTISELECT, { key: item.taxonomy, value: item.id });
}, [setSelectedFilters, selectedFilters, onAction]);

const handleClearTag = useCallback((item: OptionItem) => {
Expand All @@ -93,20 +93,20 @@ function CatalogContent({
const handleClearTags = useCallback(() => {
setSelectedFilters([]);
setExclusiveSourceSelected(null);
onAction(CatalogActions.CLEAR_TAXONOMY);
onAction(FilterActions.CLEAR_TAXONOMY);
}, [onAction]);

useEffect(() => {
if (clearedTagItem && (selectedFilters.length == prevSelectedFilters.length - 1)) {
onAction(CatalogActions.TAXONOMY_MULTISELECT, { key: clearedTagItem.taxonomy, value: clearedTagItem.id});
onAction(FilterActions.TAXONOMY_MULTISELECT, { key: clearedTagItem.taxonomy, value: clearedTagItem.id});
setClearedTagItem(undefined);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedFilters, clearedTagItem]);

useEffect(() => {
if (!selectedFilters.length) {
onAction(CatalogActions.CLEAR_TAXONOMY);
onAction(FilterActions.CLEAR_TAXONOMY);
}

setExclusiveSourceSelected(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { useNavigate } from 'react-router';
import useQsStateCreator from 'qs-state-hook';
import { taxonomyAtom } from '../atoms/taxonomy-atom';
import { searchAtom } from '../atoms/search-atom';
import { CatalogActions, CatalogViewAction, onCatalogAction } from '../../utils';
import { FilterActions, FilterAction, onFilterAction } from '../../utils';
interface UseFiltersWithQueryResult {
search: string;
taxonomies: Record<string, string[]> | Record<string, never>;
onAction: CatalogViewAction
onAction: FilterAction
}

// @TECH-DEBT: We have diverged ways of dealing with query parameters and need to consolidate them.
Expand All @@ -19,9 +19,9 @@ export function useFiltersWithURLAtom(): UseFiltersWithQueryResult {
const [search, setSearch] = useAtom(searchAtom);
const [taxonomies, setTaxonomies] = useAtom(taxonomyAtom);

const onAction = useCallback<CatalogViewAction>(
const onAction = useCallback<FilterAction>(
(action, value) =>
onCatalogAction(action, value, taxonomies, setSearch, setTaxonomies),
onFilterAction(action, value, taxonomies, setSearch, setTaxonomies),
[setSearch, setTaxonomies, taxonomies]
);

Expand All @@ -40,25 +40,25 @@ export function useFiltersWithQS(): UseFiltersWithQueryResult {

const [search, setSearch] = useQsState.memo(
{
key: CatalogActions.SEARCH,
key: FilterActions.SEARCH,
default: ''
},
[]
);

const [taxonomies, setTaxonomies] = useQsState.memo(
{
key: CatalogActions.TAXONOMY,
key: FilterActions.TAXONOMY,
default: {},
dehydrator: (v) => JSON.stringify(v), // dehydrator defines how a value is stored in the url
hydrator: (v) => (v ? JSON.parse(v) : {}) // hydrator defines how a value is read from the url
},
[]
);

const onAction = useCallback<CatalogViewAction>(
const onAction = useCallback<FilterAction>(
(action, value) =>
onCatalogAction(action, value, taxonomies, setSearch, setTaxonomies),
onFilterAction(action, value, taxonomies, setSearch, setTaxonomies),
[setSearch, setTaxonomies, taxonomies]
);

Expand Down
6 changes: 3 additions & 3 deletions app/scripts/components/common/catalog/filters-control.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useRef, useEffect, useCallback, useMemo } from 'react';
import styled from 'styled-components';
import { Taxonomy } from 'veda';
import { CatalogActions } from './utils';
import { FilterActions } from './utils';
import SearchField from '$components/common/search-field';
import CheckableFilters, { OptionItem } from '$components/common/form/checkable-filter';
import { useSlidingStickyHeader, HEADER_TRANSITION_DURATION } from '$utils/use-sliding-sticky-header';
Expand All @@ -16,7 +16,7 @@ const ControlsWrapper = styled.div<{ widthValue?: string; heightValue?: string;
`;

interface FiltersMenuProps {
onAction: (action: CatalogActions, value: any) => void;
onAction: (action: FilterActions, value: any) => void;
search?: string;
taxonomiesOptions: Taxonomy[];
allSelected: OptionItem[];
Expand Down Expand Up @@ -103,7 +103,7 @@ export default function FiltersControl(props: FiltersMenuProps) {
size='large'
placeholder='Search by title, description'
value={search ?? ''}
onChange={(v) => onAction(CatalogActions.SEARCH, v)}
onChange={(v) => onAction(FilterActions.SEARCH, v)}
/>
{taxonomiesItems.map(({ title, items }) => (
<CheckableFilters
Expand Down
40 changes: 20 additions & 20 deletions app/scripts/components/common/catalog/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { omit, set } from 'lodash';
import { CatalogActions, onCatalogAction } from './utils';
import { FilterActions, onFilterAction } from './utils';

describe('onCatalogAction', () => {
describe('onFilterAction', () => {
let setSearchMock;
let setTaxonomiesMock;
let taxonomies;
Expand All @@ -16,8 +16,8 @@ describe('onCatalogAction', () => {
});

it('should clear search and taxonomies on CLEAR action', () => {
onCatalogAction(
CatalogActions.CLEAR,
onFilterAction(
FilterActions.CLEAR,
null,
taxonomies,
setSearchMock,
Expand All @@ -29,8 +29,8 @@ describe('onCatalogAction', () => {
});

it('should clear only taxonomies on CLEAR_TAXONOMY action', () => {
onCatalogAction(
CatalogActions.CLEAR_TAXONOMY,
onFilterAction(
FilterActions.CLEAR_TAXONOMY,
null,
taxonomies,
setSearchMock,
Expand All @@ -42,8 +42,8 @@ describe('onCatalogAction', () => {
});

it('should clear only search on CLEAR_SEARCH action', () => {
onCatalogAction(
CatalogActions.CLEAR_SEARCH,
onFilterAction(
FilterActions.CLEAR_SEARCH,
null,
taxonomies,
setSearchMock,
Expand All @@ -55,8 +55,8 @@ describe('onCatalogAction', () => {
});
it('should set search value on SEARCH action', () => {
const searchValue = 'climate';
onCatalogAction(
CatalogActions.SEARCH,
onFilterAction(
FilterActions.SEARCH,
searchValue,
taxonomies,
setSearchMock,
Expand All @@ -68,8 +68,8 @@ describe('onCatalogAction', () => {

it('should add value to Topics taxonomy on TAXONOMY_MULTISELECT action', () => {
const value = { key: 'Topics', value: 'pollution' };
onCatalogAction(
CatalogActions.TAXONOMY_MULTISELECT,
onFilterAction(
FilterActions.TAXONOMY_MULTISELECT,
value,
taxonomies,
setSearchMock,
Expand All @@ -83,8 +83,8 @@ describe('onCatalogAction', () => {

it('should overwrite the existing taxonomy value with TAXONOMY action', () => {
const value = { key: 'Topics', value: 'climate' };
onCatalogAction(
CatalogActions.TAXONOMY,
onFilterAction(
FilterActions.TAXONOMY,
value,
taxonomies,
setSearchMock,
Expand All @@ -98,8 +98,8 @@ describe('onCatalogAction', () => {

it('should remove value from Topics taxonomy on TAXONOMY_MULTISELECT action', () => {
const value = { key: 'Topics', value: 'climate' };
onCatalogAction(
CatalogActions.TAXONOMY_MULTISELECT,
onFilterAction(
FilterActions.TAXONOMY_MULTISELECT,
value,
taxonomies,
setSearchMock,
Expand All @@ -114,8 +114,8 @@ describe('onCatalogAction', () => {

it('should remove Topics key when last value is removed on TAXONOMY_MULTISELECT action', () => {
const value = { key: 'Topics', value: 'climate' };
onCatalogAction(
CatalogActions.TAXONOMY_MULTISELECT,
onFilterAction(
FilterActions.TAXONOMY_MULTISELECT,
value,
{ Topics: ['climate'] },
setSearchMock,
Expand All @@ -129,8 +129,8 @@ describe('onCatalogAction', () => {

it('should initialize new taxonomy key on TAXONOMY_MULTISELECT action', () => {
const value = { key: 'Regions', value: 'Europe' };
onCatalogAction(
CatalogActions.TAXONOMY_MULTISELECT,
onFilterAction(
FilterActions.TAXONOMY_MULTISELECT,
value,
taxonomies,
setSearchMock,
Expand Down
20 changes: 10 additions & 10 deletions app/scripts/components/common/catalog/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { omit, set } from 'lodash';
import { optionAll } from '$components/common/browse-controls/constants';

export enum CatalogActions {
export enum FilterActions {
TAXONOMY_MULTISELECT = 'taxonomy_multiselect',
CLEAR = 'clear',
SEARCH = 'search',
Expand All @@ -12,34 +12,34 @@ export enum CatalogActions {
CLEAR_SEARCH = 'clear_search',
}

export type CatalogViewAction = (action: CatalogActions, value?: any) => void;
export type FilterAction = (action: FilterActions, value?: any) => void;

export function onCatalogAction(
action: CatalogActions,
export function onFilterAction(
action: FilterActions,
value: any,
taxonomies: any,
setSearch: (value: string) => void,
setTaxonomies: (value: any) => void
) {
switch (action) {
case CatalogActions.CLEAR: {
case FilterActions.CLEAR: {
setSearch('');
setTaxonomies({});
break;
}
case CatalogActions.SEARCH: {
case FilterActions.SEARCH: {
setSearch(value);
break;
}
case CatalogActions.CLEAR_TAXONOMY: {
case FilterActions.CLEAR_TAXONOMY: {
setTaxonomies({});
break;
}
case CatalogActions.CLEAR_SEARCH: {
case FilterActions.CLEAR_SEARCH: {
setSearch('');
break;
}
case CatalogActions.TAXONOMY: {
case FilterActions.TAXONOMY: {
{
const { key, value: val } = value;
if (val === optionAll.id) {
Expand All @@ -50,7 +50,7 @@ export function onCatalogAction(
}
break;
}
case CatalogActions.TAXONOMY_MULTISELECT: {
case FilterActions.TAXONOMY_MULTISELECT: {
const { key, value: val } = value;

if (taxonomies && key in taxonomies) {
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/components/common/content-taxonomy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Link } from 'react-router-dom';
import { glsp, themeVal } from '@devseed-ui/theme-provider';
import { Heading, Overline } from '@devseed-ui/typography';

import { CatalogActions } from '$components/common/catalog/utils';
import { FilterActions } from '$components/common/catalog/utils';

import { variableGlsp } from '$styles/variable-utils';
import { Pill } from '$styles/pill';
Expand Down Expand Up @@ -60,7 +60,7 @@ export function ContentTaxonomy(props: ContentTaxonomyProps) {
variation='achromic'
key={t.id}
as={Link}
to={`${linkBase}?${CatalogActions.TAXONOMY}=${encodeURIComponent(
to={`${linkBase}?${FilterActions.TAXONOMY}=${encodeURIComponent(
JSON.stringify({ [name]: [t.id] })
)}`}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import ModalFooterRender from './footer';
import CatalogContent from '$components/common/catalog/catalog-content';
import { DATASETS_PATH } from '$utils/routes';
import { useFiltersWithURLAtom } from '$components/common/catalog/controls/hooks/use-filters-with-query';
import { CatalogActions } from '$components/common/catalog/utils';
import { FilterActions } from '$components/common/catalog/utils';

const DatasetModal = styled(Modal)`
z-index: ${themeVal('zIndices.modal')};
Expand Down Expand Up @@ -88,7 +88,7 @@ export function DatasetSelectorModal(props: DatasetSelectorModalProps) {
useEffect(() => {
// Reset filter when modal is hidden
if(!revealed) {
onAction(CatalogActions.CLEAR);
onAction(FilterActions.CLEAR);
}
},[revealed, onAction]);

Expand All @@ -100,7 +100,7 @@ export function DatasetSelectorModal(props: DatasetSelectorModalProps) {
setTimelineDatasets(
reconcileDatasets(selectedIds, datasetLayers, timelineDatasets)
);
onAction(CatalogActions.CLEAR);
onAction(FilterActions.CLEAR);
close();
}, [close, selectedIds, timelineDatasets, setTimelineDatasets, onAction]);

Expand Down
Loading

0 comments on commit 7a08578

Please sign in to comment.