Implement Codemirror view for known_list dialog; add FileSelector action

Signed-off-by: Francesco Torchia <francesco.torchia@suse.com>
This commit is contained in:
Francesco Torchia 2025-01-30 16:10:45 +01:00
parent a58b553b14
commit c84264fa30
No known key found for this signature in database
GPG Key ID: E6D011B7415D4393
2 changed files with 137 additions and 102 deletions

View File

@ -1,40 +1,75 @@
<script> <script>
import { _EDIT, _VIEW } from '@shell/config/query-params';
import CodeMirror from '@shell/components/CodeMirror';
import FileSelector from '@shell/components/form/FileSelector.vue';
import AppModal from '@shell/components/AppModal.vue'; import AppModal from '@shell/components/AppModal.vue';
export default { export default {
emits: ['closed'], emits: ['closed'],
components: { AppModal }, components: {
FileSelector,
AppModal,
CodeMirror,
},
props: {
value: {
type: String,
required: true
},
mode: {
type: String,
default: _EDIT
},
},
data() { data() {
const codeMirrorOptions = {
readOnly: this.isView,
gutters: ['CodeMirror-foldgutter'],
mode: 'text/x-properties',
lint: false,
lineNumbers: !this.isView,
styleActiveLine: false,
tabSize: 2,
indentWithTabs: false,
cursorBlinkRate: 530,
};
return { return {
data: '', codeMirrorOptions,
currentVersion: '', text: this.value,
defaultRegistrySetting: null, showModal: false,
plugin: undefined,
busy: false,
version: '',
update: false,
mode: '',
showModal: false,
chartVersionInfo: null
}; };
}, },
computed: {
isView() {
return this.mode === _VIEW;
}
},
methods: { methods: {
showDialog(data) { onTextChange(value) {
this.text = value?.trim();
},
showDialog() {
this.showModal = true; this.showModal = true;
this.data = data;
}, },
closeDialog(result) { closeDialog(result) {
this.showModal = false; if (!result) {
this.text = this.value;
}
const value = (this.$refs.textbox)?.value; this.showModal = false;
this.$emit('closed', { this.$emit('closed', {
success: result, success: result,
value, value: this.text,
}); });
}, },
} }
@ -57,28 +92,38 @@ export default {
</h4> </h4>
<div class="custom mt-10"> <div class="custom mt-10">
<div class="dialog-panel"> <div class="dialog-panel">
<textarea <CodeMirror
ref="textbox" :value="text"
:value="data" class="editor"
class="edit-box" :options="codeMirrorOptions"
:showKeyMapBox="true"
@onInput="onTextChange"
/> />
</div> </div>
<div class="dialog-buttons"> <div class="dialog-actions">
<button <div class="action-pannel file-selector">
:disabled="busy" <FileSelector
class="btn role-secondary" class="btn role-secondary"
data-testid="ssh-known-hosts-dialog-cancel-btn" :label="t('generic.readFromFile')"
@click="closeDialog(false)" @selected="onTextChange"
> />
{{ t('generic.cancel') }} </div>
</button> <div class="action-pannel form-actions">
<button <button
class="btn role-primary" class="btn role-secondary"
data-testid="ssh-known-hosts-dialog-save-btn" data-testid="ssh-known-hosts-dialog-cancel-btn"
@click="closeDialog(true)" @click="closeDialog(false)"
> >
{{ t('generic.save') }} {{ t('generic.cancel') }}
</button> </button>
<button
class="btn role-primary"
data-testid="ssh-known-hosts-dialog-save-btn"
@click="closeDialog(true)"
>
{{ t('generic.save') }}
</button>
</div>
</div> </div>
</div> </div>
</div> </div>
@ -87,59 +132,58 @@ export default {
<style lang="scss" scoped> <style lang="scss" scoped>
.ssh-known-hosts-dialog { .ssh-known-hosts-dialog {
padding: 10px; padding: 15px;
h4 { h4 {
font-weight: bold; font-weight: bold;
margin-bottom: 20px;
} }
.dialog-panel { .dialog-panel {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
min-height: 100px; min-height: 100px;
border: 1px solid var(--border);
.edit-box { :deep() .editor {
font-family: monospace; display: flex;
font-size: 12px; flex-direction: column;
resize: none; resize: none;
max-height: 400px; max-height: 400px;
height: 50vh; height: 50vh;
padding: 10px;
}
p { .CodeMirror,
margin-bottom: 5px; .CodeMirror-gutters {
} min-height: 400px;
max-height: 400px;
.dialog-info { background-color: var(--yaml-editor-bg);
flex: 1;
}
.toggle-advanced {
display: flex;
align-items: center;
cursor: pointer;
margin: 10px 0;
&:hover {
text-decoration: none;
color: var(--link);
} }
}
.version-selector { .CodeMirror-gutters {
margin: 0 10px 10px 10px; width: 25px;
width: auto; }
.CodeMirror-linenumber {
padding-left: 0;
}
} }
} }
.dialog-buttons { .dialog-actions {
display: flex; display: flex;
justify-content: flex-end; justify-content: space-between;
margin-top: 10px;
> *:not(:last-child) { .action-pannel {
margin-right: 10px; margin-top: 10px;
}
.form-actions {
display: flex;
justify-content: flex-end;
> *:not(:last-child) {
margin-right: 10px;
}
} }
} }
} }

View File

@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import EditDialog from './KnownHostsEditDialog.vue'; import KnownHostsEditDialog from './KnownHostsEditDialog.vue';
import { _EDIT, _VIEW } from '@shell/config/query-params'; import { _EDIT, _VIEW } from '@shell/config/query-params';
export default defineComponent({ export default defineComponent({
@ -20,7 +20,7 @@ export default defineComponent({
}, },
}, },
components: { EditDialog }, components: { KnownHostsEditDialog },
computed: { computed: {
isViewMode() { isViewMode() {
@ -38,7 +38,7 @@ export default defineComponent({
methods: { methods: {
openDialog() { openDialog() {
(this.$refs.button as HTMLInputElement)?.blur(); (this.$refs.button as HTMLInputElement)?.blur();
(this.$refs.editDialog as any).showDialog(this.value); (this.$refs.editDialog as any).showDialog();
}, },
dialogClosed(result: any) { dialogClosed(result: any) {
@ -52,29 +52,31 @@ export default defineComponent({
<template> <template>
<div class="input-known-ssh-hosts labeled-input"> <div class="input-known-ssh-hosts labeled-input">
<label>{{ t('secret.ssh.knownHosts') }}</label> <label>{{ t('secret.ssh.knownHosts') }}</label>
<div <div class="hosts-input">
class="hosts-input"
>
{{ summary }} {{ summary }}
</div> </div>
<button <template v-if="!isViewMode">
v-if="!isViewMode" <button
ref="button" ref="button"
class="show-dialog btn" class="show-dialog-btn btn"
@click="openDialog" @click="openDialog"
> >
... <i class="icon icon-edit" />
</button> </button>
<EditDialog
v-if="!isViewMode" <KnownHostsEditDialog
ref="editDialog" ref="editDialog"
@closed="dialogClosed" :value="value"
/> :mode="mode"
@closed="dialogClosed"
/>
</template>
</div> </div>
</template> </template>
<style lang="scss" scoped> <style lang="scss" scoped>
.input-known-ssh-hosts { .input-known-ssh-hosts {
$ssKnownHostsButtonHeight: 20px; display: flex;
justify-content: space-between;
.hosts-input { .hosts-input {
cursor: default; cursor: default;
@ -82,20 +84,9 @@ export default defineComponent({
padding: 18px 0 0 0; padding: 18px 0 0 0;
} }
.show-dialog { .show-dialog-btn {
position: absolute; display: contents;
top: 28px; background-color: transparent;
padding: 0 6px;
min-height: $ssKnownHostsButtonHeight;
line-height: $ssKnownHostsButtonHeight;
right: 4px;
&:hover, &:focus {
border-color: var(--primary);
//color: var(--primary);
// TODO: Don't use hard-coded color
color: #fff
}
} }
} }
</style> </style>