Browse Source

chore(gui-v2): cleanup imports

pull/3211/head
braks 2 years ago
parent
commit
aac40e3494
  1. 55
      packages/nc-gui-v2/components/dlg/AirtableImport.vue
  2. 16
      packages/nc-gui-v2/components/dlg/TableCreate.vue
  3. 18
      packages/nc-gui-v2/pages/[projectType]/[projectId]/index/index.vue
  4. 1
      packages/nc-gui-v2/pages/[projectType]/[projectId]/index/index/index.vue

55
packages/nc-gui-v2/components/dlg/AirtableImport.vue

@ -1,12 +1,20 @@
<script setup lang="ts"> <script setup lang="ts">
import io from 'socket.io-client'
import type { Socket } from 'socket.io-client' import type { Socket } from 'socket.io-client'
import { Form, message } from 'ant-design-vue' import io from 'socket.io-client'
import type { Card as AntCard } from 'ant-design-vue' import type { Card as AntCard } from 'ant-design-vue'
import { extractSdkResponseErrorMsg, fieldRequiredValidator } from '~/utils' import { Form, message } from 'ant-design-vue'
import MdiCloseCircleOutlineIcon from '~icons/mdi/close-circle-outline' import {
import MdiCurrencyUsdIcon from '~icons/mdi/currency-usd' computed,
import MdiLoadingIcon from '~icons/mdi/loading' extractSdkResponseErrorMsg,
fieldRequiredValidator,
nextTick,
onBeforeUnmount,
onMounted,
ref,
useNuxtApp,
useProject,
watch,
} from '#imports'
interface Props { interface Props {
modelValue: boolean modelValue: boolean
@ -54,29 +62,21 @@ const syncSource = ref({
}, },
}) })
const validators = computed(() => { const validators = computed(() => ({
return {
'details.apiKey': [fieldRequiredValidator], 'details.apiKey': [fieldRequiredValidator],
'details.syncSourceUrlOrId': [fieldRequiredValidator], 'details.syncSourceUrlOrId': [fieldRequiredValidator],
} }))
})
const dialogShow = computed({ const dialogShow = computed({
get() { get: () => modelValue,
return modelValue set: (v) => emit('update:modelValue', v),
},
set(v) {
emit('update:modelValue', v)
},
}) })
const useForm = Form.useForm const useForm = Form.useForm
const { validateInfos } = useForm(syncSource, validators) const { validateInfos } = useForm(syncSource, validators)
const disableImportButton = computed(() => { const disableImportButton = computed(() => !syncSource.value.details.apiKey || !syncSource.value.details.syncSourceUrlOrId)
return !syncSource.value.details.apiKey || !syncSource.value.details.syncSourceUrlOrId
})
async function saveAndSync() { async function saveAndSync() {
await createOrUpdate() await createOrUpdate()
@ -86,6 +86,7 @@ async function saveAndSync() {
async function createOrUpdate() { async function createOrUpdate() {
try { try {
const { id, ...payload } = syncSource.value const { id, ...payload } = syncSource.value
if (id !== '') { if (id !== '') {
await $fetch(`/api/v1/db/meta/syncs/${id}`, { await $fetch(`/api/v1/db/meta/syncs/${id}`, {
baseURL, baseURL,
@ -94,13 +95,12 @@ async function createOrUpdate() {
body: payload, body: payload,
}) })
} else { } else {
const data: any = await $fetch(`/api/v1/db/meta/projects/${project.value.id}/syncs`, { syncSource.value = await $fetch(`/api/v1/db/meta/projects/${project.value.id}/syncs`, {
baseURL, baseURL,
method: 'POST', method: 'POST',
headers: { 'xc-auth': $state.token.value as string }, headers: { 'xc-auth': $state.token.value as string },
body: payload, body: payload,
}) })
syncSource.value = data
} }
} catch (e: any) { } catch (e: any) {
message.error(await extractSdkResponseErrorMsg(e)) message.error(await extractSdkResponseErrorMsg(e))
@ -113,7 +113,9 @@ async function loadSyncSrc() {
method: 'GET', method: 'GET',
headers: { 'xc-auth': $state.token.value as string }, headers: { 'xc-auth': $state.token.value as string },
}) })
const { list: srcs } = data const { list: srcs } = data
if (srcs && srcs[0]) { if (srcs && srcs[0]) {
srcs[0].details = srcs[0].details || {} srcs[0].details = srcs[0].details || {}
syncSource.value = migrateSync(srcs[0]) syncSource.value = migrateSync(srcs[0])
@ -171,6 +173,7 @@ function migrateSync(src: any) {
src.details.options.syncViews = src.syncViews src.details.options.syncViews = src.syncViews
delete src.syncViews delete src.syncViews
} }
return src return src
} }
@ -188,6 +191,7 @@ onMounted(async () => {
socket = io(new URL(baseURL, window.location.href.split(/[?#]/)[0]).href, { socket = io(new URL(baseURL, window.location.href.split(/[?#]/)[0]).href, {
extraHeaders: { 'xc-auth': $state.token.value as string }, extraHeaders: { 'xc-auth': $state.token.value as string },
}) })
socket.on('connect_error', () => { socket.on('connect_error', () => {
socket?.disconnect() socket?.disconnect()
socket = null socket = null
@ -203,7 +207,7 @@ onMounted(async () => {
progress.value.push(d) progress.value.push(d)
// FIXME: this doesn't work // FIXME: this doesn't work
nextTick(() => { await nextTick(() => {
;(logRef.value?.$el as HTMLDivElement).scrollTo() ;(logRef.value?.$el as HTMLDivElement).scrollTo()
}) })
@ -213,6 +217,7 @@ onMounted(async () => {
// TODO: add tab of the first table // TODO: add tab of the first table
} }
}) })
await loadSyncSrc() await loadSyncSrc()
}) })
@ -317,13 +322,13 @@ onBeforeUnmount(() => {
<a-card ref="logRef" :body-style="{ backgroundColor: '#000000', height: '400px', overflow: 'auto' }"> <a-card ref="logRef" :body-style="{ backgroundColor: '#000000', height: '400px', overflow: 'auto' }">
<div v-for="({ msg, status }, i) in progress" :key="i"> <div v-for="({ msg, status }, i) in progress" :key="i">
<div v-if="status === 'FAILED'" class="flex items-center"> <div v-if="status === 'FAILED'" class="flex items-center">
<MdiCloseCircleOutlineIcon class="text-red-500" /> <MdiCloseCircleOutline class="text-red-500" />
<span class="text-red-500 ml-2">{{ msg }}</span> <span class="text-red-500 ml-2">{{ msg }}</span>
</div> </div>
<div v-else class="flex items-center"> <div v-else class="flex items-center">
<MdiCurrencyUsdIcon class="text-green-500" /> <MdiCurrencyUsd class="text-green-500" />
<span class="text-green-500 ml-2">{{ msg }}</span> <span class="text-green-500 ml-2">{{ msg }}</span>
</div> </div>
@ -337,7 +342,7 @@ onBeforeUnmount(() => {
" "
class="flex items-center" class="flex items-center"
> >
<MdiLoadingIcon class="text-green-500 animate-spin" /> <MdiLoading class="text-green-500 animate-spin" />
<span class="text-green-500 ml-2"> Importing</span> <span class="text-green-500 ml-2"> Importing</span>
</div> </div>
</a-card> </a-card>

16
packages/nc-gui-v2/components/dlg/TableCreate.vue

@ -1,11 +1,10 @@
<script setup lang="ts"> <script setup lang="ts">
import { Form } from 'ant-design-vue' import { Form } from 'ant-design-vue'
import { onMounted, useProject, useTable, useTabs } from '#imports' import { computed, onMounted, ref, useProject, useTable, useTabs, useVModel, validateTableName } from '#imports'
import { validateTableName } from '~/utils/validation'
import { TabType } from '~/composables' import { TabType } from '~/composables'
interface Props { interface Props {
modelValue?: boolean modelValue: boolean
} }
const props = defineProps<Props>() const props = defineProps<Props>()
@ -16,6 +15,8 @@ const dialogShow = useVModel(props, 'modelValue', emit)
const isAdvanceOptVisible = ref(false) const isAdvanceOptVisible = ref(false)
const inputEl = ref<HTMLInputElement>()
const { addTab } = useTabs() const { addTab } = useTabs()
const { loadTables } = useProject() const { loadTables } = useProject()
@ -28,16 +29,14 @@ const { table, createTable, generateUniqueTitle, tables, project } = useTable(as
title: table.title, title: table.title,
type: TabType.TABLE, type: TabType.TABLE,
}) })
dialogShow.value = false dialogShow.value = false
}) })
const validateDuplicateAlias = (v: string) => {
return (tables?.value || []).every((t) => t.title !== (v || '')) || 'Duplicate table alias'
}
const inputEl = ref<HTMLInputElement>()
const useForm = Form.useForm const useForm = Form.useForm
const validateDuplicateAlias = (v: string) => (tables.value || []).every((t) => t.title !== (v || '')) || 'Duplicate table alias'
const validators = computed(() => { const validators = computed(() => {
return { return {
title: [validateTableName, validateDuplicateAlias], title: [validateTableName, validateDuplicateAlias],
@ -48,6 +47,7 @@ const { validateInfos } = useForm(table, validators)
onMounted(() => { onMounted(() => {
generateUniqueTitle() generateUniqueTitle()
inputEl.value?.focus() inputEl.value?.focus()
}) })
</script> </script>

18
packages/nc-gui-v2/pages/[projectType]/[projectId]/index/index.vue

@ -33,13 +33,17 @@ const icon = (tab: TabItem) => {
function openQuickImportDialog(type: string) { function openQuickImportDialog(type: string) {
$e(`a:actions:import-${type}`) $e(`a:actions:import-${type}`)
const isOpen = ref(true)
const { close } = useDialog(DlgQuickImport, { const { close } = useDialog(DlgQuickImport, {
'modelValue': true, 'modelValue': isOpen,
'importType': type, 'importType': type,
'onUpdate:modelValue': closeDialog, 'onUpdate:modelValue': closeDialog,
}) })
function closeDialog() { function closeDialog() {
isOpen.value = false
close(1000) close(1000)
} }
} }
@ -47,12 +51,16 @@ function openQuickImportDialog(type: string) {
function openTableCreateDialog() { function openTableCreateDialog() {
$e('a:actions:create-table') $e('a:actions:create-table')
const isOpen = ref(true)
const { close } = useDialog(DlgTableCreate, { const { close } = useDialog(DlgTableCreate, {
'modelValue': true, 'modelValue': isOpen,
'onUpdate:modelValue': closeDialog, 'onUpdate:modelValue': closeDialog,
}) })
function closeDialog() { function closeDialog() {
isOpen.value = false
close(1000) close(1000)
} }
} }
@ -60,12 +68,16 @@ function openTableCreateDialog() {
function openAirtableImportDialog() { function openAirtableImportDialog() {
$e('a:actions:import-airtable') $e('a:actions:import-airtable')
const isOpen = ref(true)
const { close } = useDialog(DlgAirtableImport, { const { close } = useDialog(DlgAirtableImport, {
'modelValue': true, 'modelValue': isOpen,
'onUpdate:modelValue': closeDialog, 'onUpdate:modelValue': closeDialog,
}) })
function closeDialog() { function closeDialog() {
isOpen.value = false
close(1000) close(1000)
} }
} }

1
packages/nc-gui-v2/pages/[projectType]/[projectId]/index/index/index.vue

@ -76,6 +76,7 @@ function openQuickImportDialog(type: QuickImportTypes, file: File) {
function closeDialog() { function closeDialog() {
isOpen.value = false isOpen.value = false
close(1000) close(1000)
} }
} }

Loading…
Cancel
Save