Browse Source

chore(gui-v2): run lint

pull/2795/head
Wing-Kam Wong 2 years ago
parent
commit
de60c16f15
  1. 20
      packages/nc-gui-v2/components/dashboard/TabView.vue
  2. 35
      packages/nc-gui-v2/components/dlg/AirtableImport.vue
  3. 107
      packages/nc-gui-v2/components/dlg/QuickImport.vue
  4. 2
      packages/nc-gui-v2/utils/parsers/parserHelpers.ts

20
packages/nc-gui-v2/components/dashboard/TabView.vue

@ -14,15 +14,20 @@ const { tabs, activeTab, closeTab } = useTabs()
const { isUIAllowed } = useUIPermission()
const tableCreateDialog = ref(false)
const airtableImportDialog = ref(false)
const fileImportDialog = ref(false)
const quickImportDialog = ref(false)
const importType = ref('')
const currentMenu = ref<string[]>(['addORImport'])
const onEdit = (targetKey: number, action: string) => {
function onEdit(targetKey: number, action: string) {
if (action !== 'add') {
closeTab(targetKey)
}
}
function openQuickImportDialog(type: string) {
quickImportDialog.value = true
importType.value = type
}
</script>
<template>
@ -73,7 +78,7 @@ const onEdit = (targetKey: number, action: string) => {
v-if="isUIAllowed('csvImport')"
key="quick-import-csv"
v-t="['a:actions:import-csv']"
@click="fileImportDialog = true; importType = 'csv';"
@click="openQuickImportDialog('csv')"
>
<span class="flex items-center gap-2">
<MdiCsvIcon class="text-primary" />
@ -85,7 +90,7 @@ const onEdit = (targetKey: number, action: string) => {
v-if="isUIAllowed('jsonImport')"
key="quick-import-json"
v-t="['a:actions:import-json']"
@click="fileImportDialog = true; importType = 'json';"
@click="openQuickImportDialog('json')"
>
<span class="flex items-center gap-2">
<MdiJSONIcon class="text-primary" />
@ -97,8 +102,7 @@ const onEdit = (targetKey: number, action: string) => {
v-if="isUIAllowed('excelImport')"
key="quick-import-excel"
v-t="['a:actions:import-excel']"
@click="fileImportDialog = true; importType = 'excel'"
@click="openQuickImportDialog('excel')"
>
<span class="flex items-center gap-2">
<MdiExcelIcon class="text-primary" />
@ -123,7 +127,7 @@ const onEdit = (targetKey: number, action: string) => {
</a-tabs>
<DlgTableCreate v-if="tableCreateDialog" v-model="tableCreateDialog" />
<DlgQuickImport v-if="fileImportDialog" v-model="fileImportDialog" :import-type="importType" />
<DlgQuickImport v-if="quickImportDialog" v-model="quickImportDialog" :import-type="importType" />
<DlgAirtableImport v-if="airtableImportDialog" v-model="airtableImportDialog" />
<v-window v-model="activeTab">
@ -140,4 +144,4 @@ const onEdit = (targetKey: number, action: string) => {
padding: 0px 46px 0px 16px;
margin: 0px;
}
</style>
</style>

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

@ -42,8 +42,6 @@ const syncSource = ref({
},
})
const useForm = Form.useForm
const validators = computed(() => {
return {
apiKey: [fieldRequiredValidator],
@ -51,8 +49,6 @@ const validators = computed(() => {
}
})
const { resetFields, validate, validateInfos } = useForm(syncSource, validators)
const dialogShow = computed({
get() {
return modelValue
@ -62,12 +58,15 @@ const dialogShow = computed({
},
})
const saveAndSync = async () => {
const useForm = Form.useForm
const { resetFields, validate, validateInfos } = useForm(syncSource, validators)
async function saveAndSync() {
await createOrUpdate()
sync()
}
const createOrUpdate = async () => {
async function createOrUpdate() {
// TODO: check $axios implementation
// try {
// const { id, ...payload } = syncSource.value;
@ -81,17 +80,7 @@ const createOrUpdate = async () => {
// }
}
const sync = () => {
step.value = 2
// TODO: check $axios implementation
// $axios.post(`/api/v1/db/meta/syncs/${syncSource.value.id}/trigger`, payload, {
// params: {
// id: this.socket.id,
// },
// });
}
const loadSyncSrc = async () => {
async function loadSyncSrc() {
// const {
// data: { list: srcs },
// } = await $axios.get(`/api/v1/db/meta/projects/${project.id}/syncs`)
@ -121,7 +110,17 @@ const loadSyncSrc = async () => {
// }
}
const migrateSync = (src: any) => {
function sync() {
step.value = 2
// TODO: check $axios implementation
// $axios.post(`/api/v1/db/meta/syncs/${syncSource.value.id}/trigger`, payload, {
// params: {
// id: this.socket.id,
// },
// });
}
function migrateSync(src: any) {
if (!src.details?.options) {
src.details.options = {
syncViews: false,

107
packages/nc-gui-v2/components/dlg/QuickImport.vue

@ -51,18 +51,6 @@ const validators = computed(() => {
}
})
const { resetFields, validate, validateInfos } = useForm(importState, validators)
const handleDrop = (e: DragEvent) => {
console.log(e)
}
const rejectDrop = (fileList: any[]) => {
fileList.map((file) => {
toast.error(`Failed to upload file ${file.name}`)
})
}
const importMeta = computed(() => {
if (importType === 'excel') {
return {
@ -99,7 +87,56 @@ const dialogShow = computed({
},
})
const handleChange = (info: UploadChangeParam) => {
const { resetFields, validate, validateInfos } = useForm(importState, validators)
async function handleImport() {
if (activeKey.value === 'uploadTab') {
// FIXME:
importState.fileList.map(async (file: any) => {
await parseAndExtractData(file.data, file.name)
})
} else if (activeKey.value === 'urlTab') {
try {
await validate()
await parseAndExtractData(importState.url, '')
} catch (e: any) {
toast.error(await extractSdkResponseErrorMsg(e))
}
} else if (activeKey.value === 'jsonEditorTab') {
await parseAndExtractData(JSON.stringify(importState.jsonEditor), '')
}
}
async function parseAndExtractData(val: any, name: string) {
try {
templateData.value = null
importData.value = null
const templateGenerator: any = getAdapter(name, val)
await templateGenerator.init()
templateGenerator.parse()
templateData.value = templateGenerator.getTemplate()
templateData.value.tables[0].table_name = populateUniqueTableName()
importData.value = templateGenerator.getData()
templateEditorModal.value = true
dialogShow.value = false
} catch (e: any) {
console.log(e)
toast.error(await extractSdkResponseErrorMsg(e))
}
}
function handleDrop(e: DragEvent) {
console.log(e)
}
function rejectDrop(fileList: any[]) {
fileList.map((file) => {
return toast.error(`Failed to upload file ${file.name}`)
})
}
function handleChange(info: UploadChangeParam) {
const status = info.file.status
if (status !== 'uploading') {
const reader: any = new FileReader()
@ -118,29 +155,11 @@ const handleChange = (info: UploadChangeParam) => {
}
}
const formatJson = () => {
function formatJson() {
jsonEditorRef.value.format()
}
const handleImport = async () => {
if (activeKey.value === 'uploadTab') {
// FIXME:
importState.fileList.map(async (file: any) => {
await parseAndExtractData(file.data, file.name)
})
} else if (activeKey.value === 'urlTab') {
try {
await validate()
await parseAndExtractData(importState.url, '')
} catch (e: any) {
toast.error(await extractSdkResponseErrorMsg(e))
}
} else if (activeKey.value === 'jsonEditorTab') {
await parseAndExtractData(JSON.stringify(importState.jsonEditor), '')
}
}
const populateUniqueTableName = () => {
function populateUniqueTableName() {
let c = 1
while (tables.value.some((t: TableType) => t.title === `Sheet${c}`)) {
c++
@ -148,7 +167,7 @@ const populateUniqueTableName = () => {
return `Sheet${c}`
}
const getAdapter: any = (name: string, val: any) => {
function getAdapter(name: string, val: any) {
if (importType === 'excel' || importType === 'csv') {
if (activeKey.value === 'uploadTab') {
return new ExcelTemplateAdapter(name, val, importState.parserConfig)
@ -166,26 +185,6 @@ const getAdapter: any = (name: string, val: any) => {
}
return {}
}
const parseAndExtractData = async (val: any, name: string) => {
try {
let templateGenerator
templateData.value = null
importData.value = null
templateGenerator = getAdapter(name, val)
await templateGenerator.init()
templateGenerator.parse()
templateData.value = templateGenerator.getTemplate()
templateData.value.tables[0].table_name = populateUniqueTableName()
importData.value = templateGenerator.getData()
templateEditorModal.value = true
dialogShow.value = false
} catch (e: any) {
console.log(e)
toast.error(await extractSdkResponseErrorMsg(e))
}
}
</script>
<template>

2
packages/nc-gui-v2/utils/parsers/parserHelpers.ts

@ -1,4 +1,4 @@
import { ColumnType, UITypes } from 'nocodb-sdk'
import { UITypes } from 'nocodb-sdk'
import { isValidURL } from '~/utils/urlUtils'
import { isEmail } from '~/utils/validation'

Loading…
Cancel
Save