-
Notifications
You must be signed in to change notification settings - Fork 2
SC-180 Added Drawing Button #474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
collins-self
wants to merge
50
commits into
master
Choose a base branch
from
SC-180-Drawing-Button
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
4167285
Added LocationDrawing button to AssetConnection page
e34966d
Added to nmw and fixed styling
4d658af
Made the locations an array of locations and btndropdown
22a0e1b
Added getLocations()
a3e1974
Updated LocationDrawing functionality, does not work still
3b50146
functional
76567ff
Now updates properly w loading and alert
e813040
Alert and made sure was passing in correct format
c60618b
styling
b0ef4c4
Apply suggestions from code review AssetConnection
477cd2e
removed drowpdown type
d043b55
Apply suggestions from code review
bf281f8
added tooltip back for 0 Locations
5551cbd
Tooltip and button disable
746d02b
Button wording
228a6d4
structural changes to locationdrawings
cae137c
updated imports and fixed 'undefined' error
38cd223
simplified functionality, LocationDrawings.tsx wip
66e016e
moved some redundant functions
11b2ff7
added the SetRecord functionality
d96ec5b
Changed to just an ID prop
479be17
moved fetchDrawing up, does not get called properly
df67bfc
functional as single button
a86ed29
removed the button from modal comp
93cba9d
ToolTips and Error
0244e5f
fixed hover for AssetConnection
f88b395
map
574cbd6
modified disable
c4660f7
fixed disable on MeterLocationProperties
655ed6f
refactor: replace LocationDrawingsModal with LocationDrawingsButton i…
6db7f96
fix: update LocationDrawingsButton to use location IDs for error hand…
bd0bd10
quick fixes
4fc731a
optimize multipleLocations and error management in LocationDrawingsBu…
f93c3ae
improve error handling and cleanup in LocationDrawingsButton
7c45f36
enhance LocationDrawingsButton with dropdown options and error handling
27a4819
update LocationDrawingsModal and LocationDrawingsTable for improved s…
9a7eae7
Removed unintended (whitespace) changes: ConnectionPage, AssetPage, NMW
7d97c4f
update LocationDrawingsButton and related components for loading stat…
ab95603
Made prop optional
c537b31
updated LocationDrawingsButton props with memoized location arrays
2c5c685
fixed error handling and DBSearch, organized AssetConnection changes
4c66fcb
adjust table column styles and csproj
90f86c6
Updated style of component
34faba6
rename modal handler and improve tooltip error display
6581c96
updated props and imports
3b96c34
removed redundant button fixed tooltip
09bd2c7
added missing imports
ff331c0
cleaned up NMW/AssetPage
1f8a16c
quick fixes
fac8a0f
removed fieldset
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
166 changes: 166 additions & 0 deletions
166
...SystemCenter/wwwroot/Scripts/TSX/SystemCenter/CommonComponents/LocationDrawingsButton.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| //****************************************************************************************************** | ||
| // LocationDrawings.tsx - Gbtc | ||
| // | ||
| // Copyright © 2024, Grid Protection Alliance. All Rights Reserved. | ||
| // | ||
| // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See | ||
| // the NOTICE file distributed with this work for additional information regarding copyright ownership. | ||
| // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this | ||
| // file except in compliance with the License. You may obtain a copy of the License at: | ||
| // | ||
| // http://opensource.org/licenses/MIT | ||
| // | ||
| // Unless agreed to in writing, the subject software distributed under the License is distributed on an | ||
| // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the | ||
| // License for the specific language governing permissions and limitations. | ||
| // | ||
| // Code Modification History: | ||
| // ---------------------------------------------------------------------------------------------------- | ||
| // 01/06/2024 - Collins Self | ||
| // Generated original version of source code. | ||
| // | ||
| //****************************************************************************************************** | ||
| import React from 'react'; | ||
| import { BtnDropdown, GenericController, LoadingScreen, Modal, ServerErrorIcon, ToolTip } from '@gpa-gemstone/react-interactive'; | ||
| import { OpenXDA } from '@gpa-gemstone/application-typings'; | ||
| import { CrossMark } from '@gpa-gemstone/gpa-symbols'; | ||
| import LocationDrawingsTable from '../Location/LocationDrawingsTable'; | ||
|
|
||
| const LocationDrawingController = new GenericController(`${homePath}api/LocationDrawing`, "Name", true); | ||
| interface LocationDrawingsButtonProps { | ||
| Locations: OpenXDA.Types.Location[]; | ||
| IsLoadingLocations?: boolean; | ||
| } | ||
|
|
||
| type DropDownOption = { | ||
| Label: JSX.Element | string, | ||
| Callback: () => void, | ||
| Disabled: boolean | ||
| ToolTipContent: JSX.Element, | ||
| ShowToolTip: boolean, | ||
| ToolTipLocation: ('top' | 'bottom' | 'left' | 'right'), | ||
| Key: string | number | ||
| } | ||
|
|
||
| const isValid = (location: OpenXDA.Types.Location, drawingData) => { | ||
| let e = ""; | ||
|
|
||
| if (location == null | ||
| || (location.Alias === "" | ||
| && location.Description === "" | ||
| && location.ID === 0 | ||
| && location.Latitude == null | ||
| && location.LocationKey === "" | ||
| && location.Longitude == null | ||
| && location.Name === "")) | ||
| e = 'No location(s) have been set.'; | ||
| else if (drawingData.length == 0) | ||
| e = 'No drawing(s) associated with location.'; | ||
| return e; | ||
| } | ||
|
|
||
| const LocationDrawingsButton: React.FC<LocationDrawingsButtonProps> = (props) => { | ||
| const [hover, setHover] = React.useState<'none' | 'drawings'>('none'); | ||
| const [pageState, setPageState] = React.useState<"loading" | "error" | "idle">("idle"); | ||
| const [selectedLocation, setSelectedLocation] = React.useState<OpenXDA.Types.Location>(); | ||
| const multipleLocations = React.useMemo(() => props.Locations.length > 1, [props.Locations]); | ||
| const [showDrawingsModal, setShowDrawingsModal] = React.useState<boolean>(false); | ||
| const [locationOptions, setLocationOptions] = React.useState<DropDownOption[]>([]); | ||
|
|
||
| React.useEffect(() => { // Generates the map of errors for each location | ||
| setPageState('loading'); | ||
| setLocationOptions([]); | ||
|
|
||
| const handles = props.Locations.map((location, i) => { | ||
| if (location == null) | ||
| return null; | ||
| const handle = LocationDrawingController.DBSearch([], 'Name', true, location.ID) | ||
| .done((result) => { | ||
gcsantos-gpa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const error = isValid(location, result); | ||
| const option: DropDownOption = { | ||
| Label: location.Name, | ||
| Callback: () => handleClickDrawingsModal(location), | ||
| Disabled: error != "", | ||
| ToolTipContent: <p>{CrossMark} {error}</p>, | ||
| ShowToolTip: error != "", | ||
| ToolTipLocation: "left", | ||
| Key: i | ||
| }; | ||
| setLocationOptions(prev => [...prev, option]); | ||
| }) | ||
| .fail(() => { throw new Error() }); | ||
| return handle; | ||
| }).filter(handle => handle != null); | ||
|
|
||
| Promise.all(handles) | ||
| .then(() => setPageState('idle'), | ||
| () => setPageState('error')); | ||
|
|
||
| return () => handles.forEach(handle => () => { if (handle != null && handle?.abort != null) handle.abort() }); | ||
| }, [props.Locations]); | ||
|
|
||
| const handleClickDrawingsModal = (loc?: OpenXDA.Types.Location) => { | ||
| if (showDrawingsModal) { | ||
| setShowDrawingsModal(false); | ||
| return; | ||
| } | ||
| if (loc == undefined) return; | ||
| setSelectedLocation(loc); | ||
| setShowDrawingsModal(true); | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| <LoadingScreen Show={pageState == 'loading' || props.IsLoadingLocations == true} /> | ||
| <ServerErrorIcon Show={pageState == 'error'} Size={40} Label={'A Server Error Occurred. Please Reload the Application.'} /> | ||
| {!multipleLocations | ||
| ? <> | ||
| <button | ||
| className={locationOptions[0]?.Disabled ? "btn btn-primary disabled" : "btn btn-primary"} | ||
| onClick={() => locationOptions[0]?.Disabled ? null : handleClickDrawingsModal(props.Locations[0])} | ||
| data-tooltip={"DrawingsModal"} | ||
| onMouseEnter={() => setHover('drawings')} | ||
| onMouseLeave={() => setHover('none')} | ||
| >Open {props.Locations[0]?.Name} Drawings | ||
| </button> | ||
| <ToolTip | ||
| Show={locationOptions[0]?.Disabled && hover === 'drawings'} | ||
| Position={'left'} | ||
| Target={"DrawingsModal"} | ||
| Zindex={9999} | ||
| ><p>{locationOptions[0]?.ToolTipContent}</p> | ||
| </ToolTip> | ||
| </> | ||
| : <BtnDropdown | ||
| Label={'Open ' + props.Locations[0]?.Name + ' Drawings'} | ||
| Callback={() => handleClickDrawingsModal(props.Locations[0])} | ||
| TooltipContent={ | ||
| <p>{CrossMark} {locationOptions[0]?.Disabled}</p> | ||
| } | ||
| ShowToolTip={locationOptions[0]?.ShowToolTip} | ||
| Disabled={locationOptions[0]?.Disabled} | ||
| BtnClass={'btn-primary'} | ||
| Options={locationOptions.slice(1)} | ||
| /> | ||
| } | ||
| <Modal | ||
| Show={showDrawingsModal} | ||
| Title={'Drawings for ' + selectedLocation?.Name} | ||
| ShowX={true} Size={'xlg'} | ||
| CallBack={() => setShowDrawingsModal(false)} | ||
| ShowCancel={false} | ||
| ShowConfirm={false}> | ||
| <div className="row"> | ||
| <div className="col-12"> | ||
| <LocationDrawingsTable | ||
| LocationID={selectedLocation?.ID} | ||
| RefreshDrawings={0} | ||
| /> | ||
| </div> | ||
| </div> | ||
| </Modal> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export default LocationDrawingsButton; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gcsantos-gpa I bet this conflicts with #606 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would yes