Skip to content

Commit bdaa04e

Browse files
authored
Merge pull request #77 from delegateas/patch/relationshipspatch
Fix the N:N relationship visualisation
2 parents 67e39a5 + dbfd599 commit bdaa04e

File tree

5 files changed

+39
-3
lines changed

5 files changed

+39
-3
lines changed

Generator/DTO/Relationship.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public record Relationship(
99
string TableSchema,
1010
string LookupDisplayName,
1111
string RelationshipSchema,
12+
string? IntersectEntitySchemaName,
1213
string RelationshipType,
1314
bool IsExplicit,
1415
string PublisherName,

Generator/DataverseService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public DataverseService(
251251
.Select(entMeta =>
252252
{
253253
var relevantAttributes = entMeta.Attributes.Where(attr => attributesInSolution.Contains(attr.MetadataId!.Value)).ToList();
254-
var relevantManyToManyRelations = relationshipService.ConvertManyToManyRelationships(entMeta.ManyToManyRelationships.Where(rel => relationshipsInSolution.Contains(rel.MetadataId!.Value)), entMeta.LogicalName, inclusionMap, publisherMap, componentSolutionMap, entMeta.MetadataId!.Value);
254+
var relevantManyToManyRelations = relationshipService.ConvertManyToManyRelationships(entMeta.ManyToManyRelationships.Where(rel => relationshipsInSolution.Contains(rel.MetadataId!.Value)), entMeta.LogicalName, logicalToSchema, inclusionMap, publisherMap, componentSolutionMap, entMeta.MetadataId!.Value);
255255
var relevantOneToManyRelations = relationshipService.ConvertOneToManyRelationships(entMeta.OneToManyRelationships.Where(rel => relationshipsInSolution.Contains(rel.MetadataId!.Value)), true, logicalToSchema, attributeLogicalToSchema, inclusionMap, publisherMap, componentSolutionMap, entMeta.MetadataId!.Value);
256256
var relevantManyToOneRelations = relationshipService.ConvertOneToManyRelationships(entMeta.ManyToOneRelationships.Where(rel => relationshipsInSolution.Contains(rel.MetadataId!.Value)), false, logicalToSchema, attributeLogicalToSchema, inclusionMap, publisherMap, componentSolutionMap, entMeta.MetadataId!.Value);
257257
var relevantRelationships = relevantManyToManyRelations.Concat(relevantManyToOneRelations).Concat(relevantOneToManyRelations).ToList();

Generator/Services/RelationshipService.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public Dictionary<string, string> ParseTableGroups()
8989
public IEnumerable<Relationship> ConvertManyToManyRelationships(
9090
IEnumerable<ManyToManyRelationshipMetadata> relationships,
9191
string entityLogicalName,
92+
Dictionary<string, ExtendedEntityInformation> logicalToSchema,
9293
Dictionary<Guid, bool> inclusionMap,
9394
Dictionary<Guid, (string Name, string Prefix)> publisherMap,
9495
Dictionary<Guid, List<SolutionInfo>> componentSolutionMap,
@@ -103,12 +104,21 @@ public IEnumerable<Relationship> ConvertManyToManyRelationships(
103104
var relationshipSolutions = componentSolutionMap.GetValueOrDefault(rel.MetadataId!.Value)
104105
?? componentSolutionMap.GetValueOrDefault(entityMetadataId, new List<SolutionInfo>());
105106

107+
var relatedTable = rel.Entity1LogicalName.Equals(entityLogicalName, StringComparison.OrdinalIgnoreCase)
108+
? rel.Entity2LogicalName
109+
: rel.Entity1LogicalName;
110+
111+
var relatedSchemaName = logicalToSchema.ContainsKey(relatedTable)
112+
? logicalToSchema[relatedTable].Name
113+
: relatedTable;
114+
106115
return new Relationship(
107116
rel.IsCustomRelationship ?? false,
108-
$"{rel.Entity1AssociatedMenuConfiguration.Label.ToLabelString()}{rel.Entity2AssociatedMenuConfiguration.Label.ToLabelString()}",
109-
entityLogicalName,
117+
$"{rel.Entity1LogicalName}{rel.Entity2LogicalName}",
118+
relatedSchemaName,
110119
"-",
111120
rel.SchemaName,
121+
rel.IntersectEntityName,
112122
"N:N",
113123
inclusionMap[rel.MetadataId!.Value],
114124
pName,
@@ -154,6 +164,7 @@ public IEnumerable<Relationship> ConvertOneToManyRelationships(
154164
tableSchema,
155165
lookupName,
156166
rel.SchemaName,
167+
null,
157168
!isOneToMany ? "N:1" : "1:N",
158169
inclusionMap[rel.MetadataId!.Value],
159170
pName,

Website/components/datamodelview/Relationships.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const Relationships = ({ entity, search = "", onVisibleCountChange }: IRe
2525
const [typeFilter, setTypeFilter] = useState<string>("all")
2626
const [searchQuery, setSearchQuery] = useState("")
2727
const [hideImplicitRelationships, setHideImplicitRelationships] = useState<boolean>(true)
28+
const [hideOutOfSolutionRelationships, setHideOutOfSolutionRelationships] = useState<boolean>(true)
2829

2930
const theme = useTheme();
3031

@@ -88,6 +89,11 @@ export const Relationships = ({ entity, search = "", onVisibleCountChange }: IRe
8889

8990
filteredRelationships = filteredRelationships.filter(rel => rel.IsExplicit || !hideImplicitRelationships);
9091

92+
// Filter out relationships where related table is not in solution
93+
if (hideOutOfSolutionRelationships) {
94+
filteredRelationships = filteredRelationships.filter(rel => isEntityInSolution(rel.TableSchema));
95+
}
96+
9197
if (!sortColumn || !sortDirection) return filteredRelationships
9298

9399
return [...filteredRelationships].sort((a, b) => {
@@ -225,6 +231,21 @@ export const Relationships = ({ entity, search = "", onVisibleCountChange }: IRe
225231
}
226232
</Button>
227233
</Tooltip>
234+
<Tooltip title={hideOutOfSolutionRelationships ? "Show relationships to tables not in solution" : "Hide relationships to tables not in solution"}>
235+
<Button
236+
variant="outlined"
237+
size="small"
238+
onClick={() => setHideOutOfSolutionRelationships(!hideOutOfSolutionRelationships)}
239+
className="min-w-0 p-0 h-8 w-8 md:h-10 md:w-10"
240+
sx={{
241+
borderColor: 'border.main'
242+
}}
243+
>
244+
{
245+
hideOutOfSolutionRelationships ? <ContentPasteOffRounded className="text-xs md:text-base" /> : <ContentPasteSearchRounded className="text-xs md:text-base" />
246+
}
247+
</Button>
248+
</Tooltip>
228249
{(searchQuery || typeFilter !== "all") && (
229250
<Button
230251
variant="text"
@@ -441,6 +462,8 @@ export const Relationships = ({ entity, search = "", onVisibleCountChange }: IRe
441462
</TableCell>
442463
<TableCell className="break-words py-1 md:py-1.5 text-xs md:text-sm">
443464
{relationship.RelationshipSchema}
465+
{relationship.IntersectEntitySchemaName &&
466+
(<Typography variant="body2" className="text-xs md:text-sm text-secondary"><b>Intersecting table:</b> {relationship.IntersectEntitySchemaName}</Typography>)}
444467
</TableCell>
445468
</TableRow>
446469
)}

Website/lib/Types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ export type RelationshipType = {
227227
TableSchema: string,
228228
LookupDisplayName: string,
229229
RelationshipSchema: string,
230+
IntersectEntitySchemaName: string | null,
230231
IsExplicit: boolean,
231232
RelationshipType: "N:N" | "1:N" | "N:1",
232233
CascadeConfiguration: CascadeConfigurationType | null,

0 commit comments

Comments
 (0)