fix: soft deleted records are read only (#8198)

TODO:
- [ ] It should not be possible to add tasks, notes, files, etc.

Fix for https://github.com/twentyhq/twenty/issues/7172

Note for reviewer:
- With these changes, `deletedAt` is now always included in
`recordGqlFields`.

--- Edit from Charles --
In this PR:
1) As mentionned by @pau-not-paul, we are adding deletedAt to our
recordGqlFields for board and table
2) I'm removing cellReadOnly logic, it is now fully computed using
useIsFieldValueReadonly like it's done in other places, there is no need
to maintain two read only systems
3) refactoring useIsFieldValueReadonly to take all the business logics
into one place together. It's now a function of the 5 factors (isRemote,
isDeleted, objectName, fieldName, etc...). Later it's likely to get back
to a function of Pick<FieldMetadata>, Pick<ObjectMetadata>,
record.isDeleted but we are not there yet

Note: as all cells are listening to the record (for isDeleted), updating
a field will trigger a re-rendering of the row which is not an issue
right now. It will be if we introduce bulk edition. In this case we
would need to use a selector on fields on top of record store

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
pau-not-paul
2024-11-21 14:02:09 +01:00
committed by GitHub
parent 3c5eb539bb
commit ae4fb7d113
23 changed files with 327 additions and 135 deletions

View File

@ -0,0 +1,20 @@
import { ReactNode, useEffect } from 'react';
import { useUpsertRecordsInStore } from '@/object-record/record-store/hooks/useUpsertRecordsInStore';
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
export const JestRecordStoreSetter = ({
children,
records,
}: {
children: ReactNode;
records: ObjectRecord[];
}) => {
const { upsertRecords } = useUpsertRecordsInStore();
useEffect(() => {
upsertRecords(records);
});
return <>{children}</>;
};