This repository has been archived on 2024-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
frontend/src/helpers/labels.ts
Dominik Pschenitschni 2ac3d29c13
Some checks failed
continuous-integration/drone/pr Build is failing
Merge branch 'vue3' into feature/vue3-async-await
# Conflicts:
#	src/i18n/index.js
#	src/store/modules/labels.js
#	src/store/modules/tasks.js
#	src/views/list/views/Kanban.vue
#	src/views/tasks/ShowTasks.vue
#	src/views/tasks/TaskDetailView.vue
2021-10-17 16:06:58 +02:00

40 lines
913 B
TypeScript

interface label {
id: number,
title: string,
}
interface labelState {
labels: label[],
}
/**
* Checks if a list of labels is available in the store and filters them then query
* @param {Object} state
* @param {Array} labelsToHide
* @param {String} query
* @returns {Array}
*/
export function filterLabelsByQuery(state: labelState, labelsToHide: label[], query: string) {
if (query === '') {
return []
}
const labelQuery = query.toLowerCase()
const labelIds = labelsToHide.map(({id}) => id)
return Object
.values(state.labels)
.filter(({id, title}) => {
return !labelIds.includes(id) && title.toLowerCase().includes(labelQuery)
})
}
/**
* Returns the labels by id if found
* @param {Object} state
* @param {Array} ids
* @returns {Array}
*/
export function getLabelsByIds(state: labelState, ids: number[]) {
return Object.values(state.labels).filter(({id}) => ids.includes(id))
}