Skip to content

Commit

Permalink
Handle no Ministry of form when managing External APIs (#1459)
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Sherman <[email protected]>
  • Loading branch information
usingtechnology authored Aug 13, 2024
1 parent 1b65a85 commit 11f6482
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
55 changes: 36 additions & 19 deletions app/frontend/src/components/admin/AdminAPIsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { i18n } from '~/internationalization';
import { useAdminStore } from '~/store/admin';
import { useFormStore } from '~/store/form';
import { Ministries } from '~/utils/constants';
import BaseDialog from '~/components/base/BaseDialog.vue';
export default {
Expand Down Expand Up @@ -35,33 +34,40 @@ export default {
computed: {
...mapState(useAdminStore, ['externalAPIList', 'externalAPIStatusCodes']),
...mapState(useFormStore, ['isRTL', 'lang']),
ministryList() {
return Ministries.map((ministry) => ({
id: ministry.id,
text: i18n.t(`trans.ministries.${ministry.id}`),
}));
},
headers() {
return [
{
title: i18n.t('trans.adminAPIsTable.ministry'),
align: 'start',
key: 'ministry',
},
{
title: i18n.t('trans.adminAPIsTable.ministryName'),
align: 'start',
key: 'ministryName',
// we don't want to see this (too long)
// but we need it for searching, so it needs to be in the DOM
headerProps: {
class: 'hidden',
},
cellProps: {
class: 'hidden',
},
},
{
title: i18n.t('trans.adminAPIsTable.formName'),
align: 'start',
key: 'formName',
},
{
title: i18n.t('trans.adminAPIsTable.name'),
title: i18n.t('trans.adminAPIsTable.formId'),
align: 'start',
key: 'name',
key: 'formId',
},
{
title: i18n.t('trans.adminAPIsTable.endpointUrl'),
title: i18n.t('trans.adminAPIsTable.name'),
align: 'start',
key: 'endpointUrl',
key: 'name',
},
{
title: i18n.t('trans.adminAPIsTable.display'),
Expand All @@ -77,6 +83,13 @@ export default {
},
];
},
items() {
// add ministry name to objects so we can search on them
return this.externalAPIList.map((x) => ({
...x,
ministryName: this.getMinistryName(x),
}));
},
},
async mounted() {
await this.getExternalAPIStatusCodes();
Expand All @@ -89,6 +102,9 @@ export default {
'updateExternalAPI',
'getExternalAPIStatusCodes',
]),
getMinistryName(item) {
return item.ministry ? i18n.t(`trans.ministries.${item.ministry}`) : '';
},
resetEditDialog() {
this.editDialog = {
title: '',
Expand All @@ -107,9 +123,7 @@ export default {
handleEdit(item) {
this.resetEditDialog();
this.editDialog.item = { ...item };
this.editDialog.item.ministryText = this.ministryList.find(
(x) => x.id === item.ministry
)['text'];
this.editDialog.item.ministryText = this.getMinistryName(item);
this.editDialog.title = i18n.t('trans.adminAPIsTable.editTitle');
this.editDialog.show = true;
},
Expand Down Expand Up @@ -162,24 +176,27 @@ export default {
hover
:headers="headers"
item-key="title"
:items="externalAPIList"
:items="items"
:search="search"
:loading="loading"
:loading-text="$t('trans.adminAPIsTable.loadingText')"
:lang="lang"
>
<template #item.ministry="{ item }">
{{ ministryList.find((x) => x.id === item.ministry)['text'] }}
{{ item.ministry }}
</template>
<template #item.ministryName="{ item }">
{{ getMinistryName(item) }}
</template>
<template #item.formName="{ item }">
{{ item.formName }}
</template>
<template #item.endpointUrl="{ item }">
{{ item.formId }}
</template>
<template #item.name="{ item }">
{{ item.name }}
</template>
<template #item.endpointUrl="{ item }">
{{ item.endpointUrl }}
</template>
<template #item.display="{ item }">
{{ item.display }}
</template>
Expand Down
2 changes: 2 additions & 0 deletions app/frontend/src/internationalization/trans/chefs/en/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,9 @@
"search": "Search",
"loadingText": "Loading... Please wait",
"ministry": "Ministry",
"ministryName": "Ministry Name",
"formName": "Form",
"formId": "Form ID",
"name": "API Name",
"endpointUrl": "Endpoint URL",
"display": "Status",
Expand Down

0 comments on commit 11f6482

Please sign in to comment.