From dbfd5992ce762f14e1a4cb0bf99087b48f5c5e1a Mon Sep 17 00:00:00 2001 From: Lucki2g Date: Sat, 29 Nov 2025 17:45:54 +0100 Subject: [PATCH] fix: fix the N:N relationship visualisation, and hide relationships with entities outside solution by standard --- Generator/DTO/Relationship.cs | 1 + Generator/DataverseService.cs | 2 +- Generator/Services/RelationshipService.cs | 15 ++++++++++-- .../datamodelview/Relationships.tsx | 23 +++++++++++++++++++ Website/lib/Types.ts | 1 + 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/Generator/DTO/Relationship.cs b/Generator/DTO/Relationship.cs index 938b6e3..24cf3e0 100644 --- a/Generator/DTO/Relationship.cs +++ b/Generator/DTO/Relationship.cs @@ -9,6 +9,7 @@ public record Relationship( string TableSchema, string LookupDisplayName, string RelationshipSchema, + string? IntersectEntitySchemaName, string RelationshipType, bool IsExplicit, string PublisherName, diff --git a/Generator/DataverseService.cs b/Generator/DataverseService.cs index 84b3e8c..fed21bd 100644 --- a/Generator/DataverseService.cs +++ b/Generator/DataverseService.cs @@ -251,7 +251,7 @@ public DataverseService( .Select(entMeta => { var relevantAttributes = entMeta.Attributes.Where(attr => attributesInSolution.Contains(attr.MetadataId!.Value)).ToList(); - var relevantManyToManyRelations = relationshipService.ConvertManyToManyRelationships(entMeta.ManyToManyRelationships.Where(rel => relationshipsInSolution.Contains(rel.MetadataId!.Value)), entMeta.LogicalName, inclusionMap, publisherMap, componentSolutionMap, entMeta.MetadataId!.Value); + var relevantManyToManyRelations = relationshipService.ConvertManyToManyRelationships(entMeta.ManyToManyRelationships.Where(rel => relationshipsInSolution.Contains(rel.MetadataId!.Value)), entMeta.LogicalName, logicalToSchema, inclusionMap, publisherMap, componentSolutionMap, entMeta.MetadataId!.Value); var relevantOneToManyRelations = relationshipService.ConvertOneToManyRelationships(entMeta.OneToManyRelationships.Where(rel => relationshipsInSolution.Contains(rel.MetadataId!.Value)), true, logicalToSchema, attributeLogicalToSchema, inclusionMap, publisherMap, componentSolutionMap, entMeta.MetadataId!.Value); var relevantManyToOneRelations = relationshipService.ConvertOneToManyRelationships(entMeta.ManyToOneRelationships.Where(rel => relationshipsInSolution.Contains(rel.MetadataId!.Value)), false, logicalToSchema, attributeLogicalToSchema, inclusionMap, publisherMap, componentSolutionMap, entMeta.MetadataId!.Value); var relevantRelationships = relevantManyToManyRelations.Concat(relevantManyToOneRelations).Concat(relevantOneToManyRelations).ToList(); diff --git a/Generator/Services/RelationshipService.cs b/Generator/Services/RelationshipService.cs index de69bc7..374e35c 100644 --- a/Generator/Services/RelationshipService.cs +++ b/Generator/Services/RelationshipService.cs @@ -89,6 +89,7 @@ public Dictionary ParseTableGroups() public IEnumerable ConvertManyToManyRelationships( IEnumerable relationships, string entityLogicalName, + Dictionary logicalToSchema, Dictionary inclusionMap, Dictionary publisherMap, Dictionary> componentSolutionMap, @@ -103,12 +104,21 @@ public IEnumerable ConvertManyToManyRelationships( var relationshipSolutions = componentSolutionMap.GetValueOrDefault(rel.MetadataId!.Value) ?? componentSolutionMap.GetValueOrDefault(entityMetadataId, new List()); + var relatedTable = rel.Entity1LogicalName.Equals(entityLogicalName, StringComparison.OrdinalIgnoreCase) + ? rel.Entity2LogicalName + : rel.Entity1LogicalName; + + var relatedSchemaName = logicalToSchema.ContainsKey(relatedTable) + ? logicalToSchema[relatedTable].Name + : relatedTable; + return new Relationship( rel.IsCustomRelationship ?? false, - $"{rel.Entity1AssociatedMenuConfiguration.Label.ToLabelString()} ⟷ {rel.Entity2AssociatedMenuConfiguration.Label.ToLabelString()}", - entityLogicalName, + $"{rel.Entity1LogicalName} ⟷ {rel.Entity2LogicalName}", + relatedSchemaName, "-", rel.SchemaName, + rel.IntersectEntityName, "N:N", inclusionMap[rel.MetadataId!.Value], pName, @@ -154,6 +164,7 @@ public IEnumerable ConvertOneToManyRelationships( tableSchema, lookupName, rel.SchemaName, + null, !isOneToMany ? "N:1" : "1:N", inclusionMap[rel.MetadataId!.Value], pName, diff --git a/Website/components/datamodelview/Relationships.tsx b/Website/components/datamodelview/Relationships.tsx index 334f711..94e1088 100644 --- a/Website/components/datamodelview/Relationships.tsx +++ b/Website/components/datamodelview/Relationships.tsx @@ -25,6 +25,7 @@ export const Relationships = ({ entity, search = "", onVisibleCountChange }: IRe const [typeFilter, setTypeFilter] = useState("all") const [searchQuery, setSearchQuery] = useState("") const [hideImplicitRelationships, setHideImplicitRelationships] = useState(true) + const [hideOutOfSolutionRelationships, setHideOutOfSolutionRelationships] = useState(true) const theme = useTheme(); @@ -88,6 +89,11 @@ export const Relationships = ({ entity, search = "", onVisibleCountChange }: IRe filteredRelationships = filteredRelationships.filter(rel => rel.IsExplicit || !hideImplicitRelationships); + // Filter out relationships where related table is not in solution + if (hideOutOfSolutionRelationships) { + filteredRelationships = filteredRelationships.filter(rel => isEntityInSolution(rel.TableSchema)); + } + if (!sortColumn || !sortDirection) return filteredRelationships return [...filteredRelationships].sort((a, b) => { @@ -225,6 +231,21 @@ export const Relationships = ({ entity, search = "", onVisibleCountChange }: IRe } + + + {(searchQuery || typeFilter !== "all") && (