diff --git a/frontend/web/components/tables/TableFilter.tsx b/frontend/web/components/tables/TableFilter.tsx index d22809f0abb1..cd39d5bfeb23 100644 --- a/frontend/web/components/tables/TableFilter.tsx +++ b/frontend/web/components/tables/TableFilter.tsx @@ -1,15 +1,18 @@ -import React, { FC, ReactNode, useState } from 'react' -import InlineModal from 'components/InlineModal' +import React, { FC, ReactNode } from 'react' import { IonIcon } from '@ionic/react' import { caretDown } from 'ionicons/icons' import classNames from 'classnames' +import Popover from 'components/base/Popover' +import BareButton from 'components/base/forms/BareButton' type TableFilterType = { title: string | ReactNode + // Names the filter when the title isn't plain text (it has a count) + label?: string hideTitle?: boolean dropdownTitle?: ReactNode | string className?: string - children: ReactNode + children: ReactNode | ((close: () => void) => ReactNode) 'data-test'?: string } @@ -19,26 +22,25 @@ const TableFilter: FC = ({ 'data-test': dataTest, dropdownTitle, hideTitle, + label, title, -}) => { - const [open, setOpen] = useState(false) - const toggle = function () { - if (!open) { - setOpen(true) - } - } - return ( - <> - ( + ( + @@ -51,25 +53,20 @@ const TableFilter: FC = ({ }} icon={caretDown} /> - - {open && ( - { - setTimeout(() => { - setOpen(false) - }, 10) - }} - containerClassName='px-0' - className='inline-modal table-filter inline-modal--sm right' - > - {children} - - )} - - ) -} + + )} + > + {(close) => ( + <> + {!hideTitle && ( +
+ {dropdownTitle || title} +
+ )} + {typeof children === 'function' ? children(close) : children} + + )} + +) export default TableFilter diff --git a/frontend/web/components/tables/TableFilterOptions.tsx b/frontend/web/components/tables/TableFilterOptions.tsx index 86aa64310584..c0702129c837 100644 --- a/frontend/web/components/tables/TableFilterOptions.tsx +++ b/frontend/web/components/tables/TableFilterOptions.tsx @@ -1,17 +1,15 @@ import React, { FC, ReactNode, useMemo, useState } from 'react' -import InlineModal from 'components/InlineModal' -import { IonIcon } from '@ionic/react' -import { caretDown } from 'ionicons/icons' import classNames from 'classnames' +import TableFilter from './TableFilter' import TableFilterItem from './TableFilterItem' import Input from 'components/base/forms/Input' import Utils from 'common/utils/utils' -type TableFilterType = { +type TableFilterOptionsType = { title: ReactNode + label?: string dropdownTitle?: ReactNode | string className?: string - size?: 'sm' | 'lg' isLoading?: boolean options: { label: string; value: string | number; subtitle?: string }[] onChange: (value: string | string[]) => void | Promise @@ -20,26 +18,19 @@ type TableFilterType = { showSearch?: boolean } -const TableFilter: FC = ({ +const TableFilterOptions: FC = ({ className, isLoading, + label, multiple, onChange, options, showSearch, - size = 'sm', title, value, }) => { const [filter, setFilter] = useState('') - const [open, setOpen] = useState(false) - const toggle = function () { - if (!open) { - setOpen(true) - } - } - const filteredOptions = useMemo(() => { const lowerSearch = filter?.toLowerCase() return filter @@ -51,86 +42,68 @@ const TableFilter: FC = ({ return (
- - {title} - - - {open && ( - { - setTimeout(() => { - setOpen(false) - }, 10) - }} - containerClassName='px-0' - className={`inline-modal table-filter inline-modal--${size} right`} - > - {!!showSearch && ( -
- { - setFilter(Utils.safeParseEventValue(e)) - }} - className='full-width' - value={filter} - type='text' - size='xSmall' - placeholder='Search' - search - /> - {!filteredOptions?.length && ( -
No results
- )} -
- )} -
- {filteredOptions.map((v) => ( - { - if (!multiple) { - setOpen(false) - } - if (multiple) { - if ((value || []).includes(v.value)) { - onChange( - ((value as string[]) || []).filter( - (item) => item !== v.value, - ), - ) + {(close) => ( + <> + {!!showSearch && ( +
+ { + setFilter(Utils.safeParseEventValue(e)) + }} + className='full-width' + value={filter} + type='text' + size='xSmall' + placeholder='Search' + search + /> + {!filteredOptions?.length && ( +
No results
+ )} +
+ )} +
+ {filteredOptions.map((v) => ( + { + if (!multiple) { + close() + } + if (multiple) { + if ((value || []).includes(v.value)) { + onChange( + ((value as string[]) || []).filter( + (item) => item !== v.value, + ), + ) + } else { + onChange(((value as string[]) || []).concat([v.value])) + } } else { - onChange(((value as string[]) || []).concat([v.value])) + onChange(v.value) } - } else { - onChange(v.value) + }} + isActive={ + multiple ? value?.includes(v.value) : value === v.value } - }} - isActive={ - multiple ? value?.includes(v.value) : value === v.value - } - /> - ))} -
- - )} + /> + ))} +
+ + )} +
) } -export default TableFilter +export default TableFilterOptions diff --git a/frontend/web/components/tables/TableGroupsFilter.tsx b/frontend/web/components/tables/TableGroupsFilter.tsx index b0c6f40dc57e..a98f73e25ef6 100644 --- a/frontend/web/components/tables/TableGroupsFilter.tsx +++ b/frontend/web/components/tables/TableGroupsFilter.tsx @@ -34,6 +34,7 @@ const TableGroupsFilter: FC = ({ return ( diff --git a/frontend/web/components/tables/TableOwnerFilter.tsx b/frontend/web/components/tables/TableOwnerFilter.tsx index 61fa869d0c6b..a7567c0e1e02 100644 --- a/frontend/web/components/tables/TableOwnerFilter.tsx +++ b/frontend/web/components/tables/TableOwnerFilter.tsx @@ -27,7 +27,7 @@ const TableOwnerFilter: FC = ({ return ( = ({
@@ -101,7 +102,7 @@ const TableTagFilter: FC = ({ } >
-
+
{ diff --git a/frontend/web/components/tables/TableValueFilter.tsx b/frontend/web/components/tables/TableValueFilter.tsx index 8c0c277c9a91..f5456b5a8269 100644 --- a/frontend/web/components/tables/TableValueFilter.tsx +++ b/frontend/web/components/tables/TableValueFilter.tsx @@ -49,6 +49,7 @@ const TableTagFilter: FC = ({ return (
= ({ } >
-
+