From 54cdabdd3533172ae9ab4f0c18678595603e4252 Mon Sep 17 00:00:00 2001 From: Emma Indal Date: Mon, 24 May 2021 12:47:05 +0200 Subject: [PATCH] delete search filters component Signed-off-by: Emma Indal Signed-off-by: Eric Peterson --- .../SearchFiltersNext/FiltersButtonNext.tsx | 56 ------ .../SearchFiltersNext/SearchFiltersNext.tsx | 183 ------------------ .../components/SearchFiltersNext/index.tsx | 23 --- plugins/search/src/index.ts | 3 - 4 files changed, 265 deletions(-) delete mode 100644 plugins/search/src/components/SearchFiltersNext/FiltersButtonNext.tsx delete mode 100644 plugins/search/src/components/SearchFiltersNext/SearchFiltersNext.tsx delete mode 100644 plugins/search/src/components/SearchFiltersNext/index.tsx diff --git a/plugins/search/src/components/SearchFiltersNext/FiltersButtonNext.tsx b/plugins/search/src/components/SearchFiltersNext/FiltersButtonNext.tsx deleted file mode 100644 index f7628714ca..0000000000 --- a/plugins/search/src/components/SearchFiltersNext/FiltersButtonNext.tsx +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2021 Spotify AB - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import React from 'react'; -import FilterListIcon from '@material-ui/icons/FilterList'; -import { makeStyles, IconButton, Typography } from '@material-ui/core'; - -const useStyles = makeStyles(theme => ({ - filters: { - width: '250px', - display: 'flex', - }, - icon: { - margin: theme.spacing(-1, 0, 0, 0), - }, -})); - -type FiltersButtonProps = { - numberOfSelectedFilters: number; - handleToggleFilters: () => void; -}; - -export const FiltersButtonNext = ({ - numberOfSelectedFilters, - handleToggleFilters, -}: FiltersButtonProps) => { - const classes = useStyles(); - - return ( -
- - - - - Filters ({numberOfSelectedFilters ? numberOfSelectedFilters : 0}) - -
- ); -}; diff --git a/plugins/search/src/components/SearchFiltersNext/SearchFiltersNext.tsx b/plugins/search/src/components/SearchFiltersNext/SearchFiltersNext.tsx deleted file mode 100644 index d94b8021ef..0000000000 --- a/plugins/search/src/components/SearchFiltersNext/SearchFiltersNext.tsx +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright 2021 Spotify AB - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { - Card, - CardContent, - Checkbox, - FormControl, - InputLabel, - List, - MenuItem, - ListItem, - ListItemText, - makeStyles, - Select, -} from '@material-ui/core'; -import React from 'react'; -import { useSearch } from '../SearchContext'; - -const useFilterStyles = makeStyles({ - filters: { - background: 'transparent', - boxShadow: '0px 0px 0px 0px', - }, -}); - -const useCheckBoxStyles = makeStyles(theme => ({ - checkbox: { - padding: theme.spacing(0, 1, 0, 1), - }, -})); - -const useSelectStyles = makeStyles({ - select: { - width: '100%', - }, -}); - -export type FilterOptions = { - kind: Array; - lifecycle: Array; -}; - -type FiltersProps = { - children: React.ReactChild; -}; - -type ValuedFilterProps = { - fieldName: string; - values: string[]; -}; - -export enum FilterType { - CHECKBOX = 'checkbox', - SELECT = 'select', -} - -export type NewFilterDefinition = { - component: any; - props: any; -}; - -export type FilterDefinition = { - field: string; - type: FilterType; - values: string[]; -}; - -export const CheckBoxFilter = ({ fieldName, values }: ValuedFilterProps) => { - const { filters, setFilters } = useSearch(); - const classes = useCheckBoxStyles(); - - const setCheckboxFilter = (filter: string) => { - const newFilters = filters; - const currentValues = newFilters[fieldName] as string[]; - - if (!filter) return; - - if (!currentValues) { - setFilters({ ...filters, [fieldName]: [filter] }); - } else if (!currentValues?.includes(filter)) { - setFilters({ - ...filters, - [fieldName]: [...currentValues, filter], - }); - } else { - const filterToDelete = currentValues.find(value => value === filter); - if (filterToDelete) { - currentValues.splice(currentValues.indexOf(filterToDelete), 1); - - setFilters({ ...filters, [fieldName]: currentValues }); - } - } - }; - return ( - - {fieldName} - - {values.map((value: string) => ( - setCheckboxFilter(value)} - > - - - - ))} - - - ); -}; - -export const SelectFilter = ({ fieldName, values }: ValuedFilterProps) => { - const { filters, setFilters } = useSearch(); - const classes = useSelectStyles(); - - const setSelectFilter = (filter: string) => { - const newFilters = filters; - if (newFilters[fieldName] && filter === '') { - delete newFilters[fieldName]; - setFilters({ newFilters }); - } else { - setFilters({ ...filters, [fieldName]: filter as string }); - } - }; - - return ( - - - {fieldName} - - - - ); -}; - -export const SearchFiltersNext = ({ children }: FiltersProps) => { - const classes = useFilterStyles(); - - return {children}; -}; diff --git a/plugins/search/src/components/SearchFiltersNext/index.tsx b/plugins/search/src/components/SearchFiltersNext/index.tsx deleted file mode 100644 index dd35bd3624..0000000000 --- a/plugins/search/src/components/SearchFiltersNext/index.tsx +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2021 Spotify AB - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export { FiltersButtonNext } from './FiltersButtonNext'; -export { - SearchFiltersNext, - CheckBoxFilter, - SelectFilter, - FilterType, -} from './SearchFiltersNext'; diff --git a/plugins/search/src/index.ts b/plugins/search/src/index.ts index 5ff047e986..27fd1706fc 100644 --- a/plugins/search/src/index.ts +++ b/plugins/search/src/index.ts @@ -27,9 +27,6 @@ export { export { Filters, FiltersButton, - FilterType, - CheckBoxFilter, - SelectFilter, SearchBar, SearchContextProvider, useSearch,