Skip to content

Commit

Permalink
feat: retrieve properties from store
Browse files Browse the repository at this point in the history
  • Loading branch information
caro3801 committed Nov 21, 2024
1 parent 9e7eb1f commit 271c3a4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 42 deletions.
35 changes: 25 additions & 10 deletions src/composables/task-properties.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useViewSettings } from '@/composables/view-settings'

export function useTaskProperties() {
export function useTaskProperties(propertyList) {
const { SORT_TYPE_KEY } = useViewSettings()

const propertyItem = ({
Expand All @@ -18,39 +18,54 @@ export function useTaskProperties() {
sortable,
required
})
const propertyId = propertyItem({
const id = propertyItem({
key: 'id',
icon: 'image',
sortable: true
})
const propertyName = propertyItem({
const name = propertyItem({
icon: 'image',
key: 'name',
sortable: true,
required: true
})
const propertyCreatedAt = propertyItem({
const createdAt = propertyItem({
icon: 'image',
key: 'createdAt',
sortingKey: 'creationDate',
sortingType: SORT_TYPE_KEY.DATE,
sortable: true
})
const propertyProgress = propertyItem({

const progress = propertyItem({
icon: 'image',
key: 'progress',
sortingType: SORT_TYPE_KEY.NUMBER,
sortable: true
})
const propertyState = propertyItem({
const state = propertyItem({
icon: 'image',
key: 'state',
type: SORT_TYPE_KEY.NUMBER,
sortable: false,
required: true
})

const propertyItems = [propertyState, propertyName, propertyId, propertyCreatedAt, propertyProgress]

return { propertyItems }
const propertyItems = {
id,
name,
createdAt,
progress,
state
}
const items = propertyList.reduce((acc, p) => {
if (propertyItems[p] === undefined) {
acc.push(propertyItem({ key: p }))
console.warn(`${p} does not exist`)
return acc
}
acc.push(propertyItems[p])
return acc
}, [])
console.log('propertyList', propertyList)
return { items }
}
34 changes: 5 additions & 29 deletions src/store/modules/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,27 @@ export const state = () => ({
task: {
orderBy: ['name', 'desc'],
perPage: 10,
properties: ['id', 'name', 'createdAt', 'progress', 'result', 'state']
properties: ['id', 'name', 'createdAt', 'progress', 'state']
},
entities: {
orderBy: ['name', 'desc'],
perPage: 10,
properties: ['id', 'name', 'createdAt', 'progress', 'result', 'state']
properties: ['state', 'id', 'name', 'createdAt', 'progress']
},
documents: {
orderBy: ['name', 'desc'],
perPage: 10,
properties: ['id', 'name', 'createdAt', 'progress', 'result', 'state']
properties: ['id', 'name', 'createdAt', 'progress', 'state']
},
'batch-download': {
orderBy: ['name', 'desc'],
perPage: 10,
properties: ['id', 'name', 'createdAt', 'progress', 'result', 'state']
properties: ['id', 'name', 'createdAt', 'progress', 'state']
},
'batch-search': {
orderBy: ['name', 'desc'],
perPage: 10,
properties: ['id', 'name', 'createdAt', 'progress', 'result', 'state']
properties: ['id', 'name', 'createdAt', 'progress', 'state']
},
documentView: {
tab: 'text'
Expand All @@ -64,25 +64,6 @@ export const state = () => ({
})

export const mutations = {
taskSettingsCreated(
state,
{
name = 'task',
settings: {
orderBy = ['name', 'desc'],
perPage = 10,
properties = ['id', 'name', 'createdAt', 'progress', 'result', 'state']
}
}
) {
if (!state.settings[name]) {
state.settings[name] = {
orderBy,
perPage,
properties
}
}
},
sidebarCompact(state, compact) {
state.sidebar.compact = compact
},
Expand Down Expand Up @@ -121,11 +102,6 @@ export const getters = {
return get(state.settings.views, [view, name].join('.'))
}
},
getTaskSettings(state) {
return (view, name) => {
return get(state.settings.views.task, [view, 'task', name].join('.'))
}
},
isProjectPinned(state) {
return (name) => state.pins.projects.includes(name)
}
Expand Down
8 changes: 5 additions & 3 deletions src/views/Task/task-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export function useTaskSettings(pageName) {
}
]
})
const { propertyItems } = useTaskProperties()
const vals = store.getters['app/getSettings'](pageName, 'properties')
console.log('vals', vals)
const { items } = useTaskProperties(vals)

const sortBy = ref({
label: sortByLabel,
Expand All @@ -46,7 +48,7 @@ export function useTaskSettings(pageName) {
get: () => store.getters['app/getSettings'](pageName, 'orderBy'),
set: (sort, order) => store.commit('app/setSettings', { view: pageName, orderBy: [sort, order] })
}),
options: propertyItems.reduce((acc, p) => {
options: items.reduce((acc, p) => {
if (p.sortable) {
const labelKey = p.sortingKey ?? p.key
acc.push(
Expand All @@ -66,7 +68,7 @@ export function useTaskSettings(pageName) {
get: () => store.getters['app/getSettings'](pageName, 'properties'),
set: (properties) => store.commit('app/setSettings', { view: pageName, properties })
}),
options: propertyItems.map((p) => ({
options: items.map((p) => ({
value: p.key,
icon: p.icon,
disabled: p.required,
Expand Down

0 comments on commit 271c3a4

Please sign in to comment.