Skip to content

Commit

Permalink
Merge branch 'feature/WAL-7939' into 'develop'
Browse files Browse the repository at this point in the history
[WAL-7939] Drop draft-js (deprecated), migrate to markdown editors

See merge request waldur/waldur-homeport!5410
  • Loading branch information
livenson committed Jan 24, 2025
2 parents fc4189f + 54ae7c0 commit c8c14da
Show file tree
Hide file tree
Showing 10 changed files with 2,337 additions and 283 deletions.
8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@fontsource/inter": "^4.5.14",
"@fontsource/open-sans": "^4.5.14",
"@jonkoops/matomo-tracker": "^0.7.0",
"@mdxeditor/editor": "^3.20.0",
"@phosphor-icons/react": "^2.1.5",
"@popperjs/core": "~2.10.1",
"@sentry/react": "^8.38.0",
Expand All @@ -42,14 +43,11 @@
"classnames": "^2.2.5",
"d3-scale-chromatic": "^2.0.0",
"dompurify": "^3.1.7",
"draft-js": "^0.11.7",
"draftjs-to-html": "^0.9.1",
"echarts": "^5.5.1",
"eslint-import-resolver-typescript": "^3.6.3",
"final-form": "^4.20.10",
"final-form-arrays": "^3.1.0",
"flatpickr": "^4.6.13",
"html-to-draftjs": "^1.5.0",
"immutable": "^3.8.2",
"ip-regex": "^4.2.0",
"jszip": "3.8.0",
Expand All @@ -66,7 +64,6 @@
"react": "^18.3.0",
"react-bootstrap": "^2.10.2",
"react-dom": "^18.3.0",
"react-draft-wysiwyg": "^1.15.0",
"react-dropzone": "^14.2.3",
"react-final-form": "^6.5.9",
"react-final-form-arrays": "^3.1.4",
Expand Down Expand Up @@ -202,8 +199,7 @@
"*.fixture.ts",
"*.fixture.tsx",
"src/EventsEnums.ts",
"src/FeaturesEnums.ts",
"src/core/draftjs-module.tsx"
"src/FeaturesEnums.ts"
]
},
"stylelint": {
Expand Down
8 changes: 0 additions & 8 deletions src/core/WysiwygEditor.scss

This file was deleted.

101 changes: 0 additions & 101 deletions src/core/WysiwygEditor.tsx

This file was deleted.

12 changes: 0 additions & 12 deletions src/core/draftjs-module.tsx

This file was deleted.

14 changes: 14 additions & 0 deletions src/form/MarkdownEditor.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.mdxeditor {
.mdxeditor-source-editor .cm-scroller,
.mdxeditor-diff-editor,
.editable-area {
min-height: 200px;
max-height: 400px;
height: calc(100vh - 325px);
overflow-y: auto;
}
}

.mdxeditor-popup-container {
z-index: 2000;
}
130 changes: 130 additions & 0 deletions src/form/MarkdownEditor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import {
MDXEditor,
headingsPlugin,
listsPlugin,
quotePlugin,
thematicBreakPlugin,
toolbarPlugin,
UndoRedo,
BoldItalicUnderlineToggles,
BlockTypeSelect,
ChangeCodeMirrorLanguage,
CodeToggle,
CreateLink,
InsertCodeBlock,
InsertTable,
InsertThematicBreak,
ListsToggle,
linkPlugin,
linkDialogPlugin,
tablePlugin,
codeBlockPlugin,
codeMirrorPlugin,
markdownShortcutPlugin,
ConditionalContents,
Separator,
StrikeThroughSupSubToggles,
diffSourcePlugin,
DiffSourceToggleWrapper,
} from '@mdxeditor/editor';
import { FC, useRef } from 'react';

import { FormField } from './types';

import '@mdxeditor/editor/style.css';
import './MarkdownEditor.scss';

interface MarkdownEditorProps extends FormField {
placeholder?: string;
className?: string;
}

const Toolbar = () => {
return (
<DiffSourceToggleWrapper>
<ConditionalContents
options={[
{
when: (editor) => editor?.editorType === 'codeblock',
contents: () => <ChangeCodeMirrorLanguage />,
},
{
fallback: () => (
<>
<UndoRedo />

<Separator />
<BoldItalicUnderlineToggles />
<CodeToggle />

<Separator />
<StrikeThroughSupSubToggles />

<Separator />
<ListsToggle />

<Separator />
<BlockTypeSelect />

<Separator />
<CreateLink />

<Separator />
<InsertTable />
<InsertThematicBreak />

<Separator />
<InsertCodeBlock />
</>
),
},
]}
/>
</DiffSourceToggleWrapper>
);
};

const MarkdownEditor: FC<MarkdownEditorProps> = (props) => {
const initialValue = useRef(props.input?.value);

return (
<MDXEditor
className={props.className}
contentEditableClassName="editable-area"
markdown={props.input?.value || ''}
autoFocus={props.autoFocus}
placeholder={props.placeholder}
onChange={props.input?.onChange}
plugins={[
toolbarPlugin({ toolbarContents: () => <Toolbar /> }),
listsPlugin(),
quotePlugin(),
headingsPlugin(),
linkPlugin(),
linkDialogPlugin(),
tablePlugin(),
thematicBreakPlugin(),
codeBlockPlugin({ defaultCodeBlockLanguage: '' }),
codeMirrorPlugin({
codeBlockLanguages: {
py: 'Python',
java: 'Java',
js: 'JavaScript',
tsx: 'TypeScript',
php: 'PHP',
txt: 'Plain Text',
'': 'Unspecified',
},
}),
markdownShortcutPlugin(),
diffSourcePlugin({
viewMode: 'rich-text',
readOnlyDiff: true,
diffMarkdown: initialValue.current,
}),
]}
/>
);
};

export default MarkdownEditor;
15 changes: 11 additions & 4 deletions src/marketplace/offerings/update/overview/EditOverviewDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { Modal } from 'react-bootstrap';
import { connect, useDispatch } from 'react-redux';
import { reduxForm } from 'redux-form';

import { WysiwygEditor } from '@waldur/core/WysiwygEditor';
import {
StringField,
FormContainer,
SubmitButton,
TextField,
} from '@waldur/form';
import MarkdownEditor from '@waldur/form/MarkdownEditor';
import { translate } from '@waldur/i18n';
import { updateOfferingOverview } from '@waldur/marketplace/common/api';
import { closeModalDialog } from '@waldur/modal/actions';
Expand Down Expand Up @@ -57,15 +57,22 @@ export const EditOverviewDialog = connect(
<Modal.Title>{props.resolve.attribute.title}</Modal.Title>
</Modal.Header>
<Modal.Body>
<FormContainer {...props}>
<FormContainer
{...props}
className={
props.resolve.attribute.type === 'html' ? 'size-lg' : undefined
}
>
{props.resolve.attribute.type === 'html' ? (
<WysiwygEditor name="value" />
<MarkdownEditor name="value" autoFocus hideLabel spaceless />
) : props.resolve.attribute.type === 'text' ? (
<TextField name="value" />
<TextField name="value" hideLabel spaceless />
) : (
<StringField
name="value"
maxLength={props.resolve.attribute.maxLength}
hideLabel
spaceless
/>
)}
</FormContainer>
Expand Down
4 changes: 2 additions & 2 deletions src/marketplace/offerings/update/plans/PlanForm.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Field } from 'redux-form';

import { required } from '@waldur/core/validators';
import { WysiwygEditor } from '@waldur/core/WysiwygEditor';
import { InputField } from '@waldur/form/InputField';
import MarkdownEditor from '@waldur/form/MarkdownEditor';
import { translate } from '@waldur/i18n';

import { ArticleCodeField } from '../../ArticleCodeField';
Expand All @@ -24,7 +24,7 @@ export const PlanForm = () => (
<PlanBillingPeriodField />
</FormGroup>
<FormGroup label={translate('Description')}>
<Field name="description" component={WysiwygEditor} />
<Field name="description" component={MarkdownEditor} />
</FormGroup>
<ArticleCodeField />
</>
Expand Down
4 changes: 0 additions & 4 deletions template.json
Original file line number Diff line number Diff line change
Expand Up @@ -12495,10 +12495,6 @@
"description": "marketplace/resources/list/ExpandableResourceSummary.tsx",
"message": "Unable to load detail."
},
"Unable to load editor": {
"description": "core/WysiwygEditor.tsx",
"message": "Unable to load editor"
},
"Unable to load financial overview.": {
"description": "customer/list/CustomerListContainer.tsx, customer/list/ExportAsEmailDialog.tsx",
"message": "Unable to load financial overview."
Expand Down
Loading

0 comments on commit c8c14da

Please sign in to comment.