Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fetch extra_properties types dynamically from Katsu #266

Merged
merged 10 commits into from
Aug 17, 2023
20 changes: 16 additions & 4 deletions src/components/manager/projects/ProjectJsonSchemaForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (typeof schemaTypes === "object" && schemaTypes !== null) {
return Object.entries(schemaTypes).map(([key, value]) => ({
key,
value: key,
text: value.toUpperCase(),
}));
} else {
return [];
noctillion marked this conversation as resolved.
Show resolved Hide resolved
}
};

const ProjectJsonSchemaForm = ({ style, schemaTypes, initialValues, setFileContent, fileContent, form }) => {

const onDrop = useCallback((files) => {
Expand Down Expand Up @@ -56,9 +68,9 @@ const ProjectJsonSchemaForm = ({ style, schemaTypes, initialValues, setFileConte
rules: [{ required: true }],
})(
<Select>
{schemaTypes.map(option => (
<Select.Option key={option} value={option}>
{option}
{getSchemaTypeOptions(schemaTypes).map((option) => (
<Select.Option key={option.key} value={option.value}>
{option.text}
</Select.Option>
))}
</Select>,
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 8 additions & 2 deletions src/components/manager/projects/ProjectJsonSchemaModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ 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({});
const [fileContent, setFileContent] = useState(null);
Expand Down Expand Up @@ -46,11 +49,14 @@ const ProjectJsonSchemaModal = ({projectId, visible, onOk, onCancel}) => {
icon="plus"
type="primary"
onClick={handleCreateSubmit}
loading={isCreatingJsonSchema}>Create</Button>,
loading={isCreatingJsonSchema || isFetchingExtraPropertiesSchemaTypes}
disabled={!extraPropertiesSchemaTypes || Object.keys(
extraPropertiesSchemaTypes).length === 0}
>Create</Button>,
]}
>
<ProjectJsonSchemaForm
schemaTypes={["PHENOPACKET", "BIOSAMPLE", "INDIVIDUAL"]}
schemaTypes={extraPropertiesSchemaTypes || {}}
initialValues={{}}
formValues={inputFormFields}
onChange={setInputFormFields}
Expand Down
2 changes: 2 additions & 0 deletions src/modules/auth/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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) => {
Expand Down
8 changes: 8 additions & 0 deletions src/modules/metadata/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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`,
Expand Down
12 changes: 12 additions & 0 deletions src/modules/metadata/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {

FETCH_OVERVIEW_SUMMARY,

FETCH_EXTRA_PROPERTIES_SCHEMA_TYPES,

CREATE_PROJECT_JSON_SCHEMA,
DELETE_PROJECT_JSON_SCHEMA,
} from "./actions";
Expand All @@ -42,6 +44,8 @@ export const projects = (
isSavingDataset: false,
isDeletingDataset: false,

extraPropertiesSchemaTypes: {},
noctillion marked this conversation as resolved.
Show resolved Hide resolved
isFetchingExtraPropertiesSchemaTypes: false,
isCreatingJsonSchema: false,
isDeletingJsonSchema: false,

Expand Down Expand Up @@ -203,6 +207,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, isFetchingExtraPropertiesSchemaTypes: true};
case FETCH_EXTRA_PROPERTIES_SCHEMA_TYPES.RECEIVE:
return {...state, extraPropertiesSchemaTypes: action.data};
case FETCH_EXTRA_PROPERTIES_SCHEMA_TYPES.FINISH:
return {...state, isFetchingExtraPropertiesSchemaTypes: false};

// CREATE_PROJECT_JSON_SCHEMA
case CREATE_PROJECT_JSON_SCHEMA.REQUEST:
return {...state, isCreatingJsonSchema: true};
Expand Down