From faa2daa87627abfe679b3714650efa9db1308466 Mon Sep 17 00:00:00 2001 From: dpschen Date: Wed, 6 Oct 2021 20:25:06 +0000 Subject: [PATCH] feat: remove lodash dependency (#743) Co-authored-by: Dominik Pschenitschni Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/743 Reviewed-by: konrad Co-authored-by: dpschen Co-committed-by: dpschen --- cypress/integration/task/task.spec.js | 2 +- cypress/support/factory.js | 6 ++- package.json | 1 - src/components/list/partials/filters.vue | 28 +++++++------- src/components/tasks/mixins/taskList.js | 3 +- .../tasks/partials/editAssignees.vue | 9 ++--- src/components/tasks/partials/editLabels.vue | 10 +---- src/helpers/find.ts | 3 -- src/helpers/utils.ts | 22 +++++++++++ src/models/abstractModel.js | 11 +++--- src/models/teamList.js | 11 ++---- src/models/teamMember.js | 13 +++---- src/models/teamNamespace.js | 11 ++---- src/models/userList.js | 11 ++---- src/models/userNamespace.js | 11 ++---- src/services/abstractService.js | 9 ++--- src/store/modules/attachments.js | 2 +- src/store/modules/kanban.js | 3 +- src/store/modules/labels.js | 37 ++++++++++++++++++- yarn.lock | 2 +- 20 files changed, 116 insertions(+), 89 deletions(-) delete mode 100644 src/helpers/find.ts create mode 100644 src/helpers/utils.ts diff --git a/cypress/integration/task/task.spec.js b/cypress/integration/task/task.spec.js index 83025aaa2..e661f1d29 100644 --- a/cypress/integration/task/task.spec.js +++ b/cypress/integration/task/task.spec.js @@ -353,7 +353,7 @@ describe('Task', () => { .first() .click() - cy.get('.global-notification') + cy.get('.global-notification', { timeout: 4000 }) .should('contain', 'Success') cy.get('.task-view .details.labels-list .multiselect .input-wrapper span.tag') .should('exist') diff --git a/cypress/support/factory.js b/cypress/support/factory.js index 0c50bf8fc..934f2fae9 100644 --- a/cypress/support/factory.js +++ b/cypress/support/factory.js @@ -1,5 +1,4 @@ import {seed} from './seed' -import merge from 'lodash/merge' /** * A factory makes it easy to seed the database with data. @@ -25,7 +24,10 @@ export class Factory { const data = [] for (let i = 1; i <= count; i++) { - const entry = merge(this.factory(), override) + const entry = { + ...this.factory(), + ...override, + } for (const e in entry) { if(typeof entry[e] === 'function') { entry[e] = entry[e](i) diff --git a/package.json b/package.json index b2e624944..b83283f6f 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,6 @@ "dompurify": "2.3.3", "highlight.js": "11.2.0", "is-touch-device": "1.0.1", - "lodash": "4.17.21", "marked": "3.0.4", "register-service-worker": "1.7.2", "snake-case": "3.0.4", diff --git a/src/components/list/partials/filters.vue b/src/components/list/partials/filters.vue index 67e535624..d9a25f3a2 100644 --- a/src/components/list/partials/filters.vue +++ b/src/components/list/partials/filters.vue @@ -178,9 +178,8 @@ import Fancycheckbox from '../../input/fancycheckbox' import flatPickr from 'vue-flatpickr-component' import 'flatpickr/dist/flatpickr.css' +import {includesById} from '@/helpers/utils' import {formatISO} from 'date-fns' -import differenceWith from 'lodash/differenceWith' - import PrioritySelect from '@/components/tasks/partials/prioritySelect.vue' import PercentDoneSelect from '@/components/tasks/partials/percentDoneSelect.vue' import Multiselect from '@/components/input/multiselect.vue' @@ -269,13 +268,7 @@ export default { }, computed: { foundLabels() { - const labels = (Object.values(this.$store.state.labels.labels).filter(l => { - return l.title.toLowerCase().includes(this.labelQuery.toLowerCase()) - }) ?? []) - - return differenceWith(labels, this.labels, (first, second) => { - return first.id === second.id - }) + return this.$store.getters['labels/filterLabelsByQuery'](this.labels, this.query) }, flatPickerConfig() { return { @@ -309,8 +302,13 @@ export default { this.prepareRelatedObjectFilter('namespace') this.prepareSingleValue('labels') - const labelIds = (typeof this.filters.labels === 'string' ? this.filters.labels : '').split(',').map(i => parseInt(i)) - this.labels = (Object.values(this.$store.state.labels.labels).filter(l => labelIds.includes(l.id)) ?? []) + + const labels = typeof this.filters.labels === 'string' + ? this.filters.labels + : '' + const labelIds = labels.split(',').map(i => parseInt(i)) + + this.labels = this.$store.getters['labels/getLabelsByIds'](labelIds) }, removePropertyFromFilter(propertyName) { // Because of the way arrays work, we can only ever remove one element at once. @@ -533,10 +531,10 @@ export default { this[`${kind}Service`].getAll({}, {s: query}) .then(response => { - // Filter the results to not include users who are already assigneid - this.$set(this, `found${kind}`, differenceWith(response, this[kind], (first, second) => { - return first.id === second.id - })) + // Filter users from the results who are already assigned + const unassignedUsers = response.filter(({id}) => !includesById(this[kind], id)) + + this.$set(this, `found${kind}`, unassignedUsers) }) .catch(e => { this.$message.error(e) diff --git a/src/components/tasks/mixins/taskList.js b/src/components/tasks/mixins/taskList.js index b15462f80..130e93908 100644 --- a/src/components/tasks/mixins/taskList.js +++ b/src/components/tasks/mixins/taskList.js @@ -1,5 +1,4 @@ import TaskCollectionService from '@/services/taskCollection' -import cloneDeep from 'lodash/cloneDeep' // FIXME: merge with DEFAULT_PARAMS in filters.vue const DEFAULT_PARAMS = { @@ -83,7 +82,7 @@ export default { this.tasks = r this.currentPage = page - this.loadedList = cloneDeep(currentList) + this.loadedList = JSON.parse(JSON.stringify(currentList)) }) .catch(e => { this.$message.error(e) diff --git a/src/components/tasks/partials/editAssignees.vue b/src/components/tasks/partials/editAssignees.vue index 9a666ee83..1fe0b3983 100644 --- a/src/components/tasks/partials/editAssignees.vue +++ b/src/components/tasks/partials/editAssignees.vue @@ -29,8 +29,7 @@