From 116e100ce385d9222a629517f961c13e199220fd Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 26 Jul 2022 16:14:47 +0800 Subject: [PATCH] feat(gui-v2): disable import button logic --- .../components/dlg/AirtableImport.vue | 15 ++++++-- .../nc-gui-v2/components/dlg/QuickImport.vue | 35 ++++++++++++++----- .../nc-gui-v2/components/monaco/Editor.vue | 8 +++++ 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/packages/nc-gui-v2/components/dlg/AirtableImport.vue b/packages/nc-gui-v2/components/dlg/AirtableImport.vue index 074bc566fe..a368e352f6 100644 --- a/packages/nc-gui-v2/components/dlg/AirtableImport.vue +++ b/packages/nc-gui-v2/components/dlg/AirtableImport.vue @@ -65,6 +65,10 @@ const dialogShow = computed({ const useForm = Form.useForm const { resetFields, validate, validateInfos } = useForm(syncSource, validators) +const disableImportButton = computed(() => { + return !syncSource.value.details.apiKey || !syncSourceUrlOrId.value +}) + async function saveAndSync() { await createOrUpdate() await sync() @@ -213,7 +217,14 @@ onBeforeUnmount(() => { QUICK IMPORT - AIRTABLE @@ -235,7 +246,7 @@ onBeforeUnmount(() => { - + Advanced Settings diff --git a/packages/nc-gui-v2/components/dlg/QuickImport.vue b/packages/nc-gui-v2/components/dlg/QuickImport.vue index 03fb9eeeaf..794a096f1b 100644 --- a/packages/nc-gui-v2/components/dlg/QuickImport.vue +++ b/packages/nc-gui-v2/components/dlg/QuickImport.vue @@ -58,6 +58,8 @@ const validators = computed(() => { } }) +const { resetFields, validate, validateInfos } = useForm(importState, validators) + const importMeta = computed(() => { if (IsImportTypeExcel.value) { return { @@ -94,7 +96,18 @@ const dialogShow = computed({ }, }) -const { resetFields, validate, validateInfos } = useForm(importState, validators) +const disablePreImportButton = computed(() => { + if (activeKey.value === 'uploadTab') { + return !(importState.fileList.length > 0) + } else if (activeKey.value === 'urlTab') { + if (!validateInfos.url.validateStatus) return true + return validateInfos.url.validateStatus === 'error' + } else if (activeKey.value === 'jsonEditorTab') { + return !jsonEditorRef.value?.isEditorValid() + } +}) + +const disableFormatJsonButton = computed(() => !jsonEditorRef.value?.isEditorValid()) async function handlePreImport() { loading.value = true @@ -167,9 +180,7 @@ function handleChange(info: UploadChangeParam) { } function formatJson() { - loading.value = true - jsonEditorRef.value.format() - loading.value = false + jsonEditorRef.value?.format() } function populateUniqueTableName() { @@ -206,10 +217,18 @@ function getAdapter(name: string, val: any) { () const emit = defineEmits(['update:modelValue']) +const isValid = ref(true) /** * Adding monaco editor to Vite @@ -29,8 +30,13 @@ const format = () => { editor.setValue(JSON.stringify(JSON.parse(editor?.getValue() as string), null, 2)) } +const isEditorValid = () => { + return isValid.value +} + defineExpose({ format, + isEditorValid, }) onMounted(() => { @@ -57,9 +63,11 @@ onMounted(() => { editor.onDidChangeModelContent(async (e) => { try { + isValid.value = true const obj = JSON.parse(editor.getValue()) if (!deepCompare(modelValue, obj)) emit('update:modelValue', obj) } catch (e) { + isValid.value = false console.log(e) } })