From 8f18ac9ebbc81e7c40f0da3c16c6e7695d291a37 Mon Sep 17 00:00:00 2001 From: Lucas ONeil Date: Wed, 16 Aug 2023 16:52:44 -0700 Subject: [PATCH] Display in list Signed-off-by: Lucas ONeil --- .../innkeeper/authentications/ApiKeys.vue | 39 ++++++++++++- .../createApiKey/CreateApiKeyForm.vue | 57 +++++++++++++------ .../src/components/messages/Messages.vue | 2 +- .../store/innkeeper/innkeeperTenantsStore.ts | 42 +++++++++++++- 4 files changed, 119 insertions(+), 21 deletions(-) diff --git a/services/tenant-ui/frontend/src/components/innkeeper/authentications/ApiKeys.vue b/services/tenant-ui/frontend/src/components/innkeeper/authentications/ApiKeys.vue index c7f5751e1..0469bed49 100644 --- a/services/tenant-ui/frontend/src/components/innkeeper/authentications/ApiKeys.vue +++ b/services/tenant-ui/frontend/src/components/innkeeper/authentications/ApiKeys.vue @@ -38,6 +38,26 @@ + + + + { innkeeperTenantsStore.listApiKeys().catch((err: string) => { console.error(err); toast.error(`Failure: ${err}`); }); + + // Load tenants if not already there for display + if (!tenants.value || !tenants.value.length) { + innkeeperTenantsStore.listTenants().catch((err) => { + console.error(err); + toast.error(`Failure: ${err}`); + }); + } }; // Formatting the table row @@ -140,6 +170,7 @@ const formattedApiKeys = computed(() => apiKeys.value.map((api: any) => ({ tenant_authentication_api_id: formatGuid(api.tenant_authentication_api_id), tenant_id: api.tenant_id, + name: findTenantName(api.tenant_id), alias: api.alias, created: formatDateLong(api.created_at), created_at: api.created_at, @@ -156,6 +187,10 @@ const filter = ref({ value: null, matchMode: FilterMatchMode.CONTAINS, }, + name: { + value: null, + matchMode: FilterMatchMode.CONTAINS, + }, tenant_id: { value: null, matchMode: FilterMatchMode.CONTAINS, diff --git a/services/tenant-ui/frontend/src/components/innkeeper/authentications/createApiKey/CreateApiKeyForm.vue b/services/tenant-ui/frontend/src/components/innkeeper/authentications/createApiKey/CreateApiKeyForm.vue index 3b0629235..a4f044c02 100644 --- a/services/tenant-ui/frontend/src/components/innkeeper/authentications/createApiKey/CreateApiKeyForm.vue +++ b/services/tenant-ui/frontend/src/components/innkeeper/authentications/createApiKey/CreateApiKeyForm.vue @@ -3,20 +3,27 @@
- - {{ v$.tenantId.required.$message }} - + {{ + v$.selectedTenant.required.$message + }}
@@ -42,7 +49,11 @@

- {{ $t('apiKey.generatedKeyMessage', { key: v$.tenantId.$model }) }} + {{ + $t('apiKey.generatedKeyMessage', { + key: formFields.selectedTenant.value, + }) + }}

{{ $t('apiKey.generatedKey') }}
@@ -58,8 +69,10 @@ import { reactive, ref } from 'vue'; import { useInnkeeperTenantsStore } from '@/store'; import { storeToRefs } from 'pinia'; // PrimeVue / Validation +import AutoComplete from 'primevue/autocomplete'; import Button from 'primevue/button'; import InputText from 'primevue/inputtext'; +import ProgressSpinner from 'primevue/progressspinner'; import { required } from '@vuelidate/validators'; import { useVuelidate } from '@vuelidate/core'; import { useToast } from 'vue-toastification'; @@ -70,17 +83,29 @@ const toast = useToast(); const innkeeperTenantsStore = useInnkeeperTenantsStore(); // use the loading state from the store to disable the button... -const { loading } = storeToRefs(useInnkeeperTenantsStore()); +const { loading, tenantsDropdown } = storeToRefs(useInnkeeperTenantsStore()); -const emit = defineEmits(['closed', 'success']); +// Autocomplete setup +const filteredTenants = ref(); +const searchTenants = (event: any) => { + if (!event.query.trim().length) { + filteredTenants.value = [...(tenantsDropdown as any).value]; + } else { + filteredTenants.value = (tenantsDropdown.value as any).filter( + (tenant: any) => { + return tenant.label.toLowerCase().includes(event.query.toLowerCase()); + } + ); + } +}; // Validation const formFields = reactive({ - tenantId: '', + selectedTenant: undefined as any, alias: '', }); const rules = { - tenantId: { required }, + selectedTenant: { required }, alias: {}, }; const v$ = useVuelidate(rules, formFields); @@ -97,7 +122,7 @@ const handleSubmit = async (isFormValid: boolean) => { try { const response = await innkeeperTenantsStore.createApiKey({ - tenant_id: formFields.tenantId, + tenant_id: formFields.selectedTenant.value, alias: formFields.alias, }); createdKey.value = response.data.api_key; diff --git a/services/tenant-ui/frontend/src/components/messages/Messages.vue b/services/tenant-ui/frontend/src/components/messages/Messages.vue index 993be50fd..31224693e 100644 --- a/services/tenant-ui/frontend/src/components/messages/Messages.vue +++ b/services/tenant-ui/frontend/src/components/messages/Messages.vue @@ -158,7 +158,7 @@ const loadTable = async () => { messageStore.listMessages().catch((err: any) => { toast.error(`Failure: ${err}`); }); - // messages = messages.map() + // Load contacts if not already there for display if (!contacts.value || !contacts.value.length) { listContacts().catch((err) => { diff --git a/services/tenant-ui/frontend/src/store/innkeeper/innkeeperTenantsStore.ts b/services/tenant-ui/frontend/src/store/innkeeper/innkeeperTenantsStore.ts index bdb4fb834..d7c870145 100644 --- a/services/tenant-ui/frontend/src/store/innkeeper/innkeeperTenantsStore.ts +++ b/services/tenant-ui/frontend/src/store/innkeeper/innkeeperTenantsStore.ts @@ -3,7 +3,6 @@ import { ReservationRecord, TenantAuthenticationApiRecord, TenantAuthenticationsApiRequest, - TenantAuthenticationsApiResponse, TenantConfig, TenantRecord, } from '@/types/acapyApi/acapyInterface'; @@ -12,7 +11,12 @@ import { defineStore, storeToRefs } from 'pinia'; import { computed, ref, Ref } from 'vue'; import axios from 'axios'; import { useAcapyApi } from '../acapyApi'; -import { fetchListFromAPI } from '../utils'; +import { + fetchListFromAPI, + filterByStateActive, + filterMapSortList, + sortByLabelAscending, +} from '../utils'; import { RESERVATION_STATUS_ROUTE } from '@/helpers/constants'; import { API_PATH, RESERVATION_STATUSES } from '@/helpers/constants'; import { useConfigStore } from '../configStore'; @@ -42,6 +46,25 @@ export const useInnkeeperTenantsStore = defineStore('innkeeperTenants', () => { reservations.value.filter((r) => r.state !== RESERVATION_STATUSES.REQUESTED) ); + const tenantsDropdown = computed(() => { + // Get the display list of active connections from the util + return filterMapSortList( + tenants.value, + _tenantLabelValue, + sortByLabelAscending, + filterByStateActive + ); + }); + + const findTenantName = computed(() => (id: string) => { + if (loading.value) return undefined; + // Find the tenant name for an ID + const tenant = tenants.value?.find((t: TenantRecord) => { + return t.tenant_id === id; + }); + return tenant && tenant.tenant_name ? tenant.tenant_name : ''; + }); + // actions // (using both things temporarily) @@ -262,11 +285,26 @@ export const useInnkeeperTenantsStore = defineStore('innkeeperTenants', () => { }); } + // Display for a tenant dropdown list item + const _tenantLabelValue = (item: TenantRecord) => { + let result = null; + if (item != null) { + result = { + label: item.tenant_name, + value: item.tenant_id, + status: item.state, + }; + } + return result; + }; + return { loading, error, apiKeys, + findTenantName, tenants, + tenantsDropdown, reservations, currentReservations, reservationHistory,