Skip to content

Commit

Permalink
Add algorithm variables to journal PDF output
Browse files Browse the repository at this point in the history
  • Loading branch information
vgeorge committed Oct 13, 2023
1 parent d5c62f8 commit bf37f27
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
sortReferences
} from '../../../utils/references';
import { formatDocumentTableCaptions } from '../../../utils/format-table-captions';
import { VariableItem } from '../single-view/document-body';

const ReferencesList = styled.ol`
&& {
Expand Down Expand Up @@ -217,6 +218,51 @@ ImplementationDataList.propTypes = {
)
};

function VariablesList({ list }) {
if (!list || list.length === 0) {
return EMPTY_CONTENT_MESSAGE;
}

return (
<DataListContainer>
{list?.map((variable, i) => (
<VariableItem
key={`variable-${i + 1}`}
variable={variable}
element={{ id: `variable-${i}`, label: `Variable #${i + 1}` }}
/>
))}
</DataListContainer>
);
}

VariablesList.propTypes = {
list: T.arrayOf(T.object)
};

const pChildType = T.shape({
type: T.string.isRequired,
children: T.arrayOf(
T.shape({
text: T.string.isRequired
})
).isRequired
});

const variableNodePropType = T.shape({
children: T.arrayOf(pChildType).isRequired
});

VariablesList.propTypes = {
list: T.arrayOf(
T.shape({
name: variableNodePropType.isRequired,
long_name: variableNodePropType.isRequired,
unit: variableNodePropType.isRequired
})
)
};

function ContactOutput(props) {
const { data } = props;
const { affiliations, contact, roles } = data;
Expand Down Expand Up @@ -534,10 +580,9 @@ function JournalPdfPreview() {
);
const mathematicalTheoryVisible =
hasContent(mathematical_theory) || mathematicalTheoryAssumptionsVisible;
const algorithmInputVariablesVisible = hasContent(algorithm_input_variables);
const algorithmOutputVariablesVisible = hasContent(
algorithm_output_variables
);
const algorithmInputVariablesVisible = algorithm_input_variables?.length > 0;
const algorithmOutputVariablesVisible =
algorithm_output_variables?.length > 0;
const algorithmDescriptionVisible =
scientificTheoryVisible ||
mathematicalTheoryVisible ||
Expand Down Expand Up @@ -696,15 +741,15 @@ function JournalPdfPreview() {
id='algorithm_input_variables'
title='Algorithm Input Variables'
>
<ContentView value={algorithm_input_variables} />
<VariablesList list={algorithm_input_variables} />
</Section>
)}
{algorithmOutputVariablesVisible && (
<Section
id='algorithm_output_variables'
title='Algorithm Output Variables'
>
<ContentView value={algorithm_output_variables} />
<VariablesList list={algorithm_output_variables} />
</Section>
)}
</Section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ const DataAccessItem = ({ id, label, url, description }) => (
</AtbdSubSection>
);

const VariableItem = ({ element, variable }) => (
export const VariableItem = ({ element, variable }) => (
<React.Fragment>
<h4 id={element.id} data-scroll='target'>
{element.label}
Expand Down Expand Up @@ -301,7 +301,7 @@ const ContactItem = ({ id, label, contact, roles, affiliations }) => (
</AtbdSubSection>
);

const EmptySection = ({ className }) => (
export const EmptySection = ({ className }) => (
<p className={className}>No content available.</p>
);

Expand Down

0 comments on commit bf37f27

Please sign in to comment.