Browse Source

feat: improve json editor

- allow save only if valid monaco-editor input
- show errors for invalid json

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/1821/head
mertmit 2 years ago
parent
commit
659d900443
  1. 4
      packages/nc-gui/components/monaco/MonacoJsonObjectEditor.js
  2. 15
      packages/nc-gui/components/project/spreadsheet/components/editableCell/jsonEditableCell.vue

4
packages/nc-gui/components/monaco/MonacoJsonObjectEditor.js

@ -31,7 +31,7 @@ export default {
default: true default: true
} }
}, },
emits: ['validate'],
model: { model: {
event: "change" event: "change"
}, },
@ -109,7 +109,9 @@ export default {
if (!this.deepcompare(this.value, JSON.parse(value))) { if (!this.deepcompare(this.value, JSON.parse(value))) {
this.$emit("change", JSON.parse(value), event); this.$emit("change", JSON.parse(value), event);
} }
this.$emit("validate", true);
} catch (e) { } catch (e) {
this.$emit("validate", false, e);
// console.log('monaco', e) // console.log('monaco', e)
} }
}); });

15
packages/nc-gui/components/project/spreadsheet/components/editableCell/jsonEditableCell.vue

@ -10,7 +10,7 @@
<!-- Cancel --> <!-- Cancel -->
{{ $t('general.cancel') }} {{ $t('general.cancel') }}
</v-btn> </v-btn>
<v-btn x-small color="primary" @click="save"> <v-btn x-small color="primary" :disabled="!isValid" @click="save">
<!-- Save --> <!-- Save -->
{{ $t('general.save') }} {{ $t('general.save') }}
</v-btn> </v-btn>
@ -25,13 +25,18 @@
v-model="localState" v-model="localState"
class="text-left caption" class="text-left caption"
style="width: 300px;min-height:min(600px,80vh);min-width:100%; " style="width: 300px;min-height:min(600px,80vh);min-width:100%; "
@validate="validate"
/> />
<monaco-json-object-editor <monaco-json-object-editor
v-else v-else
v-model="localState" v-model="localState"
class="text-left caption" class="text-left caption"
style="width: 300px;min-height:200px;min-width:100%;" style="width: 300px;min-height:200px;min-width:100%;"
@validate="validate"
/> />
<div v-show="error" class="px-2 py-1 text-left caption error--text">
{{ error }}
</div>
</v-dialog> </v-dialog>
</template> </template>
@ -47,7 +52,9 @@ export default {
}, },
data: () => ({ data: () => ({
localState: '', localState: '',
expand: false expand: false,
isValid: true,
error: undefined
}), }),
computed: { computed: {
@ -91,6 +98,10 @@ export default {
save() { save() {
this.expand = false this.expand = false
this.$emit('input', JSON.stringify(this.localState)) this.$emit('input', JSON.stringify(this.localState))
},
validate(n, e) {
this.isValid = n
this.error = e
} }
} }
} }

Loading…
Cancel
Save