Skip to content

Commit

Permalink
more improvements on review panel (finos#2952)
Browse files Browse the repository at this point in the history
  • Loading branch information
MauricioUyaguari authored Feb 17, 2024
1 parent d856304 commit 2a690c7
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 63 deletions.
4 changes: 4 additions & 0 deletions .changeset/few-monkeys-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
'@finos/legend-application-studio': patch
'@finos/legend-server-sdlc': patch
---
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const ProjectReviewerSideBar = observer(() => {
}
// Actions
const isDispatchingAction =
reviewStore.fetchComparisonState.isInProgress ||
reviewStore.buildReviewReportState.isInProgress ||
reviewStore.approveState.isInProgress ||
reviewStore.closeState.isInProgress ||
reviewStore.commitState.isInProgress ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const ProjectReviewerStatusBar = observer(() => {
? 'closing review...'
: reviewStore.reOpenState.isInProgress
? 'reopening review...'
: reviewStore.fetchComparisonState.isInProgress
: reviewStore.buildReviewReportState.isInProgress
? 'loading changes...'
: undefined;
const toggleAssistant = (): void =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
guaranteeNonNullable,
ActionState,
assertNonEmptyString,
isNonNullable,
} from '@finos/legend-shared';
import {
makeObservable,
Expand Down Expand Up @@ -53,38 +54,57 @@ export class ProjectReviewReport {
diffs: EntityDiff[];
fromEntities: Entity[] = [];
toEntities: Entity[] = [];
private fromConfig: PlainObject<ProjectConfiguration> | undefined;
private toConfig: PlainObject<ProjectConfiguration> | undefined;
fromToProjectConfig:
| [PlainObject<ProjectConfiguration>, PlainObject<ProjectConfiguration>]
| undefined;

constructor(diffs: EntityDiff[]) {
this.diffs = diffs;

makeObservable(this, {
fromEntities: observable,
toEntities: observable,
fromToProjectConfig: observable,
addFromConfig: action,
addToConfig: action,
});
}

findFromEntity(entityPath: string): Entity | undefined {
return this.fromEntities.find((e) => e.path === entityPath);
addFromConfig(config: PlainObject<ProjectConfiguration>): void {
this.fromConfig = config;
this.createFromToConfigIfPossible();
}

findToEntity(entityPath: string): Entity | undefined {
return this.toEntities.find((e) => e.path === entityPath);
addToConfig(config: PlainObject<ProjectConfiguration>): void {
this.toConfig = config;
this.createFromToConfigIfPossible();
}

withFromEntities(val: Entity[]): ProjectReviewReport {
this.fromEntities = val;
return this;
private createFromToConfigIfPossible(): void {
if (this.fromConfig && this.toConfig) {
this.fromToProjectConfig = [this.fromConfig, this.toConfig];
}
}

withToEntities(val: Entity[]): ProjectReviewReport {
this.toEntities = val;
findFromEntity(entityPath: string): Entity | undefined {
return this.fromEntities.find((e) => e.path === entityPath);
}

addFromEntity(entity: Entity): ProjectReviewReport {
this.fromEntities.push(entity);
return this;
}

withProjectConfigChange(
val: [PlainObject<ProjectConfiguration>, PlainObject<ProjectConfiguration>],
): ProjectReviewReport {
this.fromToProjectConfig = val;
addToEntity(entity: Entity): ProjectReviewReport {
this.toEntities.push(entity);
return this;
}

findToEntity(entityPath: string): Entity | undefined {
return this.toEntities.find((e) => e.path === entityPath);
}
}

export class ProjectReviewerStore {
Expand All @@ -96,8 +116,7 @@ export class ProjectReviewerStore {
currentReviewId?: string | undefined;
currentReview?: Review | undefined;
// comparison
fetchComparisonState = ActionState.create();
reviewComparison?: Comparison | undefined;
buildReviewReportState = ActionState.create();
reviewReport?: ProjectReviewReport | undefined;

fetchCurrentReviewState = ActionState.create();
Expand All @@ -116,7 +135,7 @@ export class ProjectReviewerStore {
currentReviewId: observable,
currentReview: observable,
fetchCurrentReviewState: observable,
fetchComparisonState: observable,
buildReviewReportState: observable,
approveState: observable,
closeState: observable,
commitState: observable,
Expand Down Expand Up @@ -160,13 +179,6 @@ export class ProjectReviewerStore {
return guaranteeNonNullable(this.currentReview, 'Review must exist');
}

get comparison(): Comparison {
return guaranteeNonNullable(
this.reviewComparison,
'review Comparison must exist',
);
}

get approvalString(): string | undefined {
const approvals = this.reviewApproval?.approvedBy;
if (approvals?.length) {
Expand Down Expand Up @@ -267,7 +279,6 @@ export class ProjectReviewerStore {

refresh(): void {
this.editorStore.tabManagerState.closeAllTabs();
this.reviewComparison = undefined;
this.reviewReport = undefined;
flowResult(this.fetchReviewComparison()).catch(
this.editorStore.applicationStore.alertUnhandledError,
Expand All @@ -279,52 +290,66 @@ export class ProjectReviewerStore {
* assume the review has completed been fetched
*/
*fetchReviewComparison(): GeneratorFn<void> {
this.fetchComparisonState.inProgress();
this.buildReviewReportState.inProgress();
try {
const [comparison, fromEntities, toEntities] = (yield Promise.all([
this.editorStore.sdlcServerClient.getReviewComparision(
this.projectId,
this.patchReleaseVersionId,
this.reviewId,
),
this.editorStore.sdlcServerClient.getReviewFromEntities(
this.projectId,
this.patchReleaseVersionId,
this.reviewId,
),
this.editorStore.sdlcServerClient.getReviewToEntities(
const comparison = Comparison.serialization.fromJson(
(yield this.editorStore.sdlcServerClient.getReviewComparision(
this.projectId,
this.patchReleaseVersionId,
this.reviewId,
),
])) as [PlainObject<Comparison>, Entity[], Entity[]];
const resolvedComparison = Comparison.serialization.fromJson(comparison);
this.reviewComparison = resolvedComparison;
)) as PlainObject<Comparison>,
);
const report = new ProjectReviewReport(
reprocessEntityDiffs(resolvedComparison.entityDiffs),
reprocessEntityDiffs(comparison.entityDiffs),
);
report.withFromEntities(fromEntities).withToEntities(toEntities);
this.reviewReport = report;
if (comparison.projectConfigurationUpdated) {
const [fromConfig, toConfig] = (yield Promise.all([
this.editorStore.sdlcServerClient.getReviewFromConfiguration(
this.projectId,
this.patchReleaseVersionId,
this.reviewId,
const fromToRequests = Promise.all([
...report.diffs
.map((diff) => diff.oldPath)
.filter(isNonNullable)
.map((fromDiff) =>
this.editorStore.sdlcServerClient
.getReviewFromEntity(
this.projectId,
this.patchReleaseVersionId,
this.reviewId,
fromDiff,
)
.then((fromEntity: Entity) => report.addFromEntity(fromEntity)),
),
this.editorStore.sdlcServerClient.getReviewToConfiguration(
this.projectId,
this.patchReleaseVersionId,
this.reviewId,
...report.diffs
.map((diff) => diff.newPath)
.filter(isNonNullable)
.map((toDiff) =>
this.editorStore.sdlcServerClient
.getReviewToEntity(
this.projectId,
this.patchReleaseVersionId,
this.reviewId,
toDiff,
)
.then((toEntity: Entity) => report.addToEntity(toEntity)),
),
])) as [
PlainObject<ProjectConfiguration> | undefined,
PlainObject<ProjectConfiguration> | undefined,
]);
if (comparison.projectConfigurationUpdated) {
[
this.editorStore.sdlcServerClient
.getReviewFromConfiguration(
this.projectId,
this.patchReleaseVersionId,
this.reviewId,
)
.then((config) => report.addFromConfig(config)),
this.editorStore.sdlcServerClient
.getReviewToConfiguration(
this.projectId,
this.patchReleaseVersionId,
this.reviewId,
)
.then((config) => report.addToConfig(config)),
];
if (fromConfig && toConfig) {
report.withProjectConfigChange([fromConfig, toConfig]);
}
}
yield fromToRequests;
} catch (error) {
assertErrorThrown(error);
this.editorStore.applicationStore.logService.error(
Expand All @@ -333,7 +358,7 @@ export class ProjectReviewerStore {
);
this.editorStore.applicationStore.notificationService.notifyError(error);
} finally {
this.fetchComparisonState.complete();
this.buildReviewReportState.complete();
}
}

Expand Down
28 changes: 27 additions & 1 deletion packages/legend-server-sdlc/src/SDLCServerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1022,14 +1022,27 @@ export class SDLCServerClient extends AbstractServerClient {
projectId: string,
patchReleaseVersionId: string | undefined,
reviewId: string,
): Promise<Entity[]> =>
): Promise<Entity> =>
this.get(
`${this._reviewComparison(
projectId,
patchReleaseVersionId,
reviewId,
)}/from/entities`,
);
getReviewFromEntity = (
projectId: string,
patchReleaseVersionId: string | undefined,
reviewId: string,
entityPath: string,
): Promise<Entity> =>
this.get(
`${this._reviewComparison(
projectId,
patchReleaseVersionId,
reviewId,
)}/from/entities/${entityPath}`,
);
getReviewToEntities = (
projectId: string,
patchReleaseVersionId: string | undefined,
Expand All @@ -1042,6 +1055,19 @@ export class SDLCServerClient extends AbstractServerClient {
reviewId,
)}/to/entities`,
);
getReviewToEntity = (
projectId: string,
patchReleaseVersionId: string | undefined,
reviewId: string,
entityPath: string,
): Promise<Entity> =>
this.get(
`${this._reviewComparison(
projectId,
patchReleaseVersionId,
reviewId,
)}/to/entities/${entityPath}`,
);

// ------------------------------------------- Conflict Resolution -------------------------------------------

Expand Down

0 comments on commit 2a690c7

Please sign in to comment.