Make filters work on export csv action (#8389)
- Create a new component state `contextStoreFiltersComponentState` and refactor `contextStoreTargetedRecordsRuleComponentState` - Refactor `computeContextStoreFilters` to use filters when no records are selected
This commit is contained in:
@ -0,0 +1,11 @@
|
||||
import { ContextStoreComponentInstanceContext } from '@/context-store/states/contexts/ContextStoreComponentInstanceContext';
|
||||
import { Filter } from '@/object-record/object-filter-dropdown/types/Filter';
|
||||
import { createComponentStateV2 } from '@/ui/utilities/state/component-state/utils/createComponentStateV2';
|
||||
|
||||
export const contextStoreFiltersComponentState = createComponentStateV2<
|
||||
Filter[]
|
||||
>({
|
||||
key: 'contextStoreFiltersComponentState',
|
||||
defaultValue: [],
|
||||
componentInstanceContext: ContextStoreComponentInstanceContext,
|
||||
});
|
||||
@ -1,5 +1,4 @@
|
||||
import { ContextStoreComponentInstanceContext } from '@/context-store/states/contexts/ContextStoreComponentInstanceContext';
|
||||
import { Filter } from '@/object-record/object-filter-dropdown/types/Filter';
|
||||
import { createComponentStateV2 } from '@/ui/utilities/state/component-state/utils/createComponentStateV2';
|
||||
|
||||
type ContextStoreTargetedRecordsRuleSelectionMode = {
|
||||
@ -10,7 +9,6 @@ type ContextStoreTargetedRecordsRuleSelectionMode = {
|
||||
type ContextStoreTargetedRecordsRuleExclusionMode = {
|
||||
mode: 'exclusion';
|
||||
excludedRecordIds: string[];
|
||||
filters: Filter[];
|
||||
};
|
||||
|
||||
export type ContextStoreTargetedRecordsRule =
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
import { ContextStoreTargetedRecordsRule } from '@/context-store/states/contextStoreTargetedRecordsRuleComponentState';
|
||||
import { computeContextStoreFilters } from '@/context-store/utils/computeContextStoreFilters';
|
||||
import { Filter } from '@/object-record/object-filter-dropdown/types/Filter';
|
||||
import { ViewFilterOperand } from '@/views/types/ViewFilterOperand';
|
||||
import { expect } from '@storybook/test';
|
||||
import { generatedMockObjectMetadataItems } from '~/testing/mock-data/generatedMockObjectMetadataItems';
|
||||
describe('computeContextStoreFilters', () => {
|
||||
const personObjectMetadataItem = generatedMockObjectMetadataItems.find(
|
||||
@ -15,6 +17,7 @@ describe('computeContextStoreFilters', () => {
|
||||
|
||||
const filters = computeContextStoreFilters(
|
||||
contextStoreTargetedRecordsRule,
|
||||
[],
|
||||
personObjectMetadataItem,
|
||||
);
|
||||
|
||||
@ -28,32 +31,35 @@ describe('computeContextStoreFilters', () => {
|
||||
it('should work for exclusion mode', () => {
|
||||
const contextStoreTargetedRecordsRule: ContextStoreTargetedRecordsRule = {
|
||||
mode: 'exclusion',
|
||||
filters: [
|
||||
{
|
||||
id: 'name-filter',
|
||||
variant: 'default',
|
||||
fieldMetadataId: personObjectMetadataItem.fields.find(
|
||||
(field) => field.name === 'name',
|
||||
)!.id,
|
||||
value: 'John',
|
||||
displayValue: 'John',
|
||||
displayAvatarUrl: undefined,
|
||||
operand: ViewFilterOperand.Contains,
|
||||
definition: {
|
||||
fieldMetadataId: personObjectMetadataItem.fields.find(
|
||||
(field) => field.name === 'name',
|
||||
)!.id,
|
||||
label: 'Name',
|
||||
iconName: 'person',
|
||||
type: 'TEXT',
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
excludedRecordIds: ['1', '2', '3'],
|
||||
};
|
||||
|
||||
const contextStoreFilters: Filter[] = [
|
||||
{
|
||||
id: 'name-filter',
|
||||
variant: 'default',
|
||||
fieldMetadataId: personObjectMetadataItem.fields.find(
|
||||
(field) => field.name === 'name',
|
||||
)!.id,
|
||||
value: 'John',
|
||||
displayValue: 'John',
|
||||
displayAvatarUrl: undefined,
|
||||
operand: ViewFilterOperand.Contains,
|
||||
definition: {
|
||||
fieldMetadataId: personObjectMetadataItem.fields.find(
|
||||
(field) => field.name === 'name',
|
||||
)!.id,
|
||||
label: 'Name',
|
||||
iconName: 'person',
|
||||
type: 'TEXT',
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const filters = computeContextStoreFilters(
|
||||
contextStoreTargetedRecordsRule,
|
||||
contextStoreFilters,
|
||||
personObjectMetadataItem,
|
||||
);
|
||||
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
import { ContextStoreTargetedRecordsRule } from '@/context-store/states/contextStoreTargetedRecordsRuleComponentState';
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { RecordGqlOperationFilter } from '@/object-record/graphql/types/RecordGqlOperationFilter';
|
||||
import { Filter } from '@/object-record/object-filter-dropdown/types/Filter';
|
||||
import { computeViewRecordGqlOperationFilter } from '@/object-record/record-filter/utils/computeViewRecordGqlOperationFilter';
|
||||
import { makeAndFilterVariables } from '@/object-record/utils/makeAndFilterVariables';
|
||||
|
||||
export const computeContextStoreFilters = (
|
||||
contextStoreTargetedRecordsRule: ContextStoreTargetedRecordsRule,
|
||||
contextStoreFilters: Filter[],
|
||||
objectMetadataItem: ObjectMetadataItem,
|
||||
) => {
|
||||
let queryFilter: RecordGqlOperationFilter | undefined;
|
||||
@ -13,7 +15,7 @@ export const computeContextStoreFilters = (
|
||||
if (contextStoreTargetedRecordsRule.mode === 'exclusion') {
|
||||
queryFilter = makeAndFilterVariables([
|
||||
computeViewRecordGqlOperationFilter(
|
||||
contextStoreTargetedRecordsRule.filters,
|
||||
contextStoreFilters,
|
||||
objectMetadataItem?.fields ?? [],
|
||||
[],
|
||||
),
|
||||
@ -36,7 +38,11 @@ export const computeContextStoreFilters = (
|
||||
in: contextStoreTargetedRecordsRule.selectedRecordIds,
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
: computeViewRecordGqlOperationFilter(
|
||||
contextStoreFilters,
|
||||
objectMetadataItem?.fields ?? [],
|
||||
[],
|
||||
);
|
||||
}
|
||||
|
||||
return queryFilter;
|
||||
|
||||
Reference in New Issue
Block a user