fix(filters): correctly transform and populate saved filter when creating and editing
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This fixes a bug where the checkbox "include nulls" during creation was not checked but would be saved as such.
This commit is contained in:
parent
ec902b051b
commit
4dd9d5de67
@ -1,11 +1,12 @@
|
||||
import type {IAbstract} from './IAbstract'
|
||||
import type {IUser} from './IUser'
|
||||
|
||||
// FIXME: what makes this different from TaskFilterParams?
|
||||
interface Filters {
|
||||
sortBy: ('start_date' | 'done' | 'id' | 'position')[],
|
||||
orderBy: ('asc' | 'desc')[],
|
||||
sort_by: ('start_date' | 'done' | 'id' | 'position')[],
|
||||
order_by: ('asc' | 'desc')[],
|
||||
filter: string,
|
||||
filterIncludeNulls: boolean,
|
||||
filter_include_nulls: boolean,
|
||||
s: string,
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { objectToSnakeCase } from '@/helpers/case'
|
||||
import AbstractModel from './abstractModel'
|
||||
import UserModel from '@/models/user'
|
||||
|
||||
@ -9,10 +10,10 @@ export default class SavedFilterModel extends AbstractModel<ISavedFilter> implem
|
||||
title = ''
|
||||
description = ''
|
||||
filters: ISavedFilter['filters'] = {
|
||||
sortBy: ['done', 'id'],
|
||||
orderBy: ['asc', 'desc'],
|
||||
sort_by: ['done', 'id'],
|
||||
order_by: ['asc', 'desc'],
|
||||
filter: 'done = false',
|
||||
filterIncludeNulls: true,
|
||||
filter_include_nulls: true,
|
||||
s: '',
|
||||
}
|
||||
|
||||
@ -26,6 +27,10 @@ export default class SavedFilterModel extends AbstractModel<ISavedFilter> implem
|
||||
|
||||
this.owner = new UserModel(this.owner)
|
||||
|
||||
// Filters are in snake_case for the API - this makes it consistent with the way filter params are used with one-off filters.
|
||||
// Should probably be camelCase everywhere, but that's a task for another day.
|
||||
this.filters = objectToSnakeCase(this.filters)
|
||||
|
||||
this.created = new Date(this.created)
|
||||
this.updated = new Date(this.updated)
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ import SavedFilterModel from '@/models/savedFilter'
|
||||
import {useBaseStore} from '@/stores/base'
|
||||
import {useProjectStore} from '@/stores/projects'
|
||||
|
||||
import {objectToSnakeCase, objectToCamelCase} from '@/helpers/case'
|
||||
import {success} from '@/message'
|
||||
import ProjectModel from '@/models/project'
|
||||
|
||||
@ -55,23 +54,6 @@ export default class SavedFilterService extends AbstractService<ISavedFilter> {
|
||||
modelFactory(data) {
|
||||
return new SavedFilterModel(data)
|
||||
}
|
||||
|
||||
processModel(model) {
|
||||
// Make filters from this.filters camelCase and set them to the model property:
|
||||
// That's easier than making the whole filter component configurable since that still needs to provide
|
||||
// the filter values in snake_sćase for url parameters.
|
||||
model.filters = objectToCamelCase(model.filters)
|
||||
|
||||
return model
|
||||
}
|
||||
|
||||
beforeUpdate(model) {
|
||||
return this.processModel(model)
|
||||
}
|
||||
|
||||
beforeCreate(model) {
|
||||
return this.processModel(model)
|
||||
}
|
||||
}
|
||||
|
||||
export function useSavedFilter(projectId?: MaybeRefOrGetter<IProject['id']>) {
|
||||
@ -98,10 +80,7 @@ export function useSavedFilter(projectId?: MaybeRefOrGetter<IProject['id']>) {
|
||||
// We assume the projectId in the route is the pseudoproject
|
||||
const savedFilterId = getSavedFilterIdFromProjectId(watchedProjectId)
|
||||
|
||||
filter.value = new SavedFilterModel({id: savedFilterId})
|
||||
const response = await filterService.get(filter.value)
|
||||
response.filters = objectToSnakeCase(response.filters)
|
||||
filter.value = response
|
||||
filter.value = await filterService.get(new SavedFilterModel({id: savedFilterId}))
|
||||
await validateTitleField()
|
||||
}, {immediate: true})
|
||||
|
||||
@ -115,7 +94,6 @@ export function useSavedFilter(projectId?: MaybeRefOrGetter<IProject['id']>) {
|
||||
const response = await filterService.update(filter.value)
|
||||
await projectStore.loadAllProjects()
|
||||
success({message: t('filters.edit.success')})
|
||||
response.filters = objectToSnakeCase(response.filters)
|
||||
filter.value = response
|
||||
await useBaseStore().setCurrentProject(new ProjectModel({
|
||||
id: getProjectId(filter.value),
|
||||
|
Loading…
Reference in New Issue
Block a user