Skip to content

Commit

Permalink
#358: added basic facility port table on resources page
Browse files Browse the repository at this point in the history
  • Loading branch information
yaxue1123 committed Dec 16, 2024
1 parent c6a023e commit dbed285
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 11 deletions.
72 changes: 72 additions & 0 deletions src/components/Resource/FacilityPortTable.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React, { Component } from "react";
import Table from "../common/Table";

class FacilityPortTable extends Component {
columns = [
{
content: (fp) => (<span className="font-monospace">{fp.name}</span>),
path: "name",
label: "Name",
},
{
content: (fp) => (
<div className="w-50">
{
fp.vlan_range && fp.vlan_range.length > 0 &&
fp.vlan_range.map((range, index) =>
<span
className="font-monospace badge bg-primary me-1"
key={`vlan-range-${index}`}
>
{`[${range}]`}
</span>
)
}
</div>
),
path: "vlan_range",
label: "VLAN Range"
},
{
content: (fp) => (
<div className="w-25">
{
fp.allocated_vlan_range && fp.allocated_vlan_range.length > 0 &&
fp.allocated_vlan_range.map((range, index) =>
<span
className="font-monospace badge bg-primary"
key={`allocate-vlan-range-${index}`}
>
{`${range}`}
</span>
)
}
</div>
),
path: "allocated_vlan_range",
label: "Allocated VLAN Range"
}
];

render() {
const { facilityPorts, totalCount } = this.props;
return (
<div>
<div className="d-flex flex-row justify-content-between p-2">
<div className="fw-bold font-monospace d-flex align-items-center">
Facility Ports ({totalCount})
</div>
</div>
<div className="px-2 pb-1">
<Table
columns={this.columns}
data={facilityPorts}
tStyle={"table-sm"}
/>
</div>
</div>
);
}
}

export default FacilityPortTable;
4 changes: 2 additions & 2 deletions src/components/Resource/SummaryTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class SummaryTable extends Component {
return (
<div>
<div className="d-flex flex-row justify-content-between p-2">
<div className="font-weight-bold text-monospace d-flex align-items-center">
<div className="fw-bold font-monospace d-flex align-items-center">
Sites ({totalCount})
</div>
<div className="d-flex flex-row w-50 justify-content-end">
Expand All @@ -79,7 +79,7 @@ class SummaryTable extends Component {
</button> */}
</div>
</div>
<div className="mx-2 mb-2 p-2 pb-1 d-flex flex-row justify-content-between bg-light rounded text-monospace">
<div className="mx-2 mb-2 p-2 pb-1 d-flex flex-row justify-content-between bg-light rounded font-monospace">
<div className="w-50">Component Available:</div>
<div className="w-75 d-flex flex-row justify-content-between">
<div className="form-check form-check-inline">
Expand Down
2 changes: 1 addition & 1 deletion src/pages/PublicationTracker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class PublicationTracker extends Component {
!showSpinner &&
<div>
<div className="d-flex flex-row justify-content-end w-100 my-2">
<span className="text-monospace">Displaying <b>{totalCount}</b> publications.</span>
<span className="font-monospace">Displaying <b>{totalCount}</b> publications.</span>
</div>
<Table
columns={this.columns}
Expand Down
38 changes: 30 additions & 8 deletions src/pages/Resources.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import SummaryTable from "../components/Resource/SummaryTable";
import withRouter from "../components/common/withRouter.jsx";
import { sitesNameMapping } from "../data/sites";
import sitesParser from "../services/parser/sitesParser";
import facilityPortsParser from "../services/parser/facilityPortsParser";
import { getResources } from "../services/resourceService.js";
import { toast } from "react-toastify";
import paginate from "../utils/paginate";
import _ from "lodash";
import FacilityPortTable from "../components/Resource/FacilityPortTable.jsx";

class Resources extends Component {
state = {
Expand All @@ -23,17 +25,20 @@ class Resources extends Component {
siteNames: [],
siteColorMapping: {},
availableComponents: [],
filterQuery: []
filterQuery: [],
facilityPorts: []
}

async componentWillMount() {
try {
const { data: res } = await getResources(1);
const parsedObj = sitesParser(res.data[0], sitesNameMapping.acronymToShortName, "level1");
const parsedSites = sitesParser(res.data[0], sitesNameMapping.acronymToShortName, "level1");
const parsedFacilityPorts = facilityPortsParser(res.data[0]);
this.setState({
resources: parsedObj.parsedSites,
siteNames: parsedObj.siteNames,
siteColorMapping: parsedObj.siteColorMapping
resources: parsedSites.parsedSites,
siteNames: parsedSites.siteNames,
siteColorMapping: parsedSites.siteColorMapping,
facilityPorts: parsedFacilityPorts
});
} catch (err) {
toast.error("Failed to load resource information. Please reload this page.");
Expand Down Expand Up @@ -115,7 +120,7 @@ class Resources extends Component {
this.setState({ activeDetailName: name });
}

getPageData = () => {
getSiteData = () => {
const {
pageSize,
currentPage,
Expand Down Expand Up @@ -154,9 +159,18 @@ class Resources extends Component {
return { totalCount: filtered.length, data: resources };
};

getFPData = () => {
const { facilityPorts } = this.state;
return { totalCount: facilityPorts.length, facilityPorts: facilityPorts };
}



render() {
const { pageSize, currentPage, sortColumn, searchQuery, activeDetailName } = this.state;
const { totalCount, data } = this.getPageData();
const { pageSize, currentPage, sortColumn, searchQuery,
activeDetailName, facilityPorts } = this.state;
const { totalCount, data } = this.getSiteData();
const { totalFPCount } = this.getFPData();

return (
<div className="container">
Expand Down Expand Up @@ -199,6 +213,14 @@ class Resources extends Component {
/>
</div>
</div>
<div className="row mt-4">
<div className="col-12 bg-info rounded">
<FacilityPortTable
facilityPorts={facilityPorts}
totalCount={facilityPorts.length}
/>
</div>
</div>
</div>
</div>
);
Expand Down
14 changes: 14 additions & 0 deletions src/services/parser/facilityPortsParser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default function parseSites(data) {
let abqm_elements = JSON.parse(data.model);
const nodes = abqm_elements.nodes;
const facility_ports = nodes.filter(n => n.Type === "FacilityPort");
const parsedFacilityPorts = [];
for (const fp of facility_ports) {
parsedFacilityPorts.push({
"name": fp["Name"],
"vlan_range": JSON.parse(fp["Labels"]).vlan_range,
"allocated_vlan_range": fp["LabelAllocations"] ? JSON.parse(fp["LabelAllocations"]).vlan : []
})
}
return parsedFacilityPorts;
}

0 comments on commit dbed285

Please sign in to comment.