Skip to content

Commit

Permalink
add some lineage fields to allow indicated source datasets, documents…
Browse files Browse the repository at this point in the history
…, software, etc that feed into models and other datasets.
  • Loading branch information
fostermh committed Aug 23, 2023
1 parent b9a3ea6 commit 375a3ac
Show file tree
Hide file tree
Showing 7 changed files with 589 additions and 1 deletion.
210 changes: 210 additions & 0 deletions src/components/FormComponents/Lineage.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
import React, { useState } from "react";
import { Add, Delete } from "@material-ui/icons";
import {
TextField,
Grid,
Typography,
Button,
Paper,
List,
ListItem,
ListItemText,
} from "@material-ui/core";
import { En, Fr, I18n } from "../I18n";
import { deepCopy } from "../../utils/misc";
import { metadataScopeCodes } from "../../isoCodeLists";
import RequiredMark from "./RequiredMark";
import AdditionalDocumentation from "./LineageAdditionalDocumentation"
import LineageSource from "./LineageSource";
import SelectInput from "./SelectInput";

const emptyLineage = {
statment: "",
scope: "",
additionalDocumentation: [],
source: [],
};

const Lineage = ({
updateLineage,
history = [],
disabled,
paperClass,
language,
}) => {

const [activeLineage, setActiveLineage] = useState(0);

function addLineage() {
updateLineage(history.concat(deepCopy(emptyLineage)));
setActiveLineage(history.length);
}
function updateLineageField(key) {
return (e) => {

const lineageCopy = [...history];
lineageCopy[activeLineage][key] = e.target.value;
updateLineage(lineageCopy);
};
}
function updateLineageSubField(key) {
return (e) => {
const lineageCopy = [...history];
lineageCopy[activeLineage][key] = e;
updateLineage(lineageCopy);
};
}
function removeLineage() {
updateLineage(
history.filter((e, index) => index !== activeLineage)
);
if (history.length) setActiveLineage(history.length - 2);
}

if (typeof history === "string") {
const item = deepCopy(emptyLineage)
item['statment'] = history
history = [deepCopy(item)];
}

// const manufacturerLabel = <I18n en="Manufacturer" fr="Fabricant" />;
// const versionLabel = <I18n en="Version" fr="Version" />;
// const typeLabel = <I18n en="Type" fr="Type" />;
// const descriptionLabel = <I18n en="Description" fr="Description" />;
const lineageStep = history.length > 0 && history[activeLineage];





return (


<Grid container direction="row" spacing={3}>
<Grid item xs={3}>
<Grid container direction="column" spacing={2}>
<Grid item xs>
<I18n>
<En>Lineage:</En>
<Fr>Lignée:</Fr>
</I18n>
<List>
{history.map((lineageItem, i) => {
return (
<ListItem
key={i}
button
onClick={() => setActiveLineage(i)}
>
<ListItemText
primary={
<Typography
style={{
fontWeight: activeLineage === i ? "bold" : "",
}}
>
{i + 1}. {
lineageItem.statment.length <= 50 ?
lineageItem.statment : lineageItem.statment.substring(0, 50) + '...'
}
</Typography>
}
/>
</ListItem>
);
})}
</List>
</Grid>

<Grid item xs>
<Button
disabled={disabled}
startIcon={<Add />}
onClick={addLineage}
style={{ height: "56px", marginLeft: "10px" }}
>
<I18n>
<En>Add Lineage</En>
<Fr>Ajouter une lignée</Fr>
</I18n>
</Button>
</Grid>
</Grid>
</Grid>
<Grid item xs>
<Grid container direction="column">
{lineageStep && (
<Paper style={paperClass}>
<Grid container direction="column" spacing={2}>
<Grid item xs>
<I18n>
<En>Lineage Statment</En>
<Fr>Déclaration de lignée</Fr>
</I18n>
<RequiredMark passes={lineageStep.statment} />
<TextField
label="Statment"
value={lineageStep.statment}
onChange={updateLineageField("statment")}
fullWidth
disabled={disabled}
/>
</Grid>
<Grid item xs>

<I18n>
<En>Scope</En>
<Fr>Portée</Fr>
</I18n>
<SelectInput
value={lineageStep.scope}
onChange={updateLineageField("scope")}
options={Object.keys(metadataScopeCodes)}
optionLabels={Object.values(metadataScopeCodes).map(
({ title }) => title[language]
)}
disabled={disabled}
fullWidth
label={<I18n en="Scope" fr="???" />}
/>
</Grid>
<Grid item xs>
<AdditionalDocumentation
documentations={lineageStep.additionalDocumentation}
updateDocumentations={updateLineageSubField("additionalDocumentation")}
disabled={disabled}
paperClass={paperClass}
/>
</Grid>
<Grid item xs>
<LineageSource
sources={lineageStep.source}
updateSources={updateLineageSubField("source")}
disabled={disabled}
paperClass={paperClass}
/>
</Grid>
<Grid item xs>
<Button
startIcon={<Delete />}
disabled={disabled}
onClick={removeLineage}
>
<I18n>
<En>Remove item</En>
<Fr>Supprimer l'instrument</Fr>
</I18n>
</Button>
</Grid>
</Grid>
</Paper>
)}
</Grid>
</Grid>
</Grid>



);
};
export default Lineage;
163 changes: 163 additions & 0 deletions src/components/FormComponents/LineageAdditionalDocumentation.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import React, { useState } from "react";
import { Add, Delete } from "@material-ui/icons";
import {
TextField,
Grid,
Typography,
Button,
Paper,
List,
ListItem,
ListItemText,
} from "@material-ui/core";
import { En, Fr, I18n } from "../I18n";
import { deepCopy } from "../../utils/misc";
import RequiredMark from "./RequiredMark";

const emptyDocumentation = {
title: "",
authority: "",
code: "",
};

const LineageAdditionalDocumentation = ({
updateDocumentations,
documentations = [],
disabled,
paperClass,
}) => {
const [activeDocumentation, setActiveDocumentation] = useState(0);

function addDocumentation() {
updateDocumentations(documentations.concat(deepCopy(emptyDocumentation)));
setActiveDocumentation(documentations.length);
}
function updateDocumentationField(key) {
return (e) => {
const documentationsCopy = [...documentations];
documentationsCopy[activeDocumentation][key] = e.target.value;
updateDocumentations(documentationsCopy);
};
}
function removeDocumentation() {
updateDocumentations(
documentations.filter((e, index) => index !== activeDocumentation)
);
if (documentations.length) setActiveDocumentation(documentations.length - 2);
}



const documentation = documentations.length > 0 && documentations[activeDocumentation];

return (
<Grid container direction="row" spacing={3}>
<Grid item xs={3}>
<Grid container direction="column" spacing={2}>
<Grid item xs>
<I18n>
<En>Additional Documentation:</En>
<Fr>Documentation Supplémentaire:</Fr>
</I18n>
<List>
{documentations.map((documentationItem, i) => {
return (
<ListItem
key={i}
button
onClick={() => setActiveDocumentation(i)}
>
<ListItemText
primary={
<Typography
style={{
fontWeight: activeDocumentation === i ? "bold" : "",
}}
>
{i + 1}. {
documentationItem.title.length <= 50 ?
documentationItem.title : documentationItem.title.substring(0, 50) + '...'
}
</Typography>
}
/>
</ListItem>
);
})}
</List>
</Grid>

<Grid item xs>
<Button
disabled={disabled}
startIcon={<Add />}
onClick={addDocumentation}
style={{ height: "56px", marginLeft: "10px" }}
>
<I18n>
<En>Add documentation</En>
<Fr>Ajouter un documentation</Fr>
</I18n>
</Button>
</Grid>
</Grid>
</Grid>
<Grid item xs>
<Grid container direction="column">
{documentation && (
<Paper style={paperClass}>
<Grid container direction="column" spacing={2}>
<Grid item xs>
<I18n>
<En>Title</En>
<Fr>Titre</Fr>
</I18n>
<RequiredMark passes={documentation.title} />
<TextField
label={<I18n en="Title" fr="Titre" />}
value={documentation.title}
onChange={updateDocumentationField("title")}
fullWidth
disabled={disabled}
/>
</Grid>
<Grid item xs>
<TextField
label={<I18n en="Authority" fr="Autorité" />}
name="authority"
value={documentation.authority}
onChange={updateDocumentationField("authority")}
fullWidth
disabled={disabled}
/>{" "}
</Grid>
<Grid item xs>
<TextField
label="Code"
value={documentation.code}
onChange={updateDocumentationField("code")}
fullWidth
disabled={disabled}
/>
</Grid>
<Grid item xs>
<Button
startIcon={<Delete />}
disabled={disabled}
onClick={removeDocumentation}
>
<I18n>
<En>Remove item</En>
<Fr>Supprimer l'documentation</Fr>
</I18n>
</Button>
</Grid>
</Grid>
</Paper>
)}
</Grid>
</Grid>
</Grid>
);
};
export default LineageAdditionalDocumentation;
Loading

0 comments on commit 375a3ac

Please sign in to comment.