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

Fix multi select filtering (#5358) #8452

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
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
Expand Up @@ -61,7 +61,7 @@ describe('useColumnDefinitionsFromFieldMetadata', () => {
result.current;

expect(columnDefinitions.length).toBe(21);
expect(filterDefinitions.length).toBe(14);
expect(filterDefinitions.length).toBe(15);
expect(sortDefinitions.length).toBe(14);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const formatFieldMetadataItemsAsFilterDefinitions = ({
FieldMetadataType.Address,
FieldMetadataType.Relation,
FieldMetadataType.Select,
FieldMetadataType.MultiSelect,
FieldMetadataType.Currency,
FieldMetadataType.Rating,
FieldMetadataType.Actor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ export type BooleanFilter = {

export type StringFilter = {
eq?: string;
gt?: string;
gte?: string;
in?: string[];
lt?: string;
lte?: string;
neq?: string;
startsWith?: string;
like?: string;
Expand All @@ -35,6 +31,12 @@ export type StringFilter = {
is?: IsFilter;
ad-elias marked this conversation as resolved.
Show resolved Hide resolved
};

export type RatingFilter = {
eq?: number;
in?: number[];
is?: IsFilter;
};

export type FloatFilter = {
eq?: number;
gt?: number;
Expand Down Expand Up @@ -104,10 +106,16 @@ export type PhonesFilter = {
primaryPhoneCountryCode?: StringFilter;
};

export type SelectFilter = {
in?: string[];
};

export type ArrayFilter = {
contains?: string[];
not_contains?: string[];
notContains?: string[];
is?: IsFilter;
containsAny?: string[];
containsIlike?: string;
};

export type RawJsonFilter = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ export const ObjectFilterDropdownFilterInput = ({
<ObjectFilterDropdownSourceSelect />
</>
)}
{filterDefinitionUsedInDropdown.type === 'SELECT' && (
{['SELECT', 'MULTI_SELECT'].includes(
filterDefinitionUsedInDropdown.type,
) && (
<>
<ObjectFilterDropdownSearchInput />
<ObjectFilterDropdownOptionSelect />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ export const getOperandsForFilterDefinition = (
];
case 'RELATION':
return [...relationOperands, ...emptyOperands];
case 'MULTI_SELECT':
return [
ViewFilterOperand.Contains,
ViewFilterOperand.DoesNotContain,
...emptyOperands,
];
case 'SELECT':
return [...relationOperands];
return [ViewFilterOperand.Is, ViewFilterOperand.IsNot, ...emptyOperands];
case 'ACTOR': {
if (isActorSourceCompositeFilter(filterDefinition)) {
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,62 +158,6 @@ describe('isMatchingStringFilter', () => {
});
});

describe('gt', () => {
it('value is greater than gt filter', () => {
expect(
isMatchingStringFilter({ stringFilter: { gt: 'a' }, value: 'b' }),
).toBe(true);
});

it('value is not greater than gt filter', () => {
expect(
isMatchingStringFilter({ stringFilter: { gt: 'b' }, value: 'a' }),
).toBe(false);
});
});

describe('gte', () => {
it('value is greater than or equal to gte filter', () => {
expect(
isMatchingStringFilter({ stringFilter: { gte: 'a' }, value: 'a' }),
).toBe(true);
});

it('value is not greater than or equal to gte filter', () => {
expect(
isMatchingStringFilter({ stringFilter: { gte: 'b' }, value: 'a' }),
).toBe(false);
});
});

describe('lt', () => {
it('value is less than lt filter', () => {
expect(
isMatchingStringFilter({ stringFilter: { lt: 'b' }, value: 'a' }),
).toBe(true);
});

it('value is not less than lt filter', () => {
expect(
isMatchingStringFilter({ stringFilter: { lt: 'a' }, value: 'b' }),
).toBe(false);
});
});

describe('lte', () => {
it('value is less than or equal to lte filter', () => {
expect(
isMatchingStringFilter({ stringFilter: { lte: 'a' }, value: 'a' }),
).toBe(true);
});

it('value is not less than or equal to lte filter', () => {
expect(
isMatchingStringFilter({ stringFilter: { lte: 'a' }, value: 'b' }),
).toBe(false);
});
});

describe('startsWith', () => {
it('value starts with the startsWith filter', () => {
expect(
Expand Down
Loading
Loading