2525import * as React from 'react' ;
2626import { OpenXDA , SystemCenter } from '@gpa-gemstone/application-typings'
2727import { LocationDrawingSlice } from '../../Store/Store' ;
28- import { Alert , BtnDropdown , LoadingIcon , Modal , ToolTip } from '@gpa-gemstone/react-interactive' ;
28+ import { BtnDropdown , LoadingIcon , Modal , ToolTip } from '@gpa-gemstone/react-interactive' ;
2929import { ReactTable } from '@gpa-gemstone/react-table' ;
3030import { useAppDispatch , useAppSelector } from '../../hooks' ;
3131import { CreateGuid } from '@gpa-gemstone/helper-functions' ;
@@ -39,22 +39,26 @@ const LocationDrawings = (props: IProps) => {
3939 const dispatch = useAppDispatch ( ) ;
4040 const guid = React . useRef ( CreateGuid ( ) ) ;
4141
42- const drawingData = useAppSelector ( LocationDrawingSlice . Data ) ; // For some reason this is full of locations on NMW and MeterLocationProperties
42+ const drawingData = useAppSelector ( LocationDrawingSlice . Data ) ;
4343 const drawingStatus = useAppSelector ( LocationDrawingSlice . Status ) ;
4444 const drawingParentID = useAppSelector ( LocationDrawingSlice . ParentID ) ;
4545 const drawingSortKey = useAppSelector ( LocationDrawingSlice . SortField ) ;
4646 const drawingAscending = useAppSelector ( LocationDrawingSlice . Ascending ) ;
4747
4848 const [ selectedLocation , setSelectedLocation ] = React . useState < number > ( ) ;
4949 const [ showDrawings , setShowDrawings ] = React . useState < boolean > ( false ) ;
50- const [ hover , setHover ] = React . useState < 'none' | 'drawings' > ( 'none' ) ;
50+ const [ showDropdown , setShowDropdown ] = React . useState < boolean > ( ) ;
5151
5252 React . useEffect ( ( ) => {
5353 if ( drawingStatus == 'unintiated' || drawingStatus == 'changed' || drawingParentID != selectedLocation ) {
5454 dispatch ( LocationDrawingSlice . Fetch ( selectedLocation ) ) ;
5555 }
5656 } , [ drawingStatus , drawingParentID , selectedLocation ] ) ;
5757
58+ React . useEffect ( ( ) => {
59+ setShowDropdown ( props . Locations . length > 1 ) ;
60+ } , [ props . Locations ] )
61+
5862 function dropdownOptions ( ) : dropdownOption [ ] {
5963 const options : dropdownOption [ ] = [ ] ;
6064 const labels : string [ ] = props . Locations . map ( loc => loc . Name ) ;
@@ -63,7 +67,7 @@ const LocationDrawings = (props: IProps) => {
6367 Label : label ,
6468 Disabled : false ,
6569 Callback : ( ) => {
66- setSelectedLocation ( props . Locations [ index ] . ID ) ; // then set loading til drawings is set
70+ setSelectedLocation ( props . Locations [ index ] . ID ) ;
6771 setShowDrawings ( true ) ;
6872 }
6973 } ) ;
@@ -73,38 +77,25 @@ const LocationDrawings = (props: IProps) => {
7377
7478 return (
7579 < div >
76- { props . Locations . length <= 1 ? // There is one Location or zero, show button to drawing or disabled
77- < >
78- < button
79- type = "button"
80- className = { "btn btn-primary" }
81- disabled = { props . Locations . length == 0
82- || drawingData . length == 0
83- || ( props . Locations [ 0 ] . Name == "" && props . Locations [ 0 ] . ID == 0 ) }
84- data-tooltip = { guid . current }
85- onMouseEnter = { ( ) => setHover ( 'drawings' ) } onMouseLeave = { ( ) => setHover ( 'none' ) }
86- onClick = { ( ) => {
87- setSelectedLocation ( props . Locations [ 0 ] . ID ) ;
88- setShowDrawings ( true ) ;
89- } }
90- > Open Drawing
91- </ button >
92- < ToolTip
93- Show = { hover === 'drawings'
94- && props . Locations . length == 0
95- || drawingData . length == 0 }
96- Theme = { 'dark' } Position = { 'top' } Target = { guid . current } Zindex = { 9999 } >
97- < p > No drawings associated with this substation.</ p >
98- </ ToolTip >
99- </ >
100- : < BtnDropdown
80+ { showDropdown ?
81+ < BtnDropdown
10182 Label = { "Open Drawings " + props . Locations [ 0 ] . Name }
10283 Callback = { ( ) => {
10384 setSelectedLocation ( props . Locations [ 0 ] . ID ) ;
10485 setShowDrawings ( true ) ; // does this run after the selected location
10586 } }
10687 Options = { dropdownOptions ( ) }
10788 />
89+ : < button
90+ type = "button"
91+ className = { "btn btn-primary" }
92+ data-tooltip = { guid . current }
93+ onClick = { ( ) => {
94+ setSelectedLocation ( props . Locations [ 0 ] . ID ) ;
95+ setShowDrawings ( true ) ;
96+ } }
97+ > Open Drawing
98+ </ button >
10899 }
109100
110101 < Modal Show = { showDrawings } Title = { 'Drawings' } ShowX = { true } Size = { 'lg' } CallBack = { ( ) => setShowDrawings ( false ) } ShowCancel = { false } ConfirmText = { 'Done' } >
0 commit comments