Skip to content

Commit

Permalink
Merge pull request #33 from anti-mony/Patch/+v0.0.1
Browse files Browse the repository at this point in the history
Patch/+v0.0.1
  • Loading branch information
mgovoni-devel authored Nov 14, 2020
2 parents 8dc28ec + 05a6355 commit c7d299b
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 458 deletions.
2 changes: 1 addition & 1 deletion backend/project/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@
"pattern": "^(.*)$"
}
},
"required": ["firstName", "lastName"]
"required": ["firstName", "lastName", "emailId"]
},
"notebookFile": {
"$id": "#/properties/info/properties/notebookFile",
Expand Down
41 changes: 41 additions & 0 deletions frontend/Utils/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,49 @@ const convertStatetoReqSchema = (state, servers) => {
return schema;
};

const convertReqSchematoState = (req) => {
const { journal, year, page, volume } = req.reference;
const publication = referenceUtil.set(journal, year, page, volume);

const state = {
curatorInfo: { ...req.info.insertedBy },
fileServerPath: req.info.fileServerPath,
paperInfo: {
PIs: namesUtil.set(req.PIs),
collections: req.collections,
tags: req.tags,
notebookFile: req.info.notebookFile,
notebookPath: req.info.notebookPath,
},
referenceInfo: {
kind: req.reference.kind,
doi: req.reference.DOI,
authors: namesUtil.set(req.reference.authors),
title: req.reference.title,
publication: publication,
year: year,
url: req.reference.URLs,
abstract: req.reference.publishedAbstract,
},
documentation: req.documentation.readme,
charts: req.charts,
tools: req.tools,
datasets: req.datasets,
scripts: req.scripts,
heads: req.heads,
workflow: {
...req.workflow,
edges: req.workflow.edges.map((edge) => ({ from: edge[0], to: edge[1] })),
},
license: req.license || "",
};

return state;
};

export {
convertViewSchemaToState,
convertStateToViewSchema,
convertStatetoReqSchema,
convertReqSchematoState,
};
4 changes: 3 additions & 1 deletion frontend/Utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const getServer = () => {

const namesUtil = {
get: (names) => {
names = names.trim();
if (names.length == 0) {
return [{ firstName: "", middleName: "", lastName: "" }];
}
Expand All @@ -35,7 +36,8 @@ const namesUtil = {
const result = names.map((name) => {
const n = [];
Object.keys(name).forEach((key) => {
n.push(name[key].trim());
let tmp = name[key] || "";
n.push(tmp.trim());
});
return n.join(" ");
});
Expand Down
8 changes: 5 additions & 3 deletions frontend/components/CuratorElements/TopActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import {

import { GetApp, Visibility } from "@material-ui/icons";

// import Ajv from "ajv";
// import schema from "../../Context/schema";
import axios from "axios";

import { useRouter } from "next/router";
Expand All @@ -26,10 +24,12 @@ import { RegularStyledButton } from "../button";

import CuratorContext from "../../Context/Curator/curatorContext";
import AlertContext from "../../Context/Alert/alertContext";
import ServerContext from "../../Context/Servers/serverContext";

const TopActions = () => {
const { metadata, setAll, resetAll } = useContext(CuratorContext);
const { setAlert } = useContext(AlertContext);
const { setSelectedHttp, selectedHttp } = useContext(ServerContext);
const [mdata, setMdata] = useState("");
const [resumeDialogOpen, setResumeDialogOpen] = useState(false);

Expand All @@ -40,7 +40,7 @@ const TopActions = () => {
setResumeDialogOpen(true);
},
download: (metadata) => {
return metadata;
return { ...metadata, selectedHttp: selectedHttp };
},
preview: (e) => {
e.preventDefault();
Expand Down Expand Up @@ -119,6 +119,8 @@ const TopActions = () => {
const useMetadata = () => {
try {
const values = JSON.parse(mdata);
setSelectedHttp(values.selectedHttp);
delete values.selectedHttp;
setAll(values);
setResumeDialogOpen(false);
} catch (e) {
Expand Down
123 changes: 11 additions & 112 deletions frontend/components/CuratorForms/ChartsInfoForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,13 @@ import {
DialogContent,
DialogTitle,
} from "@material-ui/core";
import {
AddCircleOutline,
RemoveCircleOutline,
DescriptionOutlined,
} from "@material-ui/icons";
import { AddCircleOutline, DescriptionOutlined } from "@material-ui/icons";

import { TextInputField } from "../Form/InputFields";
import TextInput from "../Form/TextInput";
import { FormInputLabel } from "../Form/Util";
import ExtraFieldInput from "../Form/ExtraFieldInput";
import { RegularStyledButton } from "../button";

import { useForm, useFieldArray } from "react-hook-form";
import { useForm } from "react-hook-form";
import { yupResolver } from "@hookform/resolvers";
import * as Yup from "yup";

Expand Down Expand Up @@ -60,16 +55,12 @@ const ChartsInfoForm = () => {
resolver: yupResolver(schema),
});

const { fields, append, remove } = useFieldArray({
control,
name: "extraFields",
});

const onSubmit = (values) => {
values.properties = values.properties.split(",").map((el) => el.trim());
values.files = values.files.split(",").map((el) => el.trim());
const extraFields = values.extraFields ? values.extraFields : [];
if (def && charts.find((el) => el.id == def.id)) {
edit("chart", { ...def, ...values });
edit("chart", { ...def, ...values, extraFields: extraFields });
} else {
values["id"] = `c${charts.length}`;
add("chart", values);
Expand Down Expand Up @@ -240,104 +231,12 @@ const ChartsInfoForm = () => {
/>
</Grid>
<Grid item>
<Grid
container
justify="flex-start"
alignItems="center"
spacing={2}
>
<Grid item>
<FormInputLabel label="Extra Fields" forId="pis" />
</Grid>
<Grid item>
<Tooltip
title={
<Typography variant="subtitle2">
Add a new custom field
</Typography>
}
placement="right"
arrow
>
<IconButton
onClick={() =>
append({
label: "",
value: "",
})
}
style={{ padding: 0 }}
>
<AddCircleOutline color="primary" />
</IconButton>
</Tooltip>
</Grid>
</Grid>
{fields.map((field, index) => (
<Grid
container
spacing={4}
key={field.id}
alignItems="center"
>
<Grid item xs={12} sm={5}>
<TextInput
InputLabelProps={{ shrink: true }}
id={`customLabel${index}`}
placeholder="Enter custom label"
name={`extraFields[${index}].label`}
label="Field Label"
helperText="Enter a custom label for a field"
error={
errors.extraFields && errors.extraFields[index].label
}
inputRef={register}
defaultValue={
def && def.extraFields && def.extraFields[index].label
}
/>
</Grid>
<Grid item xs={11} sm={6}>
<TextInput
InputLabelProps={{ shrink: true }}
id={`customValue${index}`}
placeholder="Enter value"
name={`extraFields[${index}].value`}
label="Field value"
helperText="Enter a value for the custom field label"
error={
errors.extraFields && errors.extraFields[index].value
}
inputRef={register}
defaultValue={
def && def.extraFields && def.extraFields[index].value
}
/>
</Grid>
<Grid item xs={1}>
<Tooltip
title={
<Typography variant="subtitle2">
Remove the custom field
</Typography>
}
placement="top"
arrow
>
<IconButton
size="small"
onClick={() => {
if (fields.length > 0) {
remove(index);
}
}}
>
<RemoveCircleOutline color="primary" />
</IconButton>
</Tooltip>
</Grid>
</Grid>
))}
<ExtraFieldInput
control={control}
register={register}
errors={errors && errors.extraFields}
defaults={def && def.extraFields}
/>
</Grid>
<Grid item>
<RegularStyledButton fullWidth type="submit">
Expand Down
Loading

0 comments on commit c7d299b

Please sign in to comment.