|
| 1 | +import React,{useState} from 'react' |
| 2 | +import {BaseElement} from './BaseElement'; |
| 3 | +import {Accordion} from '../../form/Accordion'; |
| 4 | +import { BaseRenderAsComponent } from "./BaseRenderAsComponent" |
| 5 | +import {GET_ICON_NAME} from '../../constants/details-labels'; |
| 6 | +import {BaseSelectComponent} from './BaseSelectComponent'; |
| 7 | +import PropTypes from "prop-types"; |
| 8 | +import {PropertyExtraInfo} from './PropertyExtraInfo' |
| 9 | +import {GraphContextObj} from '../hook/graphObjectContext'; |
| 10 | +import Badge from 'react-bootstrap/Badge'; |
| 11 | +import Stack from 'react-bootstrap/Stack'; |
| 12 | + |
| 13 | +export const GetAccordianTitle = ({ propId, nodeSchemaData, currentNodeJson, isInherited }) => { |
| 14 | + return <Stack direction='horizontal' className='w-100'> |
| 15 | + <label className='mr-3'>{propId}</label> |
| 16 | + {isInherited && <div className='w-100'> |
| 17 | + <Badge bg="dark" className='text-light strong fw-bol border border-info mr-2'> |
| 18 | + {`Inheritted from | ${isInherited.inheritedFrom}`} |
| 19 | + </Badge> |
| 20 | + </div>} |
| 21 | + <div className='ms-auto text-right'> |
| 22 | + {currentNodeJson && nodeSchemaData && <Badge bg="dark" className='text-warning mr-2'> |
| 23 | + {`${currentNodeJson.type} `} |
| 24 | + { nodeSchemaData.range && ` | ${nodeSchemaData.range}` } |
| 25 | + |
| 26 | + </Badge>} |
| 27 | + {nodeSchemaData && <Badge bg="dark" className='text-info mr-2'> |
| 28 | + {nodeSchemaData.option === "" && `Mandatory`} |
| 29 | + {nodeSchemaData.option !== "" && nodeSchemaData.option} |
| 30 | + </Badge>} |
| 31 | + </div> |
| 32 | + </Stack> |
| 33 | +} |
| 34 | + |
| 35 | +export const BaseUnitComponent = (props)=> { |
| 36 | + const {mainGraphObj} =GraphContextObj() |
| 37 | + //const extraInfoValue = props.extraInfoValue || {} |
| 38 | + //all the information about the property in the |
| 39 | + const nodeSchemaData = props.nodeSchemaData || {} |
| 40 | + const currentNodeJson=props.currentNodeJson || {} |
| 41 | + let currentPropId = nodeSchemaData.id |
| 42 | + const viewBaseSchema=props.viewBaseSchema===false ? false : true; |
| 43 | + const showAllButton=props.showAllButton || {}; |
| 44 | + const leftIconClassName=GET_ICON_NAME[currentNodeJson.type] || "custom-img-string" |
| 45 | + |
| 46 | + const [propId,setPropId] = useState(currentPropId) |
| 47 | + //const [idError,setIdError] = useState(false) |
| 48 | + |
| 49 | + const changePropertyValue=(propName,propValue)=>{ |
| 50 | + // display render as option if string is a property |
| 51 | + //if(propValue === "xsd:string") setDisplayRenderAs(Date.now()) |
| 52 | + //else setDisplayRenderAs(false) |
| 53 | + mainGraphObj.setPropertyInfo(currentNodeJson,propName,propValue) |
| 54 | + } |
| 55 | + |
| 56 | + const updateBaseValue = (propName,propValue)=>{ |
| 57 | + if(propName === 'id'){ |
| 58 | + const defaultValue = props.selectDataProvider |
| 59 | + //set the id and the type of the property |
| 60 | + mainGraphObj.setPropertyId(currentNodeJson,propValue,defaultValue) |
| 61 | + setPropId(propValue) |
| 62 | + }else if(propName === 'comment'){ |
| 63 | + mainGraphObj.setPropertyInfo(currentNodeJson,propName,propValue) |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + return( |
| 70 | + <Accordion showBody={props.showBody} |
| 71 | + arrowOpenClassName = "accordion__arrow fa fa-caret-up" |
| 72 | + arrowCloseClassName = "accordion__arrow fa fa-caret-down" |
| 73 | + title={<GetAccordianTitle propId={propId} |
| 74 | + isInherited={props.isInherited} |
| 75 | + nodeSchemaData={nodeSchemaData} |
| 76 | + currentNodeJson={currentNodeJson}/> |
| 77 | + } |
| 78 | + className='w-100' |
| 79 | + leftIconClassName={leftIconClassName} |
| 80 | + tooltip={currentNodeJson.type || ''}> |
| 81 | + |
| 82 | + {props.isInherited && <label className='m-2 text-muted fst-italic small'> |
| 83 | + Note - To edit Inherited properties, select the parent document. |
| 84 | + </label>} |
| 85 | + |
| 86 | + {viewBaseSchema && <BaseElement updateValue={updateBaseValue} |
| 87 | + removeElement={props.removeElement} |
| 88 | + nodeJsonData={currentNodeJson} |
| 89 | + view={props.view} |
| 90 | + isDisabled={props.isDisabled} |
| 91 | + showAllButton={showAllButton} |
| 92 | + nodeSchemaData={nodeSchemaData} |
| 93 | + isNodeObject={false}> |
| 94 | + </BaseElement>} |
| 95 | + </Accordion> |
| 96 | + ) |
| 97 | +} |
| 98 | + |
| 99 | + |
0 commit comments