From a2481a181c8c69b0e9039dae6a74ad24b299a3c5 Mon Sep 17 00:00:00 2001 From: deeonwuli Date: Thu, 30 May 2024 14:02:55 +0100 Subject: [PATCH 1/3] fix: add excludedDependencies to sharing warnings --- .../metadata/GetSharingSummaryUseCase.ts | 27 ++++++------------- .../sharing-summary/SharingSummary.tsx | 3 ++- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/domain/usecases/metadata/GetSharingSummaryUseCase.ts b/src/domain/usecases/metadata/GetSharingSummaryUseCase.ts index bc27d3e..9b83219 100644 --- a/src/domain/usecases/metadata/GetSharingSummaryUseCase.ts +++ b/src/domain/usecases/metadata/GetSharingSummaryUseCase.ts @@ -12,10 +12,10 @@ export class GetSharingSummaryUseCase { public execute(update: SharingUpdate, payload: MetadataPayload): FutureData { const { baseElements, excludedDependencies } = update; - return this.metadataRepository.getMetadataWithChildren(baseElements).flatMap(payloads => { - const payloadsSummary = this.getPayloadsSummary(payloads, payload, excludedDependencies); + return this.metadataRepository.getMetadataWithChildren(baseElements).flatMap(selectedMetadata => { + const payloadsSummary = this.getPayloadsSummary(selectedMetadata, payload); const metadataWithDifferentSharing = this.getMetadataWithDifferentSharing(payloadsSummary, baseElements); - const sharingWarnings = this.cleanMetadataSharing(metadataWithDifferentSharing, excludedDependencies); + const sharingWarnings = this.cleanMetadataSharing(metadataWithDifferentSharing); const sharingPayload = this.getSharingPayload(payload, excludedDependencies); return this.metadataRepository.getMetadataFromIds(excludedDependencies).flatMap(excludedPayload => { @@ -37,11 +37,7 @@ export class GetSharingSummaryUseCase { }); } - private getPayloadsSummary( - d2Payloads: MetadataPayload[], - updatedPayload: MetadataPayload, - excludedDependencies: string[] - ): MetadataPayload[] { + private getPayloadsSummary(d2Payloads: MetadataPayload[], updatedPayload: MetadataPayload): MetadataPayload[] { const cleanedPayload = this.cleanPayload(updatedPayload); return d2Payloads.map(d2Payload => { @@ -55,7 +51,7 @@ export class GetSharingSummaryUseCase { const existing = mappingArray.find(mappingItem => mappingItem.id === item.id); return existing ? { ...item, sharing: existing.sharing } : item; }) - .filter(payload => !excludedDependencies.includes(payload.id) && !isDefaultElement(payload)); + .filter(payload => !isDefaultElement(payload)); }); }); } @@ -89,10 +85,7 @@ export class GetSharingSummaryUseCase { return _.pickBy(sharingPayload, value => !_.isEmpty(value)); } - private cleanMetadataSharing( - metadataSharingWithChildren: SharingWarning[], - excludedDependencies: string[] - ): SharingWarning[] { + private cleanMetadataSharing(metadataSharingWithChildren: SharingWarning[]): SharingWarning[] { return metadataSharingWithChildren .map(item => { const children = item.children.filter(child => { @@ -107,11 +100,7 @@ export class GetSharingSummaryUseCase { public: item.sharing.public, }; - return ( - !_.isEqual(childSharing, parentSharing) && - !excludedDependencies.includes(child.id) && - !isDefaultElement(child) - ); + return !_.isEqual(childSharing, parentSharing) && !isDefaultElement(child); }); return { @@ -119,7 +108,7 @@ export class GetSharingSummaryUseCase { children: children, }; }) - .filter(item => !_.isEmpty(item.children) && !excludedDependencies.includes(item.id)); + .filter(item => !_.isEmpty(item.children)); } private getMetadataWithDifferentSharing(payload: MetadataPayload[], parentIds: string[]): SharingWarning[] { diff --git a/src/webapp/components/sharing-summary/SharingSummary.tsx b/src/webapp/components/sharing-summary/SharingSummary.tsx index a5fcd0d..5fb3056 100644 --- a/src/webapp/components/sharing-summary/SharingSummary.tsx +++ b/src/webapp/components/sharing-summary/SharingSummary.tsx @@ -65,8 +65,9 @@ const Title = styled.p` `; const Warnings = styled.div` - background-color: #FFF4E5; + background-color: #fff4e5; padding: 2rem; + margin-bottom: 1rem; `; function pluralize(str: string) { From 1b3a3bf5f2116c43fae1340d5e003894dbbb0693 Mon Sep 17 00:00:00 2001 From: deeonwuli Date: Mon, 3 Jun 2024 15:08:32 +0100 Subject: [PATCH 2/3] chore: change warning message --- src/webapp/components/sharing-summary/SharingSummary.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webapp/components/sharing-summary/SharingSummary.tsx b/src/webapp/components/sharing-summary/SharingSummary.tsx index 5fb3056..62bcce1 100644 --- a/src/webapp/components/sharing-summary/SharingSummary.tsx +++ b/src/webapp/components/sharing-summary/SharingSummary.tsx @@ -23,7 +23,7 @@ export const SharingSummary = ({ summary }: SharingSummaryProps) => { {sharingWarnings.map(metadataItem => ( ))} From b6a1ce17e8d6cdd158190307c217eb9d99f614d5 Mon Sep 17 00:00:00 2001 From: deeonwuli Date: Mon, 3 Jun 2024 15:08:47 +0100 Subject: [PATCH 3/3] chore: rename functions and variables --- .../metadata/GetSharingSummaryUseCase.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/domain/usecases/metadata/GetSharingSummaryUseCase.ts b/src/domain/usecases/metadata/GetSharingSummaryUseCase.ts index 9b83219..e89c981 100644 --- a/src/domain/usecases/metadata/GetSharingSummaryUseCase.ts +++ b/src/domain/usecases/metadata/GetSharingSummaryUseCase.ts @@ -9,14 +9,14 @@ import { NamedRef } from "../../entities/Ref"; export class GetSharingSummaryUseCase { constructor(private metadataRepository: MetadataRepository) {} - public execute(update: SharingUpdate, payload: MetadataPayload): FutureData { + public execute(update: SharingUpdate, updatedMetadata: MetadataPayload): FutureData { const { baseElements, excludedDependencies } = update; - return this.metadataRepository.getMetadataWithChildren(baseElements).flatMap(selectedMetadata => { - const payloadsSummary = this.getPayloadsSummary(selectedMetadata, payload); - const metadataWithDifferentSharing = this.getMetadataWithDifferentSharing(payloadsSummary, baseElements); - const sharingWarnings = this.cleanMetadataSharing(metadataWithDifferentSharing); - const sharingPayload = this.getSharingPayload(payload, excludedDependencies); + return this.metadataRepository.getMetadataWithChildren(baseElements).flatMap(currentMetadata => { + const payloadsSummary = this.getPayloadsSummary(currentMetadata, updatedMetadata); + const metadataTree = this.buildMetadataTreeFromPayload(payloadsSummary, baseElements); + const sharingWarnings = this.getMetadataWithDifferentSharing(metadataTree); + const sharingPayload = this.getSharingPayload(updatedMetadata, excludedDependencies); return this.metadataRepository.getMetadataFromIds(excludedDependencies).flatMap(excludedPayload => { const excludedMetadata = this.getMetadataFromPayload(excludedPayload); @@ -85,8 +85,8 @@ export class GetSharingSummaryUseCase { return _.pickBy(sharingPayload, value => !_.isEmpty(value)); } - private cleanMetadataSharing(metadataSharingWithChildren: SharingWarning[]): SharingWarning[] { - return metadataSharingWithChildren + private getMetadataWithDifferentSharing(metadataTree: SharingWarning[]): SharingWarning[] { + return metadataTree .map(item => { const children = item.children.filter(child => { const childSharing = { @@ -111,7 +111,7 @@ export class GetSharingSummaryUseCase { .filter(item => !_.isEmpty(item.children)); } - private getMetadataWithDifferentSharing(payload: MetadataPayload[], parentIds: string[]): SharingWarning[] { + private buildMetadataTreeFromPayload(payload: MetadataPayload[], parentIds: string[]): SharingWarning[] { return _(payload) .flatMap(payloadGroup => parentIds.map(parentId => {