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

CORE-1966 Initial Local Contexts support in Metadata Templates #560

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/metadata/form/AVUFormList.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ const AVUFormDialog = (props) => {
id={buildID(formID, ids.AVU_VALUE)}
InputProps={{ readOnly: !editable }}
component={FormTextField}
multiline
/>
<FastField
name={`${field}.unit`}
Expand Down
40 changes: 31 additions & 9 deletions src/components/metadata/templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { urlField } from "components/utils/validations";
import AttributeTypes from "components/models/metadata/TemplateAttributeTypes";
import ConfirmationDialog from "components/utils/ConfirmationDialog";
import DEDialog from "components/utils/DEDialog";
import markdownToHtml from "components/utils/markdownToHtml";
import TableLoading from "components/table/TableLoading";
import withErrorAnnouncer from "components/error/withErrorAnnouncer";

Expand All @@ -31,7 +32,6 @@ import {
import FormMultilineTextField from "components/forms/FormMultilineTextField";
import FormTextField from "components/forms/FormTextField";
import FormTimestampField from "components/forms/FormTimestampField";
import FormSelectField from "components/forms/FormSelectField";

import FormNumberField from "components/forms/FormNumberField";

Expand Down Expand Up @@ -98,6 +98,27 @@ const newAVU = (attrTemplate) => {
};
};

const AttributeDescription = ({ attribute }) => {
const [infoHtml, setInfoHtml] = React.useState("");

React.useEffect(() => {
if (attribute?.description) {
markdownToHtml(attribute.description).then((html) =>
setInfoHtml(html)
);
} else {
setInfoHtml("");
}
}, [attribute]);

return (
<Typography
variant="subtitle1"
dangerouslySetInnerHTML={{ __html: infoHtml }}
/>
);
};

const MetadataTemplateAttributeForm = (props) => {
const {
field,
Expand All @@ -124,8 +145,8 @@ const MetadataTemplateAttributeForm = (props) => {
const { t } = useTranslation("metadata");
const classes = useStyles();

const onAttrExpandedChange = (prevExpanded, attr, attrExpanded) => {
setExpanded({ ...prevExpanded, [attr]: attrExpanded });
const onAttrExpandedChange = (attr, attrExpanded) => {
setExpanded({ ...expanded, [attr]: attrExpanded });
};

const onAddAVU = (arrayHelpers, attribute) => {
Expand All @@ -134,7 +155,7 @@ const MetadataTemplateAttributeForm = (props) => {

arrayHelpers.push(avu);

onAttrExpandedChange(expanded, attribute.name, true);
onAttrExpandedChange(attribute.name, true);
};

const addSubAVUs = (attribute, avu) => {
Expand Down Expand Up @@ -195,9 +216,10 @@ const MetadataTemplateAttributeForm = (props) => {
break;

case AttributeTypes.ENUM:
FieldComponent = FormSelectField;
FieldComponent = FormTextField;
fieldProps = {
...fieldProps,
select: true,
children:
attribute.values &&
attribute.values.map((enumVal, index) => (
Expand Down Expand Up @@ -237,6 +259,7 @@ const MetadataTemplateAttributeForm = (props) => {

default:
FieldComponent = FormTextField;
fieldProps.multiline = true;
break;
}

Expand Down Expand Up @@ -351,7 +374,6 @@ const MetadataTemplateAttributeForm = (props) => {
expanded={!!expanded[attribute.name]}
onChange={(event, attrExpanded) =>
onAttrExpandedChange(
expanded,
attribute.name,
attrExpanded
)
Expand Down Expand Up @@ -413,9 +435,9 @@ const MetadataTemplateAttributeForm = (props) => {
alignItems="stretch"
>
<Grid item xs>
<Typography variant="subtitle1">
{attribute.description}
</Typography>
<AttributeDescription
attribute={attribute}
/>
</Grid>
{avuFields}
</Grid>
Expand Down
2 changes: 1 addition & 1 deletion src/components/utils/markdownToHtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const markdownToHtml = async (rawMarkdown) => {
const showdown = (await import("showdown")).default;
const sanitizeHtml = (await import("sanitize-html")).default;

const converter = new showdown.Converter();
const converter = new showdown.Converter({ openLinksInNewWindow: true });
converter.setFlavor("github");

return converter.makeHtml(sanitizeHtml(rawMarkdown));
Expand Down
Loading
Loading