Skip to content

Commit

Permalink
IP-431: Make new summary section to collapse information
Browse files Browse the repository at this point in the history
  • Loading branch information
rlreamy committed May 10, 2024
1 parent 0858d18 commit 994e262
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/components/Packages/MetadataModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MetadataModal extends Component {
isRemoteDataLoaded() {
return this.props.dtds && this.props.uploadPackage && this.props.dtds[this.props.uploadPackage.version];
}

render() {
if(!this.isRemoteDataLoaded()) {
return <div className="metadataModal static-modal" />;
Expand Down Expand Up @@ -54,6 +54,7 @@ class MetadataModal extends Component {
<p>ID: {this.props.uploadPackage._id}</p>
<Tree blockNode={true} defaultExpandedKeys={[defaultExpandedKeys]}>
{standardSection}
{summarizedFields}
{remainingSections}
</Tree>
</ModalBody>
Expand Down
36 changes: 30 additions & 6 deletions src/components/Packages/MetadataRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,54 @@ import { getIEFriendlyDate } from '../../helpers/timezoneUtil';
const { TreeNode } = Tree;

export class MetadataRenderer {

collapseSummarySections = (fields) => {
let fieldsSeen = [];
let list = [];
fields.forEach((field) => {
if (!fieldsSeen.includes(field.summarize.label)) {
fieldsSeen.push(field.summarize.label);
list.push(field);
}
});
return list;
}

renderSection = (section, metadata) => {
let header = section.sectionHeader;
let fields = section.fields;
let summaryFields = fields.filter(function(field){
return field.summarize !== undefined;
});
let summarySections = this.collapseSummarySections(summaryFields);
return (
<TreeNode title={header} key={header} selectable={false}>
{ fields.map((fieldJson) => this.renderField(fieldJson, metadata)) }
{ summarySections.map((fieldJson) => this.renderSummaryFields(fieldJson, metadata))}
</TreeNode>
);

}

renderSummaryFields = (fieldJson, packageInfo) => {
let fieldLabel = fieldJson.summarize.label;
let value = packageInfo[fieldJson.summarize.field];
let summaryField = fieldLabel + ": " + value;
return <TreeNode title={summaryField} key={summaryField} isLeaf selectable={false}/>
}

renderField = (fieldJson, packageInfo) => {
if (fieldJson.type === "Submitter Information") {
let name= packageInfo.submitter.firstName + " " + packageInfo.submitter.lastName;
let nameField = "Submitter: " + name;
let institutionField = "Site Name: " + packageInfo.siteName;
return (
<TreeNode title="Submitted by:" key="Submitted by:" selectable={false}>
<TreeNode title={institutionField} key={institutionField} isLeaf selectable={false}/>
<TreeNode title={nameField} key={nameField} isLeaf selectable={false}/>
</TreeNode>
<TreeNode title={nameField} key={nameField} isLeaf selectable={false}/>
);
} else if (fieldJson.summarize !== undefined) {
let field = fieldJson.summarize.label + ": " + packageInfo[fieldJson.summarize.site];
return <TreeNode title={field} key={field} isLeaf selectable={false}/>
} else {
if (fieldJson.fieldName ==="siteName") {
if (fieldJson.displayInSummary !== undefined && fieldJson.displayInSummary === false) {
return "";
}
let fieldValue = packageInfo[fieldJson.fieldName] === undefined ? "" : packageInfo[fieldJson.fieldName];
Expand Down
11 changes: 0 additions & 11 deletions src/components/Packages/PackageList.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,10 @@ class PackageList extends Component {

async componentDidUpdate(prevProps, prevState, snapShot) {
if (this.props !== prevProps) {
console.log("inside of component did update if statement")
console.log("filtering props")
console.log(this.props.filtering)
console.log("prevProps filtering props")
console.log(prevProps.filtering)
if (this.props.filtering !== prevProps.filtering) {
console.log("in nested if statement in side of component did update")
this.setState({packages: applyFilters(this.props.filtering.filters, this.state.unfilteredPackages, this.props.filtering.packageTypes)});
}
console.log("filters")
console.log(this.props.filtering.filters)
console.log("unfiltered packages: ")
console.log(this.state.unfilteredPackages)
console.log("package Types")
console.log(this.props.filtering.packageTypes)
if (this.props.refreshPackages) {
await this.getPackages();
this.props.setRefreshPackages(false)
Expand Down

0 comments on commit 994e262

Please sign in to comment.