Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M2-6235: In progress activity flow/activity name is changing after editing, when it shouldn't #768

Draft
wants to merge 6 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/abstract/lib/types/entityProgress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ export type FlowProgress = {
currentActivityImage: string | null;
currentActivityStartAt: number | null;
executionGroupKey: string;
entityName: string;
};

export type ActivityProgress = {
type: ActivityPipelineType.Regular;
entityName: string;
};

export type EntityProgress = FlowProgress | ActivityProgress;
Expand Down
1 change: 1 addition & 0 deletions src/abstract/lib/utils/progressConvert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const convertProgress = (storeProgress: StoreProgress): Progress => {
executionGroupKey: uuidv4(),
pipelineActivityOrder: flowProgress.pipelineActivityOrder,
totalActivitiesInPipeline: flowProgress.totalActivitiesInPipeline,
entityName: flowProgress.entityName,
vmkhitaryanscn marked this conversation as resolved.
Show resolved Hide resolved
};
result[appletId][entityId][eventId] = payload;
}
Expand Down
2 changes: 2 additions & 0 deletions src/app/model/migrations/MigrationFactory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { __queryClient__ } from '@app/app/ui/AppProvider/ReactQueryProvider';

import { MigrationToVersion0001 } from './migrations/to0001/MigrationToVersion0001';
import { MigrationToVersion0002 } from './migrations/to0002/MigrationToVersion0002';
import { IMigration } from './types';

type VersionFrom = number;
Expand All @@ -11,6 +12,7 @@ export class MigrationFactory {
public createMigrations(): Migrations {
return {
1: new MigrationToVersion0001(__queryClient__),
2: new MigrationToVersion0002(),
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { ActivityPipelineType } from '@app/abstract/lib';

export type FlowProgressFrom = {
type: ActivityPipelineType.Flow;
pipelineActivityOrder: number;
totalActivitiesInPipeline: number;
currentActivityId: string;
currentActivityName: string;
currentActivityDescription: string;
currentActivityImage: string | null;
currentActivityStartAt: number | null;
executionGroupKey: string;
};

type ActivityProgressFrom = {
type: ActivityPipelineType.Regular;
};

type EntityProgressFrom = FlowProgressFrom | ActivityProgressFrom;

export type StoreProgressPayloadFrom = EntityProgressFrom & {
startAt: number;
endAt: number | null;
};

type StoreEventsProgressFrom = Record<string, StoreProgressPayloadFrom>;

type StoreEntitiesProgressFrom = Record<string, StoreEventsProgressFrom>;

type StoreProgressFrom = Record<string, StoreEntitiesProgressFrom>;

export type FlowProgressTo = {
type: ActivityPipelineType.Flow;
pipelineActivityOrder: number;
totalActivitiesInPipeline: number;
currentActivityId: string;
currentActivityName: string;
currentActivityDescription: string;
currentActivityImage: string | null;
currentActivityStartAt: number | null;
executionGroupKey: string;
entityName: string;
};

type ActivityProgressTo = {
type: ActivityPipelineType.Regular;
entityName: string;
};

type EntityProgressTo = FlowProgressTo | ActivityProgressTo;

export type StoreProgressPayloadTo = EntityProgressTo & {
startAt: number;
endAt: number | null;
};

type StoreEventsProgressTo = Record<string, StoreProgressPayloadTo>;

type StoreEntitiesProgressTo = Record<string, StoreEventsProgressTo>;

export type StoreProgressTo = Record<string, StoreEntitiesProgressTo>;

export type RootStateFrom = {
applets: {
inProgress: StoreProgressFrom;
completedEntities: any;

Check warning on line 66 in src/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts#L66

Unexpected any. Specify a different type (@typescript-eslint/no-explicit-any)
completions: any;

Check warning on line 67 in src/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts#L67

Unexpected any. Specify a different type (@typescript-eslint/no-explicit-any)
};
streaming: any;

Check warning on line 69 in src/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts#L69

Unexpected any. Specify a different type (@typescript-eslint/no-explicit-any)
identity: any;

Check warning on line 70 in src/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts#L70

Unexpected any. Specify a different type (@typescript-eslint/no-explicit-any)
};

export type RootStateTo = {
applets: {
inProgress: StoreProgressTo;
completedEntities: any;

Check warning on line 76 in src/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts#L76

Unexpected any. Specify a different type (@typescript-eslint/no-explicit-any)
completions: any;

Check warning on line 77 in src/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts#L77

Unexpected any. Specify a different type (@typescript-eslint/no-explicit-any)
};
streaming: any;

Check warning on line 79 in src/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts#L79

Unexpected any. Specify a different type (@typescript-eslint/no-explicit-any)
identity: any;

Check warning on line 80 in src/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts#L80

Unexpected any. Specify a different type (@typescript-eslint/no-explicit-any)
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
type FlowPipelineItemFrom = {
type: 'Stepper' | 'Intermediate' | 'Summary' | 'Finish';
payload: {
appletId: string;
activityId: string;
eventId: string;
flowId?: string;
order: number;
activityName: string;
activityDescription?: string;
activityImage?: string | null;
};
};

export type FlowStateFrom = {
vmkhitaryanscn marked this conversation as resolved.
Show resolved Hide resolved
step: number;
pipeline: FlowPipelineItemFrom[];
isCompletedDueToTimer: boolean;
context: Record<string, unknown>;
flowName: string;
};

type FlowPipelineItemTo = FlowPipelineItemFrom;

Check warning on line 23 in src/app/model/migrations/migrations/to0002/MigrationStorageTypes0002.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/app/model/migrations/migrations/to0002/MigrationStorageTypes0002.ts#L23

'FlowPipelineItemTo' is defined but never used. Allowed unused vars must match /^_/u (unused-imports/no-unused-vars)

export type FlowStateTo = FlowStateFrom;
194 changes: 194 additions & 0 deletions src/app/model/migrations/migrations/to0002/MigrationToVersion0002.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
import { Logger } from '@app/shared/lib';

import {
RootStateFrom,
RootStateTo,
StoreProgressPayloadTo,
} from './MigrationReduxTypes0002.ts';
import { FlowStateFrom } from './MigrationStorageTypes0002.ts';
import {
getUpdatedReduxState,
selectNotCompletedEntities,
} from './MigrationUtils0002';
import {
NotCompletedEntitiesFrom,
NotCompletedEntitiesTo,
} from './MigrationUtils0002.ts';
import {
IMigration,
MigrationInput,
MigrationOutput,
Storages,
} from '../../types';
import { getStorageRecord } from '../../utils.ts';

export class MigrationToVersion0002 implements IMigration {
private getFlowState = (key: string): FlowStateFrom | null => {
return getStorageRecord(Storages.FlowProgress, key);
};

private getFlowRecordKey = (
appletId: string,
flowId: string | null,
eventId: string,
) => {
const flowKey = flowId ?? 'default_one_step_flow';
return `${flowKey}-${appletId}-${eventId}`;
};

private getUpdatedFlowProgress(
progressFlowFrom: NotCompletedEntitiesFrom,
entityName: string,
): NotCompletedEntitiesTo {
const storeProgressPayloadTo: StoreProgressPayloadTo = {
...progressFlowFrom.payload,
entityName: entityName,
};

return {
appletId: progressFlowFrom.appletId,
eventId: progressFlowFrom.eventId,
entityId: progressFlowFrom.entityId,
type: progressFlowFrom.type,
payload: storeProgressPayloadTo,
};
}

private getUpdatedActivityProgress(
progressFlowFrom: NotCompletedEntitiesFrom,
entityName: string,
): NotCompletedEntitiesTo {
const storeProgressPayloadTo: StoreProgressPayloadTo = {
...progressFlowFrom.payload,
entityName: entityName,
};

return {
appletId: progressFlowFrom.appletId,
eventId: progressFlowFrom.eventId,
entityId: progressFlowFrom.entityId,
type: progressFlowFrom.type,
payload: storeProgressPayloadTo,
};
}

private getUpdatedProgressForFlows(
vmkhitaryanscn marked this conversation as resolved.
Show resolved Hide resolved
reduxState: RootStateFrom,
): NotCompletedEntitiesTo[] {
const progressFlowsFrom = selectNotCompletedEntities(reduxState, 'flows');
const progressFlowsTo: NotCompletedEntitiesTo[] = [];
let logFlowName = '';
let logFlowStateFrom = '';

for (const progressFlowFrom of progressFlowsFrom) {
const logProgressFlowFrom = JSON.stringify(progressFlowFrom, null, 2);

const { appletId, entityId, eventId } = progressFlowFrom;

try {
const key = this.getFlowRecordKey(appletId, entityId, eventId);
const flowState = this.getFlowState(key)!;

Check warning on line 90 in src/app/model/migrations/migrations/to0002/MigrationToVersion0002.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/app/model/migrations/migrations/to0002/MigrationToVersion0002.ts#L90

Forbidden non-null assertion (@typescript-eslint/no-non-null-assertion)

if (!flowState) {
Logger.warn(
`[MigrationToVersion0002.getUpdatedProgressForFlows]: Migration cannot be executed as flowState doesn't exist appletId=${appletId}, entityId=${entityId}, eventId=${eventId}`,
);
continue;
}

logFlowStateFrom = JSON.stringify(flowState, null, 2);
logFlowName = flowState?.flowName;
const flowName = flowState?.flowName ?? '[Name unknown]';

const progressFlowTo = this.getUpdatedFlowProgress(
progressFlowFrom,
flowName,
);

progressFlowsTo.push(progressFlowTo);
} catch (error) {
Logger.warn(
`[MigrationToVersion0002.getUpdatedProgressForFlows]: Error occurred flowName=${logFlowName}, progressFlowFrom=${logProgressFlowFrom}, flowState=${logFlowStateFrom} \nerror: \n${error}`,

Check warning on line 111 in src/app/model/migrations/migrations/to0002/MigrationToVersion0002.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/app/model/migrations/migrations/to0002/MigrationToVersion0002.ts#L111

Invalid type "unknown" of template literal expression (@typescript-eslint/restrict-template-expressions)
);
}
}

return progressFlowsTo;
}

private getUpdatedProgressForActivities(
reduxState: RootStateFrom,
): NotCompletedEntitiesTo[] {
const progressActivitiesFrom = selectNotCompletedEntities(
reduxState,
'activities',
);

const progressActivitiesTo: NotCompletedEntitiesTo[] = [];
let logActivityName = '';
let logFlowStateFrom = '';

for (const progressActivityFrom of progressActivitiesFrom) {
const logProgressFlowFrom = JSON.stringify(progressActivityFrom, null, 2);
const { appletId, entityId, eventId } = progressActivityFrom;

try {
const key = this.getFlowRecordKey(appletId, null, eventId);
const flowState = this.getFlowState(key)!;

Check warning on line 137 in src/app/model/migrations/migrations/to0002/MigrationToVersion0002.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/app/model/migrations/migrations/to0002/MigrationToVersion0002.ts#L137

Forbidden non-null assertion (@typescript-eslint/no-non-null-assertion)

if (!flowState) {
Logger.warn(
`[MigrationToVersion0002.getUpdatedProgressForActivities]: Migration cannot be executed as flowState doesn't exist appletId=${appletId}, entityId=${entityId}, eventId=${eventId}`,
);
continue;
}

logFlowStateFrom = JSON.stringify(flowState, null, 2);
logActivityName = flowState?.pipeline?.[0]?.payload?.activityName;

const activityName =
flowState?.pipeline?.[0]?.payload?.activityName ?? '[Name unknown]';

const progressActivityTo = this.getUpdatedActivityProgress(
progressActivityFrom,
activityName,
);

progressActivitiesTo.push(progressActivityTo);
} catch (error) {
Logger.warn(
`[MigrationToVersion0002.getUpdatedProgressForActivities]: Error occurred activityName=${logActivityName}, progressFlowFrom=${logProgressFlowFrom}, flowState=${logFlowStateFrom} \nerror: \n${error}`,

Check warning on line 160 in src/app/model/migrations/migrations/to0002/MigrationToVersion0002.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/app/model/migrations/migrations/to0002/MigrationToVersion0002.ts#L160

Invalid type "unknown" of template literal expression (@typescript-eslint/restrict-template-expressions)
);
}
}

return progressActivitiesTo;
}

private getUpdatedProgress(
reduxState: RootStateFrom,
): NotCompletedEntitiesTo[] {
const activitiesProgressTo =
this.getUpdatedProgressForActivities(reduxState);

const flowsProgressTo = this.getUpdatedProgressForFlows(reduxState);
vmkhitaryanscn marked this conversation as resolved.
Show resolved Hide resolved

return [...activitiesProgressTo, ...flowsProgressTo];
}

migrate(input: MigrationInput): MigrationOutput {
const result: MigrationOutput = {
reduxState: { ...input.reduxState } as RootStateTo,
};

const reduxRootStateFrom: RootStateFrom = input.reduxState as RootStateFrom;

const progressTo = this.getUpdatedProgress(reduxRootStateFrom);

result.reduxState = getUpdatedReduxState(reduxRootStateFrom, progressTo);
vmkhitaryanscn marked this conversation as resolved.
Show resolved Hide resolved

return result;
}
}

export default MigrationToVersion0002;
Loading
Loading