Skip to content

Commit

Permalink
feat(#492): Adding a reusable mixing for user xml operations
Browse files Browse the repository at this point in the history
  • Loading branch information
tholulomo committed Jun 23, 2024
1 parent 666d48a commit c733213
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 35 deletions.
4 changes: 2 additions & 2 deletions app/src/mixins/deployVersion.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { watch } from 'vue';
import { mapMutations, mapGetters, mapActions, mapState } from 'vuex';

export default {
Expand All @@ -14,8 +13,9 @@ export default {
isAdmin: 'auth/isAdmin'
}),
isProduction() {
// The expectation of version toggling is only enabled for production and not lower environment.
// Version toggling is only enabled for production and not lower environment.
return new URL(window.location.origin)?.host === 'materialsmine.org';
// return new URL(window.location.origin)?.host === 'localhost';
},
...mapState('portal', [
'isSuccess',
Expand Down
52 changes: 19 additions & 33 deletions app/src/mixins/xmlOperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { mapGetters, mapMutations } from 'vuex';
import { XML_FINDER } from '@/modules/gql/xml-gql';
import dialogBox from '@/components/Dialog.vue';

const NULL_INIT = null;
export default {
data() {
return {
Expand All @@ -11,7 +12,7 @@ export default {
pageSize: 20,
filterParams: {},
error: null,
dialogBoxAction: null
dialogBoxAction: NULL_INIT
};
},
components: {
Expand All @@ -25,14 +26,13 @@ export default {
dialogBoxActive: 'dialogBox'
})
},

mixins: [explorerQueryParams],
methods: {
...mapMutations({
toggleDialogBox: 'setDialogBox'
}),
isAuthorized(xmlUser) {
return this.isAuth && (xmlUser === this.userId || this.isAdmin);
isOwner(xmlUser) {
return this.isAuth && xmlUser === this.userId;
},
editCuration(id, isNew) {
this.$router.push({
Expand All @@ -42,26 +42,21 @@ export default {
},
confirmAction() {
if (this.dialogBoxAction) {
this.dialogBoxAction();
// TODO (@tee): Check if xml is not ingested into KG before calling `this.dialogBoxAction()` to delete
// this.dialogBoxAction();
this.closeDialogBox();
}
},
openDialogBox(id, isNew, func = null) {
openDialogBox(id, isNew) {
if (!id) return;
this.dialogBoxAction = !func
? () => this.deleteXmlCuration(id, isNew)
: func;
if (!this.dialogBoxActive) {
this.toggleDialogBox();
}
this.dialogBoxAction = this.deleteXmlCuration(id, isNew);
this.toggleDialogBox();
},
closeDialogBox() {
if (this.dialogBoxActive) {
this.toggleDialogBox();
}
this.dialogBoxAction = null;
this.dialogBoxAction = NULL_INIT;
this.toggleDialogBox();
},
async deleteXmlCuration(id, isNew = null) {
async deleteXmlCuration(id, isNew = NULL_INIT) {
if (id && isNew !== null) {
await this.$store.dispatch('explorer/curation/deleteCuration', {
xmlId: id,
Expand All @@ -70,21 +65,8 @@ export default {
await this.$apollo.queries.xmlFinder.refetch();
}
},
setApprovalStatus() {
// return approvalStatus
switch (this.$route.name) {
case 'CuratedXML':
return 'Not_Approved';
case 'ApprovedCuration':
return 'Approved';
default:
return null;
}
},
updateFilterParams() {
if (!this.isAdmin) {
this.filterParams = { user: this.userId };
}
return this.isAuth && (this.filterParams = { user: this.userId });
}
},
apollo: {
Expand All @@ -99,15 +81,19 @@ export default {
filter: {
param: this.$route.query?.q,
...this.filterParams,
status: this.setApprovalStatus()
// User Portal Page: Show curation based on status depending on a route a user entered.
...(this.$route.name === 'ApprovedCuration'
? { status: 'Approved' }
: { status: 'Not_Approved' })
}
}
};
},
fetchPolicy: 'cache-first',
result({ data, loading }) {
if (!loading && data) this.error = null;
if (!loading && data) this.error = NULL_INIT;
},
// TODO (@tee): Put this in the global store action as it is reusable for other gql calls
error(error) {
if (error.networkError) {
const err = error.networkError;
Expand Down

0 comments on commit c733213

Please sign in to comment.