-
Notifications
You must be signed in to change notification settings - Fork 3
Notification Pages Slice Removal #911
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
nbeatty-gpa
wants to merge
8
commits into
master
Choose a base branch
from
notificationPaginationFixes
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
8 commits
Select commit
Hold shift + click to select a range
3788891
use controller in ByCellCarrier
nbeatty-gpa dfc45a1
use controller in EmailCategory components
nbeatty-gpa 9aa0926
use controller in ByUserInformation
nbeatty-gpa 88062e7
use controller in Subscription components
nbeatty-gpa d09e164
use controller in Report components
nbeatty-gpa 01f9cdb
use controller in Event Filter components
nbeatty-gpa 2a49b4b
use controller in Email Types components
nbeatty-gpa 98a26c1
remove unused slices from store
nbeatty-gpa 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
208 changes: 208 additions & 0 deletions
208
.../Applications/SystemCenterNotification/Scripts/TSX/CommonComponents/ControllerSelects.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,208 @@ | ||
| //****************************************************************************************************** | ||
| // ControllerSelects.tsx - Gbtc | ||
| // | ||
| // Copyright © 2026, 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: | ||
| // ---------------------------------------------------------------------------------------------------- | ||
| // 07/15/2026 - N. Beatty | ||
| // Generated original version of source code. | ||
| // | ||
| //****************************************************************************************************** | ||
|
|
||
| import _ from "lodash"; | ||
| import * as React from 'react'; | ||
| import { Application } from '@gpa-gemstone/application-typings'; | ||
| import { ReactIcons } from '@gpa-gemstone/gpa-symbols'; | ||
| import { GenericController, Modal, Search } from '@gpa-gemstone/react-interactive'; | ||
| import { Column, ConfigurableColumn, FilterableColumn, Paging, Table } from '@gpa-gemstone/react-table'; | ||
|
|
||
| interface IProps<T> { | ||
| Controller: GenericController<T>, | ||
| Show: boolean, | ||
| Title: string, | ||
| Selection: T[], | ||
| PrimaryKey: keyof T, | ||
| OnClose: (selected: T[], conf: boolean) => void, | ||
| Searchbar: (children: React.ReactNode, SetFilter: (filters: Search.IFilter<T>[]) => void, SearchStatus: Application.Types.Status, ResultCount: number) => React.ReactNode, | ||
| MinSelection: number, | ||
| Type?: 'single' | 'multiple', | ||
| DefaultSortField: keyof T, | ||
| children?: React.ReactNode | ||
| } | ||
|
|
||
| export const ControllerSelects = <T,>(props: IProps<T>) => { | ||
| const [data, setData] = React.useState<T[]>([]); | ||
| const [filters, setFilters] = React.useState<Search.IFilter<T>[]>([]); | ||
| const [sortField, setSortField] = React.useState<keyof T>(props.DefaultSortField); | ||
| const [ascending, setAscending] = React.useState<boolean>(true); | ||
| const [activePage, setActivePage] = React.useState<number>(0); | ||
| const [totalPages, setTotalPages] = React.useState<number>(0); | ||
| const [totalRecords, setTotalRecords] = React.useState<number>(0); | ||
| const [searchStatus, setSearchStatus] = React.useState<Application.Types.Status>('uninitiated'); | ||
|
|
||
| const [selectedData, setSelectedData] = React.useState<T[]>(props.Selection); | ||
| const [sortKeySelected, setSortKeySelected] = React.useState<string>(''); | ||
| const [ascendingSelected, setAscendingSelected] = React.useState<boolean>(false); | ||
|
|
||
| //keep the active page valid when the filtered result set shrinks | ||
| React.useEffect(() => { | ||
| if (totalPages > 0 && activePage >= totalPages) | ||
| setActivePage(totalPages - 1); | ||
| }, [totalPages, activePage]); | ||
|
|
||
| React.useEffect(() => { | ||
| setSelectedData(props.Selection); | ||
| }, [props.Selection]) | ||
|
|
||
| // when controller is changed, use default sort field. | ||
| React.useEffect(() => { | ||
| setSortField(props.DefaultSortField); | ||
| },[props.Controller, props.DefaultSortField]) | ||
|
|
||
| React.useEffect(() => { | ||
| setSearchStatus('loading') | ||
| const h = props.Controller.PagedSearch(filters, sortField, ascending, activePage); | ||
| h.done((d) => { | ||
| setData(JSON.parse(d.Data)); | ||
| setTotalPages(d.NumberOfPages); | ||
| setTotalRecords(d.TotalRecords); | ||
| setSearchStatus('idle') | ||
| }) | ||
| h.fail(() => setSearchStatus('error')) | ||
| return function cleanup() { | ||
| if (h != null && h.abort != null) | ||
| h.abort(); | ||
| } | ||
| }, [props.Controller, filters, sortField, ascending, activePage]) | ||
|
|
||
| return ( | ||
| <Modal | ||
| Show={props.Show} | ||
| Title={props.Title} | ||
| CallBack={(conf) => props.OnClose(selectedData, conf)} | ||
| ShowX={true} | ||
| Size={'xlg'} | ||
| BodyStyle={{ display: 'flex', flexDirection: 'column', height: 'calc(100vh - 210px)', overflow: 'hidden' }} | ||
| DisableConfirm={props.MinSelection !== undefined && selectedData.length < props.MinSelection} | ||
| ConfirmShowToolTip={props.MinSelection !== undefined && selectedData.length < props.MinSelection} | ||
| ConfirmToolTipContent={ | ||
| <p> | ||
| <ReactIcons.CrossMark /> At least {props.MinSelection} items must be selected. | ||
| </p> | ||
| } | ||
| > | ||
|
|
||
| <div className="row" style={{ flexShrink: 0 }}> | ||
| <div className="col" style={{ width: (props.Type === undefined || props.Type === 'single' ? '100%' : '60%') }}> | ||
| {props.Searchbar( | ||
| <> | ||
| {React.Children.map(props.children, (e) => { | ||
| if (React.isValidElement(e)) { | ||
| if (((e as React.ReactElement).type === FilterableColumn) || | ||
| ((e as React.ReactElement).type === Column) || | ||
| ((e as React.ReactElement).type === ConfigurableColumn) | ||
| ) return null; | ||
| return e; | ||
| } | ||
| return null; | ||
| })} | ||
| </>, setFilters, searchStatus, totalRecords)} | ||
| </div> | ||
| {props.Type === 'multiple' ? <div className="col" style={{ width: '40%', borderLeft: '1px solid #dee2e6' }}> | ||
| <h3> Current Selection </h3> | ||
| </div> : null} | ||
| </div> | ||
| <div className="row d-flex" style={{ flex: 1, overflow: 'hidden'}}> | ||
| <div className="col d-flex h-100" style={{ width: (props.Type === undefined || props.Type === 'single' ? '100%' : '60%') }}> | ||
| <Table<T> | ||
| TableClass="table table-hover h-100" | ||
| Data={data} | ||
| SortKey={sortField as string} | ||
| Ascending={ascending} | ||
| OnSort={(d) => { | ||
| if (d.colKey === "Scroll") | ||
| return; | ||
| if (d.colKey === sortField) | ||
| setAscending(!ascending); | ||
| else { | ||
| setSortField(d.colField as keyof T); | ||
| setAscending(true); | ||
| } | ||
| }} | ||
| OnClick={(d, e) => { | ||
| //the table fires OnClick for both the clicked cell and the bubbled row, so stop | ||
| //propagation to avoid a double toggle that would immediately deselect the row | ||
| e.stopPropagation(); | ||
| setSelectedData((s) => { | ||
| const isSelected = s.findIndex(item => item[props.PrimaryKey] === d.row[props.PrimaryKey]) > -1; | ||
|
|
||
| if (isSelected) | ||
| return s.filter(item => item[props.PrimaryKey] !== d.row[props.PrimaryKey]); | ||
|
|
||
| if (props.Type === undefined || props.Type === 'single') | ||
| return [d.row] | ||
|
|
||
| return [...s, d.row] | ||
| }) | ||
| }} | ||
| Selected={(item) => selectedData.findIndex(d => d[props.PrimaryKey] === item[props.PrimaryKey]) > -1} | ||
| KeySelector={item => item[props.PrimaryKey] as string | number} | ||
| > | ||
| {props.children} | ||
| </Table> | ||
| </div> | ||
| {props.Type === 'multiple' ? <div className="col h-100" style={{ width: '40%', borderLeft: '1px solid #dee2e6' }}> | ||
| <Table<T> | ||
| TableClass="table table-hover h-100" | ||
| Data={selectedData} | ||
| SortKey={sortKeySelected} | ||
| Ascending={ascendingSelected} | ||
| OnSort={(d) => { | ||
| if (d.colKey === sortKeySelected) { | ||
| const ordered = _.orderBy<T[]>(selectedData, [d.colKey], [(!ascendingSelected ? "asc" : "desc")]) as T[]; | ||
| setAscendingSelected(!ascendingSelected); | ||
| setSelectedData(ordered); | ||
| } | ||
| else { | ||
| const ordered = _.orderBy(selectedData, [d.colKey], ["asc"]) as T[]; | ||
| setAscendingSelected(!ascendingSelected); | ||
| setSelectedData(ordered); | ||
| setSortKeySelected(d.colKey); | ||
| } | ||
| }} | ||
| OnClick={(d) => setSelectedData([...selectedData.filter(item => item[props.PrimaryKey] !== d.row[props.PrimaryKey])])} | ||
| Selected={() => false} | ||
| KeySelector={item => item[props.PrimaryKey] as string | number} | ||
| > | ||
| {props.children} | ||
| </Table> | ||
| </div> : null} | ||
| </div> | ||
| <div className="row" style={{ flexShrink: 0 }}> | ||
| <div className="col" style={{ width: (props.Type === undefined || props.Type === 'single' ? '100%' : '60%') }}> | ||
| <Paging | ||
| Current={activePage + 1} | ||
| Total={totalPages} | ||
| SetPage={(p) => setActivePage(p - 1)} | ||
| /> | ||
| </div> | ||
| {props.Type === 'multiple' ? | ||
| <div className="col" style={{ width: '40%' }} /> | ||
| : null | ||
| } | ||
| </div> | ||
| </Modal> | ||
| ) | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.