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==========================================================================
19 import React, { useState } from 'react';
20 import { RouteComponentProps, withRouter } from 'react-router-dom';
22 import { WithStyles, withStyles, createStyles, Theme } from '@material-ui/core/styles';
24 import connect, { IDispatcher, Connect } from "../../../../framework/src/flux/connect";
25 import { IApplicationStoreState } from "../../../../framework/src/store/applicationStore";
26 import MaterialTable, { ColumnModel, ColumnType, MaterialTableCtorType } from "../../../../framework/src/components/material-table";
27 import { Loader } from "../../../../framework/src/components/material-ui/loader";
28 import { renderObject } from '../../../../framework/src/components/objectDump';
30 import { DisplayModeType } from '../handlers/viewDescriptionHandler';
31 import { SetSelectedValue, splitVPath, updateDataActionAsyncCreator, updateViewActionAsyncCreator, removeElementActionAsyncCreator, executeRpcActionAsyncCreator } from "../actions/deviceActions";
32 import { ViewSpecification, isViewElementString, isViewElementNumber, isViewElementBoolean, isViewElementObjectOrList, isViewElementSelection, isViewElementChoise, ViewElement, ViewElementChoise, isViewElementUnion, isViewElementRpc, ViewElementRpc, isViewElementEmpty, isViewElementDate } from "../models/uiModels";
34 import { getAccessPolicyByUrl } from "../../../../framework/src/services/restService";
36 import Fab from '@material-ui/core/Fab';
37 import AddIcon from '@material-ui/icons/Add';
38 import PostAdd from '@material-ui/icons/PostAdd';
39 import ArrowBack from '@material-ui/icons/ArrowBack';
40 import RemoveIcon from '@material-ui/icons/RemoveCircleOutline';
41 import SaveIcon from '@material-ui/icons/Save';
42 import EditIcon from '@material-ui/icons/Edit';
43 import Tooltip from "@material-ui/core/Tooltip";
44 import FormControl from "@material-ui/core/FormControl";
45 import IconButton from "@material-ui/core/IconButton";
47 import InputLabel from "@material-ui/core/InputLabel";
48 import Select from "@material-ui/core/Select";
49 import MenuItem from "@material-ui/core/MenuItem";
50 import Breadcrumbs from "@material-ui/core/Breadcrumbs";
51 import Button from '@material-ui/core/Button';
52 import Link from "@material-ui/core/Link";
53 import Accordion from '@material-ui/core/Accordion';
54 import AccordionSummary from '@material-ui/core/AccordionSummary';
55 import AccordionDetails from '@material-ui/core/AccordionDetails';
56 import Typography from '@material-ui/core/Typography';
57 import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
60 import { BaseProps } from '../components/baseProps';
61 import { UIElementReference } from '../components/uiElementReference';
62 import { UiElementNumber } from '../components/uiElementNumber';
63 import { UiElementString } from '../components/uiElementString';
64 import { UiElementBoolean } from '../components/uiElementBoolean';
65 import { UiElementSelection } from '../components/uiElementSelection';
66 import { UIElementUnion } from '../components/uiElementUnion';
67 import { UiElementLeafList } from '../components/uiElementLeafList';
69 import { useConfirm } from 'material-ui-confirm';
70 import restService from '../services/restServices';
72 const styles = (theme: Theme) => createStyles({
75 "justifyContent": "space-between",
78 "justifyContent": "left"
84 "alignItems": "center",
85 "justifyContent": "center",
93 "flexDirection": "column",
96 "marginRight": theme.spacing(0.5),
101 "margin": theme.spacing(1),
109 '& label.Mui-focused': {
112 '& .MuiInput-underline:after': {
113 borderBottomColor: 'green',
115 '& .MuiOutlinedInput-root': {
119 '&:hover fieldset': {
120 borderColor: 'yellow',
122 '&.Mui-focused fieldset': {
123 borderColor: 'green',
132 borderBottom: `2px solid ${theme.palette.divider}`,
135 width: 485, marginLeft: 20, marginRight: 20
137 verificationElements: {
138 width: 485, marginLeft: 20, marginRight: 20
141 fontSize: theme.typography.pxToRem(15),
142 fontWeight: theme.typography.fontWeightRegular,
153 const mapProps = (state: IApplicationStoreState) => ({
154 collectingData: state.configuration.valueSelector.collectingData,
155 listKeyProperty: state.configuration.valueSelector.keyProperty,
156 listSpecification: state.configuration.valueSelector.listSpecification,
157 listData: state.configuration.valueSelector.listData,
158 vPath: state.configuration.viewDescription.vPath,
159 nodeId: state.configuration.deviceDescription.nodeId,
160 viewData: state.configuration.viewDescription.viewData,
161 outputData: state.configuration.viewDescription.outputData,
162 displaySpecification: state.configuration.viewDescription.displaySpecification,
165 const mapDispatch = (dispatcher: IDispatcher) => ({
166 onValueSelected: (value: any) => dispatcher.dispatch(new SetSelectedValue(value)),
167 onUpdateData: (vPath: string, data: any) => dispatcher.dispatch(updateDataActionAsyncCreator(vPath, data)),
168 reloadView: (vPath: string) => dispatcher.dispatch(updateViewActionAsyncCreator(vPath)),
169 removeElement: (vPath: string) => dispatcher.dispatch(removeElementActionAsyncCreator(vPath)),
170 executeRpc: (vPath: string, data: any) => dispatcher.dispatch(executeRpcActionAsyncCreator(vPath, data)),
173 const SelectElementTable = MaterialTable as MaterialTableCtorType<{ [key: string]: any }>;
175 type ConfigurationApplicationComponentProps = RouteComponentProps & Connect<typeof mapProps, typeof mapDispatch> & WithStyles<typeof styles>;
177 type ConfigurationApplicationComponentState = {
181 viewData: { [key: string]: any } | null;
182 choises: { [path: string]: { selectedCase: string, data: { [property: string]: any } } };
185 type GetStatelessComponentProps<T> = T extends (props: infer P & { children?: React.ReactNode }) => any ? P : any
186 const AccordionSummaryExt: React.FC<GetStatelessComponentProps<typeof AccordionSummary>> = (props) => {
187 const [disabled, setDisabled] = useState(true);
188 const onMouseDown = (ev: React.MouseEvent<HTMLElement>) => {
189 if (ev.button === 1) {
190 setDisabled(!disabled);
195 <div onMouseDown={onMouseDown} >
196 <AccordionSummary {...{ ...props, disabled: props.disabled && disabled }} />
201 const OldProps = Symbol("OldProps");
202 class ConfigurationApplicationComponent extends React.Component<ConfigurationApplicationComponentProps, ConfigurationApplicationComponentState> {
207 constructor(props: ConfigurationApplicationComponentProps) {
219 private static getChoisesFromElements = (elements: { [name: string]: ViewElement }, viewData: any) => {
220 return Object.keys(elements).reduce((acc, cur) => {
221 const elm = elements[cur];
222 if (isViewElementChoise(elm)) {
223 const caseKeys = Object.keys(elm.cases);
225 // find the right case for this choise, use the first one with data, at least use index 0
226 const selectedCase = caseKeys.find(key => {
227 const caseElm = elm.cases[key];
228 return Object.keys(caseElm.elements).some(caseElmKey => {
229 const caseElmElm = caseElm.elements[caseElmKey];
230 return viewData[caseElmElm.label] !== undefined || viewData[caseElmElm.id] != undefined;
234 // extract all data of the active case
235 const caseElements = elm.cases[selectedCase].elements;
236 const data = Object.keys(caseElements).reduce((dataAcc, dataCur) => {
237 const dataElm = caseElements[dataCur];
238 if (isViewElementEmpty(dataElm)) {
239 dataAcc[dataElm.label] = null;
240 } else if (viewData[dataElm.label] !== undefined) {
241 dataAcc[dataElm.label] = viewData[dataElm.label];
242 } else if (viewData[dataElm.id] !== undefined) {
243 dataAcc[dataElm.id] = viewData[dataElm.id];
246 }, {} as { [name: string]: any });
254 }, {} as { [path: string]: { selectedCase: string, data: { [property: string]: any } } }) || {}
257 static getDerivedStateFromProps(nextProps: ConfigurationApplicationComponentProps, prevState: ConfigurationApplicationComponentState & { [OldProps]: ConfigurationApplicationComponentProps }) {
259 if (!prevState || !prevState[OldProps] || (prevState[OldProps].viewData !== nextProps.viewData)) {
260 const isNew: boolean = nextProps.vPath?.endsWith("[]") || false;
265 viewData: nextProps.viewData || null,
266 [OldProps]: nextProps,
267 choises: nextProps.displaySpecification.displayMode === DisplayModeType.doNotDisplay
269 : nextProps.displaySpecification.displayMode === DisplayModeType.displayAsRPC
270 ? nextProps.displaySpecification.inputViewSpecification && ConfigurationApplicationComponent.getChoisesFromElements(nextProps.displaySpecification.inputViewSpecification.elements, nextProps.viewData) || []
271 : ConfigurationApplicationComponent.getChoisesFromElements(nextProps.displaySpecification.viewSpecification.elements, nextProps.viewData)
278 private navigate = (path: string) => {
279 this.props.history.push(`${this.props.match.url}${path}`);
282 private changeValueFor = (property: string, value: any) => {
285 ...this.state.viewData,
291 private collectData = (elements: { [name: string]: ViewElement }) => {
292 // ensure only active choises will be contained
293 const viewData: { [key: string]: any } = { ...this.state.viewData };
294 const choiseKeys = Object.keys(elements).filter(elmKey => isViewElementChoise(elements[elmKey]));
295 const elementsToRemove = choiseKeys.reduce((acc, curChoiceKey) => {
296 const currentChoice = elements[curChoiceKey] as ViewElementChoise;
297 const selectedCase = this.state.choises[curChoiceKey].selectedCase;
298 Object.keys(currentChoice.cases).forEach(caseKey => {
299 const caseElements = currentChoice.cases[caseKey].elements;
300 if (caseKey === selectedCase) {
301 Object.keys(caseElements).forEach(caseElementKey => {
302 const elm = caseElements[caseElementKey];
303 if (isViewElementEmpty(elm)) {
304 // insert null for all empty elements
305 viewData[elm.id] = null;
310 Object.keys(caseElements).forEach(caseElementKey => {
311 acc.push(caseElements[caseElementKey]);
315 }, [] as ViewElement[]);
317 return viewData && Object.keys(viewData).reduce((acc, cur) => {
318 if (!elementsToRemove.some(elm => elm.label === cur || elm.id === cur)) {
319 acc[cur] = viewData[cur];
322 }, {} as { [key: string]: any });
325 private isPolicyViewElementForbidden = (element: ViewElement, dataPath: string): boolean => {
326 const policy = getAccessPolicyByUrl(`${dataPath}/${element.id}`);
327 return !(policy.GET && policy.POST);
330 private isPolicyModuleForbidden = (moduleName: string, dataPath: string): boolean => {
331 const policy = getAccessPolicyByUrl(`${dataPath}/${moduleName}`);
332 return !(policy.GET && policy.POST);
335 private getEditorForViewElement = (uiElement: ViewElement): (null | React.ComponentType<BaseProps<any>>) => {
336 if (isViewElementEmpty(uiElement)) {
338 } else if (isViewElementSelection(uiElement)) {
339 return UiElementSelection;
340 } else if (isViewElementBoolean(uiElement)) {
341 return UiElementBoolean;
342 } else if (isViewElementString(uiElement)) {
343 return UiElementString;
344 } else if (isViewElementDate(uiElement)) {
345 return UiElementString;
346 } else if (isViewElementNumber(uiElement)) {
347 return UiElementNumber;
348 } else if (isViewElementUnion(uiElement)) {
349 return UIElementUnion;
351 if (process.env.NODE_ENV !== "production") {
352 console.error(`Unknown element type - ${(uiElement as any).uiType} in ${(uiElement as any).id}.`)
358 private renderUIElement = (uiElement: ViewElement, viewData: { [key: string]: any }, keyProperty: string | undefined, editMode: boolean, isNew: boolean) => {
359 const isKey = (uiElement.label === keyProperty);
360 const canEdit = editMode && (isNew || (uiElement.config && !isKey));
362 // do not show elements w/o any value from the backend
363 if (viewData[uiElement.id] == null && !editMode) {
365 } else if (isViewElementEmpty(uiElement)) {
367 } else if (uiElement.isList) {
368 /* element is a leaf-list */
369 return <UiElementLeafList
371 inputValue={viewData[uiElement.id] == null ? [] : viewData[uiElement.id]}
374 disabled={editMode && !canEdit}
375 onChange={(e) => { this.changeValueFor(uiElement.id, e) }}
376 getEditorForViewElement={this.getEditorForViewElement}
379 const Element = this.getEditorForViewElement(uiElement);
380 return Element != null
385 inputValue={viewData[uiElement.id] == null ? '' : viewData[uiElement.id]}
388 disabled={editMode && !canEdit}
389 onChange={(e) => { this.changeValueFor(uiElement.id, e) }}
395 // private renderUIReference = (uiElement: ViewElement, viewData: { [key: string]: any }, keyProperty: string | undefined, editMode: boolean, isNew: boolean) => {
396 // const isKey = (uiElement.label === keyProperty);
397 // const canEdit = editMode && (isNew || (uiElement.config && !isKey));
398 // if (isViewElementObjectOrList(uiElement)) {
400 // <FormControl key={uiElement.id} style={{ width: 485, marginLeft: 20, marginRight: 20 }}>
401 // <Tooltip title={uiElement.description || ''}>
402 // <Button className={this.props.classes.leftButton} color="secondary" disabled={this.state.editMode} onClick={() => {
403 // this.navigate(`/${uiElement.id}`);
404 // }}>{uiElement.label}</Button>
409 // if (process.env.NODE_ENV !== "production") {
410 // console.error(`Unknown reference type - ${(uiElement as any).uiType} in ${(uiElement as any).id}.`)
416 private renderUIChoise = (uiElement: ViewElementChoise, viewData: { [key: string]: any }, keyProperty: string | undefined, editMode: boolean, isNew: boolean) => {
417 const isKey = (uiElement.label === keyProperty);
419 const currentChoise = this.state.choises[uiElement.id];
420 const currentCase = currentChoise && uiElement.cases[currentChoise.selectedCase];
422 const canEdit = editMode && (isNew || (uiElement.config && !isKey));
423 if (isViewElementChoise(uiElement)) {
424 const subElements = currentCase?.elements;
427 <FormControl key={uiElement.id} style={{ width: 485, marginLeft: 20, marginRight: 20 }}>
428 <InputLabel htmlFor={`select-${uiElement.id}`} >{uiElement.label}</InputLabel>
430 aria-label={uiElement.label + '-selection'}
431 required={!!uiElement.mandatory}
433 if (currentChoise.selectedCase === e.target.value) {
434 return; // nothing changed
436 this.setState({ choises: { ...this.state.choises, [uiElement.id]: { ...this.state.choises[uiElement.id], selectedCase: e.target.value as string } } });
439 disabled={editMode && !canEdit}
440 value={this.state.choises[uiElement.id].selectedCase}
443 id: `select-${uiElement.id}`,
447 Object.keys(uiElement.cases).map(caseKey => {
448 const caseElm = uiElement.cases[caseKey];
450 <MenuItem key={caseElm.id} value={caseKey} aria-label={caseKey}><Tooltip title={caseElm.description || ''}><div style={{ width: "100%" }}>{caseElm.label}</div></Tooltip></MenuItem>
457 ? Object.keys(subElements).map(elmKey => {
458 const elm = subElements[elmKey];
459 return this.renderUIElement(elm, viewData, keyProperty, editMode, isNew);
461 : <h3>Invalid Choise</h3>
466 if (process.env.NODE_ENV !== "production") {
467 console.error(`Unknown type - ${(uiElement as any).uiType} in ${(uiElement as any).id}.`)
473 private renderUIView = (viewSpecification: ViewSpecification, dataPath: string, viewData: { [key: string]: any }, keyProperty: string | undefined, editMode: boolean, isNew: boolean) => {
474 const { classes } = this.props;
478 const orderFunc = (vsA: ViewElement, vsB: ViewElement) => {
480 // if (vsA.label === vsB.label) return 0;
481 if (vsA.label === keyProperty) return -1;
482 if (vsB.label === keyProperty) return +1;
485 // if (vsA.uiType === vsB.uiType) return 0;
486 // if (vsA.uiType !== "object" && vsB.uiType !== "object") return 0;
487 // if (vsA.uiType === "object") return +1;
491 const sections = Object.keys(viewSpecification.elements).reduce((acc, cur) => {
492 const elm = viewSpecification.elements[cur];
493 if (isViewElementObjectOrList(elm)) {
494 acc.references.push(elm);
495 } else if (isViewElementChoise(elm)) {
496 acc.choises.push(elm);
497 } else if (isViewElementRpc(elm)) {
500 acc.elements.push(elm);
503 }, { elements: [] as ViewElement[], references: [] as ViewElement[], choises: [] as ViewElementChoise[], rpcs: [] as ViewElementRpc[] });
505 sections.elements = sections.elements.sort(orderFunc);
508 <div className={classes.uiView}>
509 <div className={classes.section} />
510 {sections.elements.length > 0
512 <div className={classes.section}>
513 {sections.elements.map(element => this.renderUIElement(element, viewData, keyProperty, editMode, isNew))}
517 {sections.references.length > 0
519 <div className={classes.section}>
520 {sections.references.map(element => (
521 <UIElementReference key={element.id} element={element} disabled={editMode || this.isPolicyViewElementForbidden(element, dataPath)} onOpenReference={(elm) => { this.navigate(`/${elm.id}`) }} />
526 {sections.choises.length > 0
528 <div className={classes.section}>
529 {sections.choises.map(element => this.renderUIChoise(element, viewData, keyProperty, editMode, isNew))}
533 {sections.rpcs.length > 0
535 <div className={classes.section}>
536 {sections.rpcs.map(element => (
537 <UIElementReference key={element.id} element={element} disabled={editMode || this.isPolicyViewElementForbidden(element, dataPath)} onOpenReference={(elm) => { this.navigate(`/${elm.id}`) }} />
546 private renderUIViewSelector = (viewSpecification: ViewSpecification, dataPath: string, viewData: { [key: string]: any }, keyProperty: string | undefined, editMode: boolean, isNew: boolean) => {
547 const { classes } = this.props;
548 // group by module name
549 const modules = Object.keys(viewSpecification.elements).reduce<{ [key: string]: ViewSpecification }>((acc, cur) => {
550 const elm = viewSpecification.elements[cur];
551 const moduleView = (acc[elm.module] = acc[elm.module] || { ...viewSpecification, elements: {} });
552 moduleView.elements[cur] = elm;
556 const moduleKeys = Object.keys(modules).sort();
559 <div className={classes.moduleCollection}>
561 moduleKeys.map(key => {
562 const moduleView = modules[key];
564 <Accordion key={key} defaultExpanded={moduleKeys.length < 4} aria-label={key + '-panel'} >
565 <AccordionSummaryExt expandIcon={<ExpandMoreIcon />} aria-controls={`content-${key}`} id={`header-${key}`} disabled={this.isPolicyModuleForbidden(`${key}:`, dataPath)} >
566 <Typography className={classes.heading}>{key}</Typography>
567 </AccordionSummaryExt>
569 {this.renderUIView(moduleView, dataPath, viewData, keyProperty, editMode, isNew)}
579 private renderUIViewList(listSpecification: ViewSpecification, dataPath: string, listKeyProperty: string, apiDocPath: string, listData: { [key: string]: any }[]) {
580 const listElements = listSpecification.elements;
581 const apiDocPathCreate = apiDocPath ? `${location.origin}${apiDocPath
582 .replace("$$$standard$$$", "topology-netconfnode%20resources%20-%20RestConf%20RFC%208040")
583 .replace("$$$action$$$", "put")}${listKeyProperty ? `_${listKeyProperty.replace(/[\/=\-\:]/g, '_')}_` : '' }` : undefined;
585 const config = listSpecification.config && listKeyProperty; // We can not configure a list with no key.
587 const navigate = (path: string) => {
588 this.props.history.push(`${this.props.match.url}${path}`);
591 const addNewElementAction = {
594 ariaLabel:'add-element',
596 navigate("[]"); // empty key means new element
601 const addWithApiDocElementAction = {
604 ariaLabel:'add-element-via-api-doc',
606 window.open(apiDocPathCreate, '_blank');
611 const { classes, removeElement } = this.props;
613 const DeleteIconWithConfirmation: React.FC<{disabled?: boolean, rowData: { [key: string]: any }, onReload: () => void }> = (props) => {
614 const confirm = useConfirm();
617 <Tooltip title={"Remove"} >
618 <IconButton disabled={props.disabled} className={classes.button} aria-label="remove-element-button"
619 onClick={async (e) => {
622 confirm({ title: "Do you really want to delete this element ?", description: "This action is permanent!", confirmationButtonProps: { color: "secondary" } })
623 .then(() => removeElement(`${this.props.vPath}[${props.rowData[listKeyProperty]}]`))
624 .then(props.onReload);
633 <SelectElementTable stickyHeader idProperty={listKeyProperty} rows={listData} customActionButtons={apiDocPathCreate ? [addNewElementAction, addWithApiDocElementAction] : [addNewElementAction]} columns={
634 Object.keys(listElements).reduce<ColumnModel<{ [key: string]: any }>[]>((acc, cur) => {
635 const elm = listElements[cur];
636 if (elm.uiType !== "object" && listData.every(entry => entry[elm.label] != null)) {
637 if (elm.label !== listKeyProperty) {
638 acc.push(elm.uiType === "boolean"
639 ? { property: elm.label, type: ColumnType.boolean }
640 : elm.uiType === "date"
641 ? { property: elm.label, type: ColumnType.date }
642 : { property: elm.label, type: elm.uiType === "number" ? ColumnType.numeric : ColumnType.text });
644 acc.unshift(elm.uiType === "boolean"
645 ? { property: elm.label, type: ColumnType.boolean }
646 : elm.uiType === "date"
647 ? { property: elm.label, type: ColumnType.date }
648 : { property: elm.label, type: elm.uiType === "number" ? ColumnType.numeric : ColumnType.text });
653 property: "Actions", disableFilter: true, disableSorting: true, type: ColumnType.custom, customControl: (({ rowData }) => {
655 <DeleteIconWithConfirmation disabled={!config} rowData={rowData} onReload={() => this.props.vPath && this.props.reloadView(this.props.vPath)} />
659 } onHandleClick={(ev, row) => {
661 listKeyProperty && navigate(`[${encodeURIComponent(row[listKeyProperty])}]`); // Do not navigate without key.
662 }} ></SelectElementTable>
666 private renderUIViewRPC(inputViewSpecification: ViewSpecification | undefined, dataPath: string, inputViewData: { [key: string]: any }, outputViewData: { [key: string]: any }, keyProperty: string | undefined, editMode: boolean, isNew: boolean) {
667 const { classes } = this.props;
669 const orderFunc = (vsA: ViewElement, vsB: ViewElement) => {
671 // if (vsA.label === vsB.label) return 0;
672 if (vsA.label === keyProperty) return -1;
673 if (vsB.label === keyProperty) return +1;
676 // if (vsA.uiType === vsB.uiType) return 0;
677 // if (vsA.uiType !== "object" && vsB.uiType !== "object") return 0;
678 // if (vsA.uiType === "object") return +1;
682 const sections = inputViewSpecification && Object.keys(inputViewSpecification.elements).reduce((acc, cur) => {
683 const elm = inputViewSpecification.elements[cur];
684 if (isViewElementObjectOrList(elm)) {
685 console.error("Object should not appear in RPC view !");
686 } else if (isViewElementChoise(elm)) {
687 acc.choises.push(elm);
688 } else if (isViewElementRpc(elm)) {
689 console.error("RPC should not appear in RPC view !");
691 acc.elements.push(elm);
694 }, { elements: [] as ViewElement[], references: [] as ViewElement[], choises: [] as ViewElementChoise[], rpcs: [] as ViewElementRpc[] })
695 || { elements: [] as ViewElement[], references: [] as ViewElement[], choises: [] as ViewElementChoise[], rpcs: [] as ViewElementRpc[] };
697 sections.elements = sections.elements.sort(orderFunc);
701 <div className={classes.section} />
702 { sections.elements.length > 0
704 <div className={classes.section}>
705 {sections.elements.map(element => this.renderUIElement(element, inputViewData, keyProperty, editMode, isNew))}
709 { sections.choises.length > 0
711 <div className={classes.section}>
712 {sections.choises.map(element => this.renderUIChoise(element, inputViewData, keyProperty, editMode, isNew))}
716 <Button onClick={() => {
717 const resultingViewData = inputViewSpecification && this.collectData(inputViewSpecification.elements);
718 this.props.executeRpc(this.props.vPath!, resultingViewData);
720 <div className={classes.objectReult}>
721 {outputViewData !== undefined
722 ? renderObject(outputViewData)
730 private renderBreadCrumps() {
731 const { editMode } = this.state;
732 const { displaySpecification, vPath, nodeId } = this.props;
733 const pathParts = splitVPath(vPath!, /(?:([^\/\["]+)(?:\[([^\]]*)\])?)/g); // 1 = property / 2 = optional key
734 let lastPath = `/configuration`;
735 let basePath = `/configuration/${nodeId}`;
737 <div className={this.props.classes.header}>
739 <Breadcrumbs aria-label="breadcrumbs">
740 <Link color="inherit" href="#" aria-label="back-breadcrumb"
741 onClick={(ev: React.MouseEvent<HTMLElement>) => {
743 this.props.history.push(lastPath);
745 <Link color="inherit" href="#"
746 aria-label={nodeId + '-breadcrumb'}
747 onClick={(ev: React.MouseEvent<HTMLElement>) => {
749 this.props.history.push(`/configuration/${nodeId}`);
750 }}><span>{nodeId}</span></Link>
752 pathParts.map(([prop, key], ind) => {
753 const path = `${basePath}/${prop}`;
754 const keyPath = key && `${basePath}/${prop}[${key}]`;
755 const propTitle = prop.replace(/^[^:]+:/, "");
758 <Link color="inherit" href="#"
759 aria-label={propTitle + '-breadcrumb'}
760 onClick={(ev: React.MouseEvent<HTMLElement>) => {
762 this.props.history.push(path);
763 }}><span>{propTitle}</span></Link>
765 keyPath && <Link color="inherit" href="#"
766 aria-label={key + '-breadcrumb'}
767 onClick={(ev: React.MouseEvent<HTMLElement>) => {
769 this.props.history.push(keyPath);
770 }}>{`[${key}]`}</Link> || null
775 basePath = keyPath || path;
781 {this.state.editMode && (
782 <Fab color="secondary" aria-label="back-button" className={this.props.classes.fab} onClick={async () => {
783 this.props.vPath && await this.props.reloadView(this.props.vPath);
784 this.setState({ editMode: false });
785 }} ><ArrowBack /></Fab>
787 { /* do not show edit if this is a list or it can't be edited */
788 displaySpecification.displayMode === DisplayModeType.displayAsObject && displaySpecification.viewSpecification.canEdit && (<div>
789 <Fab color="secondary" aria-label={editMode ? 'save-button' : 'edit-button'} className={this.props.classes.fab} onClick={() => {
790 if (this.state.editMode) {
791 // ensure only active choises will be contained
792 const resultingViewData = this.collectData(displaySpecification.viewSpecification.elements);
793 this.props.onUpdateData(this.props.vPath!, resultingViewData);
795 this.setState({ editMode: !editMode });
808 private renderValueSelector() {
809 const { listKeyProperty, listSpecification, listData, onValueSelected } = this.props;
810 if (!listKeyProperty || !listSpecification) {
811 throw new Error("ListKex ot view not specified.");
815 <div className={this.props.classes.container}>
816 <SelectElementTable stickyHeader idProperty={listKeyProperty} rows={listData} columns={
817 Object.keys(listSpecification.elements).reduce<ColumnModel<{ [key: string]: any }>[]>((acc, cur) => {
818 const elm = listSpecification.elements[cur];
819 if (elm.uiType !== "object" && listData.every(entry => entry[elm.label] != null)) {
820 if (elm.label !== listKeyProperty) {
821 acc.push({ property: elm.label, type: elm.uiType === "number" ? ColumnType.numeric : ColumnType.text });
823 acc.unshift({ property: elm.label, type: elm.uiType === "number" ? ColumnType.numeric : ColumnType.text });
828 } onHandleClick={(ev, row) => { ev.preventDefault(); onValueSelected(row); }} ></SelectElementTable>
833 private renderValueEditor() {
834 const { displaySpecification: ds, outputData } = this.props;
835 const { viewData, editMode, isNew } = this.state;
838 <div className={this.props.classes.container}>
839 {this.renderBreadCrumps()}
840 {ds.displayMode === DisplayModeType.doNotDisplay
842 : ds.displayMode === DisplayModeType.displayAsList && viewData instanceof Array
843 ? this.renderUIViewList(ds.viewSpecification, ds.dataPath!, ds.keyProperty!, ds.apidocPath!, viewData)
844 : ds.displayMode === DisplayModeType.displayAsRPC
845 ? this.renderUIViewRPC(ds.inputViewSpecification, ds.dataPath!, viewData!, outputData, undefined, true, false)
846 : this.renderUIViewSelector(ds.viewSpecification, ds.dataPath!, viewData!, ds.keyProperty, editMode, isNew)
852 private renderCollectingData() {
854 <div className={this.props.classes.outer}>
855 <div className={this.props.classes.inner}>
857 <h3>Processing ...</h3>
864 return this.props.collectingData || !this.state.viewData
865 ? this.renderCollectingData()
866 : this.props.listSpecification
867 ? this.renderValueSelector()
868 : this.renderValueEditor();
872 export const ConfigurationApplication = withStyles(styles)(withRouter(connect(mapProps, mapDispatch)(ConfigurationApplicationComponent)));
873 export default ConfigurationApplication;