Skip to content

Commit

Permalink
Extract config item component
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas ONeil <[email protected]>
  • Loading branch information
loneil committed Nov 16, 2023
1 parent 757e758 commit dcb4c2c
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 103 deletions.
32 changes: 32 additions & 0 deletions services/tenant-ui/frontend/src/components/common/ConfigItem.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<template>
<p>
<strong v-if="props.title">
{{ title }}{{ $t('common.configDelim') }}
</strong>
<strong v-else>
<slot name="title"></slot>{{ $t('common.configDelim') }}
</strong>

<span v-if="contentToString">{{ props.content }}</span>
<slot v-else name="content"></slot>
</p>
</template>

<script setup lang="ts">
import { computed } from 'vue';
// Can pass in the fields as props, or use slots if more customization needed
const props = withDefaults(
defineProps<{
title?: string;
content?: string | number | boolean;
}>(),
{
title: '',
content: '',
}
);
const contentToString = computed(() =>
typeof props.content === 'boolean' ? props.content.toString() : props.content
);
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
<ProgressSpinner v-if="loading" />
<div v-else>
<!-- Topline version info -->
<p>
<strong>{{ $t('serverConfig.acapyVersion') }}</strong>
{{ serverConfig?.config?.version }}
</p>
<p>
<strong>{{ $t('serverConfig.tractionProxy') }}</strong>
{{ config.frontend.tenantProxyPath }}
<a :href="swaggerUrl" target="_blank">
<i class="pi pi-external-link ml-2" />
</a>
</p>
<ConfigItem
:title="$t('serverConfig.acapyVersion')"
:content="serverConfig?.config.version"
/>

<ConfigItem :title="$t('serverConfig.tractionProxy')">
<template #content>
{{ config.frontend.tenantProxyPath }}
<a :href="swaggerUrl" target="_blank">
<i class="pi pi-external-link ml-2" />
</a>
</template>
</ConfigItem>

<div class="grid mt-3">
<div class="col">
Expand All @@ -25,22 +27,22 @@
:legend="$t('serverConfig.ledger.ledgerDetails')"
:toggleable="true"
>
<p class="mt-0">
<p>
<strong>{{ $t('serverConfig.ledger.ledgerList') }}</strong>
</p>
<DataTable :value="ledgerConfigList" size="small" striped-rows>
<Column field="id" header="id"></Column>
<Column field="endorser_alias" header="endorser_alias"></Column>
<Column field="endorser_did" header="endorser_did"></Column>
<Column field="id" header="id" />
<Column field="endorser_alias" header="endorser_alias" />
<Column field="endorser_did" header="endorser_did" />
</DataTable>
<p>
<strong>{{ $t('serverConfig.ledger.quickConnect') }}</strong>
{{ config.frontend.quickConnectEndorserName }}
</p>
<p>
<strong>{{ $t('serverConfig.ledger.default') }}</strong>
{{ serverConfig?.config?.['ledger.write_ledger'] }}
</p>
<ConfigItem
:title="$t('serverConfig.ledger.quickConnect')"
:content="config.frontend.quickConnectEndorserName"
/>
<ConfigItem
:title="$t('serverConfig.ledger.default')"
:content="serverConfig?.config['ledger.write_ledger']"
/>
</Fieldset>

<!-- Traction cfg - storage -->
Expand All @@ -49,22 +51,18 @@
:legend="$t('serverConfig.storage.title')"
:toggleable="true"
>
<p class="mt-0">
<strong>{{
$t('serverConfig.storage.walletStorageConfig')
}}</strong>
{{ serverConfig?.config?.['wallet.storage_config'] }}
</p>
<p>
<strong>{{
$t('serverConfig.storage.walletStorageType')
}}</strong>
{{ serverConfig?.config?.['wallet.storage_type'] }}
</p>
<p>
<strong>{{ $t('serverConfig.storage.walletType') }}</strong>
{{ serverConfig?.config?.['wallet.type'] }}
</p>
<ConfigItem
:title="$t('serverConfig.storage.walletStorageConfig')"
:content="serverConfig?.config['wallet.storage_config']"
/>
<ConfigItem
:title="$t('serverConfig.storage.walletStorageType')"
:content="serverConfig?.config['wallet.storage_type']"
/>
<ConfigItem
:title="$t('serverConfig.storage.walletType')"
:content="serverConfig?.config['wallet.type']"
/>
</Fieldset>

<!-- Plugins from API call to get them -->
Expand All @@ -87,49 +85,42 @@
:legend="$t('serverConfig.tenants.title')"
:toggleable="true"
>
<p class="mt-0">
<strong>{{ $t('serverConfig.tenants.token') }}</strong>
{{
<ConfigItem
:title="$t('serverConfig.tenants.token')"
:content="
serverConfig?.config?.plugin_config?.multitenant_provider
?.token_expiry?.amount
}}
{{
?.token_expiry?.amount +
' ' +
serverConfig?.config?.plugin_config?.multitenant_provider
?.token_expiry?.units
}}
</p>
"
/>
<h3>{{ $t('serverConfig.tenants.reservation') }}</h3>
<p>
<strong>{{
$t('serverConfig.tenants.reservationExpiry')
}}</strong>
{{
<ConfigItem
:title="$t('serverConfig.tenants.reservationExpiry')"
:content="
serverConfig?.config?.plugin_config?.traction_innkeeper
?.reservation?.expiry_minutes
}}
</p>
<p>
<strong>{{
$t('serverConfig.tenants.reservationAutoApprove')
}}</strong>
{{
"
/>
<ConfigItem
:title="$t('serverConfig.tenants.reservationAutoApprove')"
:content="
serverConfig?.config?.plugin_config?.traction_innkeeper
?.reservation?.auto_approve
}}
</p>
<p>
<strong>{{
$t('serverConfig.tenants.reservationAutoIssuer')
}}</strong>
{{
"
/>
<ConfigItem
:title="$t('serverConfig.tenants.reservationAutoIssuer')"
:content="
serverConfig?.config?.plugin_config?.traction_innkeeper
?.reservation?.auto_issuer
}}
</p>
<p class="">
<strong>{{ $t('serverConfig.tenants.reservationOidc') }}</strong>
{{ config.frontend.showOIDCReservationLogin }}
</p>
"
/>
<ConfigItem
:title="$t('serverConfig.tenants.reservationOidc')"
:content="config.frontend.showOIDCReservationLogin"
/>
<div class="grid mt-0">
<div class="col xl:col-8">
<Accordion>
Expand All @@ -152,23 +143,23 @@
:legend="$t('serverConfig.tenantUi.tenantUi')"
:toggleable="true"
>
<p class="mt-0">
<strong>{{ $t('serverConfig.tenantUi.showWrite') }}</strong>
{{ config.frontend.showWritableComponents }}
</p>
<p>
<strong>{{ $t('serverConfig.tenantUi.sessionExpiry') }}</strong>
{{
<ConfigItem
:title="$t('serverConfig.tenantUi.showWrite')"
:content="config.frontend.showWritableComponents"
/>
<ConfigItem
:title="$t('serverConfig.tenantUi.sessionExpiry')"
:content="
$t('serverConfig.tenantUi.sessionExpiryVal', [
config.frontend.session?.timeoutSeconds,
config.frontend.session?.countdownSeconds,
])
}}
</p>
<p>
<strong>{{ $t('serverConfig.tenantUi.oidc') }}</strong>
{{ config.frontend.oidc?.authority }}
</p>
"
/>
<ConfigItem
:title="$t('serverConfig.tenantUi.oidc')"
:content="config.frontend.oidc?.authority"
/>
</Fieldset>

<!-- Tenant UI config endpoint raw json -->
Expand Down Expand Up @@ -201,6 +192,7 @@ import VueJsonPretty from 'vue-json-pretty';
import { useToast } from 'vue-toastification';
// Components
import { useConfigStore, useInnkeeperTenantsStore } from '@/store';
import ConfigItem from '@/components/common/ConfigItem.vue';
import MainCardContent from '../../layout/mainCard/MainCardContent.vue';
import PluginList from '@/components/about/PluginList.vue';
Expand Down
35 changes: 18 additions & 17 deletions services/tenant-ui/frontend/src/plugins/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"alias": "Alias",
"apiKey": "API Key",
"byName": "Search By Name",
"configDelim": ": ",
"confirmation": "Confirmation",
"connectionName": "Connection Name",
"contactName": "Contact Name",
Expand Down Expand Up @@ -416,42 +417,42 @@
"phone": "Phone / Mobile"
},
"serverConfig": {
"acapyVersion": "ACA-Py Version:",
"acapyVersion": "ACA-Py Version",
"expand": "Show full ACA-Py server config",
"ledger": {
"default": "Default base ledger:",
"default": "Default base ledger",
"ledgerDetails": "Ledger Details",
"ledgerList": "Ledger List",
"quickConnect": "Tenant UI quick-connect endorser:"
"quickConnect": "Tenant UI quick-connect endorser"
},
"serverConfig": "Server Configuration",
"storage": {
"multitenantWalletName": "Multitenant Wallet Name:",
"multitenantWalletType": "Multitenant Wallet Type:",
"multitenantWalletName": "Multitenant Wallet Name",
"multitenantWalletType": "Multitenant Wallet Type",
"title": "Storage",
"walletStorageConfig": "Wallet Storage Config:",
"walletStorageType": "Wallet Storage Type:",
"walletType": "Wallet Type:"
"walletStorageConfig": "Wallet Storage Config",
"walletStorageType": "Wallet Storage Type",
"walletType": "Wallet Type"
},
"tenants": {
"reservation": "Reservation",
"reservationAutoApprove": "Auto approve reservations:",
"reservationAutoIssuer": "Auto issuance approval:",
"reservationExpiry": "Reservation expiry (minutes):",
"reservationAutoApprove": "Auto approve reservations",
"reservationAutoIssuer": "Auto issuance approval",
"reservationExpiry": "Reservation expiry (minutes)",
"reservationForm": "Reservation Form",
"reservationOidc": "OIDC login requried for reservation:",
"reservationOidc": "OIDC login requried for reservation",
"title": "Tenants/Reservations",
"token": "Token Expiry:"
"token": "Token Expiry"
},
"tenantUi": {
"expand": "Show Full Tenant UI Frontend Config",
"oidc": "OIDC Endpoint:",
"sessionExpiry": "Frontend session expiry:",
"oidc": "OIDC Endpoint",
"sessionExpiry": "Frontend session expiry",
"sessionExpiryVal": "{0} seconds (Countdown: {1} seconds)",
"showWrite": "Show 'Write' Components:",
"showWrite": "Show 'Write' Components",
"tenantUi": "Tenant UI"
},
"tractionProxy": "Traction Proxy URL:"
"tractionProxy": "Traction Proxy URL"
},
"session": {
"countdown": "You are going to be logged out in { seconds } seconds...",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"alias": "Alias <FR>",
"apiKey": "API Key <FR>",
"byName": "Search By Name <FR>",
"configDelim": ": ",
"confirmation": "Confirmation <FR>",
"connectionName": "Connection Name <FR>",
"contactName": "Contact Name <FR>",
Expand Down
3 changes: 2 additions & 1 deletion services/tenant-ui/frontend/src/plugins/i18n/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"alias": "Alias <JA>",
"apiKey": "API Key <JA>",
"byName": "Search By Name <JA>",
"configDelim": ": ",
"confirmation": "Confirmation <JA>",
"connectionName": "Connection Name <JA>",
"contactName": "Contact Name <JA>",
Expand Down Expand Up @@ -554,4 +555,4 @@
},
"tractionProxy": "Traction Proxy URL: <JA>"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { mount, shallowMount } from '@vue/test-utils';
import PrimeVue from 'primevue/config';
import { describe, expect, test } from 'vitest';

import ConfigItem from '@/components/common/ConfigItem.vue';

const mountConfigItem = () =>
mount(ConfigItem, {
props: {
title: 'the_header',
content: 'the_content',
},
global: {
plugins: [PrimeVue],
},
});

const mountConfigItemSlot = () =>
mount(ConfigItem, {
slots: {
title: 'the_header',
content: '<div>test</div>',
},
global: {
plugins: [PrimeVue],
},
});

describe('ConfigItem', () => {
test('mount renders with props', async () => {
const wrapper = mountConfigItem();

const strongTitle = wrapper.find('strong');
const spanContent = wrapper.find('span');
expect(strongTitle.html()).toContain('the_header');
expect(strongTitle.html()).toContain('configDelim');
expect(spanContent.html()).toContain('the_content');
});

test('mount renders with slots', async () => {
const wrapper = mountConfigItemSlot();

const strongTitle = wrapper.find('strong');
const spanContent = wrapper.find('div');
expect(strongTitle.html()).toContain('the_header');
expect(strongTitle.html()).toContain('configDelim');
expect(spanContent.html()).toContain('test');
});
});

0 comments on commit dcb4c2c

Please sign in to comment.