Skip to content

Commit ac0fd41

Browse files
Issue #770: Update Mapping tab allow all models for Source and all non-Source models for Target (#797)
Adjusted Source and Target Model selector conditions
1 parent bacadc2 commit ac0fd41

1 file changed

Lines changed: 50 additions & 46 deletions

File tree

frontends/mdr-frontend/src/pages/Explore/Mappings/MappingsView.tsx

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ const MappingsView: React.FC = () => {
737737
useEffect(() => {
738738
const loadModels = async () => {
739739
try {
740-
const data = await listModels({ type: 'SourceSchema' });
740+
const data = await listModels();
741741
const list = Array.isArray(data)
742742
? (data as any[]).map((m) => ({ Id: m.Id, Name: m.Name }))
743743
: [];
@@ -836,21 +836,28 @@ const MappingsView: React.FC = () => {
836836
[allGroups, versionByGroupId]
837837
);
838838

839-
// Count groups for a given source pointing to selected target (default normalize to 1 when absent)
839+
// Count groups for a given source pointing to selected target
840840
const countGroupsForSource = useCallback(
841841
(sourceId: number) => {
842842
if (!allGroups) return 0;
843-
const normalize = (id?: number) => (id && id > 0 ? id : 1);
844-
const targetId = selectedTargetId ?? 1;
845-
return allGroups.filter(
846-
(g) =>
847-
g.SourceDataModelId === sourceId &&
848-
normalize(g.TargetDataModelId) === normalize(targetId)
849-
).length;
843+
sourceId = sourceId ?? 0;
844+
const targetId = selectedTargetId ?? 0;
845+
return allGroups.filter((g) => g.SourceDataModelId === sourceId && g.TargetDataModelId === targetId).length;
850846
},
851847
[allGroups, selectedTargetId]
852848
);
853849

850+
// Count groups for a given target pointing to selected source
851+
const countGroupsForTarget = useCallback(
852+
(targetId: number) => {
853+
if (!allGroups) return 0;
854+
targetId = targetId ?? 0;
855+
const sourceId = selectedSourceId ?? 0;
856+
return allGroups.filter((g) => g.SourceDataModelId === sourceId && g.TargetDataModelId === targetId).length;
857+
},
858+
[allGroups, selectedSourceId]
859+
);
860+
854861
const onChangeSourceModel = useCallback(
855862
(nextId: number) => {
856863
// Update selection
@@ -2221,24 +2228,15 @@ const MappingsView: React.FC = () => {
22212228
)}
22222229
</RdxSelect.Trigger>
22232230
<RdxSelect.Content>
2224-
{allModels.map((m) => {
2225-
const count = countGroupsForSource(
2226-
m.Id
2227-
);
2231+
{allModels.filter((m: any) => m.Id !== selectedTargetId)
2232+
.map((m) => {
2233+
const count = countGroupsForSource(m.Id);
22282234
return (
2229-
<RdxSelect.Item
2230-
key={m.Id}
2231-
value={String(m.Id)}
2232-
>
2235+
<RdxSelect.Item key={m.Id} value={String(m.Id)}>
22332236
<div className="mappings-select-item-row">
22342237
<span>{m.Name}</span>
22352238
{count > 0 && (
2236-
<Badge
2237-
variant="soft"
2238-
color="gray"
2239-
>
2240-
{count}
2241-
</Badge>
2239+
<Badge variant="soft" color="gray">{count}</Badge>
22422240
)}
22432241
</div>
22442242
</RdxSelect.Item>
@@ -2496,12 +2494,10 @@ const MappingsView: React.FC = () => {
24962494
query={targetQuery}
24972495
onQueryChange={setTargetQuery}
24982496
headerNameNode={(() => {
2499-
const selected = orgLifModels.find(
2500-
(m) => m.Id === selectedTargetId
2501-
);
2502-
if (!orgLifModels.length) return 'Target';
2503-
if (orgLifModels.length === 1)
2504-
return selected?.Name || orgLifModels[0].Name;
2497+
const selected = allModels.find((m) => m.Id === selectedTargetId);
2498+
const selectedCount = selected
2499+
? countGroupsForTarget(selected.Id)
2500+
: 0;
25052501
return (
25062502
<RdxSelect.Root
25072503
value={
@@ -2513,25 +2509,33 @@ const MappingsView: React.FC = () => {
25132509
onChangeTargetModel(Number(v))
25142510
}
25152511
>
2516-
<RdxSelect.Trigger
2517-
className="mappings-source-select"
2518-
title="Select target OrgLIF model"
2519-
>
2520-
<span>
2521-
{selected?.Name || 'Select target'}
2522-
</span>
2512+
<RdxSelect.Trigger className="mappings-target-select" title="Select target data model">
2513+
<span>{selected?.Name || 'Select target'}</span>
2514+
{selectedCount > 0 && (
2515+
<Badge
2516+
variant="soft"
2517+
color="gray"
2518+
className="mappings-source-trigger-count"
2519+
>
2520+
{selectedCount}
2521+
</Badge>
2522+
)}
25232523
</RdxSelect.Trigger>
25242524
<RdxSelect.Content>
2525-
{orgLifModels.map((m) => (
2526-
<RdxSelect.Item
2527-
key={m.Id}
2528-
value={String(m.Id)}
2529-
>
2530-
<div className="mappings-select-item-row">
2531-
<span>{m.Name}</span>
2532-
</div>
2533-
</RdxSelect.Item>
2534-
))}
2525+
{allModels.filter((m: any) => m.Id !== selectedSourceId)
2526+
.map((m) => {
2527+
const count = countGroupsForTarget(m.Id);
2528+
return (
2529+
<RdxSelect.Item key={m.Id} value={String(m.Id)}>
2530+
<div className="mappings-select-item-row">
2531+
<span>{m.Name}</span>
2532+
{count > 0 && (
2533+
<Badge variant="soft" color="gray">{count}</Badge>
2534+
)}
2535+
</div>
2536+
</RdxSelect.Item>
2537+
);
2538+
})}
25352539
</RdxSelect.Content>
25362540
</RdxSelect.Root>
25372541
);

0 commit comments

Comments
 (0)