Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add multiple filters of same FieldMetadataType #5892

Merged
merged 4 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useRecoilValue } from 'recoil';
import { v4 } from 'uuid';

import { useFilterDropdown } from '@/object-record/object-filter-dropdown/hooks/useFilterDropdown';
import { InternalDatePicker } from '@/ui/input/components/internal/date/components/InternalDatePicker';
Expand All @@ -8,6 +9,7 @@ export const ObjectFilterDropdownDateInput = () => {
const {
filterDefinitionUsedInDropdownState,
selectedOperandInDropdownState,
selectedFilterState,
setIsObjectFilterDropdownUnfolded,
selectFilter,
} = useFilterDropdown();
Expand All @@ -19,10 +21,13 @@ export const ObjectFilterDropdownDateInput = () => {
selectedOperandInDropdownState,
);

const selectedFilter = useRecoilValue(selectedFilterState);

const handleChange = (date: Date | null) => {
if (!filterDefinitionUsedInDropdown || !selectedOperandInDropdown) return;

selectFilter?.({
id: selectedFilter?.id ? selectedFilter.id : v4(),
fieldMetadataId: filterDefinitionUsedInDropdown.fieldMetadataId,
value: isDefined(date) ? date.toISOString() : '',
operand: selectedOperandInDropdown,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ChangeEvent } from 'react';
import { useRecoilValue } from 'recoil';
import { v4 } from 'uuid';

import { useFilterDropdown } from '@/object-record/object-filter-dropdown/hooks/useFilterDropdown';
import { DropdownMenuInput } from '@/ui/layout/dropdown/components/DropdownMenuInput';
Expand All @@ -8,6 +9,7 @@ export const ObjectFilterDropdownNumberInput = () => {
const {
selectedOperandInDropdownState,
filterDefinitionUsedInDropdownState,
selectedFilterState,
selectFilter,
} = useFilterDropdown();

Expand All @@ -18,6 +20,8 @@ export const ObjectFilterDropdownNumberInput = () => {
selectedOperandInDropdownState,
);

const selectedFilter = useRecoilValue(selectedFilterState);

return (
filterDefinitionUsedInDropdown &&
selectedOperandInDropdown && (
Expand All @@ -27,6 +31,7 @@ export const ObjectFilterDropdownNumberInput = () => {
placeholder={filterDefinitionUsedInDropdown.label}
onChange={(event: ChangeEvent<HTMLInputElement>) => {
selectFilter?.({
id: selectedFilter?.id ? selectedFilter.id : v4(),
fieldMetadataId: filterDefinitionUsedInDropdown.fieldMetadataId,
value: event.target.value,
operand: selectedOperandInDropdown,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useRecoilValue } from 'recoil';
import { v4 } from 'uuid';

import { useFilterDropdown } from '@/object-record/object-filter-dropdown/hooks/useFilterDropdown';
import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer';
Expand Down Expand Up @@ -42,6 +43,7 @@ export const ObjectFilterDropdownOperandSelect = () => {
isDefined(selectedFilter)
) {
selectFilter?.({
id: selectedFilter.id ? selectedFilter.id : v4(),
fieldMetadataId: selectedFilter.fieldMetadataId,
displayValue: selectedFilter.displayValue,
operand: newOperand,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useState } from 'react';
import { useRecoilValue } from 'recoil';
import { v4 } from 'uuid';

import { FieldMetadataItemOption } from '@/object-metadata/types/FieldMetadataItem';
import { useFilterDropdown } from '@/object-record/object-filter-dropdown/hooks/useFilterDropdown';
Expand All @@ -22,6 +23,7 @@ export const ObjectFilterDropdownOptionSelect = () => {
objectFilterDropdownSearchInputState,
selectedOperandInDropdownState,
objectFilterDropdownSelectedOptionValuesState,
selectedFilterState,
selectFilter,
} = useFilterDropdown();

Expand All @@ -38,6 +40,8 @@ export const ObjectFilterDropdownOptionSelect = () => {
objectFilterDropdownSelectedOptionValuesState,
);

const selectedFilter = useRecoilValue(selectedFilterState);

const fieldMetaDataId = filterDefinitionUsedInDropdown?.fieldMetadataId ?? '';

const { selectOptions } = useOptionsForSelect(fieldMetaDataId);
Expand Down Expand Up @@ -96,6 +100,7 @@ export const ObjectFilterDropdownOptionSelect = () => {
: EMPTY_FILTER_VALUE;

selectFilter({
id: selectedFilter?.id ? selectedFilter.id : v4(),
definition: filterDefinitionUsedInDropdown,
operand: selectedOperandInDropdown,
displayValue: filterDisplayValue,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { useState } from 'react';
import { useRecoilValue } from 'recoil';
import { v4 } from 'uuid';

import { useFilterDropdown } from '@/object-record/object-filter-dropdown/hooks/useFilterDropdown';
import { MultipleRecordSelectDropdown } from '@/object-record/select/components/MultipleRecordSelectDropdown';
import { useRecordsForSelect } from '@/object-record/select/hooks/useRecordsForSelect';
import { SelectableRecord } from '@/object-record/select/types/SelectableRecord';
import { useCombinedViewFilters } from '@/views/hooks/useCombinedViewFilters';
import { useGetCurrentView } from '@/views/hooks/useGetCurrentView';
import { isDefined } from '~/utils/isDefined';

export const EMPTY_FILTER_VALUE = '[]';
Expand All @@ -14,12 +18,16 @@ export const ObjectFilterDropdownRecordSelect = () => {
filterDefinitionUsedInDropdownState,
objectFilterDropdownSearchInputState,
selectedOperandInDropdownState,
selectedFilterState,
setObjectFilterDropdownSelectedRecordIds,
objectFilterDropdownSelectedRecordIdsState,
selectFilter,
emptyFilterButKeepDefinition,
} = useFilterDropdown();

const { removeCombinedViewFilter } = useCombinedViewFilters();
const { currentViewWithCombinedFiltersAndSorts } = useGetCurrentView();

const filterDefinitionUsedInDropdown = useRecoilValue(
filterDefinitionUsedInDropdownState,
);
Expand All @@ -32,6 +40,9 @@ export const ObjectFilterDropdownRecordSelect = () => {
const objectFilterDropdownSelectedRecordIds = useRecoilValue(
objectFilterDropdownSelectedRecordIdsState,
);
const [fieldId] = useState(v4());

const selectedFilter = useRecoilValue(selectedFilterState);

const objectNameSingular =
filterDefinitionUsedInDropdown?.relationObjectMetadataNameSingular ?? '';
Expand Down Expand Up @@ -60,6 +71,7 @@ export const ObjectFilterDropdownRecordSelect = () => {

if (newSelectedRecordIds.length === 0) {
emptyFilterButKeepDefinition();
removeCombinedViewFilter(fieldId);
return;
}

Expand Down Expand Up @@ -91,7 +103,17 @@ export const ObjectFilterDropdownRecordSelect = () => {
? JSON.stringify(newSelectedRecordIds)
: EMPTY_FILTER_VALUE;

const viewFilter =
currentViewWithCombinedFiltersAndSorts?.viewFilters.find(
(viewFilter) =>
viewFilter.fieldMetadataId ===
filterDefinitionUsedInDropdown.fieldMetadataId,
);

const filterId = viewFilter?.id ?? fieldId;

selectFilter({
id: selectedFilter?.id ? selectedFilter.id : filterId,
definition: filterDefinitionUsedInDropdown,
operand: selectedOperandInDropdown,
displayValue: filterDisplayValue,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ChangeEvent } from 'react';
import { ChangeEvent, useState } from 'react';
import { useRecoilValue } from 'recoil';
import { v4 } from 'uuid';

import { useFilterDropdown } from '@/object-record/object-filter-dropdown/hooks/useFilterDropdown';
import { DropdownMenuSearchInput } from '@/ui/layout/dropdown/components/DropdownMenuSearchInput';
Expand All @@ -14,6 +15,8 @@ export const ObjectFilterDropdownTextSearchInput = () => {
selectFilter,
} = useFilterDropdown();

const [filterId] = useState(v4());

const filterDefinitionUsedInDropdown = useRecoilValue(
filterDefinitionUsedInDropdownState,
);
Expand All @@ -37,6 +40,7 @@ export const ObjectFilterDropdownTextSearchInput = () => {
setObjectFilterDropdownSearchInput(event.target.value);

selectFilter?.({
id: selectedFilter?.id ? selectedFilter.id : filterId,
fieldMetadataId: filterDefinitionUsedInDropdown.fieldMetadataId,
value: event.target.value,
operand: selectedOperandInDropdown,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const filterDefinitions: FilterDefinition[] = [
];

const mockFilter: Filter = {
id: 'id',
definition: filterDefinitions[0],
displayValue: '',
fieldMetadataId: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ViewFilterOperand } from '@/views/types/ViewFilterOperand';
import { FilterDefinition } from './FilterDefinition';

export type Filter = {
id: string;
fieldMetadataId: string;
value: string;
displayValue: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useCallback } from 'react';
import { v4 } from 'uuid';

import { useColumnDefinitionsFromFieldMetadata } from '@/object-metadata/hooks/useColumnDefinitionsFromFieldMetadata';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
Expand Down Expand Up @@ -46,6 +47,7 @@ export const useHandleToggleColumnFilter = ({
const defaultOperand = availableOperandsForFilter[0];

const newFilter: Filter = {
id: v4(),
fieldMetadataId,
operand: defaultOperand,
displayValue: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export const EditableFilterChip = ({
const { getIcon } = useIcons();
return (
<SortOrFilterChip
key={viewFilter.fieldMetadataId}
testId={viewFilter.fieldMetadataId}
key={viewFilter.id}
testId={viewFilter.id}
labelKey={viewFilter.definition.label}
labelValue={`${getOperandLabelShort(viewFilter.operand)} ${
viewFilter.displayValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ export const EditableFilterDropdownButton = ({
const handleRemove = () => {
closeDropdown();

removeCombinedViewFilter(viewFilter.fieldMetadataId);
removeCombinedViewFilter(viewFilter.id);
};

const handleDropdownClickOutside = useCallback(() => {
const { value, fieldMetadataId } = viewFilter;
const { id: fieldId, value } = viewFilter;
if (!value) {
removeCombinedViewFilter(fieldMetadataId);
removeCombinedViewFilter(fieldId);
}
}, [viewFilter, removeCombinedViewFilter]);

Expand Down
Loading
Loading