From 4b5cd79591d8fc6483578e6a3ac4dea32ab3de3c Mon Sep 17 00:00:00 2001 From: Julian Date: Fri, 30 Jun 2023 15:00:33 -0400 Subject: [PATCH 01/10] Added fetching action for extra schema types --- src/modules/metadata/actions.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/modules/metadata/actions.js b/src/modules/metadata/actions.js index ccc37bc54..acfd45674 100644 --- a/src/modules/metadata/actions.js +++ b/src/modules/metadata/actions.js @@ -31,6 +31,7 @@ export const CREATE_PROJECT = createNetworkActionTypes("CREATE_PROJECT"); export const DELETE_PROJECT = createNetworkActionTypes("DELETE_PROJECT"); export const SAVE_PROJECT = createNetworkActionTypes("SAVE_PROJECT"); +export const FETCH_EXTRA_PROPERTIES_SCHEMA_TYPES = createNetworkActionTypes("FETCH_EXTRA_PROPERTIES_SCHEMA_TYPES"); export const CREATE_PROJECT_JSON_SCHEMA = createNetworkActionTypes("CREATE_PROJECT_JSON_SCHEMA"); export const DELETE_PROJECT_JSON_SCHEMA = createNetworkActionTypes("DELETE_PROJECT_JSON_SCHEMA"); @@ -103,6 +104,13 @@ export const createProjectIfPossible = (project, history) => (dispatch, getState }; +export const fetchExtraPropertiesSchemaTypes = networkAction(() => (dispatch, getState) => ({ + types: FETCH_EXTRA_PROPERTIES_SCHEMA_TYPES, + url: `${getState().services.metadataService.url}/api/extra_properties_schema_types`, + error: "Error fetching extra properties schema types", +})); + + const createProjectJsonSchema = networkAction(projectJsonSchema => (dispatch, getState) => ({ types: CREATE_PROJECT_JSON_SCHEMA, url: `${getState().services.metadataService.url}/api/project_json_schemas`, From 56c180ff6b796aa3bad666c37fa8c6327f9dca7f Mon Sep 17 00:00:00 2001 From: Julian Date: Fri, 30 Jun 2023 15:02:35 -0400 Subject: [PATCH 02/10] Implement fetching of extra property schema types --- src/modules/metadata/reducers.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/modules/metadata/reducers.js b/src/modules/metadata/reducers.js index d4b3be512..cd30c4771 100644 --- a/src/modules/metadata/reducers.js +++ b/src/modules/metadata/reducers.js @@ -9,6 +9,7 @@ import { DELETE_PROJECT, SAVE_PROJECT, + FETCH_EXTRA_PROPERTIES_SCHEMA_TYPES, ADD_PROJECT_DATASET, SAVE_PROJECT_DATASET, DELETE_PROJECT_DATASET, @@ -42,6 +43,7 @@ export const projects = ( isSavingDataset: false, isDeletingDataset: false, + extraPropertiesSchemaTypes: {}, isCreatingJsonSchema: false, isDeletingJsonSchema: false, @@ -203,6 +205,14 @@ export const projects = ( case DELETE_PROJECT_DATASET.FINISH: return {...state, isDeletingDataset: false}; + // FETCH_EXTRA_PROPERTIES_SCHEMA_TYPES + case FETCH_EXTRA_PROPERTIES_SCHEMA_TYPES.REQUEST: + return {...state, isFetchingExtraPropertiesSchemaInfo: true}; + case FETCH_EXTRA_PROPERTIES_SCHEMA_TYPES.RECEIVE: + return {...state, extraPropertiesSchemaTypes: action.data}; + case FETCH_EXTRA_PROPERTIES_SCHEMA_TYPES.FINISH: + return {...state, isFetchingExtraPropertiesSchemaInfo: false}; + // CREATE_PROJECT_JSON_SCHEMA case CREATE_PROJECT_JSON_SCHEMA.REQUEST: return {...state, isCreatingJsonSchema: true}; From 18b6a68819529d92e8460d5f7e2bacdcd7233bc8 Mon Sep 17 00:00:00 2001 From: Julian Date: Fri, 30 Jun 2023 15:06:26 -0400 Subject: [PATCH 03/10] Mapping of schema types to selection options in form --- .../manager/projects/ProjectJsonSchemaForm.js | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/components/manager/projects/ProjectJsonSchemaForm.js b/src/components/manager/projects/ProjectJsonSchemaForm.js index cbb0d5804..870bf697b 100644 --- a/src/components/manager/projects/ProjectJsonSchemaForm.js +++ b/src/components/manager/projects/ProjectJsonSchemaForm.js @@ -14,6 +14,18 @@ const ajv = new Ajv({ // Does not actually query over http, the URI is the key to the draft-07 meta-schema const validateSchema = ajv.getSchema("http://json-schema.org/draft-07/schema"); +const getSchemaTypeOptions = (schemaTypes) => { + if (schemaTypes instanceof Object) { + return Object.entries(schemaTypes).map(([key, value]) => ({ + key, + value: key, + text: value.toUpperCase(), + })); + } else { + return []; + } +}; + const ProjectJsonSchemaForm = ({ style, schemaTypes, initialValues, setFileContent, fileContent, form }) => { const onDrop = useCallback((files) => { @@ -56,9 +68,9 @@ const ProjectJsonSchemaForm = ({ style, schemaTypes, initialValues, setFileConte rules: [{ required: true }], })( , @@ -110,7 +122,7 @@ const JSON_SCHEMA_FORM_SHAPE = PropTypes.shape({ ProjectJsonSchemaForm.propTypes = { style: PropTypes.object, - schemaTypes: PropTypes.arrayOf(PropTypes.string).isRequired, + schemaTypes: PropTypes.objectOf(PropTypes.string).isRequired, initialValues: JSON_SCHEMA_FORM_SHAPE, formValues: JSON_SCHEMA_FORM_SHAPE, fileContent: PropTypes.object, From eb432fe6a3cf9c6e0ec04bb337f8c9f7bacf0277 Mon Sep 17 00:00:00 2001 From: Julian Date: Fri, 30 Jun 2023 15:11:38 -0400 Subject: [PATCH 04/10] Pass extra property schema types as component prop --- .../manager/projects/ProjectJsonSchemaModal.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/manager/projects/ProjectJsonSchemaModal.js b/src/components/manager/projects/ProjectJsonSchemaModal.js index 8c221512f..751da0c5d 100644 --- a/src/components/manager/projects/ProjectJsonSchemaModal.js +++ b/src/components/manager/projects/ProjectJsonSchemaModal.js @@ -7,6 +7,7 @@ import PropTypes from "prop-types"; const ProjectJsonSchemaModal = ({projectId, visible, onOk, onCancel}) => { const dispatch = useDispatch(); + const extraPropertiesSchemaTypes = useSelector((state) => state.projects.extraPropertiesSchemaTypes); const isCreatingJsonSchema = useSelector((state) => state.projects.isCreatingJsonSchema); const [inputFormFields, setInputFormFields] = useState({}); const [fileContent, setFileContent] = useState(null); @@ -46,11 +47,14 @@ const ProjectJsonSchemaModal = ({projectId, visible, onOk, onCancel}) => { icon="plus" type="primary" onClick={handleCreateSubmit} - loading={isCreatingJsonSchema}>Create, + loading={isCreatingJsonSchema} + disabled={!extraPropertiesSchemaTypes || Object.keys( + extraPropertiesSchemaTypes).length === 0} + >Create, ]} > Date: Fri, 30 Jun 2023 15:14:16 -0400 Subject: [PATCH 05/10] Include schemaTypes in user data fetch --- src/modules/auth/actions.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modules/auth/actions.js b/src/modules/auth/actions.js index 771543694..7c680e9b6 100644 --- a/src/modules/auth/actions.js +++ b/src/modules/auth/actions.js @@ -14,6 +14,7 @@ import { fetchDropBoxTreeOrFail } from "../manager/actions"; import { fetchProjectsWithDatasetsAndTables, fetchOverviewSummary, + fetchExtraPropertiesSchemaTypes, } from "../metadata/actions"; import { fetchNotifications } from "../notifications/actions"; import { fetchServicesWithMetadataAndDataTypesAndTablesIfNeeded } from "../services/actions"; @@ -35,6 +36,7 @@ export const fetchServiceDependentData = () => dispatch => Promise.all([ fetchNotifications, fetchOverviewSummary, performGetGohanVariantsOverviewIfPossible, + fetchExtraPropertiesSchemaTypes, ].map(a => dispatch(a()))); export const fetchUserDependentData = (servicesCb) => async (dispatch, getState) => { From 283516e519a08026ec2ae8ee52a637a2a8c50bdd Mon Sep 17 00:00:00 2001 From: Julian Date: Thu, 10 Aug 2023 11:10:59 -0400 Subject: [PATCH 06/10] Handle non-object input in getSchemaTypeOptions --- src/components/manager/projects/ProjectJsonSchemaForm.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/manager/projects/ProjectJsonSchemaForm.js b/src/components/manager/projects/ProjectJsonSchemaForm.js index 870bf697b..f03565c9d 100644 --- a/src/components/manager/projects/ProjectJsonSchemaForm.js +++ b/src/components/manager/projects/ProjectJsonSchemaForm.js @@ -15,7 +15,7 @@ const ajv = new Ajv({ const validateSchema = ajv.getSchema("http://json-schema.org/draft-07/schema"); const getSchemaTypeOptions = (schemaTypes) => { - if (schemaTypes instanceof Object) { + if (typeof schemaTypes === "object" && schemaTypes !== null) { return Object.entries(schemaTypes).map(([key, value]) => ({ key, value: key, From 00a0d04599bb5b16f45e8ac1b5caf60e9c3acbc9 Mon Sep 17 00:00:00 2001 From: Julian Date: Thu, 10 Aug 2023 11:11:37 -0400 Subject: [PATCH 07/10] minor refactor --- src/modules/metadata/reducers.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/modules/metadata/reducers.js b/src/modules/metadata/reducers.js index cd30c4771..052e33a27 100644 --- a/src/modules/metadata/reducers.js +++ b/src/modules/metadata/reducers.js @@ -9,7 +9,6 @@ import { DELETE_PROJECT, SAVE_PROJECT, - FETCH_EXTRA_PROPERTIES_SCHEMA_TYPES, ADD_PROJECT_DATASET, SAVE_PROJECT_DATASET, DELETE_PROJECT_DATASET, @@ -25,6 +24,8 @@ import { FETCH_OVERVIEW_SUMMARY, + FETCH_EXTRA_PROPERTIES_SCHEMA_TYPES, + CREATE_PROJECT_JSON_SCHEMA, DELETE_PROJECT_JSON_SCHEMA, } from "./actions"; @@ -44,6 +45,7 @@ export const projects = ( isDeletingDataset: false, extraPropertiesSchemaTypes: {}, + isFetchingExtraPropertiesSchemaInfo: false, isCreatingJsonSchema: false, isDeletingJsonSchema: false, From c5eca88d1f3627ed9aacdc278cb720b7afb6286f Mon Sep 17 00:00:00 2001 From: Julian Date: Wed, 16 Aug 2023 11:12:28 -0400 Subject: [PATCH 08/10] Remove extraPropertiesSchemaTypes from propTypes --- src/components/manager/projects/ProjectJsonSchemaModal.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/manager/projects/ProjectJsonSchemaModal.js b/src/components/manager/projects/ProjectJsonSchemaModal.js index 751da0c5d..a09aa64bc 100644 --- a/src/components/manager/projects/ProjectJsonSchemaModal.js +++ b/src/components/manager/projects/ProjectJsonSchemaModal.js @@ -71,7 +71,6 @@ ProjectJsonSchemaModal.propTypes = { onOk: PropTypes.func, onCancel: PropTypes.func, - extraPropertiesSchemaTypes: PropTypes.object.isRequired, }; export default ProjectJsonSchemaModal; From fbdba34e258825b9ef6fbc40560621394d2ca9bd Mon Sep 17 00:00:00 2001 From: Julian Date: Thu, 17 Aug 2023 11:02:39 -0400 Subject: [PATCH 09/10] Rename state variable --- src/modules/metadata/reducers.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/metadata/reducers.js b/src/modules/metadata/reducers.js index 052e33a27..b24d4930b 100644 --- a/src/modules/metadata/reducers.js +++ b/src/modules/metadata/reducers.js @@ -45,7 +45,7 @@ export const projects = ( isDeletingDataset: false, extraPropertiesSchemaTypes: {}, - isFetchingExtraPropertiesSchemaInfo: false, + isFetchingExtraPropertiesSchemaTypes: false, isCreatingJsonSchema: false, isDeletingJsonSchema: false, @@ -209,11 +209,11 @@ export const projects = ( // FETCH_EXTRA_PROPERTIES_SCHEMA_TYPES case FETCH_EXTRA_PROPERTIES_SCHEMA_TYPES.REQUEST: - return {...state, isFetchingExtraPropertiesSchemaInfo: true}; + return {...state, isFetchingExtraPropertiesSchemaTypes: true}; case FETCH_EXTRA_PROPERTIES_SCHEMA_TYPES.RECEIVE: return {...state, extraPropertiesSchemaTypes: action.data}; case FETCH_EXTRA_PROPERTIES_SCHEMA_TYPES.FINISH: - return {...state, isFetchingExtraPropertiesSchemaInfo: false}; + return {...state, isFetchingExtraPropertiesSchemaTypes: false}; // CREATE_PROJECT_JSON_SCHEMA case CREATE_PROJECT_JSON_SCHEMA.REQUEST: From 81f7f8686c6cb80395f941dfdef333fcca7d0075 Mon Sep 17 00:00:00 2001 From: Julian Date: Thu, 17 Aug 2023 11:09:58 -0400 Subject: [PATCH 10/10] Add extraProperties SchemaTypes selector with loading state --- src/components/manager/projects/ProjectJsonSchemaModal.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/manager/projects/ProjectJsonSchemaModal.js b/src/components/manager/projects/ProjectJsonSchemaModal.js index a09aa64bc..906fb2099 100644 --- a/src/components/manager/projects/ProjectJsonSchemaModal.js +++ b/src/components/manager/projects/ProjectJsonSchemaModal.js @@ -7,6 +7,8 @@ import PropTypes from "prop-types"; const ProjectJsonSchemaModal = ({projectId, visible, onOk, onCancel}) => { const dispatch = useDispatch(); + const isFetchingExtraPropertiesSchemaTypes = useSelector((state) => + state.projects.isFetchingExtraPropertiesSchemaTypes); const extraPropertiesSchemaTypes = useSelector((state) => state.projects.extraPropertiesSchemaTypes); const isCreatingJsonSchema = useSelector((state) => state.projects.isCreatingJsonSchema); const [inputFormFields, setInputFormFields] = useState({}); @@ -47,7 +49,7 @@ const ProjectJsonSchemaModal = ({projectId, visible, onOk, onCancel}) => { icon="plus" type="primary" onClick={handleCreateSubmit} - loading={isCreatingJsonSchema} + loading={isCreatingJsonSchema || isFetchingExtraPropertiesSchemaTypes} disabled={!extraPropertiesSchemaTypes || Object.keys( extraPropertiesSchemaTypes).length === 0} >Create,