Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace modal mixin with modalData() for async modal components #945

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 14 additions & 24 deletions src/components/form-draft/status.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ except according to the terms contained in the LICENSE file.
</i18n-t>
<div id="form-draft-status-standard-buttons-container">
<form-version-standard-buttons :version="formDraft.get()"
@view-xml="showModal('viewXml')"/>
@view-xml="viewXml.show()"/>
</div>
<div>
<button id="form-draft-status-upload-button" type="button"
class="btn btn-primary" @click="showModal('upload')">
class="btn btn-primary" @click="upload.show()">
<span class="icon-upload"></span>{{ $t('currentDraft.action.upload') }}&hellip;
</button>
</div>
Expand All @@ -63,25 +63,24 @@ except according to the terms contained in the LICENSE file.
</template>
<template #body>
<button id="form-draft-status-publish-button" type="button"
class="btn btn-primary" @click="showModal('publish')">
class="btn btn-primary" @click="publish.show()">
<span class="icon-check"></span>{{ $t('actions.action.publish') }}&hellip;
</button>
<button id="form-draft-status-abandon-button" type="button"
class="btn btn-danger" @click="showModal('abandon')">
class="btn btn-danger" @click="abandon.show()">
<span class="icon-trash"></span>{{ $t('actions.action.abandon') }}&hellip;
</button>
</template>
</page-section>
</div>
</div>

<form-version-view-xml v-bind="viewXml" @hide="hideModal('viewXml')"/>
<form-new v-bind="upload" @hide="hideModal('upload')"
@success="afterUpload"/>
<form-draft-publish v-bind="publish" @hide="hideModal('publish')"
<form-version-view-xml v-bind="viewXml" @hide="viewXml.hide()"/>
<form-new v-bind="upload" @hide="upload.hide()" @success="afterUpload"/>
<form-draft-publish v-bind="publish" @hide="publish.hide()"
@success="afterPublish"/>
<form-draft-abandon v-if="form.dataExists" v-bind="abandon"
@hide="hideModal('abandon')" @success="afterAbandon"/>
@hide="abandon.hide()" @success="afterAbandon"/>
</div>
</template>

Expand All @@ -99,11 +98,11 @@ import PageSection from '../page/section.vue';
import SummaryItem from '../summary-item.vue';
import DatasetSummary from '../dataset/summary.vue';

import modal from '../../mixins/modal';
import useRoutes from '../../composables/routes';
import { afterNextNavigation } from '../../util/router';
import { apiPaths } from '../../util/request';
import { loadAsync } from '../../util/load-async';
import { modalData } from '../../util/reactivity';
import { noop } from '../../util/util';
import { useRequestData } from '../../request-data';

Expand All @@ -122,7 +121,6 @@ export default {
SummaryItem,
DatasetSummary
},
mixins: [modal({ viewXml: 'FormVersionViewXml' })],
inject: ['alert'],
props: {
projectId: {
Expand All @@ -146,18 +144,10 @@ export default {
data() {
return {
// Modals
viewXml: {
state: false
},
upload: {
state: false
},
publish: {
state: false
},
abandon: {
state: false
}
viewXml: modalData('FormVersionViewXml'),
upload: modalData(),
publish: modalData(),
abandon: modalData()
};
},
created() {
Expand All @@ -175,7 +165,7 @@ export default {
afterUpload() {
this.$emit('fetch-draft');
this.formDraftDatasetDiff.reset();
this.hideModal('upload');
this.upload.hide();
this.alert.success(this.$t('alert.upload'));
},
afterPublish() {
Expand Down
11 changes: 4 additions & 7 deletions src/components/form-version/list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ except according to the terms contained in the LICENSE file.
-->
<template>
<div>
<form-version-table @view-xml="showModal('viewXml')"/>
<form-version-table @view-xml="viewXml.show()"/>
<loading :state="formVersions.initiallyLoading"/>

<form-version-view-xml v-bind="viewXml" @hide="hideModal('viewXml')"/>
<form-version-view-xml v-bind="viewXml" @hide="viewXml.hide()"/>
</div>
</template>

Expand All @@ -24,9 +24,9 @@ import { defineAsyncComponent } from 'vue';
import FormVersionTable from './table.vue';
import Loading from '../loading.vue';

import modal from '../../mixins/modal';
import { apiPaths } from '../../util/request';
import { loadAsync } from '../../util/load-async';
import { modalData } from '../../util/reactivity';
import { noop } from '../../util/util';
import { useRequestData } from '../../request-data';

Expand All @@ -37,7 +37,6 @@ export default {
FormVersionViewXml: defineAsyncComponent(loadAsync('FormVersionViewXml')),
Loading
},
mixins: [modal({ viewXml: 'FormVersionViewXml' })],
props: {
projectId: {
type: String,
Expand All @@ -54,9 +53,7 @@ export default {
},
data() {
return {
viewXml: {
state: false
}
viewXml: modalData('FormVersionViewXml')
};
},
created() {
Expand Down
19 changes: 7 additions & 12 deletions src/components/form/overview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ except according to the terms contained in the LICENSE file.
<div class="row">
<div class="col-xs-6">
<loading :state="initiallyLoading"/>
<form-overview-right-now v-if="dataExists"
@view-xml="showModal('viewXml')"/>
<form-overview-right-now v-if="dataExists" @view-xml="viewXml.show()"/>
</div>
<div v-if="formDraft.dataExists" id="form-overview-draft" class="col-xs-6">
<page-section v-if="formDraft.isDefined()">
Expand All @@ -35,7 +34,7 @@ except according to the terms contained in the LICENSE file.
</i18n-t>
<div>
<form-version-standard-buttons :version="formDraft.get()"
@view-xml="showModal('viewXml')"/>
@view-xml="viewXml.show()"/>
</div>
</template>
</summary-item>
Expand All @@ -52,7 +51,7 @@ except according to the terms contained in the LICENSE file.
</page-section>
</div>
</div>
<form-version-view-xml v-bind="viewXml" @hide="hideModal('viewXml')"/>
<form-version-view-xml v-bind="viewXml" @hide="viewXml.hide()"/>
</div>
</template>

Expand All @@ -67,11 +66,11 @@ import PageSection from '../page/section.vue';
import SummaryItem from '../summary-item.vue';
import Loading from '../loading.vue';

import modal from '../../mixins/modal';
import { loadAsync } from '../../util/load-async';
import { useRequestData } from '../../request-data';
import { apiPaths } from '../../util/request';
import { loadAsync } from '../../util/load-async';
import { modalData } from '../../util/reactivity';
import { noop } from '../../util/util';
import { useRequestData } from '../../request-data';

export default {
name: 'FormOverview',
Expand All @@ -85,7 +84,6 @@ export default {
SummaryItem,
Loading
},
mixins: [modal({ viewXml: 'FormVersionViewXml' })],
props: {
projectId: {
type: String,
Expand All @@ -102,10 +100,7 @@ export default {
},
data() {
return {
// Modals
viewXml: {
state: false
}
viewXml: modalData('FormVersionViewXml')
};
},
created() {
Expand Down
11 changes: 4 additions & 7 deletions src/components/navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ except according to the terms contained in the LICENSE file.
<navbar-links v-if="loggedIn"/>
<div class="navbar-right">
<a v-show="showsAnalyticsNotice" id="navbar-analytics-notice"
href="#" @click.prevent="showModal('analyticsIntroduction')">
href="#" @click.prevent="analyticsIntroduction.show()">
{{ $t('analyticsNotice') }}
</a>
<ul class="nav navbar-nav">
Expand All @@ -41,7 +41,7 @@ except according to the terms contained in the LICENSE file.
</div>
</nav>
<analytics-introduction v-if="config.showsAnalytics" v-bind="analyticsIntroduction"
@hide="hideModal('analyticsIntroduction')"/>
@hide="analyticsIntroduction.hide()"/>
</div>
</template>

Expand All @@ -53,9 +53,9 @@ import NavbarHelpDropdown from './navbar/help-dropdown.vue';
import NavbarLinks from './navbar/links.vue';
import NavbarLocaleDropdown from './navbar/locale-dropdown.vue';

import modal from '../mixins/modal';
import useRoutes from '../composables/routes';
import { loadAsync } from '../util/load-async';
import { modalData } from '../util/reactivity';
import { useRequestData } from '../request-data';

export default {
Expand All @@ -67,7 +67,6 @@ export default {
NavbarLinks,
NavbarLocaleDropdown
},
mixins: [modal({ analyticsIntroduction: 'AnalyticsIntroduction' })],
inject: ['config'],
setup() {
// The component does not assume that this data will exist when the
Expand All @@ -78,9 +77,7 @@ export default {
},
data() {
return {
analyticsIntroduction: {
state: false
}
analyticsIntroduction: modalData('AnalyticsIntroduction')
};
},
computed: {
Expand Down
22 changes: 1 addition & 21 deletions src/mixins/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,8 @@ methods for toggling a modal.
The component using this mixin must define a data property for each modal that
it contains. The property should be an object that has a property named `state`
that indicates whether the modal should be shown.

If a component loads a modal component asynchronously, then when the component
uses the mixin, it should specify the name of the modal component along with the
name of the associated property. For example:

modal({ submissionOptions: 'ProjectSubmissionOptions' })
*/

import { loadedAsync } from '../util/load-async';

// @vue/component
const mixin = {
methods: {
Expand All @@ -41,16 +33,4 @@ const mixin = {
}
};

const mixinForAsyncModals = (asyncModals) => ({
methods: {
showModal(name) {
const componentName = asyncModals[name];
if (componentName == null || loadedAsync(componentName))
this[name].state = true;
},
hideModal: mixin.methods.hideModal
}
});

export default (asyncModals = undefined) =>
(asyncModals == null ? mixin : mixinForAsyncModals(asyncModals));
export default () => mixin;