From 424f5c6fceda48c5271cb0ab293cbbfe9853444f Mon Sep 17 00:00:00 2001 From: Johannes Millan Date: Mon, 23 Sep 2019 22:58:14 +0200 Subject: [PATCH] feat: add migration for task archive --- src/app/core/persistence/persistence.service.ts | 5 ++--- .../features/config/migrate-global-config.util.ts | 5 +++-- .../features/project/migrate-projects-state.util.ts | 5 ++--- src/app/features/tasks/migrate-task-state.util.ts | 13 +++++++++---- .../schedule-page/schedule-page.component.html | 2 +- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/app/core/persistence/persistence.service.ts b/src/app/core/persistence/persistence.service.ts index d064e33b83..eb80be5941 100644 --- a/src/app/core/persistence/persistence.service.ts +++ b/src/app/core/persistence/persistence.service.ts @@ -52,7 +52,7 @@ import {metricReducer} from '../../features/metric/store/metric.reducer'; import {improvementReducer} from '../../features/metric/improvement/store/improvement.reducer'; import {obstructionReducer} from '../../features/metric/obstruction/store/obstruction.reducer'; import {migrateProjectState} from '../../features/project/migrate-projects-state.util'; -import {migrateTaskState} from '../../features/tasks/migrate-task-state.util'; +import {migrateTaskArchiveState, migrateTaskState} from '../../features/tasks/migrate-task-state.util'; import {migrateGlobalConfigState} from '../../features/config/migrate-global-config.util'; @@ -89,8 +89,7 @@ export class PersistenceService { // NOTE: this might be problematic, as we don't really have reducer logic for the archive // TODO add a working reducer for task archive taskReducer, - // TODO needs migration - // migrateTaskState, + migrateTaskArchiveState, ); taskAttachment = this._cmProject( LS_TASK_ATTACHMENT_STATE, diff --git a/src/app/features/config/migrate-global-config.util.ts b/src/app/features/config/migrate-global-config.util.ts index beab374bf8..228ec06c79 100644 --- a/src/app/features/config/migrate-global-config.util.ts +++ b/src/app/features/config/migrate-global-config.util.ts @@ -5,10 +5,9 @@ import {MODEL_VERSION_KEY} from '../../app.constants'; const MODEL_VERSION = 1; export const migrateGlobalConfigState = (globalConfigState: GlobalConfigState): GlobalConfigState => { - if (globalConfigState && globalConfigState[MODEL_VERSION_KEY] === MODEL_VERSION) { + if (!globalConfigState || (globalConfigState && globalConfigState[MODEL_VERSION_KEY] === MODEL_VERSION)) { return globalConfigState; } else { - globalConfigState[MODEL_VERSION_KEY] = MODEL_VERSION; } // NOTE: needs to run before default stuff @@ -16,6 +15,8 @@ export const migrateGlobalConfigState = (globalConfigState: GlobalConfigState): // NOTE: absolutely needs to come last as otherwise the previous defaults won't work globalConfigState = _extendConfigDefaults(globalConfigState); + + globalConfigState[MODEL_VERSION_KEY] = MODEL_VERSION; return globalConfigState; }; diff --git a/src/app/features/project/migrate-projects-state.util.ts b/src/app/features/project/migrate-projects-state.util.ts index fb6389cdca..f5f8466d8b 100644 --- a/src/app/features/project/migrate-projects-state.util.ts +++ b/src/app/features/project/migrate-projects-state.util.ts @@ -10,10 +10,8 @@ import {MODEL_VERSION_KEY, THEME_COLOR_MAP} from '../../app.constants'; const MODEL_VERSION = 1; export const migrateProjectState = (projectState: ProjectState): ProjectState => { - if (projectState && projectState[MODEL_VERSION_KEY] === MODEL_VERSION) { + if (!projectState || (projectState && projectState[MODEL_VERSION_KEY] === MODEL_VERSION)) { return projectState; - } else { - projectState[MODEL_VERSION_KEY] = MODEL_VERSION; } const projectEntities: Dictionary = {...projectState.entities}; @@ -25,6 +23,7 @@ export const migrateProjectState = (projectState: ProjectState): ProjectState => projectEntities[key] = _extendProjectDefaults(projectEntities[key]); }); + projectState[MODEL_VERSION_KEY] = MODEL_VERSION; return { ...projectState, entities: projectEntities, diff --git a/src/app/features/tasks/migrate-task-state.util.ts b/src/app/features/tasks/migrate-task-state.util.ts index 797d3be004..c72428b069 100644 --- a/src/app/features/tasks/migrate-task-state.util.ts +++ b/src/app/features/tasks/migrate-task-state.util.ts @@ -1,15 +1,13 @@ import {Dictionary} from '@ngrx/entity'; -import {Task, TaskState} from './task.model'; +import {Task, TaskArchive, TaskState} from './task.model'; import {GITHUB_TYPE, LEGACY_GITHUB_TYPE} from '../issue/issue.const'; import {MODEL_VERSION_KEY} from '../../app.constants'; const MODEL_VERSION = 1; export const migrateTaskState = (taskState: TaskState, projectId: string): TaskState => { - if (taskState && taskState[MODEL_VERSION_KEY] === MODEL_VERSION) { + if (!taskState || (taskState && taskState[MODEL_VERSION_KEY] === MODEL_VERSION)) { return taskState; - } else { - taskState[MODEL_VERSION_KEY] = MODEL_VERSION; } const taskEntities: Dictionary = {...taskState.entities}; @@ -17,9 +15,16 @@ export const migrateTaskState = (taskState: TaskState, projectId: string): TaskS taskEntities[key] = _addProjectId(taskEntities[key], projectId); taskEntities[key] = _replaceLegacyGitType(taskEntities[key]); }); + + taskState[MODEL_VERSION_KEY] = MODEL_VERSION; return {...taskState, entities: taskEntities}; }; +export const migrateTaskArchiveState = ( + taskArchiveState: TaskArchive, + projectId: string +): TaskArchive => migrateTaskState((taskArchiveState as TaskState), projectId); + const _addProjectId = (task: Task, projectId: string): Task => { return (task.hasOwnProperty('projectId') && task.projectId !== null && task.projectId) ? task diff --git a/src/app/pages/schedule-page/schedule-page.component.html b/src/app/pages/schedule-page/schedule-page.component.html index b3977c403d..3fc0a62a41 100644 --- a/src/app/pages/schedule-page/schedule-page.component.html +++ b/src/app/pages/schedule-page/schedule-page.component.html @@ -14,7 +14,7 @@
-
{{task.title}}
+
{{task.projectId}} {{task.title}}