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
This commit is contained in:
40
src/helpers/labels.test.ts
Normal file
40
src/helpers/labels.test.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import {filterLabelsByQuery} from './labels'
|
||||
|
||||
describe('filter labels', () => {
|
||||
const state = {
|
||||
labels: [
|
||||
{id: 1, title: 'label1'},
|
||||
{id: 2, title: 'label2'},
|
||||
{id: 3, title: 'label3'},
|
||||
{id: 4, title: 'label4'},
|
||||
{id: 5, title: 'label5'},
|
||||
{id: 6, title: 'label6'},
|
||||
{id: 7, title: 'label7'},
|
||||
{id: 8, title: 'label8'},
|
||||
{id: 9, title: 'label9'},
|
||||
],
|
||||
}
|
||||
|
||||
it('should return an empty array for an empty query', () => {
|
||||
const labels = filterLabelsByQuery(state, [], '')
|
||||
|
||||
expect(labels).toHaveLength(0)
|
||||
})
|
||||
it('should return labels for a query', () => {
|
||||
const labels = filterLabelsByQuery(state, [], 'label2')
|
||||
|
||||
expect(labels).toHaveLength(1)
|
||||
expect(labels[0].title).toBe('label2')
|
||||
})
|
||||
it('should not return found but hidden labels', () => {
|
||||
interface label {
|
||||
id: number,
|
||||
title: string,
|
||||
}
|
||||
|
||||
const labelsToHide: label[] = [{id: 1, title: 'label1'}]
|
||||
const labels = filterLabelsByQuery(state, labelsToHide, 'label1')
|
||||
|
||||
expect(labels).toHaveLength(0)
|
||||
})
|
||||
})
|
40
src/helpers/labels.ts
Normal file
40
src/helpers/labels.ts
Normal file
@ -0,0 +1,40 @@
|
||||
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))
|
||||
}
|
Reference in New Issue
Block a user