Skip to content

Commit

Permalink
modifications after comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bosiraphael committed Oct 21, 2024
1 parent f0ef4dd commit 01c5022
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ export const DeleteRecordsActionEffect = ({
contextStoreTargetedRecordsRuleState,
);

const filter = computeContextStoreFilters(
const graphqlFilter = computeContextStoreFilters(
contextStoreTargetedRecordsRule,
objectMetadataItem ?? undefined,
objectMetadataItem,
);

const { fetchAllRecordIds } = useFetchAllRecordIds({
objectNameSingular: objectMetadataItem?.nameSingular ?? '',
filter,
objectNameSingular: objectMetadataItem.nameSingular,
filter: graphqlFilter,
});

const handleDeleteClick = useCallback(async () => {
Expand Down Expand Up @@ -79,7 +79,7 @@ export const DeleteRecordsActionEffect = ({
resetTableRowSelection,
]);

const isRemoteObject = objectMetadataItem?.isRemote ?? false;
const isRemoteObject = objectMetadataItem.isRemote;

const canDelete =
!isRemoteObject &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ export const ManageFavoritesActionEffect = ({
const selectedRecordId =
contextStoreTargetedRecordsRule.mode === 'selection'
? contextStoreTargetedRecordsRule.selectedRecordIds[0]
: '';
: undefined;

const selectedRecord = useRecoilValue(
recordStoreFamilyState(selectedRecordId),
recordStoreFamilyState(selectedRecordId ?? ''),
);

const foundFavorite = favorites?.find(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ export const RecordActionMenuEntriesSetter = () => {
objectId: contextStoreCurrentObjectMetadataId ?? '',
});

if (!objectMetadataItem || !contextStoreNumberOfSelectedRecords) {

if (!objectMetadataItem) {
throw new Error(
`Object metadata item not found for id ${contextStoreCurrentObjectMetadataId}`,
);
}

if (!contextStoreNumberOfSelectedRecords) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { ContextStoreTargetedRecordsRule } from '@/context-store/states/contextStoreTargetedRecordsRuleState';
import { computeContextStoreFilters } from '@/context-store/utils/computeContextStoreFilters';
import { ViewFilterOperand } from '@/views/types/ViewFilterOperand';
import { generatedMockObjectMetadataItems } from '~/testing/mock-data/generatedMockObjectMetadataItems';
describe('computeContextStoreFilters', () => {
const personObjectMetadataItem =
generatedMockObjectMetadataItems.find(
(item) => item.nameSingular === 'person',
)!;

it('should work for selection mode', () => {
const contextStoreTargetedRecordsRule: ContextStoreTargetedRecordsRule = {
mode: 'selection',
selectedRecordIds: ['1', '2', '3'],
};

const filters = computeContextStoreFilters(
contextStoreTargetedRecordsRule,
personObjectMetadataItem,
);

expect(filters).toEqual({
id: {
in: ['1', '2', '3'],
},
});
});

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: 'field1',
label: 'Label 1',
iconName: 'icon1',
type: 'TEXT',
},
},
],
excludedRecordIds: ['1', '2', '3'],
};

const filters = computeContextStoreFilters(
contextStoreTargetedRecordsRule,
personObjectMetadataItem,
);

expect(filters).toEqual({
and: [
{
name: {
ilike: '%John%',
},
},
{
not: {
id: {
in: ['1', '2', '3'],
},
},
},
],
});
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { makeAndFilterVariables } from '@/object-record/utils/makeAndFilterVaria

export const computeContextStoreFilters = (
contextStoreTargetedRecordsRule: ContextStoreTargetedRecordsRule,
objectMetadataItem?: ObjectMetadataItem,
objectMetadataItem: ObjectMetadataItem,
) => {
let queryFilter: RecordGqlOperationFilter | undefined;

Expand Down

0 comments on commit 01c5022

Please sign in to comment.