Skip to content

Commit 58a00e6

Browse files
committed
ui: remove codemirror and use formule's instead
Signed-off-by: Miguel Garcia Garcia <[email protected]>
1 parent 812ca0f commit 58a00e6

File tree

8 files changed

+33
-197
lines changed

8 files changed

+33
-197
lines changed

ui/cap-react/package.json

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,13 @@
3131
"dependencies": {
3232
"@ant-design/icons": "4.7.0",
3333
"@ant-design/pro-layout": "7.10.3",
34-
"@codemirror/commands": "6.1.2",
35-
"@codemirror/lang-json": "6.0.1",
36-
"@codemirror/language": "6.6.0",
37-
"@codemirror/legacy-modes": "6.3.0",
38-
"@codemirror/lint": "6.1.0",
39-
"@codemirror/merge": "6.0.0",
40-
"@codemirror/state": "6.1.3",
41-
"@codemirror/view": "6.4.2",
4234
"@datapunt/matomo-tracker-react": "0.5.1",
4335
"@sentry/react": "^5.0.0",
4436
"@vitejs/plugin-react": "^4.2.0",
4537
"antd": "^5.4.2",
4638
"axios": "0.27.2",
4739
"classnames": "2.3.1",
4840
"clean-deep": "3.3.0",
49-
"codemirror": "6.0.1",
5041
"connected-react-router": "6.5.2",
5142
"dayjs": "1.11.7",
5243
"deep-equal": "2.0.3",

ui/cap-react/src/antd/admin/components/Header.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ import {
2222
SettingOutlined,
2323
} from "@ant-design/icons";
2424
import { CMS } from "../../routes";
25-
import CodeViewer from "../../utils/CodeViewer";
26-
import { json } from "@codemirror/lang-json";
27-
import CodeDiffViewer from "../../utils/CodeDiffViewer";
25+
import { CodeViewer } from "react-formule";
26+
import { CodeDiffViewer } from "react-formule";
2827

2928
const { useBreakpoint } = Grid;
3029
const Header = ({
@@ -71,30 +70,32 @@ const Header = ({
7170
uiSchema: (
7271
<CodeViewer
7372
value={JSON.stringify(formuleCurrentUiSchema, null, 2)}
74-
lang={json}
73+
lang="json"
7574
height="100%"
75+
reset
7676
/>
7777
),
7878
schema: (
7979
<CodeViewer
8080
value={JSON.stringify(formuleCurrentSchema, null, 2)}
81-
lang={json}
81+
lang="json"
8282
height="100%"
83+
reset
8384
/>
8485
),
8586
uiSchemaDiff: (
8687
<CodeDiffViewer
8788
left={JSON.stringify(formuleState?.initial?.uiSchema, null, 2)}
8889
right={JSON.stringify(formuleCurrentUiSchema, null, 2)}
89-
lang={json}
90+
lang="json"
9091
height="100%"
9192
/>
9293
),
9394
schemaDiff: (
9495
<CodeDiffViewer
9596
left={JSON.stringify(formuleState?.initial?.schema, null, 2)}
9697
right={JSON.stringify(formuleCurrentSchema, null, 2)}
97-
lang={json}
98+
lang="json"
9899
height="100%"
99100
/>
100101
),

ui/cap-react/src/antd/forms/customFields/services/CAPDeposit.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
11
import PropTypes from "prop-types";
2-
import {
3-
Card,
4-
Divider,
5-
Modal,
6-
Space,
7-
Tag,
8-
Typography,
9-
} from "antd";
2+
import { Card, Divider, Modal, Space, Tag, Typography } from "antd";
103
import { EyeFilled, LinkOutlined } from "@ant-design/icons";
114
import { useState } from "react";
12-
import CodeEditor from "../../../utils/CodeEditor";
13-
import { json, jsonParseLinter } from "@codemirror/lang-json";
5+
import { CodeEditor } from "react-formule";
146

157
const CAPDeposit = ({ data }) => {
168
const [showModal, setShowModal] = useState(false);
179

10+
console.log(JSON.stringify(data, null, 2));
11+
1812
return (
1913
<>
2014
<Modal open={showModal} onCancel={() => setShowModal(false)}>
2115
<CodeEditor
22-
lang={json}
23-
value={JSON.stringify(data, null, 2)}
24-
lint={jsonParseLinter}
25-
isReadOnly={true}
16+
lang="json"
17+
initialValue={JSON.stringify(data, null, 2)}
18+
lint="json"
19+
isEditable={false} // TODO: Change to !isEditable?
2620
height="calc(100vh - 325px)"
2721
/>
2822
</Modal>
@@ -33,7 +27,9 @@ const CAPDeposit = ({ data }) => {
3327
<Space style={{ flex: 1 }}>
3428
<Card.Meta
3529
size="small"
36-
avatar={data?.schema?.fullname && <Tag>{data?.schema?.fullname}</Tag>}
30+
avatar={
31+
data?.schema?.fullname && <Tag>{data?.schema?.fullname}</Tag>
32+
}
3733
title={data?.metadata?.general_title || "No title"}
3834
description={"No description"}
3935
/>

ui/cap-react/src/antd/schemas/components/Schemas.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ import {
2121
UndoOutlined,
2222
} from "@ant-design/icons";
2323
import ErrorScreen from "../../partials/Error";
24-
import CodeEditor from "../../utils/CodeEditor";
25-
import { json, jsonParseLinter } from "@codemirror/lang-json";
26-
import CodeDiffViewer from "../../utils/CodeDiffViewer";
24+
import { CodeEditor } from "react-formule";
25+
import { CodeDiffViewer } from "react-formule";
2726
import { CMS } from "../../routes";
2827

2928
const { useBreakpoint } = Grid;
@@ -165,11 +164,13 @@ const Schemas = ({ match, pushPath }) => {
165164
title={`${selection} diff`}
166165
width={1000}
167166
footer={null}
168-
style={{ body: {
169-
overflowX: "scroll",
170-
overflowY: "auto",
171-
maxHeight: "calc(100vh - 200px)",
172-
}}}
167+
style={{
168+
body: {
169+
overflowX: "scroll",
170+
overflowY: "auto",
171+
maxHeight: "calc(100vh - 200px)",
172+
},
173+
}}
173174
>
174175
<CodeDiffViewer
175176
left={JSON.stringify(
@@ -338,15 +339,16 @@ const Schemas = ({ match, pushPath }) => {
338339
<Row justify="center" style={{ backgroundColor: "white" }}>
339340
<Col xs={24}>
340341
<CodeEditor
341-
value={JSON.stringify(
342+
initialValue={JSON.stringify(
342343
selection === FULL_SCHEMA ? schema : schema[selection],
343344
null,
344345
2
345346
)}
346-
lang={json}
347-
isReadOnly={!EDITABLE_FIELDS.includes(selection)}
347+
lang="json"
348+
isEditable={EDITABLE_FIELDS.includes(selection)}
348349
handleEdit={handleEdit}
349-
lint={jsonParseLinter}
350+
lint="json"
351+
reset
350352
schema={schema} // to render a new editor instance on schema change
351353
height="calc(100vh - 325px)"
352354
/>

ui/cap-react/src/antd/utils/CodeDiffViewer.js

Lines changed: 0 additions & 67 deletions
This file was deleted.

ui/cap-react/src/antd/utils/CodeEditor.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

ui/cap-react/src/antd/utils/CodeViewer.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

ui/cap-react/vite.config.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ export default defineConfig(({ mode }) => {
7070
define: {
7171
"process.env": {},
7272
},
73-
// Avoid duplicate dependencies (codemirror was breaking because of this)
74-
resolve: {
75-
dedupe: ["@codemirror/state", "@codemirror/view"],
76-
},
7773
// Avoid errors when accesing e.g. document from tests
7874
test: {
7975
environment: "happy-dom",

0 commit comments

Comments
 (0)