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

Don't use Pinia for requestData even in development #1050

Merged
merged 5 commits into from
Nov 19, 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
68 changes: 0 additions & 68 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"marked": "~4",
"pako": "~1.0",
"papaparse": "^5.4.1",
"pinia": "^2.0.23",
"qrcode-generator": "~1",
"ramda": "~0.27",
"vue": "~3",
Expand Down
40 changes: 5 additions & 35 deletions src/components/async-route.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ except according to the terms contained in the LICENSE file.
<template>
<div v-if="loading === 'tab'">
<loading :state="showsLoading"/>
<component :is="component" v-if="component != null" v-bind="propsAndAttrs"/>
<component :is="component" v-if="component != null" v-bind="bindings"/>
</div>
<page-body v-else-if="showsLoading">
<loading :state="true"/>
</page-body>
<component :is="component" v-else-if="component != null" v-bind="propsAndAttrs"/>
<component :is="component" v-else-if="component != null" v-bind="bindings"/>
</template>

<script>
Expand Down Expand Up @@ -66,44 +66,14 @@ export default {
};
},
computed: {
propsAndAttrs() {
bindings() {
// The main use of this.$attrs is to pass along event listeners to the
// component.
return { ...this.props, ...this.$attrs };
},
componentNameAndKey() {
return [this.componentName, this.k];
return { ...this.props, ...this.$attrs, key: this.k };
matthew-white marked this conversation as resolved.
Show resolved Hide resolved
}
},
watch: {
componentNameAndKey([newComponentName], [oldComponentName]) {
if (newComponentName !== oldComponentName) {
this.load();
} else if (this.component != null) {
/*
If this.k has changed, then we need to re-render the component (unless
this.component == null, in which case there is no component to
re-render). We will cause a re-render by setting this.component to
`null` for a tick.

Previously, we used the `key` attribute to cause the component to
re-render. However, that results in the following lifecycle stages:

- `beforeUnmount` for the old component
- `setup` for the new component
- `unmounted` for the old component

Because we use `unmounted` hooks with requestData, we need `unmounted`
for the old component to happen before `setup` for the new component.
Otherwise, the new component might try to create a local resource with
the same name as one created by the old component, whose local resources
haven't been removed yet.
*/
const { component } = this;
this.component = null;
this.$nextTick(() => { this.component = component; });
}
}
componentName: 'load'
},
created() {
this.load();
Expand Down
8 changes: 4 additions & 4 deletions src/components/entity/conflict-summary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ const markAsResolved = () => {
.then(({ data }) => {
hideConfirm();
alert.success(t('conflictResolved'));
entity.patch(() => {
entity.conflict = data.conflict;
entity.updatedAt = data.updatedAt;
});

entity.conflict = data.conflict;
entity.updatedAt = data.updatedAt;

emit('resolve');
})
.catch(noop);
Expand Down
17 changes: 8 additions & 9 deletions src/components/entity/show.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,14 @@ const afterUpdate = (updatedEntity) => {
fetchActivityData();
updateModal.hide();
alert.success(i18n.t('alert.updateEntity'));
entity.patch(() => {
// entity.currentVersion will no longer have extended metadata, but we don't
// need it to.
entity.currentVersion = updatedEntity.currentVersion;
entity.updatedAt = updatedEntity.updatedAt;
// Update entity.conflict in case a conflict has been resolved by another
// user or in another tab.
entity.conflict = updatedEntity.conflict;
});

// entity.currentVersion will no longer have extended metadata, but we don't
// need it to.
entity.currentVersion = updatedEntity.currentVersion;
entity.updatedAt = updatedEntity.updatedAt;
// Update entity.conflict in case a conflict has been resolved by another user
// or in another tab.
entity.conflict = updatedEntity.conflict;
};

const deleteModal = modalData();
Expand Down
29 changes: 13 additions & 16 deletions src/components/form-attachment/list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -337,17 +337,17 @@ export default {
if (this.$route !== initialRoute) return;
if (updates.length === this.uploadStatus.total)
this.alert.success(this.$tcn('alert.success', updates.length));
this.attachments.patch(() => {
for (const [name, updatedAt] of updates) {
const attachment = this.attachments.get(name);
attachment.blobExists = true;
attachment.datasetExists = false;
attachment.exists = true;
attachment.updatedAt = updatedAt;

this.updatedAttachments.add(name);
}
});
for (const [name, updatedAt] of updates) {
const attachment = this.attachments.get(name);
attachment.blobExists = true;
attachment.datasetExists = false;
attachment.exists = true;
attachment.updatedAt = updatedAt;

this.updatedAttachments.add(name);
}

this.uploadStatus = { total: 0, remaining: 0, current: null, progress: 0 };
});
this.plannedUploads = [];
Expand All @@ -362,16 +362,13 @@ export default {
afterLinkDataset() {
const { attachment } = this.linkDatasetModal;
this.linkDatasetModal.hide();

this.alert.success(this.$t('alert.link', {
attachmentName: attachment.name
}));

this.attachments.patch(() => {
attachment.datasetExists = true;
attachment.blobExists = false;
attachment.exists = true;
});
attachment.datasetExists = true;
attachment.blobExists = false;
attachment.exists = true;
}
}
};
Expand Down
6 changes: 0 additions & 6 deletions src/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ except according to the terms contained in the LICENSE file.
*/
import axios from 'axios';
import { Translation } from 'vue-i18n';
import { createPinia } from 'pinia';

import createAlert from './alert';
import createCentralI18n from './i18n';
import createCentralRouter from './router';
import createUnsavedChanges from './unsaved-changes';
import { $tcn } from './util/i18n';
import { createRequestData } from './request-data';
import { noop } from './util/util';

const provide = [
'alert',
Expand All @@ -29,8 +27,6 @@ const provide = [
'logger'
];

const piniaMock = { install: noop };

export default ({
// `router` must be a function that returns an object. The function will be
// passed a partial container. It is also possible to create a container
Expand All @@ -47,7 +43,6 @@ export default ({
logger = console
} = {}) => {
const container = {
pinia: process.env.NODE_ENV === 'development' ? createPinia() : piniaMock,
i18n: i18n.global,
alert,
unsavedChanges,
Expand All @@ -64,7 +59,6 @@ export default ({
// eslint-disable-next-line no-param-reassign
app.config.globalProperties.$tcn = $tcn;

app.use(container.pinia);
app.use(container.requestData);
if (container.router != null) app.use(container.router);

Expand Down
Loading