Skip to content

Commit

Permalink
ui: replace occurrences of moses with formule
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Garcia Garcia <miguel.garcia.garcia@cern.ch>
  • Loading branch information
miguelgrc committed Dec 1, 2023
1 parent 6b30800 commit cb3ca10
Show file tree
Hide file tree
Showing 20 changed files with 3,662 additions and 3,719 deletions.
2 changes: 1 addition & 1 deletion ui/cap-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"@vitejs/plugin-react": "^4.2.0",
"antd": "^5.4.2",
"axios": "0.27.2",
"cap-moses": "file:.yalc/cap-moses",
"classnames": "2.3.1",
"clean-deep": "3.3.0",
"codemirror": "6.0.1",
Expand All @@ -64,6 +63,7 @@
"query-string": "^5.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-formule": "file:.yalc/react-formule",
"react-input-mask": "3.0.0-alpha.2",
"react-joyride": "^2.5.4",
"react-markdown-editor-lite": "1.2.4",
Expand Down
26 changes: 13 additions & 13 deletions ui/cap-react/src/actions/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { fromJS } from "immutable";
import { push } from "connected-react-router";
import { notification } from "antd";
import { CMS, CMS_NEW } from "../antd/routes";
import { initMosesSchemaWithNotifications } from "../antd/admin/utils";
import { initFormuleSchemaWithNotifications } from "../antd/admin/utils";
import { updateDepositGroups } from "./auth";
import { getMosesState } from "cap-moses";
import { getFormuleState } from "react-formule";

export const SYNCHRONIZE_MOSES_STATE = "SYNCHRONIZE_MOSES_STATE";
export const SYNCHRONIZE_FORMULE_STATE = "SYNCHRONIZE_FORMULE_STATE";

export const SET_SCHEMA_LOADING = "SET_SCHEMA_LOADING";
export const UPDATE_SCHEMA_CONFIG = "UPDATE_SCHEMA_CONFIG";
Expand All @@ -18,8 +18,8 @@ export const UPDATE_NOTIFICATIONS = "UPDATE_NOTIFICATIONS";
export const REMOVE_NOTIFICATION = "REMOVE_NOTIFICATION";
export const CREATE_NOTIFICATION_GROUP = "CREATE_NOTIFICATION_GROUP";

export const synchronizeMosesState = value => ({
type: SYNCHRONIZE_MOSES_STATE,
export const synchronizeFormuleState = value => ({
type: SYNCHRONIZE_FORMULE_STATE,
value,
});

Expand Down Expand Up @@ -109,8 +109,8 @@ export const getSchema = (name, version = null) => {
let { deposit_schema, deposit_options } = schema;

if (deposit_schema && deposit_options) {
// The schemas are sent to be managed by moses but the config is kept in CAP (see function body)
initMosesSchemaWithNotifications(schema);
// The schemas are sent to be managed by formule but the config is kept in CAP (see function body)
initFormuleSchemaWithNotifications(schema);
dispatch(setSchemaLoading(false));
}
})
Expand All @@ -127,11 +127,11 @@ export const getSchema = (name, version = null) => {
export const saveSchemaChanges = () => (dispatch, getState) => {
const state = getState();
const config = state.builder.get("config");
const mosesState = getMosesState();
const formuleState = getFormuleState();
const pathname = state.router.location.pathname;
const sendData = {
deposit_schema: mosesState.current.schema,
deposit_options: mosesState.current.uiSchema,
deposit_schema: formuleState.current.schema,
deposit_options: formuleState.current.uiSchema,
...config.toJS(),
};

Expand All @@ -151,8 +151,8 @@ export const saveSchemaChanges = () => (dispatch, getState) => {

// check whether there are changes to the deposit schema
const isSchemaUpdated = !isEqual(
mosesState.current.schema,
mosesState.initial.schema
formuleState.current.schema,
formuleState.initial.schema
);
// check whether there are changes to the config object
const isConfigVersionUpdated =
Expand All @@ -170,7 +170,7 @@ export const saveSchemaChanges = () => (dispatch, getState) => {
return axios
.post("/api/jsonschemas", sendData)
.then(res => {
initMosesSchemaWithNotifications(res.data);
initFormuleSchemaWithNotifications(res.data);
notification.success({
message: "New schema created",
description: "schema successfully created",
Expand Down
16 changes: 8 additions & 8 deletions ui/cap-react/src/antd/App/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import useTrackPageViews from "../hooks/useTrackPageViews";
import { lazy } from "react";
import Loading from "../routes/Loading/Loading";
import MessageBanner from "../partials/MessageBanner";
import { MosesContext } from "cap-moses";
import { FormuleContext } from "react-formule";
import { theme } from "../utils/theme";
import { customFieldTypes, customFields } from "../forms/mosesConfig";
import { customFieldTypes, customFields } from "../forms/formuleConfig";
import { isEmpty } from "lodash-es";
import { transformSchema } from "../partials/Utils/schema";

Expand All @@ -37,7 +37,7 @@ const App = ({
loadingInit,
history,
roles,
synchronizeMosesState,
synchronizeFormuleState,
formDataChange,
}) => {
useEffect(() => {
Expand All @@ -46,8 +46,8 @@ const App = ({

useTrackPageViews(history.location.pathname);

const handleMosesStateChange = newState => {
synchronizeMosesState(newState);
const handleFormuleStateChange = newState => {
synchronizeFormuleState(newState);
const newFormData = { ...newState.formData };
if (!isEmpty(newFormData)) {
formDataChange(newFormData);
Expand Down Expand Up @@ -81,8 +81,8 @@ const App = ({
</Layout.Header>
<Layout.Content className="__mainContent__">
<Suspense fallback={<Loading pastDelay />}>
<MosesContext
synchronizeState={handleMosesStateChange}
<FormuleContext
synchronizeState={handleFormuleStateChange}
theme={theme}
customFieldTypes={customFieldTypes}
customFields={customFields}
Expand All @@ -98,7 +98,7 @@ const App = ({
{isAdmin && <Route path={CMS} component={AdminPage} />}
<Route path={HOME} component={requireAuth(IndexPage)} />
</Switch>
</MosesContext>
</FormuleContext>
</Suspense>
</Layout.Content>
<Layout.Footer>
Expand Down
5 changes: 3 additions & 2 deletions ui/cap-react/src/antd/App/AppContainer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { initCurrentUser } from "../../actions/auth";
import { synchronizeMosesState } from "../../actions/builder";
import { synchronizeFormuleState } from "../../actions/builder";
import { formDataChange } from "../../actions/draftItem";
import App from "./App";
import { connect } from "react-redux";
Expand All @@ -12,7 +12,8 @@ const mapStateToProps = state => ({

const mapDispatchToProps = dispatch => ({
initCurrentUser: next => dispatch(initCurrentUser(next)),
synchronizeMosesState: newState => dispatch(synchronizeMosesState(newState)),
synchronizeFormuleState: newState =>
dispatch(synchronizeFormuleState(newState)),
formDataChange: newFormData => dispatch(formDataChange(newFormData)),
});

Expand Down
10 changes: 5 additions & 5 deletions ui/cap-react/src/antd/admin/components/AdminPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import { CarOutlined } from "@ant-design/icons";
import useStickyState from "../../hooks/useStickyState";
import { PRIMARY_COLOR } from "../../utils/theme";
import { isEmpty } from "lodash-es";
import { initMosesSchemaWithNotifications } from "../utils";
import { initFormuleSchemaWithNotifications } from "../utils";

const AdminPanel = ({ location, match, getSchema, loading, mosesState }) => {
const AdminPanel = ({ location, match, getSchema, loading, formuleState }) => {
useEffect(() => {
let { schema_name, schema_version } = match.params;

if (schema_name == "new") {
// If the schema hasn't been initialized yet (i.e. the user has navigated directly to /new), initialize it
if (isEmpty(mosesState?.current?.schema)) {
initMosesSchemaWithNotifications();
if (isEmpty(formuleState?.current?.schema)) {
initFormuleSchemaWithNotifications();
}
// Otherwise do nothing as it means it's been already initialized in CreateForm or DropDownBox
} else {
Expand Down Expand Up @@ -69,7 +69,7 @@ const AdminPanel = ({ location, match, getSchema, loading, mosesState }) => {
<Notifications />
) : (
<SchemaWizard
loading={isEmpty(mosesState?.current?.schema) || loading}
loading={isEmpty(formuleState?.current?.schema) || loading}
/>
)}
<FloatButton
Expand Down
4 changes: 2 additions & 2 deletions ui/cap-react/src/antd/admin/components/CreateForm.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Button, Form, Input } from "antd";
import { CMS_NEW } from "../../routes";
import { withRouter } from "react-router";
import { initMosesSchemaWithNotifications } from "../utils";
import { initFormuleSchemaWithNotifications } from "../utils";

const CreateForm = ({ history }) => {
const onFinish = content => {
let { name, description } = content;
const config = { config: { fullname: name } };
initMosesSchemaWithNotifications({ config }, name, description);
initFormuleSchemaWithNotifications({ config }, name, description);
history.push(CMS_NEW);
};

Expand Down
4 changes: 2 additions & 2 deletions ui/cap-react/src/antd/admin/components/DropZoneForm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { notification, Upload } from "antd";
import { InboxOutlined } from "@ant-design/icons";
import { initMosesSchemaWithNotifications } from "../utils";
import { initFormuleSchemaWithNotifications } from "../utils";
import { CMS_NEW } from "../../routes";
import { withRouter } from "react-router";

Expand All @@ -27,7 +27,7 @@ const DropZoneForm = ({ history }) => {
reader.onload = function (event) {
const newSchema = JSON.parse(event.target.result);
if (newSchema["deposit_schema"] && newSchema["deposit_options"]) {
initMosesSchemaWithNotifications(newSchema);
initFormuleSchemaWithNotifications(newSchema);
history.push(CMS_NEW);
} else {
notification.error({
Expand Down
26 changes: 13 additions & 13 deletions ui/cap-react/src/antd/admin/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ import { configSchema } from "../utils/schemaSettings";
import CodeViewer from "../../utils/CodeViewer";
import { json } from "@codemirror/lang-json";
import CodeDiffViewer from "../../utils/CodeDiffViewer";
import { MosesForm } from "cap-moses";
import { FormuleForm } from "react-formule";

const { useBreakpoint } = Grid;
const Header = ({
config,
pushPath,
saveSchemaChanges,
mosesState,
formuleState,
updateSchemaConfig,
display,
setDisplay,
Expand All @@ -48,14 +48,14 @@ const Header = ({
maxHeight: "calc(100vh - 300px)",
};

const mosesCurrentSchema = mosesState?.current?.schema;
const mosesCurrentUiSchema = mosesState?.current?.uiSchema;
const formuleCurrentSchema = formuleState?.current?.schema;
const formuleCurrentUiSchema = formuleState?.current?.uiSchema;

const _getSchema = () => {
const fileData = JSON.stringify(
{
deposit_schema: mosesCurrentSchema,
deposit_options: mosesCurrentUiSchema,
deposit_schema: formuleCurrentSchema,
deposit_options: formuleCurrentUiSchema,
...config.toJS(),
},
null,
Expand All @@ -72,30 +72,30 @@ const Header = ({
let previews = {
uiSchema: (
<CodeViewer
value={JSON.stringify(mosesCurrentUiSchema, null, 2)}
value={JSON.stringify(formuleCurrentUiSchema, null, 2)}
lang={json}
height="100%"
/>
),
schema: (
<CodeViewer
value={JSON.stringify(mosesCurrentSchema, null, 2)}
value={JSON.stringify(formuleCurrentSchema, null, 2)}
lang={json}
height="100%"
/>
),
uiSchemaDiff: (
<CodeDiffViewer
left={JSON.stringify(mosesState?.initial?.uiSchema, null, 2)}
right={JSON.stringify(mosesCurrentUiSchema, null, 2)}
left={JSON.stringify(formuleState?.initial?.uiSchema, null, 2)}
right={JSON.stringify(formuleCurrentUiSchema, null, 2)}
lang={json}
height="100%"
/>
),
schemaDiff: (
<CodeDiffViewer
left={JSON.stringify(mosesState?.initial?.schema, null, 2)}
right={JSON.stringify(mosesCurrentSchema, null, 2)}
left={JSON.stringify(formuleState?.initial?.schema, null, 2)}
right={JSON.stringify(formuleCurrentSchema, null, 2)}
lang={json}
height="100%"
/>
Expand Down Expand Up @@ -167,7 +167,7 @@ const Header = ({
onClick: () => setSettingsModal(false),
}}
>
<MosesForm
<FormuleForm
{...configSchema}
formData={config.toJS()}
onChange={data => updateSchemaConfig(data.formData)}
Expand Down
2 changes: 1 addition & 1 deletion ui/cap-react/src/antd/admin/components/SchemaWizard.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PropTypes from "prop-types";
import { Col, Row, Spin } from "antd";
import { FormPreview, SchemaPreview, SelectOrEdit } from "cap-moses";
import { FormPreview, SchemaPreview, SelectOrEdit } from "react-formule";

const SchemaWizard = ({ loading }) => {
if (loading)
Expand Down
2 changes: 1 addition & 1 deletion ui/cap-react/src/antd/admin/containers/AdminPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getSchema } from "../../../actions/builder";

const mapStateToProps = state => ({
loading: state.builder.get("loading"),
mosesState: state.builder.get("mosesState"),
formuleState: state.builder.get("formuleState"),
});

const mapDispatchToProps = dispatch => ({
Expand Down
2 changes: 1 addition & 1 deletion ui/cap-react/src/antd/admin/containers/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function mapStateToProps(state) {
return {
config: state.builder.get("config"),
pathname: state.router.location.pathname,
mosesState: state.builder.get("mosesState"),
formuleState: state.builder.get("formuleState"),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Button, Col, Popconfirm, Row } from "antd";
import { PageHeader } from "@ant-design/pro-layout";
import { schema, uiSchema } from "../utils";
import { DeleteOutlined } from "@ant-design/icons";
import { MosesForm } from "cap-moses";
import { FormuleForm } from "react-formule";
const NotificationEdit = ({
schemaConfig,
removeNotification,
Expand Down Expand Up @@ -42,7 +42,7 @@ const NotificationEdit = ({
/>
<Row justify="center">
<Col span={12}>
<MosesForm
<FormuleForm
schema={schema}
uiSchema={uiSchema}
onChange={({ formData }) =>
Expand Down
6 changes: 3 additions & 3 deletions ui/cap-react/src/antd/admin/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { initMosesSchema } from "cap-moses";
import { initFormuleSchema } from "react-formule";
import { merge } from "lodash-es";
import store from "../../../store/configureStore";
import { updateSchemaConfig } from "../../../actions/builder";
Expand Down Expand Up @@ -31,13 +31,13 @@ export const slugify = text => {
.replace(/-+$/, ""); // Trim - from end of text
};

export const initMosesSchemaWithNotifications = (
export const initFormuleSchemaWithNotifications = (
data = {},
name,
description
) => {
data.config = merge(data.config || {}, NOTIFICATIONS);
initMosesSchema(data, name, description);
initFormuleSchema(data, name, description);
/* eslint no-unused-vars: ["error", { "ignoreRestSiblings": true }]*/
const { deposit_schema, deposit_options, ...configs } = data;
store.dispatch(updateSchemaConfig(configs));
Expand Down
4 changes: 2 additions & 2 deletions ui/cap-react/src/antd/drafts/components/Editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Error from "../../../partials/Error/";
import { transformSchema } from "../../../partials/Utils/schema";
import Header from "../../containers/EditorHeader";
import { canEdit } from "../../utils/permissions";
import { MosesForm } from "cap-moses";
import { FormuleForm } from "react-formule";

const Editor = ({
schemaErrors,
Expand All @@ -32,7 +32,7 @@ const Editor = ({
<Layout style={{ height: "100%", padding: 0 }}>
<Header formRef={formRef} mode={mode} updateMode={setMode} />
<Layout.Content style={{ height: "100%", overflowX: "hidden" }}>
<MosesForm
<FormuleForm
formData={formData || {}}
formRef={formRef}
schema={_schema}
Expand Down
Loading

0 comments on commit cb3ca10

Please sign in to comment.