Skip to content
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

SC-206 Filters out used Channels #531

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +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(() => {
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 @@ -448,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 @@ -475,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 @@ -516,7 +522,7 @@ export default function AssetPage(props: IProps) {
<div className="col-12 d-flex flex-column">
<ChannelSelector
Label="Associated Channels"
Channels={props.Channels}
Channels={filterChannels}
SelectedChannels={newEditAsset.Channels}
UpdateChannels={(c) => {
setNewEditAsset((prev) => ({ ...prev, Channels: c }));
Expand All @@ -533,7 +539,7 @@ export default function AssetPage(props: IProps) {
<div className="col-6 d-flex flex-column">
<ChannelSelector
Label="Associated Channels Bus Side"
Channels={props.Channels}
Channels={filterChannels}
SelectedChannels={newEditAsset.Channels.filter(ch => ch.ConnectionPriority == 0)}
UpdateChannels={(c) => {
let asset = _.clone(newEditAsset as OpenXDA.Types.Asset);
Expand All @@ -551,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={props.Channels}
Channels={filterChannels}
SelectedChannels={newEditAsset.Channels.filter(ch => ch.ConnectionPriority == 1)}
UpdateChannels={(c) => {
let asset = _.clone(newEditAsset as OpenXDA.Types.Asset);
Expand All @@ -564,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={props.Channels}
Channels={filterChannels}
SelectedChannels={newEditAsset.Channels.filter(ch => ch.ConnectionPriority == 0)}
UpdateChannels={(c) => {
let asset = _.clone(newEditAsset as OpenXDA.Types.Asset);
Expand All @@ -590,7 +596,7 @@ export default function AssetPage(props: IProps) {
<div className="col-4 d-flex flex-column">
<ChannelSelector
Label="Associated Channels Secondary Side"
Channels={props.Channels}
Channels={filterChannels}
SelectedChannels={newEditAsset.Channels.filter(ch => ch.ConnectionPriority == 1)}
UpdateChannels={(c) => {
let asset = _.clone(newEditAsset as OpenXDA.Types.Asset);
Expand All @@ -608,7 +614,7 @@ export default function AssetPage(props: IProps) {
<div className="col-4 d-flex flex-column">
<ChannelSelector
Label="Associated Channels Tertiary Side"
Channels={props.Channels}
Channels={filterChannels}
SelectedChannels={newEditAsset.Channels.filter(ch => ch.ConnectionPriority == 2)}
UpdateChannels={(c) => {
let asset = _.clone(newEditAsset as OpenXDA.Types.Asset);
Expand All @@ -621,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 All @@ -632,5 +638,4 @@ export default function AssetPage(props: IProps) {
</Modal>
</div>
);

}