-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
…Name, refactor, code review fixes
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { ImageUrl } from '@app/shared/lib'; | ||
|
||
export type ActivityRecordDto = { | ||
id: string; | ||
name: string; | ||
description: string; | ||
image: ImageUrl | null; | ||
order: number; | ||
}; | ||
|
||
export type ActivityFlowRecordDto = { | ||
id: string; | ||
name: string; | ||
description: string; | ||
order: number; | ||
activityIds: Array<string>; | ||
}; | ||
|
||
export type AppletDetailsDto = { | ||
id: string; | ||
displayName: string; | ||
activities: ActivityRecordDto[]; | ||
activityFlows: ActivityFlowRecordDto[]; | ||
}; | ||
|
||
export type AppletDetailsResponse = { | ||
result: AppletDetailsDto; | ||
}; |
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 GitHub Actions / ESLintsrc/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts#L66
|
||
completions: any; | ||
Check warning on line 67 in src/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts GitHub Actions / ESLintsrc/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts#L67
|
||
}; | ||
streaming: any; | ||
Check warning on line 69 in src/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts GitHub Actions / ESLintsrc/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts#L69
|
||
identity: any; | ||
Check warning on line 70 in src/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts GitHub Actions / ESLintsrc/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts#L70
|
||
}; | ||
|
||
export type RootStateTo = { | ||
applets: { | ||
inProgress: StoreProgressTo; | ||
completedEntities: any; | ||
Check warning on line 76 in src/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts GitHub Actions / ESLintsrc/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts#L76
|
||
completions: any; | ||
Check warning on line 77 in src/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts GitHub Actions / ESLintsrc/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts#L77
|
||
}; | ||
streaming: any; | ||
Check warning on line 79 in src/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts GitHub Actions / ESLintsrc/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts#L79
|
||
identity: any; | ||
Check warning on line 80 in src/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts GitHub Actions / ESLintsrc/app/model/migrations/migrations/to0002/MigrationReduxTypes0002.ts#L80
|
||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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 = { | ||
step: number; | ||
pipeline: FlowPipelineItemFrom[]; | ||
isCompletedDueToTimer: boolean; | ||
context: Record<string, unknown>; | ||
flowName: string; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
import { QueryClient } from '@tanstack/react-query'; | ||
|
||
import { Logger } from '@app/shared/lib'; | ||
|
||
import { | ||
RootStateFrom, | ||
RootStateTo, | ||
StoreProgressPayloadTo, | ||
} from './MigrationReduxTypes0002.ts'; | ||
import { FlowStateFrom } from './MigrationStorageTypes0002.ts'; | ||
import { | ||
getUpdatedReduxState, | ||
selectNotCompletedActivities, | ||
selectNotCompletedFlows, | ||
} from './MigrationUtils0002'; | ||
import { QueryDataUtils } from './MigrationUtils0002.ts'; | ||
import { | ||
NotCompletedEntitiesFrom, | ||
NotCompletedEntitiesTo, | ||
} from './MigrationUtils0002.ts'; | ||
import { | ||
IMigration, | ||
MigrationInput, | ||
MigrationOutput, | ||
Storages, | ||
} from '../../types'; | ||
import { getStorageRecord } from '../../utils.ts'; | ||
|
||
export class MigrationToVersion0002 implements IMigration { | ||
private queryDataUtils: QueryDataUtils; | ||
|
||
constructor(queryClient: QueryClient) { | ||
this.queryDataUtils = new QueryDataUtils(queryClient); | ||
} | ||
|
||
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( | ||
reduxState: RootStateFrom, | ||
): NotCompletedEntitiesTo[] { | ||
const progressFlowsFrom = selectNotCompletedFlows(reduxState); | ||
const progressFlowsTo: NotCompletedEntitiesTo[] = []; | ||
|
||
for (const progressFlowFrom of progressFlowsFrom) { | ||
const { appletId, entityId, eventId } = progressFlowFrom; | ||
|
||
const logAppletName = '', | ||
logFlowName = ''; | ||
const logFlowStateFrom = ''; | ||
const logCurrentActivityDto = ''; | ||
const logActivityFlowDto = ''; | ||
const logProgressFlowFrom = JSON.stringify(progressFlowFrom, null, 2); | ||
|
||
try { | ||
const key = this.getFlowRecordKey(appletId, entityId, eventId); | ||
|
||
const flowStateFrom = this.getFlowState(key)!; | ||
Check warning on line 103 in src/app/model/migrations/migrations/to0002/MigrationToVersion0002.ts GitHub Actions / ESLintsrc/app/model/migrations/migrations/to0002/MigrationToVersion0002.ts#L103
|
||
|
||
if (!flowStateFrom) { | ||
Logger.warn( | ||
`[MigrationToVersion0002.getUpdatedProgressForFlows]: Migration cannot be executed as flowState doesn't exist appletName=${logAppletName}, appletId=${appletId}, entityId=${entityId}, eventId=${eventId}`, | ||
); | ||
continue; | ||
} | ||
const flowName = flowStateFrom.flowName; | ||
|
||
const progressFlowTo = this.getUpdatedFlowProgress( | ||
progressFlowFrom, | ||
flowName, | ||
); | ||
|
||
progressFlowsTo.push(progressFlowTo); | ||
} catch (error) { | ||
Logger.warn( | ||
`[MigrationToVersion0002.getUpdatedProgressForFlows]: Error occurred, appletName=${logAppletName}, flowName=${logFlowName}, progressFlowFrom=${logProgressFlowFrom}, flowStateFrom=${logFlowStateFrom}, currentActivityDto=${logCurrentActivityDto}, activityFlowDto=${logActivityFlowDto} \nerror: \n${error}`, | ||
Check warning on line 121 in src/app/model/migrations/migrations/to0002/MigrationToVersion0002.ts GitHub Actions / ESLintsrc/app/model/migrations/migrations/to0002/MigrationToVersion0002.ts#L121
|
||
); | ||
} | ||
} | ||
|
||
return progressFlowsTo; | ||
} | ||
|
||
private getUpdatedProgressForActivities( | ||
reduxState: RootStateFrom, | ||
): NotCompletedEntitiesTo[] { | ||
const progressActivitiesFrom = selectNotCompletedActivities(reduxState); | ||
const progressActivitiesTo = []; | ||
|
||
for (const progressActivityFrom of progressActivitiesFrom) { | ||
const { appletId, entityId } = progressActivityFrom; | ||
let logAppletName = '', | ||
logActivityName = ''; | ||
const logActivityStateFrom = ''; | ||
const logCurrentActivityDto = ''; | ||
const logActivityActivityDto = ''; | ||
const logProgressActivityFrom = JSON.stringify( | ||
progressActivityFrom, | ||
null, | ||
2, | ||
); | ||
|
||
try { | ||
const appletDto = this.queryDataUtils.getAppletDto(appletId); | ||
|
||
if (!appletDto) { | ||
Logger.warn( | ||
"[MigrationToVersion0002.getUpdatedProgressForActivities]: Migration cannot be executed as applet doesn't exist: " + | ||
appletId, | ||
); | ||
continue; | ||
} | ||
logAppletName = appletDto.displayName; | ||
|
||
const activityDto = appletDto.activities.find(f => f.id === entityId); | ||
|
||
if (!activityDto) { | ||
Logger.warn( | ||
"[MigrationToVersion0002.getUpdatedProgressForActivities]: activityFlow doesn't exist: " + | ||
entityId, | ||
); | ||
continue; | ||
} | ||
|
||
logActivityName = activityDto.name; | ||
|
||
const progressActivityTo = this.getUpdatedActivityProgress( | ||
progressActivityFrom, | ||
activityDto.name, | ||
); | ||
|
||
progressActivitiesTo.push(progressActivityTo); | ||
} catch (error) { | ||
Logger.warn( | ||
`[MigrationToVersion0002.getUpdatedProgressForActivities]: Error occurred, appletName=${logAppletName}, flowName=${logActivityName}, progressActivityFrom=${logProgressActivityFrom}, flowStateFrom=${logActivityStateFrom}, currentActivityDto=${logCurrentActivityDto}, activityActivityDto=${logActivityActivityDto} \nerror: \n${error}`, | ||
Check warning on line 180 in src/app/model/migrations/migrations/to0002/MigrationToVersion0002.ts GitHub Actions / ESLintsrc/app/model/migrations/migrations/to0002/MigrationToVersion0002.ts#L180
|
||
); | ||
} | ||
} | ||
|
||
return progressActivitiesTo; | ||
} | ||
|
||
private getUpdatedProgress( | ||
reduxState: RootStateFrom, | ||
): NotCompletedEntitiesTo[] { | ||
const activitiesProgressTo = | ||
this.getUpdatedProgressForActivities(reduxState); | ||
const flowsProgressTo = this.getUpdatedProgressForFlows(reduxState); | ||
|
||
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); | ||
|
||
return result; | ||
} | ||
} | ||
|
||
export default MigrationToVersion0002; |