Skip to content

Commit

Permalink
fixed bugs with assetpage channels
Browse files Browse the repository at this point in the history
  • Loading branch information
collins-self committed Dec 6, 2024
1 parent 141188a commit 3be1a01
Showing 1 changed file with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<AssetType>(AssetAttributes.getNewAsset('Line'));
const [editAssetKey, setEditAssetKey] = React.useState<string>('');
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<boolean>(false);
Expand Down Expand Up @@ -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<OpenXDA.Types.Channel> = _.clone(props.Channels);
Expand All @@ -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}
Expand Down Expand Up @@ -521,7 +522,7 @@ export default function AssetPage(props: IProps) {
<div className="col-12 d-flex flex-column">
<ChannelSelector
Label="Associated Channels"
Channels={filterChannels}
Channels={filterChannels}
SelectedChannels={newEditAsset.Channels}
UpdateChannels={(c) => {
setNewEditAsset((prev) => ({ ...prev, Channels: c }));
Expand All @@ -538,7 +539,7 @@ export default function AssetPage(props: IProps) {
<div className="col-6 d-flex flex-column">
<ChannelSelector
Label="Associated Channels Bus Side"
Channels={filterChannels}
Channels={filterChannels}
SelectedChannels={newEditAsset.Channels.filter(ch => ch.ConnectionPriority == 0)}
UpdateChannels={(c) => {
let asset = _.clone(newEditAsset as OpenXDA.Types.Asset);
Expand All @@ -556,7 +557,7 @@ export default function AssetPage(props: IProps) {
<div className="col-6 d-flex flex-column">
<ChannelSelector
Label="Associated Channels Line/XFR Side"
Channels={filterChannels}
Channels={filterChannels}
SelectedChannels={newEditAsset.Channels.filter(ch => ch.ConnectionPriority == 1)}
UpdateChannels={(c) => {
let asset = _.clone(newEditAsset as OpenXDA.Types.Asset);
Expand All @@ -569,15 +570,15 @@ 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);
}}
/>
/>
</div> </> : null}
{newEditAsset.AssetType === 'Transformer' ? (
<div className="col-12">
<div className="row justify-content-center h-100">
<div className="col-4 d-flex flex-column">
<ChannelSelector
Label="Associated Channels Primary Side"
Channels={filterChannels}
Channels={filterChannels}
SelectedChannels={newEditAsset.Channels.filter(ch => ch.ConnectionPriority == 0)}
UpdateChannels={(c) => {
let asset = _.clone(newEditAsset as OpenXDA.Types.Asset);
Expand All @@ -595,7 +596,7 @@ export default function AssetPage(props: IProps) {
<div className="col-4 d-flex flex-column">
<ChannelSelector
Label="Associated Channels Secondary Side"
Channels={filterChannels}
Channels={filterChannels}
SelectedChannels={newEditAsset.Channels.filter(ch => ch.ConnectionPriority == 1)}
UpdateChannels={(c) => {
let asset = _.clone(newEditAsset as OpenXDA.Types.Asset);
Expand All @@ -613,7 +614,7 @@ export default function AssetPage(props: IProps) {
<div className="col-4 d-flex flex-column">
<ChannelSelector
Label="Associated Channels Tertiary Side"
Channels={filterChannels}
Channels={filterChannels}
SelectedChannels={newEditAsset.Channels.filter(ch => ch.ConnectionPriority == 2)}
UpdateChannels={(c) => {
let asset = _.clone(newEditAsset as OpenXDA.Types.Asset);
Expand All @@ -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);
}}
/>
/>
</div>
</div>
</div>
Expand Down

0 comments on commit 3be1a01

Please sign in to comment.