Skip to content

Commit

Permalink
Merge pull request #22 from EyeSeeTea/fix/sharings-warnings
Browse files Browse the repository at this point in the history
fix sharing warnings
  • Loading branch information
MiquelAdell authored Jun 7, 2024
2 parents 673dcbd + b6a1ce1 commit a8a6e89
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
37 changes: 13 additions & 24 deletions src/domain/usecases/metadata/GetSharingSummaryUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import { NamedRef } from "../../entities/Ref";
export class GetSharingSummaryUseCase {
constructor(private metadataRepository: MetadataRepository) {}

public execute(update: SharingUpdate, payload: MetadataPayload): FutureData<SharingSummary> {
public execute(update: SharingUpdate, updatedMetadata: MetadataPayload): FutureData<SharingSummary> {
const { baseElements, excludedDependencies } = update;

return this.metadataRepository.getMetadataWithChildren(baseElements).flatMap(payloads => {
const payloadsSummary = this.getPayloadsSummary(payloads, payload, excludedDependencies);
const metadataWithDifferentSharing = this.getMetadataWithDifferentSharing(payloadsSummary, baseElements);
const sharingWarnings = this.cleanMetadataSharing(metadataWithDifferentSharing, excludedDependencies);
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);
Expand All @@ -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 => {
Expand All @@ -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));
});
});
}
Expand Down Expand Up @@ -89,11 +85,8 @@ export class GetSharingSummaryUseCase {
return _.pickBy(sharingPayload, value => !_.isEmpty(value));
}

private cleanMetadataSharing(
metadataSharingWithChildren: SharingWarning[],
excludedDependencies: string[]
): SharingWarning[] {
return metadataSharingWithChildren
private getMetadataWithDifferentSharing(metadataTree: SharingWarning[]): SharingWarning[] {
return metadataTree
.map(item => {
const children = item.children.filter(child => {
const childSharing = {
Expand All @@ -107,22 +100,18 @@ export class GetSharingSummaryUseCase {
public: item.sharing.public,
};

return (
!_.isEqual(childSharing, parentSharing) &&
!excludedDependencies.includes(child.id) &&
!isDefaultElement(child)
);
return !_.isEqual(childSharing, parentSharing) && !isDefaultElement(child);
});

return {
...item,
children: children,
};
})
.filter(item => !_.isEmpty(item.children) && !excludedDependencies.includes(item.id));
.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 => {
Expand Down
5 changes: 3 additions & 2 deletions src/webapp/components/sharing-summary/SharingSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const SharingSummary = ({ summary }: SharingSummaryProps) => {
{sharingWarnings.map(metadataItem => (
<MetadataList
key={metadataItem.id}
title={`${metadataItem.name} (${metadataItem.id}) has different sharing settings from:`}
title={`${metadataItem.name} (${metadataItem.id}) will have different sharing settings from:`}
metadata={metadataItem.children}
/>
))}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit a8a6e89

Please sign in to comment.