1
0

fix: label search in tasks not working

This commit is contained in:
kolaente
2021-10-17 13:20:51 +02:00
parent 7e29dde717
commit 529b3d2890
3 changed files with 73 additions and 20 deletions

View File

@ -1,34 +1,18 @@
import LabelService from '@/services/label'
import Vue from 'vue'
import {setLoading} from '@/store/helper'
import {filterLabelsByQuery} from '@/helpers/labels'
/**
* Returns the labels by id if found
* @param {Object} state
* @param {Array} ids
* @param {Object} state
* @param {Array} ids
* @returns {Array}
*/
function getLabelsByIds(state, ids) {
return Object.values(state.labels).filter(({id}) => ids.includes(id))
}
/**
* Checks if a list of labels is available in the store and filters them then query
* @param {Object} state
* @param {Array} labels
* @param {String} query
* @returns {Array}
*/
function filterLabelsByQuery(state, labels, query) {
const labelIds = labels.map(({id}) => id)
const foundLabels = getLabelsByIds(state, labelIds)
const labelQuery = query.toLowerCase()
return foundLabels.filter(({title}) => {
return !title.toLowerCase().includes(labelQuery)
})
}
export default {
namespaced: true,
state: () => ({
@ -57,7 +41,7 @@ export default {
return (ids) => getLabelsByIds(state, ids)
},
filterLabelsByQuery(state) {
return (...arr) => filterLabelsByQuery(state, ...arr)
return (labelsToHide, query) => filterLabelsByQuery(state, labelsToHide, query)
},
},
actions: {