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:
@ -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(
|
||||
|
||||
Reference in New Issue
Block a user