Skip to content

Commit a448870

Browse files
authored
Merge branch 'main' into add-email-contact-to-tenants
2 parents 0f0ff09 + 576c751 commit a448870

File tree

11 files changed

+274
-132
lines changed

11 files changed

+274
-132
lines changed

deploy/traction/values-development.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ ui:
9494
showMessage: true
9595
oidc:
9696
active: true
97-
authority: https://dev.loginproxy.gov.bc.ca/auth/realms/digitaltrust-nrm
98-
jwksUri: https://dev.loginproxy.gov.bc.ca/auth/realms/digitaltrust-nrm/protocol/openid-connect/certs
97+
authority: https://dev.loginproxy.gov.bc.ca/auth/realms/digitaltrust-citz
98+
jwksUri: https://dev.loginproxy.gov.bc.ca/auth/realms/digitaltrust-citz/protocol/openid-connect/certs
9999
reservationForm: >-
100100
{
101101
"formDataSchema": {

deploy/traction/values-pr.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ ui:
8585
showMessage: true
8686
oidc:
8787
active: true
88-
authority: https://dev.loginproxy.gov.bc.ca/auth/realms/digitaltrust-nrm
89-
jwksUri: https://dev.loginproxy.gov.bc.ca/auth/realms/digitaltrust-nrm/protocol/openid-connect/certs
88+
authority: https://dev.loginproxy.gov.bc.ca/auth/realms/digitaltrust-citz
89+
jwksUri: https://dev.loginproxy.gov.bc.ca/auth/realms/digitaltrust-citz/protocol/openid-connect/certs
9090
reservationForm: >-
9191
{
9292
"formDataSchema": {

services/tenant-ui/config/default.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
"oidc": {
1717
"active": false,
18-
"authority": "https://dev.loginproxy.gov.bc.ca/auth/realms/digitaltrust-nrm",
18+
"authority": "https://dev.loginproxy.gov.bc.ca/auth/realms/digitaltrust-citz",
1919
"client": "innkeeper-frontend",
2020
"label": "IDIR"
2121
},
@@ -53,8 +53,8 @@
5353
"staticFiles": "../../frontend/dist",
5454
"tractionUrl": "http://localhost:5100",
5555
"oidc": {
56-
"jwksUri": "https://dev.loginproxy.gov.bc.ca/auth/realms/digitaltrust-nrm/protocol/openid-connect/certs",
57-
"realm": "digitaltrust-nrm",
56+
"jwksUri": "https://dev.loginproxy.gov.bc.ca/auth/realms/digitaltrust-citz/protocol/openid-connect/certs",
57+
"realm": "digitaltrust-citz",
5858
"roleName": "innkeeper"
5959
},
6060
"innkeeper": {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<template>
2+
<div class="mt-2">
3+
<div class="flex justify-content-end">
4+
{{ $t('common.json') }}
5+
<InputSwitch v-model="showRawJson" class="ml-1" @input="toggleJson" />
6+
</div>
7+
<div v-show="!showRawJson">
8+
<slot></slot>
9+
</div>
10+
<div v-show="showRawJson">
11+
<Textarea
12+
id="credentialValuesEdit"
13+
v-model="valuesJson"
14+
:auto-resize="true"
15+
rows="20"
16+
cols="60"
17+
class="w-full mt-1"
18+
/>
19+
</div>
20+
</div>
21+
</template>
22+
23+
<script setup lang="ts" generic="T">
24+
// Libraries
25+
import { ref, defineExpose } from 'vue';
26+
// Source
27+
import InputSwitch from 'primevue/inputswitch';
28+
import Textarea from 'primevue/textarea';
29+
30+
const showRawJson = ref<boolean>(false);
31+
const valuesJson = ref<string>('');
32+
33+
// Undefined indicates that the conversion was a failure
34+
// note that indication of the error should be handled in the
35+
// toJson and fromJson using libraries like vue-toastification
36+
const props = defineProps<{
37+
toJson: () => string | undefined;
38+
fromJson: (jsonRepresentation: string) => T | undefined;
39+
}>();
40+
41+
defineExpose({
42+
showRawJson,
43+
valuesJson,
44+
});
45+
46+
const toggleJson = () => {
47+
if (showRawJson.value) {
48+
const res = props.toJson();
49+
if (res) {
50+
valuesJson.value = res;
51+
} else {
52+
showRawJson.value = !showRawJson.value;
53+
}
54+
} else {
55+
if (!props.fromJson(valuesJson.value)) {
56+
showRawJson.value = !showRawJson.value;
57+
}
58+
}
59+
};
60+
</script>

services/tenant-ui/frontend/src/components/issuance/credentials/EnterCredentialValues.vue

Lines changed: 44 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,13 @@
1111
</div>
1212

1313
<div class="field mt-5">
14-
<!-- Label/toggle -->
15-
<div class="flex justify-content-between">
16-
<div class="flex justify-content-start">
17-
<label for="credentialValuesEdit">
18-
<strong>{{ $t('issue.credentialFieldValues') }}</strong>
19-
</label>
20-
</div>
21-
<div class="flex justify-content-end">
22-
{{ $t('common.json') }}
23-
<InputSwitch v-model="showRawJson" class="ml-1" @input="toggleJson" />
24-
</div>
25-
</div>
26-
27-
<!-- Raw JSON input mode -->
28-
<div v-show="showRawJson">
29-
<Textarea
30-
id="credentialValuesEdit"
31-
v-model="credentialValuesJson"
32-
:auto-resize="true"
33-
rows="20"
34-
cols="60"
35-
class="w-full mt-1"
36-
/>
37-
38-
<div class="flex justify-content-end">
39-
<small>
40-
<!-- eslint-disable-next-line @intlify/vue-i18n/no-raw-text -->
41-
{{ $t('issue.schema') }}: {{ schemaForSelectedCred.schema.name }}
42-
<!-- eslint-disable-next-line @intlify/vue-i18n/no-raw-text -->
43-
{{ $t('issue.version') }}:
44-
{{ schemaForSelectedCred.schema.version }}
45-
</small>
46-
</div>
47-
</div>
48-
49-
<!-- Dynamic Attribute field list -->
50-
<div v-show="!showRawJson">
14+
<ToggleJson
15+
ref="jsonVal"
16+
:to-json="credentialValueToJson"
17+
:from-json="jsonToCredentialValue"
18+
generic="CredentialValue[]"
19+
>
20+
<!-- Dynamic Attribute field list -->
5121
<div
5222
v-for="(item, index) in credentialValuesRaw"
5323
:key="item.name"
@@ -62,8 +32,16 @@
6232
class="w-full"
6333
/>
6434
</div>
35+
</ToggleJson>
36+
<div class="flex justify-content-end">
37+
<small>
38+
<!-- eslint-disable-next-line @intlify/vue-i18n/no-raw-text -->
39+
{{ $t('issue.schema') }}: {{ schemaForSelectedCred.schema.name }}
40+
<!-- eslint-disable-next-line @intlify/vue-i18n/no-raw-text -->
41+
{{ $t('issue.version') }}:
42+
{{ schemaForSelectedCred.schema.version }}
43+
</small>
6544
</div>
66-
6745
<Button label="Save" class="mt-5 w-full" @click="saveCredValues" />
6846
</div>
6947
</template>
@@ -73,16 +51,20 @@
7351
import { onMounted, ref } from 'vue';
7452
// PrimeVue / Validation
7553
import Button from 'primevue/button';
76-
import InputSwitch from 'primevue/inputswitch';
7754
import InputText from 'primevue/inputtext';
78-
import Textarea from 'primevue/textarea';
7955
import { useToast } from 'vue-toastification';
56+
import { tryParseJson } from '@/helpers/jsonParsing';
57+
import ToggleJson from '@/components/common/ToggleJson.vue';
8058
8159
const toast = useToast();
8260
8361
// Props
62+
interface CredentialValue {
63+
name: string;
64+
value: string;
65+
}
8466
interface Props {
85-
existingCredentialValues?: { name: string; value: string }[];
67+
existingCredentialValues?: CredentialValue[];
8668
header: String;
8769
schemaForSelectedCred: any;
8870
}
@@ -91,58 +73,43 @@ const props = defineProps<Props>();
9173
const emit = defineEmits(['back', 'save']);
9274
9375
// Fields
94-
const credentialValuesJson = ref('');
95-
const credentialValuesRaw = ref([] as { name: string; value: string }[]);
96-
97-
const showRawJson = ref(false);
76+
const credentialValuesRaw = ref<CredentialValue[]>([]);
9877
99-
// TODO: util function file
100-
function _tryParseJson(jsonString: string) {
101-
try {
102-
const o = JSON.parse(jsonString);
103-
if (o && typeof o === 'object') {
104-
return o;
105-
}
106-
return false;
107-
} catch (e) {
108-
return false;
109-
}
110-
}
78+
const jsonVal = ref<{ showRawJson: boolean; valuesJson: string }>({
79+
showRawJson: false,
80+
valuesJson: '',
81+
});
11182
112-
function _jsonToCredRaw() {
113-
const parsed = _tryParseJson(credentialValuesJson.value);
83+
function jsonToCredentialValue(
84+
jsonString: string
85+
): CredentialValue[] | undefined {
86+
const parsed = tryParseJson<CredentialValue[]>(jsonString);
11487
if (parsed) {
115-
credentialValuesRaw.value = JSON.parse(credentialValuesJson.value);
88+
credentialValuesRaw.value = parsed;
89+
return parsed;
11690
} else {
11791
toast.warning('The JSON you inputted has invalid syntax');
92+
return undefined;
11893
}
11994
}
12095
121-
const toggleJson = () => {
122-
if (showRawJson.value) {
123-
// Convert over to the json from what was entered on the fields
124-
credentialValuesJson.value = JSON.stringify(
125-
credentialValuesRaw.value,
126-
undefined,
127-
2
128-
);
129-
} else {
130-
// Parse the entered JSON into fields, or ignore and warn if invalid syntax
131-
_jsonToCredRaw();
132-
}
133-
};
96+
function credentialValueToJson(): string | undefined {
97+
// Convert over to the json from what was entered on the fields
98+
const j = JSON.stringify(credentialValuesRaw.value, undefined, 2);
99+
return j;
100+
}
134101
135102
const saveCredValues = () => {
136-
if (showRawJson.value) {
137-
_jsonToCredRaw();
103+
if (jsonVal.value.showRawJson) {
104+
jsonToCredentialValue(jsonVal.value.valuesJson);
138105
}
139106
emit('save', credentialValuesRaw.value);
140107
};
141108
142-
// Whnen the component is intialized set up the fields and raw JSON based
109+
// When the component is initialized set up the fields and raw JSON based
143110
// on the supplied schema and if there is existing values already
144111
onMounted(() => {
145-
// Popuplate cred editor if it's not already been edited
112+
// Populate cred editor if it's not already been edited
146113
if (!props.existingCredentialValues?.length) {
147114
const schemaFillIn = props.schemaForSelectedCred.schema.attrNames.map(
148115
(a: string) => {
@@ -158,10 +125,5 @@ onMounted(() => {
158125
} else {
159126
credentialValuesRaw.value = props.existingCredentialValues;
160127
}
161-
credentialValuesJson.value = JSON.stringify(
162-
credentialValuesRaw.value,
163-
undefined,
164-
2
165-
);
166128
});
167129
</script>

0 commit comments

Comments
 (0)