-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: replace all records ids state by selector
- Loading branch information
Showing
23 changed files
with
185 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
...front/src/modules/object-record/record-index/states/recordIndexAllRowIdsComponentState.ts
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
...s/object-record/record-index/states/selectors/recordIndexAllRecordIdsComponentSelector.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { recordGroupIdsComponentState } from '@/object-record/record-group/states/recordGroupIdsComponentState'; | ||
import { recordIndexRowIdsByGroupComponentFamilyState } from '@/object-record/record-index/states/recordIndexRowIdsByGroupComponentFamilyState'; | ||
import { ObjectRecord } from '@/object-record/types/ObjectRecord'; | ||
import { createComponentSelectorV2 } from '@/ui/utilities/state/component-state/utils/createComponentSelectorV2'; | ||
import { ViewComponentInstanceContext } from '@/views/states/contexts/ViewComponentInstanceContext'; | ||
import { v4 } from 'uuid'; | ||
|
||
/** | ||
* Do not use this key outside of this file. | ||
* This is a temporary key to store the record ids for the default record group. | ||
*/ | ||
const defaultFamilyKey = v4(); | ||
|
||
export const recordIndexAllRecordIdsComponentSelector = | ||
createComponentSelectorV2<ObjectRecord['id'][]>({ | ||
key: 'recordIndexAllRecordIdsComponentSelector', | ||
componentInstanceContext: ViewComponentInstanceContext, | ||
get: | ||
({ instanceId }) => | ||
({ get }) => { | ||
const recordGroupIds = get( | ||
recordGroupIdsComponentState.atomFamily({ | ||
instanceId, | ||
}), | ||
); | ||
|
||
if (recordGroupIds.length === 0) { | ||
return get( | ||
recordIndexRowIdsByGroupComponentFamilyState.atomFamily({ | ||
instanceId, | ||
familyKey: defaultFamilyKey, | ||
}), | ||
); | ||
} | ||
|
||
return recordGroupIds.reduce<ObjectRecord['id'][]>( | ||
(acc, recordGroupId) => { | ||
const rowIds = get( | ||
recordIndexRowIdsByGroupComponentFamilyState.atomFamily({ | ||
instanceId, | ||
familyKey: recordGroupId, | ||
}), | ||
); | ||
|
||
return [...acc, ...rowIds]; | ||
}, | ||
[], | ||
); | ||
}, | ||
set: | ||
({ instanceId }) => | ||
({ set }, recordIds) => | ||
set( | ||
recordIndexRowIdsByGroupComponentFamilyState.atomFamily({ | ||
instanceId, | ||
familyKey: defaultFamilyKey, | ||
}), | ||
recordIds, | ||
), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...-front/src/modules/object-record/record-table/components/RecordTableNoRecordGroupRows.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.