feat: add migration for task archive

This commit is contained in:
Johannes Millan 2019-09-23 22:58:14 +02:00
parent cc15a71b9a
commit 424f5c6fce
5 changed files with 17 additions and 13 deletions

View file

@ -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<AttachmentState, Attachment>(
LS_TASK_ATTACHMENT_STATE,

View file

@ -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;
};

View file

@ -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<Project> = {...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,

View file

@ -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<Task> = {...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

View file

@ -14,7 +14,7 @@
<div class="content">
<div class="task-info">
<div class="title">
<div class="task-title">{{task.title}}</div>
<div class="task-title">{{task.projectId}} {{task.title}}</div>
<div *ngIf="(projectService.getById$(task.reminderData.projectId)|async) as project"
class="project">
<div [ngStyle]="getThemeColor(project.theme?.primary || project.themeColor)"