Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save Markdown and BlockNote in RICH_TEXT fields (#7613) #9279

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
dbdfd1a
Make RICH_TEXT composite WiP
ad-elias Dec 29, 2024
45b68d0
Make RICH_TEXT composite WiP
ad-elias Dec 29, 2024
4f5ae94
Frontend handling of composite RICH_TEXT WiP
ad-elias Dec 29, 2024
29df7e6
Merge branch 'main' into feat/7613-composite-rich-text
ad-elias Dec 29, 2024
3445e35
Merge branch 'main' into feat/7613-composite-rich-text
ad-elias Jan 2, 2025
b65d6f2
Add old RICH_TEXT field as RICH_TEXT_OLD
ad-elias Jan 2, 2025
032c115
Add isFieldRichTextOldValue fn
ad-elias Jan 2, 2025
73dfe30
Fix errors adding RICH_TEXT_OLD
ad-elias Jan 3, 2025
10ffd6a
Rename to RICH_TEXT_DEPRECATED
ad-elias Jan 4, 2025
2be5673
Move notes to new RICH_TEXT WiP
ad-elias Jan 5, 2025
1dbf828
Merge branch 'main' into feat/7613-composite-rich-text
ad-elias Jan 5, 2025
2a41f07
Fix notes loading
ad-elias Jan 6, 2025
dad7024
Fix RICH_TEXT value displaying
ad-elias Jan 7, 2025
dfaaf6e
Import composite RICH_TEXT fields
ad-elias Jan 7, 2025
e564754
Fix typo, add todo
ad-elias Jan 7, 2025
00b4b12
Override markdown and blocknote values WiP
ad-elias Jan 8, 2025
eda4f09
BlockNote server util import testing
ad-elias Jan 8, 2025
2db9cf4
Downgrade @blocknote/server-util to fix import
ad-elias Jan 8, 2025
94983fc
Fix rich text value updating
ad-elias Jan 9, 2025
bb7b4b8
Composite RICH_TEXT upgade command WiP
ad-elias Jan 9, 2025
017defe
Upgade command fixes
ad-elias Jan 9, 2025
a2f207a
Remove debug throw
ad-elias Jan 9, 2025
1b4aae5
Composite RICH_TEXT upgade command works
ad-elias Jan 10, 2025
080c16e
Merge branch 'main' into feat/7613-composite-rich-text
ad-elias Jan 10, 2025
6c991d7
Merge branch 'main' into feat/7613-composite-rich-text
ad-elias Jan 10, 2025
b8e21da
Fix lint
ad-elias Jan 10, 2025
3357f66
Move upgrade command to a separate branch
ad-elias Jan 10, 2025
513a623
Fix import
ad-elias Jan 10, 2025
fabfd83
Fix command menu note and task search
ad-elias Jan 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@aws-sdk/credential-providers": "^3.363.0",
"@blocknote/mantine": "^0.22.0",
"@blocknote/react": "^0.22.0",
"@blocknote/server-util": "0.17.1",
"@codesandbox/sandpack-react": "^2.13.5",
"@dagrejs/dagre": "^1.1.2",
"@emotion/react": "^11.11.1",
Expand Down
1 change: 1 addition & 0 deletions packages/twenty-front/src/generated-metadata/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ export enum FieldMetadataType {
Rating = 'RATING',
RawJson = 'RAW_JSON',
Relation = 'RELATION',
RichTextDeprecated = 'RICH_TEXT_DEPRECATED',
RichText = 'RICH_TEXT',
Select = 'SELECT',
Text = 'TEXT',
Expand Down
1 change: 1 addition & 0 deletions packages/twenty-front/src/generated/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ export enum FieldMetadataType {
RawJson = 'RAW_JSON',
Relation = 'RELATION',
RichText = 'RICH_TEXT',
RichTextDeprecated = 'RICH_TEXT_DEPRECATED',
Select = 'SELECT',
Text = 'TEXT',
TsVector = 'TS_VECTOR',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ export const ActivityRichTextEditor = ({
upsertActivity({
activity,
input: {
body: newBody,
body: {
blocknote: newBody,
markdown: null,
},
},
});
}
Expand Down Expand Up @@ -165,10 +168,10 @@ export const ActivityRichTextEditor = ({
const initialBody = useMemo(() => {
if (
isDefined(activity) &&
isNonEmptyString(activity.body) &&
activity?.body !== '{}'
isNonEmptyString(activity.body.blocknote) &&
activity?.body.blocknote !== '{}'
) {
return JSON.parse(activity.body);
return JSON.parse(activity.body.blocknote);
}
}, [activity]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ const task = {
createdAt: '2023-04-26T10:12:42.33625+00:00',
updatedAt: '2023-04-26T10:23:42.33625+00:00',
title: 'Task title',
body: null,
body: {
blocknote: null,
markdown: null,
},
assigneeId: null,
status: null,
dueAt: '2023-04-26T10:12:42.33625+00:00',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const NoteCard = ({
const openActivityRightDrawer = useOpenActivityRightDrawer({
objectNameSingular: CoreObjectNameSingular.Note,
});
const body = getActivityPreview(note.body);
const body = getActivityPreview(note.body.blocknote);

const { FieldContextProvider: NoteTargetsContextProvider } = useFieldContext({
objectNameSingular: CoreObjectNameSingular.Note,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const TaskRow = ({ task }: { task: Task }) => {
objectNameSingular: CoreObjectNameSingular.Task,
});

const body = getActivitySummary(task.body);
const body = getActivitySummary(task.body.blocknote);
const { completeTask } = useCompleteTask(task);

const { FieldContextProvider: TaskTargetsContextProvider } = useFieldContext({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ const task: Task = {
id: '123',
status: 'DONE',
title: 'Test',
body: 'Test',
body: {
blocknote: 'Test',
markdown: 'Test',
},
dueAt: '2024-03-15T07:33:14.212Z',
createdAt: '2024-03-15T07:33:14.212Z',
updatedAt: '2024-03-15T07:33:14.212Z',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ export type Activity = {
createdAt: string;
updatedAt: string;
title: string;
body: string | null;
body: {
blocknote: string | null;
markdown: string | null;
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ export const useCommandMenuCommands = () => {
filter: deferredCommandMenuSearch
? makeOrFilterVariables([
{ title: { ilike: `%${deferredCommandMenuSearch}%` } },
{ body: { ilike: `%${deferredCommandMenuSearch}%` } },
{
body: {
blocknote: { ilike: `%${deferredCommandMenuSearch}%` },
},
},
])
: undefined,
limit: 3,
Expand All @@ -158,7 +162,11 @@ export const useCommandMenuCommands = () => {
filter: deferredCommandMenuSearch
? makeOrFilterVariables([
{ title: { ilike: `%${deferredCommandMenuSearch}%` } },
{ body: { ilike: `%${deferredCommandMenuSearch}%` } },
{
body: {
blocknote: { ilike: `%${deferredCommandMenuSearch}%` },
},
},
])
: undefined,
limit: 3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const mapFieldMetadataToGraphQLQuery = ({
FieldMetadataType.MultiSelect,
FieldMetadataType.Position,
FieldMetadataType.RawJson,
FieldMetadataType.RichText,
FieldMetadataType.RichTextDeprecated,
FieldMetadataType.Array,
].includes(fieldType);

Expand Down Expand Up @@ -162,5 +162,13 @@ ${mapObjectMetadataToGraphQLQuery({
}`;
}

if (fieldType === FieldMetadataType.RichText) {
return `${field.name}
{
blocknote
markdown
}`;
}

return '';
};
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ export type RawJsonFilter = {
is?: IsFilter;
};

export type RichTextLeafFilter = {
ilike?: string;
};

export type RichTextFilter = {
blocknote?: RichTextLeafFilter;
markdown?: RichTextLeafFilter;
};

export type LeafFilter =
| UUIDFilter
| StringFilter
Expand All @@ -144,6 +153,7 @@ export type LeafFilter =
| PhonesFilter
| ArrayFilter
| RawJsonFilter
| RichTextFilter
| undefined;

export type AndObjectRecordFilter = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { LinksFieldDisplay } from '@/object-record/record-field/meta-types/displ
import { PhonesFieldDisplay } from '@/object-record/record-field/meta-types/display/components/PhonesFieldDisplay';
import { RatingFieldDisplay } from '@/object-record/record-field/meta-types/display/components/RatingFieldDisplay';
import { RelationFromManyFieldDisplay } from '@/object-record/record-field/meta-types/display/components/RelationFromManyFieldDisplay';
import { RichTextDeprecatedFieldDisplay } from '@/object-record/record-field/meta-types/display/components/RichTextDeprecatedFieldDisplay';
import { RichTextFieldDisplay } from '@/object-record/record-field/meta-types/display/components/RichTextFieldDisplay';
import { isFieldIdentifierDisplay } from '@/object-record/record-field/meta-types/display/utils/isFieldIdentifierDisplay';
import { isFieldActor } from '@/object-record/record-field/types/guards/isFieldActor';
Expand All @@ -20,6 +21,7 @@ import { isFieldRating } from '@/object-record/record-field/types/guards/isField
import { isFieldRelationFromManyObjects } from '@/object-record/record-field/types/guards/isFieldRelationFromManyObjects';
import { isFieldRelationToOneObject } from '@/object-record/record-field/types/guards/isFieldRelationToOneObject';
import { isFieldRichText } from '@/object-record/record-field/types/guards/isFieldRichText';
import { isFieldRichTextDeprecated } from '@/object-record/record-field/types/guards/isFieldRichTextDeprecated';
import { FieldContext } from '../contexts/FieldContext';
import { AddressFieldDisplay } from '../meta-types/display/components/AddressFieldDisplay';
import { ChipFieldDisplay } from '../meta-types/display/components/ChipFieldDisplay';
Expand Down Expand Up @@ -88,6 +90,8 @@ export const FieldDisplay = () => {
<BooleanFieldDisplay />
) : isFieldRating(fieldDefinition) ? (
<RatingFieldDisplay />
) : isFieldRichTextDeprecated(fieldDefinition) ? (
<RichTextDeprecatedFieldDisplay />
) : isFieldRichText(fieldDefinition) ? (
<RichTextFieldDisplay />
) : isFieldActor(fieldDefinition) ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import { RecordForSelect } from '@/object-record/relation-picker/types/RecordFor

import { isFieldArray } from '@/object-record/record-field/types/guards/isFieldArray';
import { isFieldArrayValue } from '@/object-record/record-field/types/guards/isFieldArrayValue';
import { isFieldRichText } from '@/object-record/record-field/types/guards/isFieldRichText';
import { isFieldRichTextValue } from '@/object-record/record-field/types/guards/isFieldRichTextValue';
import { isFieldRichTextDeprecated } from '@/object-record/record-field/types/guards/isFieldRichTextDeprecated';
import { isFieldRichTextDeprecatedValue } from '@/object-record/record-field/types/guards/isFieldRichTextDeprecatedValue';
import { FieldContext } from '../contexts/FieldContext';
import { isFieldBoolean } from '../types/guards/isFieldBoolean';
import { isFieldBooleanValue } from '../types/guards/isFieldBooleanValue';
Expand Down Expand Up @@ -113,9 +113,9 @@ export const usePersistField = () => {
isFieldRawJson(fieldDefinition) &&
isFieldRawJsonValue(valueToPersist);

const fieldIsRichText =
isFieldRichText(fieldDefinition) &&
isFieldRichTextValue(valueToPersist);
const fieldIsRichTextDeprecated =
isFieldRichTextDeprecated(fieldDefinition) &&
isFieldRichTextDeprecatedValue(valueToPersist);

const fieldIsArray =
isFieldArray(fieldDefinition) && isFieldArrayValue(valueToPersist);
Expand All @@ -138,7 +138,7 @@ export const usePersistField = () => {
fieldIsAddress ||
fieldIsRawJson ||
fieldIsArray ||
fieldIsRichText;
fieldIsRichTextDeprecated;

if (isValuePersistable) {
const fieldName = fieldDefinition.metadata.fieldName;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useRichTextDeprecatedFieldDisplay } from '@/object-record/record-field/meta-types/hooks/useRichTextDeprecatedFieldDisplay';
import { getFirstNonEmptyLineOfRichText } from '@/ui/input/editor/utils/getFirstNonEmptyLineOfRichText';

export const RichTextDeprecatedFieldDisplay = () => {
const { fieldValue } = useRichTextDeprecatedFieldDisplay();

return (
<div>
<span>{getFirstNonEmptyLineOfRichText(fieldValue)}</span>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { useRichTextFieldDisplay } from '@/object-record/record-field/meta-types/hooks/useRichTextFieldDisplay';
import { getFirstNonEmptyLineOfRichText } from '@/ui/input/editor/utils/getFirstNonEmptyLineOfRichText';
import { PartialBlock } from '@blocknote/core';
import { parseJson } from '~/utils/parseJson';

export const RichTextFieldDisplay = () => {
const { fieldValue } = useRichTextFieldDisplay();

const blocks = parseJson<PartialBlock[]>(fieldValue?.blocknote);

return (
<div>
<span>{getFirstNonEmptyLineOfRichText(fieldValue)}</span>
<span>{getFirstNonEmptyLineOfRichText(blocks)}</span>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { useContext } from 'react';
import { useRecoilState, useRecoilValue } from 'recoil';

import { useRecordFieldInput } from '@/object-record/record-field/hooks/useRecordFieldInput';
import { FieldRichTextDeprecatedValue } from '@/object-record/record-field/types/FieldMetadata';
import { recordStoreFamilySelector } from '@/object-record/record-store/states/selectors/recordStoreFamilySelector';
import { FieldMetadataType } from '~/generated-metadata/graphql';

import { usePersistField } from '@/object-record/record-field/hooks/usePersistField';
import { isFieldRichTextDeprecated } from '@/object-record/record-field/types/guards/isFieldRichTextDeprecated';
import { isFieldRichTextDeprecatedValue } from '@/object-record/record-field/types/guards/isFieldRichTextDeprecatedValue';
import { PartialBlock } from '@blocknote/core';
import { isNonEmptyString } from '@sniptt/guards';
import { FieldContext } from '../../contexts/FieldContext';
import { assertFieldMetadata } from '../../types/guards/assertFieldMetadata';

export const useRichTextDeprecatedField = () => {
const { recordId, fieldDefinition, hotkeyScope, maxWidth } =
useContext(FieldContext);

assertFieldMetadata(
FieldMetadataType.RichTextDeprecated,
isFieldRichTextDeprecated,
fieldDefinition,
);

const fieldName = fieldDefinition.metadata.fieldName;

const [fieldValue, setFieldValue] =
useRecoilState<FieldRichTextDeprecatedValue>(
recordStoreFamilySelector({
recordId,
fieldName: fieldName,
}),
);
const fieldRichTextDeprecatedValue = isFieldRichTextDeprecatedValue(
fieldValue,
)
? fieldValue
: '';

const { setDraftValue, getDraftValueSelector } =
useRecordFieldInput<FieldRichTextDeprecatedValue>(
`${recordId}-${fieldName}`,
);

const draftValue = useRecoilValue(getDraftValueSelector());

const draftValueParsed: PartialBlock[] = isNonEmptyString(draftValue)
? JSON.parse(draftValue)
: draftValue;

const persistField = usePersistField();

const persistRichTextDeprecatedField = (nextValue: PartialBlock[]) => {
if (!nextValue) {
persistField(null);
} else {
const parsedValueToPersist = JSON.stringify(nextValue);

persistField(parsedValueToPersist);
}
};

return {
draftValue: draftValueParsed,
setDraftValue,
maxWidth,
fieldDefinition,
fieldValue: fieldRichTextDeprecatedValue,
setFieldValue,
hotkeyScope,
persistRichTextDeprecatedField,
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { useContext } from 'react';

import { useRecordFieldValue } from '@/object-record/record-store/contexts/RecordFieldValueSelectorContext';

import { FieldRichTextDeprecatedValue } from '@/object-record/record-field/types/FieldMetadata';
import { assertFieldMetadata } from '@/object-record/record-field/types/guards/assertFieldMetadata';
import { isFieldRichTextDeprecated } from '@/object-record/record-field/types/guards/isFieldRichTextDeprecated';
import { PartialBlock } from '@blocknote/core';
import { FieldMetadataType } from '~/generated-metadata/graphql';
import { parseJson } from '~/utils/parseJson';
import { FieldContext } from '../../contexts/FieldContext';

export const useRichTextDeprecatedFieldDisplay = () => {
const { recordId, fieldDefinition, hotkeyScope } = useContext(FieldContext);

assertFieldMetadata(
FieldMetadataType.RichTextDeprecated,
isFieldRichTextDeprecated,
fieldDefinition,
);

const fieldName = fieldDefinition.metadata.fieldName;

const fieldValue = useRecordFieldValue<
FieldRichTextDeprecatedValue | undefined
>(recordId, fieldName);

const fieldValueParsed = parseJson<PartialBlock[]>(fieldValue);

return {
fieldDefinition,
fieldValue: fieldValueParsed,
hotkeyScope,
};
};
Loading
Loading