-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #939 from bcgov/toggle-json-for-schema
Add support toggling json view of schemas in CreateSchemaForm
- Loading branch information
Showing
7 changed files
with
266 additions
and
124 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
services/tenant-ui/frontend/src/components/common/ToggleJson.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<template> | ||
<div class="mt-2"> | ||
<div class="flex justify-content-end"> | ||
{{ $t('common.json') }} | ||
<InputSwitch v-model="showRawJson" class="ml-1" @input="toggleJson" /> | ||
</div> | ||
<div v-show="!showRawJson"> | ||
<slot></slot> | ||
</div> | ||
<div v-show="showRawJson"> | ||
<Textarea | ||
id="credentialValuesEdit" | ||
v-model="valuesJson" | ||
:auto-resize="true" | ||
rows="20" | ||
cols="60" | ||
class="w-full mt-1" | ||
/> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts" generic="T"> | ||
// Libraries | ||
import { ref, defineExpose } from 'vue'; | ||
// Source | ||
import InputSwitch from 'primevue/inputswitch'; | ||
import Textarea from 'primevue/textarea'; | ||
const showRawJson = ref<boolean>(false); | ||
const valuesJson = ref<string>(''); | ||
// Undefined indicates that the conversion was a failure | ||
// note that indication of the error should be handled in the | ||
// toJson and fromJson using libraries like vue-toastification | ||
const props = defineProps<{ | ||
toJson: () => string | undefined; | ||
fromJson: (jsonRepresentation: string) => T | undefined; | ||
}>(); | ||
defineExpose({ | ||
showRawJson, | ||
valuesJson, | ||
}); | ||
const toggleJson = () => { | ||
if (showRawJson.value) { | ||
const res = props.toJson(); | ||
if (res) { | ||
valuesJson.value = res; | ||
} else { | ||
showRawJson.value = !showRawJson.value; | ||
} | ||
} else { | ||
if (!props.fromJson(valuesJson.value)) { | ||
showRawJson.value = !showRawJson.value; | ||
} | ||
} | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.