RICH_TEXT_V2 upgrade command (#10094)

Adds two migration commands:
- copy note and task `body` data to `bodyV2`
- hide `body` view field and swap position with `bodyV2` view field

Related to issue https://github.com/twentyhq/twenty/issues/7613

---------

Co-authored-by: ad-elias <elias@autodiligence.com>
Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
This commit is contained in:
eliasylonen
2025-02-12 12:26:29 +01:00
committed by GitHub
parent 33af71ccd3
commit 23d2e54439
12 changed files with 605 additions and 78 deletions

View File

@ -2,9 +2,11 @@ import { useSelectedRecordIdOrThrow } from '@/action-menu/actions/record-actions
import { ActionHookWithObjectMetadataItem } from '@/action-menu/actions/types/ActionHook';
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
import { BlockNoteEditor } from '@blocknote/core';
import { useRecoilValue } from 'recoil';
import { isDefined } from 'twenty-shared';
import { FeatureFlagKey } from '~/generated/graphql';
export const useExportNoteAction: ActionHookWithObjectMetadataItem = ({
objectMetadataItem,
@ -22,13 +24,35 @@ export const useExportNoteAction: ActionHookWithObjectMetadataItem = ({
const shouldBeRegistered =
isDefined(objectMetadataItem) && isDefined(selectedRecord) && isNoteOrTask;
const isRichTextV2Enabled = useIsFeatureEnabled(
FeatureFlagKey.IsRichTextV2Enabled,
);
const onClick = async () => {
if (!shouldBeRegistered || !selectedRecord?.body) {
return;
}
const editor = await BlockNoteEditor.create({
initialContent: JSON.parse(selectedRecord.body),
const initialBody = isRichTextV2Enabled
? selectedRecord.bodyV2?.blocknote
: selectedRecord.body;
let parsedBody = [];
// TODO: Remove this once we have removed the old rich text
try {
parsedBody = JSON.parse(initialBody);
} catch (error) {
// eslint-disable-next-line no-console
console.warn(
`Failed to parse body for record ${recordId}, for rich text version ${isRichTextV2Enabled ? 'v2' : 'v1'}`,
);
// eslint-disable-next-line no-console
console.warn(initialBody);
}
const editor = BlockNoteEditor.create({
initialContent: parsedBody,
});
const { exportBlockNoteEditorToPdf } = await import(