From 263623cb1b599ee096879831ab9dec0798c18772 Mon Sep 17 00:00:00 2001 From: collins-self Date: Fri, 25 Oct 2024 09:56:39 -0400 Subject: [PATCH 1/3] added a filter for channels with assets --- .../SystemCenter/NewMeterWizard/AssetPage.tsx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Source/Applications/SystemCenter/wwwroot/Scripts/TSX/SystemCenter/NewMeterWizard/AssetPage.tsx b/Source/Applications/SystemCenter/wwwroot/Scripts/TSX/SystemCenter/NewMeterWizard/AssetPage.tsx index 38c65dee0..ac0394cd1 100644 --- a/Source/Applications/SystemCenter/wwwroot/Scripts/TSX/SystemCenter/NewMeterWizard/AssetPage.tsx +++ b/Source/Applications/SystemCenter/wwwroot/Scripts/TSX/SystemCenter/NewMeterWizard/AssetPage.tsx @@ -275,6 +275,12 @@ export default function AssetPage(props: IProps) { return ; } + function filterChannels(chs: OpenXDA.Types.Channel[]) { + return chs.filter(ch => + !(ch.Asset.length > 0) + ); + } + return (
@@ -516,7 +522,7 @@ export default function AssetPage(props: IProps) {
{ setNewEditAsset((prev) => ({ ...prev, Channels: c })); @@ -533,7 +539,7 @@ export default function AssetPage(props: IProps) {
ch.ConnectionPriority == 0)} UpdateChannels={(c) => { let asset = _.clone(newEditAsset as OpenXDA.Types.Asset); @@ -551,7 +557,7 @@ export default function AssetPage(props: IProps) {
ch.ConnectionPriority == 1)} UpdateChannels={(c) => { let asset = _.clone(newEditAsset as OpenXDA.Types.Asset); @@ -572,7 +578,7 @@ export default function AssetPage(props: IProps) {
ch.ConnectionPriority == 0)} UpdateChannels={(c) => { let asset = _.clone(newEditAsset as OpenXDA.Types.Asset); @@ -590,7 +596,7 @@ export default function AssetPage(props: IProps) {
ch.ConnectionPriority == 1)} UpdateChannels={(c) => { let asset = _.clone(newEditAsset as OpenXDA.Types.Asset); @@ -608,7 +614,7 @@ export default function AssetPage(props: IProps) {
ch.ConnectionPriority == 2)} UpdateChannels={(c) => { let asset = _.clone(newEditAsset as OpenXDA.Types.Asset); @@ -632,5 +638,4 @@ export default function AssetPage(props: IProps) {
); - } From 141188a8d2a51e4131a32e64f793ee65d17caa86 Mon Sep 17 00:00:00 2001 From: collins-self Date: Mon, 4 Nov 2024 14:56:22 -0500 Subject: [PATCH 2/3] changed to useMemo --- .../SystemCenter/NewMeterWizard/AssetPage.tsx | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Source/Applications/SystemCenter/wwwroot/Scripts/TSX/SystemCenter/NewMeterWizard/AssetPage.tsx b/Source/Applications/SystemCenter/wwwroot/Scripts/TSX/SystemCenter/NewMeterWizard/AssetPage.tsx index ac0394cd1..8dfeaf042 100644 --- a/Source/Applications/SystemCenter/wwwroot/Scripts/TSX/SystemCenter/NewMeterWizard/AssetPage.tsx +++ b/Source/Applications/SystemCenter/wwwroot/Scripts/TSX/SystemCenter/NewMeterWizard/AssetPage.tsx @@ -75,6 +75,11 @@ export default function AssetPage(props: IProps) { const [newEditAsset, setNewEditAsset] = React.useState(AssetAttributes.getNewAsset('Line')); const [editAssetKey, setEditAssetKey] = React.useState(''); const allAssetKeys = React.useMemo(() => detailedAssets.filter(a => a.ID !== newEditAsset.ID).map(a => a.AssetKey).concat(props.Assets.filter((a) => a.AssetKey !== editAssetKey).map(a => a.AssetKey)), [detailedAssets, props.Assets, newEditAsset.ID, editAssetKey]) + const filterChannels = React.useMemo(() => { + return props.Channels.filter(ch => + !(ch.Asset.length > 0) + ); + }, [props.Channels]); const [newEdit, setNewEdit] = React.useState<'New' | 'Edit'>('New'); const [showAssetModal, setShowAssetModal] = React.useState(false); @@ -275,12 +280,6 @@ export default function AssetPage(props: IProps) { return ; } - function filterChannels(chs: OpenXDA.Types.Channel[]) { - return chs.filter(ch => - !(ch.Asset.length > 0) - ); - } - return (
@@ -522,7 +521,7 @@ export default function AssetPage(props: IProps) {
{ setNewEditAsset((prev) => ({ ...prev, Channels: c })); @@ -539,7 +538,7 @@ export default function AssetPage(props: IProps) {
ch.ConnectionPriority == 0)} UpdateChannels={(c) => { let asset = _.clone(newEditAsset as OpenXDA.Types.Asset); @@ -557,7 +556,7 @@ export default function AssetPage(props: IProps) {
ch.ConnectionPriority == 1)} UpdateChannels={(c) => { let asset = _.clone(newEditAsset as OpenXDA.Types.Asset); @@ -578,7 +577,7 @@ export default function AssetPage(props: IProps) {
ch.ConnectionPriority == 0)} UpdateChannels={(c) => { let asset = _.clone(newEditAsset as OpenXDA.Types.Asset); @@ -596,7 +595,7 @@ export default function AssetPage(props: IProps) {
ch.ConnectionPriority == 1)} UpdateChannels={(c) => { let asset = _.clone(newEditAsset as OpenXDA.Types.Asset); @@ -614,7 +613,7 @@ export default function AssetPage(props: IProps) {
ch.ConnectionPriority == 2)} UpdateChannels={(c) => { let asset = _.clone(newEditAsset as OpenXDA.Types.Asset); From 3be1a01089be9898005852797b8408c92f546649 Mon Sep 17 00:00:00 2001 From: collins-self Date: Wed, 4 Dec 2024 10:46:11 -0500 Subject: [PATCH 3/3] fixed bugs with assetpage channels --- .../SystemCenter/NewMeterWizard/AssetPage.tsx | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/Source/Applications/SystemCenter/wwwroot/Scripts/TSX/SystemCenter/NewMeterWizard/AssetPage.tsx b/Source/Applications/SystemCenter/wwwroot/Scripts/TSX/SystemCenter/NewMeterWizard/AssetPage.tsx index 8dfeaf042..f8e4496ae 100644 --- a/Source/Applications/SystemCenter/wwwroot/Scripts/TSX/SystemCenter/NewMeterWizard/AssetPage.tsx +++ b/Source/Applications/SystemCenter/wwwroot/Scripts/TSX/SystemCenter/NewMeterWizard/AssetPage.tsx @@ -71,15 +71,16 @@ export default function AssetPage(props: IProps) { const aStatus = useAppSelector(SelectAssetStatus); const byAssetStatus = useAppSelector(ByAssetSlice.Status); const detailedAssets = useAppSelector(ByAssetSlice.Data); - + const [newEditAsset, setNewEditAsset] = React.useState(AssetAttributes.getNewAsset('Line')); const [editAssetKey, setEditAssetKey] = React.useState(''); const allAssetKeys = React.useMemo(() => detailedAssets.filter(a => a.ID !== newEditAsset.ID).map(a => a.AssetKey).concat(props.Assets.filter((a) => a.AssetKey !== editAssetKey).map(a => a.AssetKey)), [detailedAssets, props.Assets, newEditAsset.ID, editAssetKey]) const filterChannels = React.useMemo(() => { - return props.Channels.filter(ch => - !(ch.Asset.length > 0) - ); - }, [props.Channels]); + const chans = props.Channels.filter(ch => { + return (ch.Asset === editAssetKey) || (ch.Asset === ""); + }); + return chans; + }, [props.Channels, editAssetKey]); const [newEdit, setNewEdit] = React.useState<'New' | 'Edit'>('New'); const [showAssetModal, setShowAssetModal] = React.useState(false); @@ -453,12 +454,12 @@ export default function AssetPage(props: IProps) { Size={'xlg'} CallBack={(confirm) => { setShowAssetModal(false); - + if (!confirm) { setNewEditAsset(AssetAttributes.getNewAsset('Line')); return; } - + let record: OpenXDA.Types.Asset = _.clone(newEditAsset); let list = _.clone(props.Assets); let channels: Array = _.clone(props.Channels); @@ -480,7 +481,7 @@ export default function AssetPage(props: IProps) { props.UpdateChannels(channels); props.UpdateAssets(list); - setNewEditAsset(AssetAttributes.getNewAsset('Line')); + setNewEditAsset(AssetAttributes.getNewAsset('Line')); }} DisableConfirm={(AssetAttributes.AssetError(newEditAsset, newEditAsset.AssetType, allAssetKeys).length > 0) } ConfirmShowToolTip={AssetAttributes.AssetError(newEditAsset, newEditAsset.AssetType, allAssetKeys).length > 0} @@ -521,7 +522,7 @@ export default function AssetPage(props: IProps) {
{ setNewEditAsset((prev) => ({ ...prev, Channels: c })); @@ -538,7 +539,7 @@ export default function AssetPage(props: IProps) {
ch.ConnectionPriority == 0)} UpdateChannels={(c) => { let asset = _.clone(newEditAsset as OpenXDA.Types.Asset); @@ -556,7 +557,7 @@ export default function AssetPage(props: IProps) {
ch.ConnectionPriority == 1)} UpdateChannels={(c) => { let asset = _.clone(newEditAsset as OpenXDA.Types.Asset); @@ -569,7 +570,7 @@ export default function AssetPage(props: IProps) { channels = channels.map(ch => ({ ...ch, ConnectionPriority: c.find(d => d.ID == ch.ID) == null ? ch.ConnectionPriority : 1 })); props.UpdateChannels(channels); }} - /> + />
: null} {newEditAsset.AssetType === 'Transformer' ? (
@@ -577,7 +578,7 @@ export default function AssetPage(props: IProps) {
ch.ConnectionPriority == 0)} UpdateChannels={(c) => { let asset = _.clone(newEditAsset as OpenXDA.Types.Asset); @@ -595,7 +596,7 @@ export default function AssetPage(props: IProps) {
ch.ConnectionPriority == 1)} UpdateChannels={(c) => { let asset = _.clone(newEditAsset as OpenXDA.Types.Asset); @@ -613,7 +614,7 @@ export default function AssetPage(props: IProps) {
ch.ConnectionPriority == 2)} UpdateChannels={(c) => { let asset = _.clone(newEditAsset as OpenXDA.Types.Asset); @@ -626,7 +627,7 @@ export default function AssetPage(props: IProps) { channels = channels.map(ch => ({ ...ch, ConnectionPriority: c.find(d => d.ID == ch.ID) == null ? ch.ConnectionPriority : 2})); props.UpdateChannels(channels); }} - /> + />