From a54cf7bfd93c91cf6edd1126cddc2c7e365eac25 Mon Sep 17 00:00:00 2001 From: Matthew White Date: Tue, 7 May 2024 22:53:53 -0400 Subject: [PATCH] Finish replacing modal mixin with modalData() (#990) --- CONTRIBUTING.md | 4 -- src/components/analytics/list.vue | 17 ++---- .../form-attachment/link-dataset.vue | 23 +++----- src/components/form-attachment/list.vue | 47 ++++++---------- src/components/form-attachment/row.vue | 2 +- src/components/form/list.vue | 11 ++-- src/components/form/settings.vue | 16 ++---- src/components/form/submissions.vue | 18 ++---- src/components/form/trash-list.vue | 28 ++-------- src/components/project/form-access.vue | 11 ++-- src/components/project/list.vue | 17 ++---- src/components/project/settings.vue | 25 +++------ src/components/public-link/list.vue | 42 +++++--------- src/components/submission/activity.vue | 9 ++- src/components/submission/list.vue | 37 ++++-------- src/components/submission/show.vue | 25 +++------ src/components/user/list.vue | 56 ++++++------------- src/mixins/modal.js | 36 ------------ test/components/submission/activity.spec.js | 6 +- 19 files changed, 125 insertions(+), 305 deletions(-) delete mode 100644 src/mixins/modal.js diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 43e29b17a..2b030af8b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -117,10 +117,6 @@ Most components are named according to the combination of a resource and an acti * `Edit` or `Update`. A component used to update an existing resource of a particular type. * `Delete`. A modal used to delete an existing resource of a particular type. -### Vue Mixins - -Each component may use one or more mixins. Each file in [`/src/mixins/`](/src/mixins/) exports a mixin factory for a single type of mixin. (We use factories so that the component can pass in options for the mixin. We don't use this pattern much anymore though, so we will likely change this when we move to Vue 3.) - ### Composables Each component may use one or more of the composables in [`/src/composables/`](/src/composables/). Most composables will reside in that directory, but if it makes sense to group a composable with other functionality, it may be defined elsewhere. For example, the `useSessions()` composable is defined in [`/src/util/session.js`](/src/util/session.js). diff --git a/src/components/analytics/list.vue b/src/components/analytics/list.vue index e6ac99564..61fc1eddc 100644 --- a/src/components/analytics/list.vue +++ b/src/components/analytics/list.vue @@ -22,7 +22,7 @@ except according to the terms contained in the LICENSE file. - + @@ -43,8 +43,8 @@ import AuditTable from '../audit/table.vue'; import Loading from '../loading.vue'; import PageSection from '../page/section.vue'; -import modal from '../../mixins/modal'; import { apiPaths } from '../../util/request'; +import { modalData } from '../../util/reactivity'; import { useRequestData } from '../../request-data'; export default { @@ -56,19 +56,12 @@ export default { Loading, PageSection }, - mixins: [modal()], setup() { const { analyticsConfig, createResource, resourceStates } = useRequestData(); const audits = createResource('audits'); return { - analyticsConfig, audits, ...resourceStates([analyticsConfig, audits]) - }; - }, - data() { - return { - preview: { - state: false - } + analyticsConfig, audits, ...resourceStates([analyticsConfig, audits]), + previewModal: modalData() }; }, created() { diff --git a/src/components/form-attachment/link-dataset.vue b/src/components/form-attachment/link-dataset.vue index 57b2184ff..395dc7eb9 100644 --- a/src/components/form-attachment/link-dataset.vue +++ b/src/components/form-attachment/link-dataset.vue @@ -15,11 +15,13 @@ except according to the terms contained in the LICENSE file. @@ -88,9 +88,9 @@ import FormAttachmentRow from './row.vue'; import FormAttachmentUploadFiles from './upload-files.vue'; import SentenceSeparator from '../sentence-separator.vue'; -import modal from '../../mixins/modal'; import useRequest from '../../composables/request'; import { apiPaths } from '../../util/request'; +import { modalData } from '../../util/reactivity'; import { noop } from '../../util/util'; import { useRequestData } from '../../request-data'; @@ -106,7 +106,6 @@ export default { FormAttachmentUploadFiles, SentenceSeparator }, - mixins: [modal()], inject: ['alert'], props: { projectId: { @@ -165,16 +164,9 @@ export default { }, updatedAttachments: new Set(), // Modals - uploadFilesModal: { - state: false - }, - nameMismatch: { - state: false - }, - linkDatasetModal: { - state: false, - attachmentName: '' - } + uploadFilesModal: modalData(), + nameMismatch: modalData(), + linkDatasetModal: modalData() }; }, computed: { @@ -203,7 +195,7 @@ export default { // FILE INPUT afterFileInputSelection(files) { - this.hideModal('uploadFilesModal'); + this.uploadFilesModal.hide(); this.updatedAttachments.clear(); this.matchFilesToAttachments(files); }, @@ -247,7 +239,7 @@ export default { if (upload.file.name === upload.attachment.name) this.uploadFiles(); else - this.showModal('nameMismatch'); + this.nameMismatch.show(); } else { // The else case can be reached even if this.countOfFilesOverDropZone // was 1, if the drop was not over a row. @@ -367,24 +359,19 @@ export default { resend: false }).catch(noop); }, - showLinkDatasetModal({ name, blobExists }) { - this.linkDatasetModal.attachmentName = name; - this.linkDatasetModal.blobExists = blobExists; - this.showModal('linkDatasetModal'); - }, afterLinkDataset() { + const { attachment } = this.linkDatasetModal; + this.linkDatasetModal.hide(); + this.alert.success(this.$t('alert.link', { - attachmentName: this.linkDatasetModal.attachmentName + attachmentName: attachment.name })); this.attachments.patch(() => { - const attachment = this.attachments.get(this.linkDatasetModal.attachmentName); attachment.datasetExists = true; attachment.blobExists = false; attachment.exists = true; }); - - this.hideModal('linkDatasetModal'); } } }; diff --git a/src/components/form-attachment/row.vue b/src/components/form-attachment/row.vue index 18e9c3ee8..286fd2c0b 100644 --- a/src/components/form-attachment/row.vue +++ b/src/components/form-attachment/row.vue @@ -52,7 +52,7 @@ except according to the terms contained in the LICENSE file. - @@ -43,15 +43,14 @@ import Loading from '../loading.vue'; import PageSection from '../page/section.vue'; import FormSort from './sort.vue'; -import modal from '../../mixins/modal'; import sortFunctions from '../../util/sort'; import useRoutes from '../../composables/routes'; +import { modalData } from '../../util/reactivity'; import { useRequestData } from '../../request-data'; export default { name: 'FormList', components: { FormTable, FormNew, FormSort, Loading, PageSection }, - mixins: [modal()], inject: ['alert'], setup() { // The component does not assume that this data will exist when the @@ -62,9 +61,7 @@ export default { }, data() { return { - newForm: { - state: false - }, + createModal: modalData(), sortMode: 'alphabetical' }; }, diff --git a/src/components/form/settings.vue b/src/components/form/settings.vue index abbc1b7d4..a4d71fe59 100644 --- a/src/components/form/settings.vue +++ b/src/components/form/settings.vue @@ -34,7 +34,7 @@ except according to the terms contained in the LICENSE file.

@@ -42,7 +42,7 @@ except according to the terms contained in the LICENSE file.
- @@ -50,26 +50,18 @@ except according to the terms contained in the LICENSE file.