feat: record group insert at bottom when created (#9053)
Fix #9050 When we add a new record in a record group this one should be added at them bottom.
This commit is contained in:
@ -56,8 +56,8 @@ export const RecordTableRecordGroupRows = () => {
|
||||
/>
|
||||
);
|
||||
})}
|
||||
<RecordTableRecordGroupSectionLoadMore />
|
||||
<RecordTablePendingRecordGroupRow />
|
||||
<RecordTableRecordGroupSectionLoadMore />
|
||||
<RecordTableRecordGroupSectionAddNew />
|
||||
</>
|
||||
);
|
||||
|
||||
@ -4,6 +4,8 @@ import { getLabelIdentifierFieldMetadataItem } from '@/object-metadata/utils/get
|
||||
import { useCreateOneRecord } from '@/object-record/hooks/useCreateOneRecord';
|
||||
import { recordFieldInputDraftValueComponentSelector } from '@/object-record/record-field/states/selectors/recordFieldInputDraftValueComponentSelector';
|
||||
import { recordGroupDefinitionFamilyState } from '@/object-record/record-group/states/recordGroupDefinitionFamilyState';
|
||||
import { recordIndexRecordIdsByGroupComponentFamilyState } from '@/object-record/record-index/states/recordIndexRecordIdsByGroupComponentFamilyState';
|
||||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
|
||||
import { useRecordTableContextOrThrow } from '@/object-record/record-table/contexts/RecordTableContext';
|
||||
import { recordTablePendingRecordIdByGroupComponentFamilyState } from '@/object-record/record-table/states/recordTablePendingRecordIdByGroupComponentFamilyState';
|
||||
import { getScopeIdFromComponentId } from '@/ui/utilities/recoil-scope/utils/getScopeIdFromComponentId';
|
||||
@ -26,6 +28,11 @@ export const useUpsertTableRecordInGroup = (recordGroupId: string) => {
|
||||
recordTablePendingRecordIdByGroupComponentFamilyState,
|
||||
);
|
||||
|
||||
const recordIndexRecordIdsByGroupFamilyState =
|
||||
useRecoilComponentCallbackStateV2(
|
||||
recordIndexRecordIdsByGroupComponentFamilyState,
|
||||
);
|
||||
|
||||
const upsertTableRecordInGroup = useRecoilCallback(
|
||||
({ snapshot }) =>
|
||||
(persistField: () => void, recordId: string, fieldName: string) => {
|
||||
@ -54,11 +61,23 @@ export const useUpsertTableRecordInGroup = (recordGroupId: string) => {
|
||||
recordGroupDefinitionFamilyState(recordGroupId),
|
||||
);
|
||||
|
||||
const recordGroupIds = getSnapshotValue(
|
||||
snapshot,
|
||||
recordIndexRecordIdsByGroupFamilyState(recordGroupId),
|
||||
);
|
||||
|
||||
const recordGroupFieldMetadataItem = objectMetadataItem.fields.find(
|
||||
(fieldMetadata) =>
|
||||
fieldMetadata.id === recordGroupDefinition?.fieldMetadataId,
|
||||
);
|
||||
|
||||
const lastId = recordGroupIds?.[recordGroupIds.length - 1];
|
||||
|
||||
const objectRecord = getSnapshotValue(
|
||||
snapshot,
|
||||
recordStoreFamilyState(lastId),
|
||||
);
|
||||
|
||||
if (
|
||||
isDefined(recordTablePendingRecordId) &&
|
||||
isDefined(recordGroupDefinition) &&
|
||||
@ -69,7 +88,7 @@ export const useUpsertTableRecordInGroup = (recordGroupId: string) => {
|
||||
id: recordTablePendingRecordId,
|
||||
[labelIdentifierFieldMetadataItem?.name ?? 'name']: draftValue,
|
||||
[recordGroupFieldMetadataItem.name]: recordGroupDefinition.value,
|
||||
position: 'first',
|
||||
position: (objectRecord?.position ?? 0) + 0.0001,
|
||||
});
|
||||
} else if (!recordTablePendingRecordId) {
|
||||
persistField();
|
||||
@ -79,6 +98,7 @@ export const useUpsertTableRecordInGroup = (recordGroupId: string) => {
|
||||
createOneRecord,
|
||||
objectMetadataItem,
|
||||
recordGroupId,
|
||||
recordIndexRecordIdsByGroupFamilyState,
|
||||
recordTablePendingRecordIdByGroupFamilyState,
|
||||
],
|
||||
);
|
||||
|
||||
@ -3,22 +3,14 @@ import { recordIndexAllRecordIdsComponentSelector } from '@/object-record/record
|
||||
import { useRecordTableContextOrThrow } from '@/object-record/record-table/contexts/RecordTableContext';
|
||||
import { useCreateNewTableRecord } from '@/object-record/record-table/hooks/useCreateNewTableRecords';
|
||||
import { RecordTableActionRow } from '@/object-record/record-table/record-table-row/components/RecordTableActionRow';
|
||||
import { recordTablePendingRecordIdByGroupComponentFamilyState } from '@/object-record/record-table/states/recordTablePendingRecordIdByGroupComponentFamilyState';
|
||||
import { useRecoilComponentFamilyValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentFamilyValueV2';
|
||||
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
|
||||
import { IconPlus } from 'twenty-ui';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
|
||||
export const RecordTableRecordGroupSectionAddNew = () => {
|
||||
const { recordTableId } = useRecordTableContextOrThrow();
|
||||
|
||||
const currentRecordGroupId = useCurrentRecordGroupId();
|
||||
|
||||
const pendingRecordId = useRecoilComponentFamilyValueV2(
|
||||
recordTablePendingRecordIdByGroupComponentFamilyState,
|
||||
currentRecordGroupId,
|
||||
);
|
||||
|
||||
const recordIds = useRecoilComponentValueV2(
|
||||
recordIndexAllRecordIdsComponentSelector,
|
||||
);
|
||||
@ -30,8 +22,6 @@ export const RecordTableRecordGroupSectionAddNew = () => {
|
||||
createNewTableRecordInGroup(currentRecordGroupId);
|
||||
};
|
||||
|
||||
if (isDefined(pendingRecordId)) return null;
|
||||
|
||||
return (
|
||||
<RecordTableActionRow
|
||||
draggableId={`add-new-record-${currentRecordGroupId}`}
|
||||
|
||||
Reference in New Issue
Block a user