Skip to content

Commit 3b48eeb

Browse files
miguelgrcpamfilos
authored andcommitted
ui: formule to 1.3.0, update schema saving/loading
Signed-off-by: Miguel Garcia Garcia <[email protected]>
1 parent f008925 commit 3b48eeb

File tree

17 files changed

+71
-64
lines changed

17 files changed

+71
-64
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repos:
1414
args: ["--config=.flake8"]
1515

1616
- repo: https://github.com/pycqa/isort
17-
rev: "5.10.1"
17+
rev: "5.12.0"
1818
hooks:
1919
- id: isort
2020

ui/cap-react/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"query-string": "^5.1.0",
5858
"react": "^18.2.0",
5959
"react-dom": "^18.2.0",
60-
"react-formule": "1.2.1",
60+
"react-formule": "1.3.0",
6161
"react-infinite-scroll-component": "6.1.0",
6262
"react-input-mask": "3.0.0-alpha.2",
6363
"react-joyride": "^2.5.4",

ui/cap-react/src/actions/builder.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const SYNCHRONIZE_FORMULE_STATE = "SYNCHRONIZE_FORMULE_STATE";
1212

1313
export const SET_SCHEMA_LOADING = "SET_SCHEMA_LOADING";
1414
export const UPDATE_SCHEMA_CONFIG = "UPDATE_SCHEMA_CONFIG";
15+
export const UPDATE_SCHEMA_INITIAL_CONFIG = "UPDATE_SCHEMA_INITIAL_CONFIG";
1516

1617
export const UPDATE_NOTIFICATION_BY_INDEX = "UPDATE_NOTIFICATION_BY_INDEX";
1718
export const UPDATE_NOTIFICATIONS = "UPDATE_NOTIFICATIONS";
@@ -35,6 +36,11 @@ export const updateSchemaConfig = config => ({
3536
config,
3637
});
3738

39+
export const updateSchemaInitialConfig = config => ({
40+
type: UPDATE_SCHEMA_INITIAL_CONFIG,
41+
config,
42+
});
43+
3844
export const updateNotificationByIndex = data => ({
3945
type: UPDATE_NOTIFICATION_BY_INDEX,
4046
payload: data,
@@ -158,7 +164,7 @@ export const saveSchemaChanges = () => (dispatch, getState) => {
158164
);
159165
// check whether there are changes to the config object
160166
const isConfigVersionUpdated =
161-
config.get("version") != state.builder.get("initialConfig").version;
167+
config.get("version") != state.builder.getIn(["initialConfig", "version"]);
162168

163169
if (isSchemaUpdated && !isConfigVersionUpdated) {
164170
notification.warning({

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const AdminPanel = ({ location, match, getSchema, loading, formuleState }) => {
4646
case "notifications":
4747
return <Notifications />;
4848
case "permissions":
49-
return <Permissions />;
49+
return <Permissions isNew={match.params.schema_name === "new"} />;
5050
default:
5151
return (
5252
<SchemaWizard

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import { initFormuleSchemaWithNotifications } from "../utils";
66
const CreateForm = ({ history }) => {
77
const onFinish = content => {
88
let { name, description } = content;
9-
const config = { config: { fullname: name } };
10-
initFormuleSchemaWithNotifications({ config }, name, description);
9+
initFormuleSchemaWithNotifications({ fullname: name }, name, description);
1110
history.push(CMS_NEW);
1211
};
1312

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ const Header = ({
5959

6060
const a = document.createElement("a");
6161
const file = new Blob([fileData], { type: "text/json" });
62+
const { name, version } = config.toJS();
63+
const versionStr = version ? `v${version}` : "";
6264
a.href = URL.createObjectURL(file);
63-
a.download = `${config.toJS().name || "cap-schema"}-export-v${
64-
config.toJS().version
65-
}-${Date.now()}.json`;
65+
a.download = `${
66+
name || "cap-schema"
67+
}-export${versionStr}-${Date.now()}.json`;
6668
a.click();
6769
};
6870
const _renderSchemaPreview = schemaPreviewDisplay => {

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { connect } from "react-redux";
2-
import {
3-
saveSchemaChanges,
4-
updateSchemaConfig,
5-
} from "../../../actions/builder";
2+
import { saveSchemaChanges } from "../../../actions/builder";
63
import { pushPath } from "../../../actions/support";
74
import Header from "../components/Header";
85

@@ -18,7 +15,6 @@ function mapDispatchToProps(dispatch) {
1815
return {
1916
saveSchemaChanges: () => dispatch(saveSchemaChanges()),
2017
pushPath: path => dispatch(pushPath(path)),
21-
updateSchemaConfig: config => dispatch(updateSchemaConfig(config)),
2218
};
2319
}
2420

ui/cap-react/src/antd/admin/permissions/Permissions.js

+22-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,23 @@ import {
2929
import { configSchema } from "../utils/schemaSettings";
3030
import { FormuleForm } from "react-formule";
3131

32+
// Left as documentation
33+
/*
34+
const initialStatePermissions = Map({
35+
deposit: {
36+
read: { users: [], roles: [] },
37+
update: { users: [], roles: [] },
38+
admin: { users: [], roles: [] },
39+
review: { users: [], roles: [] },
40+
create: { users: [], roles: [] },
41+
},
42+
records: {
43+
read: { users: [], roles: [] },
44+
review: { users: [], roles: [] },
45+
},
46+
});
47+
*/
48+
3249
const Permissions = ({
3350
schemaName,
3451
schemaVersion,
@@ -38,11 +55,12 @@ const Permissions = ({
3855
deleteSchemaPermissions,
3956
config,
4057
updateSchemaConfig,
58+
isNew,
4159
}) => {
4260
const [editable, setEditable] = useState(false);
4361
const [addEnabled, setAddEnabled] = useState(false);
4462
useEffect(() => {
45-
getSchemaPermissions(schemaName, schemaVersion);
63+
!isNew && getSchemaPermissions(schemaName, schemaVersion);
4664
}, []);
4765

4866
const addSchemaPermissionsToEmail = (
@@ -148,7 +166,7 @@ const Permissions = ({
148166
<Typography.Paragraph style={{ marginBottom: 0 }}>
149167
Here you can manage access to your{" "}
150168
<Typography.Text strong>
151-
{schemaName} ({schemaVersion})
169+
{schemaName} {schemaVersion && `(${schemaVersion})`}
152170
</Typography.Text>{" "}
153171
collection. You can determine who can perform specific
154172
action for both states of your document
@@ -205,8 +223,8 @@ Permissions.propTypes = {
205223

206224
const mapStateToProps = state => {
207225
return {
208-
schemaName: state.builder.get("formuleState").config.name,
209-
schemaVersion: state.builder.get("formuleState").config.version,
226+
schemaName: state.builder.getIn(["config", "name"]),
227+
schemaVersion: state.builder.getIn(["config", "version"]),
210228
permissions: state.builder.get("permissions"),
211229
config: state.builder.get("config"),
212230
};
+11-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { initFormuleSchema } from "react-formule";
22
import { merge } from "lodash-es";
33
import store from "../../../store/configureStore";
4-
import { updateSchemaConfig } from "../../../actions/builder";
4+
import {
5+
updateSchemaConfig,
6+
updateSchemaInitialConfig,
7+
} from "../../../actions/builder";
58

69
export const SIZE_OPTIONS = {
710
xsmall: 8,
@@ -20,25 +23,18 @@ const NOTIFICATIONS = {
2023
},
2124
};
2225

23-
export const slugify = text => {
24-
return text
25-
.toString()
26-
.toLowerCase()
27-
.replace(/\s+/g, "-") // Replace spaces with -
28-
.replace(/[^\w-]+/g, "") // Remove all non-word chars
29-
.replace(/--+/g, "-") // Replace multiple - with single -
30-
.replace(/^-+/, "") // Trim - from start of text
31-
.replace(/-+$/, ""); // Trim - from end of text
32-
};
33-
3426
export const initFormuleSchemaWithNotifications = (
3527
data = {},
36-
name,
28+
title,
3729
description
3830
) => {
3931
data.config = merge(data.config || {}, NOTIFICATIONS);
40-
initFormuleSchema(data, name, description);
41-
/* eslint no-unused-vars: ["error", { "ignoreRestSiblings": true }]*/
4232
const { deposit_schema, deposit_options, ...configs } = data;
33+
initFormuleSchema(
34+
{ schema: deposit_schema, uiSchema: deposit_options, id: configs.name },
35+
title,
36+
description
37+
);
4338
store.dispatch(updateSchemaConfig(configs));
39+
store.dispatch(updateSchemaInitialConfig(configs));
4440
};

ui/cap-react/src/antd/drafts/components/Editor/Editor.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ const Editor = ({
6464
schema={_schema}
6565
uiSchema={schemas.uiSchema || {}}
6666
extraErrors={extraErrors || {}}
67-
draftEditor
68-
readonly={mode != "edit" || !canEdit(canAdmin, canUpdate)}
67+
readonly={!canEdit(canAdmin, canUpdate)}
68+
isPublished={mode != "edit"}
6969
transformErrors={transformErrors}
7070
/>
7171
</Layout.Content>

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@ import PropTypes from "prop-types";
22
import { Card, Divider, Modal, Space, Tag, Typography } from "antd";
33
import { EyeFilled, LinkOutlined } from "@ant-design/icons";
44
import { useState } from "react";
5-
import { CodeEditor } from "react-formule";
5+
import { CodeViewer } from "react-formule";
66

77
const CAPDeposit = ({ data }) => {
88
const [showModal, setShowModal] = useState(false);
99

10-
console.log(JSON.stringify(data, null, 2));
11-
1210
return (
1311
<>
14-
<Modal open={showModal} onCancel={() => setShowModal(false)}>
15-
<CodeEditor
12+
<Modal
13+
open={showModal}
14+
onCancel={() => setShowModal(false)}
15+
footer={null}
16+
width={1000}
17+
>
18+
<CodeViewer
1619
lang="json"
17-
initialValue={JSON.stringify(data, null, 2)}
18-
lint="json"
19-
isEditable={false} // TODO: Change to !isEditable?
20+
value={JSON.stringify(data, null, 2)}
2021
height="calc(100vh - 325px)"
2122
/>
2223
</Modal>

ui/cap-react/src/antd/forms/formuleConfig.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import CernUsers from "./customFields/CernUsers";
55
import CapFiles from "./customFields/CapFiles";
66
import IdFetcher from "./customFields/IdFetcher";
77
import ImportDataField from "./customFields/ImportDataField";
8+
import SchemaPathSuggester from "./customFields/SchemaPathSuggester";
89

910
export const customFieldTypes = {
1011
advanced: {
@@ -93,7 +94,6 @@ export const customFieldTypes = {
9394
properties: {},
9495
},
9596
uiSchema: {
96-
"ui:serfvicesList": ["orcid", "ror", "zenodo"],
9797
"ui:servicesList": ["capDeposits"],
9898
"ui:field": "idFetcher",
9999
},
@@ -202,4 +202,5 @@ export const customFields = {
202202
CapFiles: CapFiles,
203203
idFetcher: IdFetcher,
204204
importData: ImportDataField,
205+
schemaPathSuggester: SchemaPathSuggester,
205206
};

ui/cap-react/src/antd/partials/JSONSchemaPreviewer/JSONSchemaPreviewer.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@ import { FormuleForm } from "react-formule";
22
import PropTypes from "prop-types";
33

44
const JSONSchemaPreviewer = ({
5-
isPublished,
65
schema,
76
uiSchema,
87
children,
98
display = "tabView",
109
onChange,
1110
onSubmit,
1211
formData,
13-
className,
1412
}) => {
1513
return (
1614
schema && (
1715
<FormuleForm
18-
className={className}
1916
schema={schema}
2017
showErrorList={false}
2118
uiSchema={{
@@ -30,11 +27,7 @@ const JSONSchemaPreviewer = ({
3027
onBlur={() => {}}
3128
onChange={onChange}
3229
onSubmit={onSubmit}
33-
formContext={{
34-
tabView: display === "tabView",
35-
readonlyPreview: true,
36-
isPublished: isPublished,
37-
}}
30+
isPublished
3831
>
3932
{children}
4033
</FormuleForm>

ui/cap-react/src/antd/published/components/Preview.js

-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ const Preview = ({
149149
schema={transformSchema(schemas.schema)}
150150
schemaType={schemaType}
151151
uiSchema={schemas.uiSchema}
152-
isPublished
153-
className={["__PublishedForm__"]}
154152
>
155153
<span />
156154
</JSONSchemaPreviewer>

ui/cap-react/src/reducers/builder.js

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Map, fromJS } from "immutable";
22

33
import {
44
UPDATE_SCHEMA_CONFIG,
5+
UPDATE_SCHEMA_INITIAL_CONFIG,
56
UPDATE_NOTIFICATION_BY_INDEX,
67
UPDATE_NOTIFICATIONS,
78
REMOVE_NOTIFICATION,
@@ -26,6 +27,8 @@ export default function schemaReducer(state = initialState, action) {
2627
return state.set("loading", action.value);
2728
case UPDATE_SCHEMA_CONFIG:
2829
return state.set("config", fromJS(action.config));
30+
case UPDATE_SCHEMA_INITIAL_CONFIG:
31+
return state.set("initialConfig", fromJS(action.config));
2932
case UPDATE_NOTIFICATION_BY_INDEX:
3033
return state.setIn(action.payload.path, action.payload.value);
3134
case UPDATE_NOTIFICATIONS:

ui/cap-react/src/style.less

-6
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,3 @@ body,
104104
border-radius: 2px;
105105
font-family: "Titillium Web";
106106
}
107-
108-
.__PublishedForm__ {
109-
textarea {
110-
resize: none;
111-
}
112-
}

ui/yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -14235,10 +14235,10 @@ react-floater@^0.7.9:
1423514235
prop-types "^15.8.1"
1423614236
tree-changes "^0.9.1"
1423714237

14238-
react-formule@1.2.1:
14239-
version "1.2.1"
14240-
resolved "https://registry.yarnpkg.com/react-formule/-/react-formule-1.2.1.tgz#2c48212abfd0ef9a526e71f289c30cc0e0fd710d"
14241-
integrity sha512-pSpadIfKQLgw64gIT9QD11p+jlJQjG1djWwE0qkXvnPLBWuIyJ98ys3Pnp0d4+lhMHGd9NV/SjS4iU6hllWnjg==
14238+
react-formule@1.3.0:
14239+
version "1.3.0"
14240+
resolved "https://registry.yarnpkg.com/react-formule/-/react-formule-1.3.0.tgz#7ee88d794716e828de28201c418cf324e71807c6"
14241+
integrity sha512-Evd4d4z8dTWCidgfy8WxDXp7Iw1WpSupMnWPDjJHFZvxdDT1fo0bQ64h4yhhYDEbwnebCjb9UhRtKQFRnDiIKg==
1424214242
dependencies:
1424314243
"@ant-design/pro-layout" "^7.16.4"
1424414244
"@codemirror/lang-json" "^6.0.1"

0 commit comments

Comments
 (0)