2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt odlux
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
18 import * as React from 'react';
20 import Button from '@mui/material/Button';
21 import Dialog from '@mui/material/Dialog';
22 import DialogActions from '@mui/material/DialogActions';
23 import DialogTitle from '@mui/material/DialogTitle';
25 import { ColumnType, MaterialTable, MaterialTableCtorType } from '../../../../framework/src/components/material-table';
26 import { connect, Connect } from '../../../../framework/src/flux/connect';
28 import { NetworkElementConnection } from '../models/networkElementConnection';
29 import { AvailableCapabilities } from '../models/yangCapabilitiesType';
31 export enum InfoNetworkElementDialogMode {
33 InfoNetworkElement = 'infoNetworkElement',
36 const mapDispatch = () => ({
39 const InfoElementTable = MaterialTable as MaterialTableCtorType<AvailableCapabilities>;
41 type DialogSettings = {
43 dialogDescription: string;
44 cancelButtonText: string;
47 const settings: { [key: string]: DialogSettings } = {
48 [InfoNetworkElementDialogMode.None]: {
50 dialogDescription: '',
53 [InfoNetworkElementDialogMode.InfoNetworkElement]: {
54 dialogTitle: 'YANG Capabilities of the Node',
55 dialogDescription: '',
56 cancelButtonText: 'OK',
60 type InfoNetworkElementDialogComponentProps = Connect<undefined, typeof mapDispatch> & {
61 mode: InfoNetworkElementDialogMode;
62 initialNetworkElement: NetworkElementConnection;
66 type InfoNetworkElementDialogComponentState = NetworkElementConnection;
68 class InfoNetworkElementDialogComponent extends React.Component<InfoNetworkElementDialogComponentProps, InfoNetworkElementDialogComponentState> {
69 constructor(props: InfoNetworkElementDialogComponentProps) {
73 nodeId: this.props.initialNetworkElement.nodeId,
75 host: this.props.initialNetworkElement.host,
76 port: this.props.initialNetworkElement.port,
80 render(): JSX.Element {
81 const setting = settings[this.props.mode];
82 const availableCapabilities = this.props.state.connect.elementInfo.elementInfo['netconf-node-topology:available-capabilities']['available-capability'];
83 let yangFeatures = this.props.state.connect.elementFeatureInfo.elementFeatureInfo;
84 let yangCapabilities: AvailableCapabilities[] = [];
86 availableCapabilities.forEach(value => {
87 const capabilty = value.capability;
88 const indexRevision = capabilty.indexOf('revision=');
89 const indexModule = capabilty.indexOf(')', indexRevision);
90 if (indexRevision > 0 && indexModule > 0) {
91 let moduleName = capabilty.substring(indexModule + 1);
92 let ModuleFeaturesList;
93 for (let index = 0; index < yangFeatures.length; index++) {
94 if (yangFeatures[index].name == moduleName) {
95 ModuleFeaturesList = yangFeatures[index].feature ? yangFeatures[index].feature : null;
99 const featuresListCommaSeparated = ModuleFeaturesList ? ModuleFeaturesList.toString() : '';
100 let featuresList = featuresListCommaSeparated.replace(',', ', ');
102 yangCapabilities.push({
104 revision: capabilty.substring(indexRevision + 9, indexRevision + 19),
105 features: featuresList,
110 yangCapabilities = yangCapabilities.sort((a, b) => a.module === b.module ? 0 : a.module > b.module ? 1 : -1);
114 <Dialog open={this.props.mode !== InfoNetworkElementDialogMode.None} >
115 <DialogTitle id="form-dialog-title">{`${setting.dialogTitle}: "${this.state.nodeId}"`}</DialogTitle>
116 <InfoElementTable stickyHeader isPopup tableId="info-element-table" asynchronus columns={[
117 { property: 'module', title: 'YANG Capability', type: ColumnType.text, width: 900 },
119 property: 'revision', title: 'Revision', type: ColumnType.custom, customControl: ({ rowData }) => {
122 <a href={`/yang-schema/${rowData.module}/${rowData.revision}`} target="_blank" > {rowData.revision} </a>
127 { property: 'features', title: 'Features', type: ColumnType.text, width: 500 },
128 ]} idProperty="id" rows={yangCapabilities} >
131 <Button aria-label="ok-button" onClick={(event) => {
133 event.preventDefault();
134 event.stopPropagation();
135 }} color="secondary"> {setting.cancelButtonText} </Button>
142 private onCancel = () => {
143 this.props.onClose();
146 static getDerivedStateFromProps(props: InfoNetworkElementDialogComponentProps, state: InfoNetworkElementDialogComponentState & { initialNetworkElement: NetworkElementConnection }): InfoNetworkElementDialogComponentState & { initialNetworkElement: NetworkElementConnection } {
147 let returnState = state;
148 if (props.initialNetworkElement !== state.initialNetworkElement) {
151 ...props.initialNetworkElement,
152 initialNetworkElement: props.initialNetworkElement,
159 export const InfoNetworkElementDialog = connect(undefined, mapDispatch)(InfoNetworkElementDialogComponent);
160 export default InfoNetworkElementDialog;