Browse Source

chore(gui-v2): cleanup typecheck issues

pull/3158/head
braks 2 years ago
parent
commit
cf853e6bc8
  1. 15
      packages/nc-gui-v2/components/smartsheet-column/FormulaOptions.vue
  2. 12
      packages/nc-gui-v2/composables/useColumnCreateStore.ts
  3. 24
      packages/nc-gui-v2/composables/useExpandedFormStore.ts
  4. 16
      packages/nc-gui-v2/composables/useGlobal/state.ts
  5. 2
      packages/nc-gui-v2/composables/useGlobal/types.ts
  6. 33
      packages/nc-gui-v2/composables/useLTARStore.ts
  7. 3
      packages/nc-gui-v2/composables/useViewColumns.ts
  8. 5
      packages/nc-gui-v2/composables/useViewFilters.ts
  9. 5
      packages/nc-gui-v2/composables/useViews.ts

15
packages/nc-gui-v2/components/smartsheet-column/FormulaOptions.vue

@ -4,9 +4,8 @@ import type { ListItem as AntListItem } from 'ant-design-vue'
import jsep from 'jsep' import jsep from 'jsep'
import type { ColumnType } from 'nocodb-sdk' import type { ColumnType } from 'nocodb-sdk'
import { UITypes, jsepCurlyHook } from 'nocodb-sdk' import { UITypes, jsepCurlyHook } from 'nocodb-sdk'
import { onMounted, useDebounceFn } from '#imports'
import { MetaInj } from '~/context'
import { import {
MetaInj,
NcAutocompleteTree, NcAutocompleteTree,
formulaList, formulaList,
formulaTypes, formulaTypes,
@ -14,8 +13,11 @@ import {
getUIDTIcon, getUIDTIcon,
getWordUntilCaret, getWordUntilCaret,
insertAtCursor, insertAtCursor,
onMounted,
useColumnCreateStoreOrThrow,
useDebounceFn,
validateDateWithUnknownFormat, validateDateWithUnknownFormat,
} from '@/utils' } from '#imports'
interface Props { interface Props {
value: Record<string, any> value: Record<string, any>
@ -615,10 +617,11 @@ onMounted(() => {
</a-form-item> </a-form-item>
<div class="text-gray-600 mt-2 mb-4 prose-sm"> <div class="text-gray-600 mt-2 mb-4 prose-sm">
Hint: Use {} to reference columns, e.g: {column_name}. For more, please check out Hint: Use {} to reference columns, e.g: {column_name}. For more, please check out
<a class="prose-sm" href="https://docs.nocodb.com/setup-and-usages/formulas#available-formula-features" target="_blank" <a class="prose-sm" href="https://docs.nocodb.com/setup-and-usages/formulas#available-formula-features" target="_blank">
>Formulas</a Formulas.
>. </a>
</div> </div>
<div class="h-[250px] overflow-auto scrollbar-thin-primary"> <div class="h-[250px] overflow-auto scrollbar-thin-primary">
<a-list ref="sugListRef" :data-source="suggestion" :locale="{ emptyText: 'No suggested formula was found' }"> <a-list ref="sugListRef" :data-source="suggestion" :locale="{ emptyText: 'No suggested formula was found' }">
<template #renderItem="{ item, index }"> <template #renderItem="{ item, index }">

12
packages/nc-gui-v2/composables/useColumnCreateStore.ts

@ -1,23 +1,13 @@
import { createInjectionState } from '@vueuse/core'
import clone from 'just-clone' import clone from 'just-clone'
import { Form, message } from 'ant-design-vue' import { Form, message } from 'ant-design-vue'
import type { ColumnType, TableType } from 'nocodb-sdk' import type { ColumnType, TableType } from 'nocodb-sdk'
import { UITypes } from 'nocodb-sdk' import { UITypes } from 'nocodb-sdk'
import type { Ref } from 'vue' import type { Ref } from 'vue'
import { useColumn } from './useColumn' import { useColumn } from './useColumn'
import { computed } from '#imports' import { computed, createInjectionState, extractSdkResponseErrorMsg, useNuxtApp } from '#imports'
import { useNuxtApp } from '#app'
import { extractSdkResponseErrorMsg } from '~/utils/errorUtils'
const useForm = Form.useForm const useForm = Form.useForm
// enum ColumnAlterType {
// NEW=4,
// EDIT=2,
// RENAME=8,
// DELETE=0,
// }
const columnToValidate = [UITypes.Email, UITypes.URL, UITypes.PhoneNumber] const columnToValidate = [UITypes.Email, UITypes.URL, UITypes.PhoneNumber]
const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState( const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState(

24
packages/nc-gui-v2/composables/useExpandedFormStore.ts

@ -3,17 +3,22 @@ import type { ColumnType, TableType } from 'nocodb-sdk'
import type { Ref } from 'vue' import type { Ref } from 'vue'
import { message } from 'ant-design-vue' import { message } from 'ant-design-vue'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { useApi, useInjectionState, useProject, useProvideSmartsheetRowStore } from '#imports' import {
import { NOCO } from '~/lib' NOCO,
import { useNuxtApp } from '#app' extractPkFromRow,
import type { Row } from '~/composables/useViewData' extractSdkResponseErrorMsg,
import { extractPkFromRow, extractSdkResponseErrorMsg } from '~/utils' useApi,
useInjectionState,
useNuxtApp,
useProject,
useProvideSmartsheetRowStore,
} from '#imports'
import type { Row } from '~/composables'
const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState((meta: Ref<TableType>, row: Ref<Row>) => { const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState((meta: Ref<TableType>, row: Ref<Row>) => {
const { $e, $state, $api } = useNuxtApp() const { $e, $state, $api } = useNuxtApp()
const { api, isLoading: isCommentsLoading, error: commentsError } = useApi() const { api, isLoading: isCommentsLoading, error: commentsError } = useApi()
// { useGlobalInstance: true },
// state
const commentsOnly = ref(false) const commentsOnly = ref(false)
const commentsAndLogs = ref([]) const commentsAndLogs = ref([])
const comment = ref('') const comment = ref('')
@ -84,11 +89,14 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState((m
await api.utils.commentRow({ await api.utils.commentRow({
fk_model_id: meta.value?.id as string, fk_model_id: meta.value?.id as string,
row_id: rowId, row_id: rowId,
// todo: description missing from argument type
description: comment.value, description: comment.value,
}) } as any)
comment.value = '' comment.value = ''
message.success('Comment added successfully') message.success('Comment added successfully')
await loadCommentsAndLogs() await loadCommentsAndLogs()
} catch (e: any) { } catch (e: any) {
message.error(e.message) message.error(e.message)

16
packages/nc-gui-v2/composables/useGlobal/state.ts

@ -72,7 +72,21 @@ export function useGlobalState(storageKey = 'nocodb-gui-v2'): State {
set: (val) => (storage.value.token = val), set: (val) => (storage.value.token = val),
}) })
const appInfo = ref<AppInfo>({ ncSiteUrl: 'localhost:8080' }) const appInfo = ref<AppInfo>({
ncSiteUrl: 'localhost:8080',
authType: 'jwt',
connectToExternalDB: false,
defaultLimit: 0,
firstUser: true,
githubAuthEnabled: false,
googleAuthEnabled: true,
ncMin: false,
oneClick: false,
projectHasAdmin: false,
teleEnabled: true,
type: 'nocodb',
version: '0.0.0',
})
/** reactive token payload */ /** reactive token payload */
const { payload } = useJwt<JwtPayload & User>(token) const { payload } = useJwt<JwtPayload & User>(token)

2
packages/nc-gui-v2/composables/useGlobal/types.ts

@ -13,7 +13,7 @@ export interface FeedbackForm {
export interface AppInfo { export interface AppInfo {
ncSiteUrl: string ncSiteUrl: string
authType: 'jwt' | 'masterKey' | 'none' authType: 'jwt' | 'none'
connectToExternalDB: boolean connectToExternalDB: boolean
defaultLimit: number defaultLimit: number
firstUser: boolean firstUser: boolean

33
packages/nc-gui-v2/composables/useLTARStore.ts

@ -1,10 +1,18 @@
import type { ColumnType, LinkToAnotherRecordType, PaginatedType, TableType } from 'nocodb-sdk' import type { ColumnType, LinkToAnotherRecordType, PaginatedType, TableType } from 'nocodb-sdk'
import type { ComputedRef, Ref } from 'vue' import type { ComputedRef, Ref } from 'vue'
import { Modal, message } from 'ant-design-vue' import { Modal, message } from 'ant-design-vue'
import { useInjectionState, useMetas, useProject } from '#imports' import {
import { NOCO } from '~/lib' NOCO,
computed,
extractSdkResponseErrorMsg,
reactive,
ref,
useInjectionState,
useMetas,
useNuxtApp,
useProject,
} from '#imports'
import type { Row } from '~/composables' import type { Row } from '~/composables'
import { extractSdkResponseErrorMsg } from '~/utils'
interface DataApiResponse { interface DataApiResponse {
list: Record<string, any> list: Record<string, any>
@ -13,13 +21,13 @@ interface DataApiResponse {
/** Store for managing Link to another cells */ /** Store for managing Link to another cells */
const [useProvideLTARStore, useLTARStore] = useInjectionState( const [useProvideLTARStore, useLTARStore] = useInjectionState(
(column: Ref<Required<ColumnType>>, row?: Ref<Row>, isNewRow: ComputedRef<boolean> | Ref<boolean>, reloadData = () => {}) => { (column: Ref<Required<ColumnType>>, row: Ref<Row>, isNewRow: ComputedRef<boolean> | Ref<boolean>, reloadData = () => {}) => {
// state // state
const { metas, getMeta } = useMetas() const { metas, getMeta } = useMetas()
const { project } = useProject() const { project } = useProject()
const { $api } = useNuxtApp() const { $api } = useNuxtApp()
const childrenExcludedList: Ref<DataApiResponse | undefined> = ref() const childrenExcludedList = ref<DataApiResponse | undefined>()
const childrenList: Ref<DataApiResponse | undefined> = ref() const childrenList = ref<DataApiResponse | undefined>()
const childrenExcludedListPagination = reactive({ const childrenExcludedListPagination = reactive({
page: 1, page: 1,
query: '', query: '',
@ -95,12 +103,13 @@ const [useProvideLTARStore, useLTARStore] = useInjectionState(
colOptions.type as 'mm' | 'hm', colOptions.type as 'mm' | 'hm',
column?.value?.title, column?.value?.title,
{ {
limit: childrenExcludedListPagination.size, limit: String(childrenExcludedListPagination.size),
offset: childrenExcludedListPagination.size * (childrenExcludedListPagination.page - 1), offset: String(childrenExcludedListPagination.size * (childrenExcludedListPagination.page - 1)),
// todo: where clause is missing from type
where: where:
childrenExcludedListPagination.query && childrenExcludedListPagination.query &&
`(${relatedTablePrimaryValueProp.value},like,${childrenExcludedListPagination.query})`, `(${relatedTablePrimaryValueProp.value},like,${childrenExcludedListPagination.query})`,
}, } as any,
) )
} }
} catch (e: any) { } catch (e: any) {
@ -120,10 +129,10 @@ const [useProvideLTARStore, useLTARStore] = useInjectionState(
colOptions.type as 'mm' | 'hm', colOptions.type as 'mm' | 'hm',
column?.value?.title, column?.value?.title,
{ {
limit: childrenListPagination.size, limit: String(childrenListPagination.size),
offset: childrenListPagination.size * (childrenListPagination.page - 1), offset: String(childrenListPagination.size * (childrenListPagination.page - 1)),
where: childrenListPagination.query && `(${relatedTablePrimaryValueProp.value},like,${childrenListPagination.query})`, where: childrenListPagination.query && `(${relatedTablePrimaryValueProp.value},like,${childrenListPagination.query})`,
}, } as any,
) )
} catch (e: any) { } catch (e: any) {
message.error(`Failed to load children list: ${await extractSdkResponseErrorMsg(e)}`) message.error(`Failed to load children list: ${await extractSdkResponseErrorMsg(e)}`)

3
packages/nc-gui-v2/composables/useViewColumns.ts

@ -113,7 +113,8 @@ export function useViewColumns(
const showSystemFields = computed({ const showSystemFields = computed({
get() { get() {
return view?.value?.show_system_fields || false // todo: show_system_fields missing from ViewType
return (view?.value as any)?.show_system_fields || false
}, },
set(v: boolean) { set(v: boolean) {
if (view?.value?.id) { if (view?.value?.id) {

5
packages/nc-gui-v2/composables/useViewFilters.ts

@ -78,10 +78,11 @@ export function useViewFilters(
fk_parent_id: parentId, fk_parent_id: parentId,
}) })
} else { } else {
filters.value[i] = await $api.dbTableFilter.create(view?.value?.id as string, { // todo: return type of dbTableFilter is void?
filters.value[i] = (await $api.dbTableFilter.create(view?.value?.id as string, {
...filter, ...filter,
fk_parent_id: parentId, fk_parent_id: parentId,
}) })) as any
} }
reloadData?.() reloadData?.()
} }

5
packages/nc-gui-v2/composables/useViews.ts

@ -1,16 +1,17 @@
import type { TableType, ViewType } from 'nocodb-sdk' import type { TableType, ViewType } from 'nocodb-sdk'
import type { MaybeRef } from '@vueuse/core' import type { MaybeRef } from '@vueuse/core'
import { useNuxtApp } from '#app' import { unref, useNuxtApp, watch } from '#imports'
export function useViews(meta: MaybeRef<TableType | undefined>) { export function useViews(meta: MaybeRef<TableType | undefined>) {
let views = $ref<ViewType[]>([]) let views = $ref<ViewType[]>([])
const { $api } = useNuxtApp() const { $api } = useNuxtApp()
const loadViews = async () => { const loadViews = async () => {
const _meta = unref(meta) const _meta = unref(meta)
if (_meta && _meta.id) { if (_meta && _meta.id) {
const response = (await $api.dbView.list(_meta.id)).list const response = (await $api.dbView.list(_meta.id)).list as ViewType[]
if (response) { if (response) {
views = response.sort((a, b) => a.order! - b.order!) views = response.sort((a, b) => a.order! - b.order!)
} }

Loading…
Cancel
Save