Browse Source

fix(gui-v2): prevent missing injection warnings

pull/3211/head
braks 2 years ago
parent
commit
26e64c60d9
  1. 2
      packages/nc-gui-v2/components.d.ts
  2. 26
      packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilterMenu.vue
  3. 25
      packages/nc-gui-v2/components/smartsheet-toolbar/FieldsMenu.vue
  4. 8
      packages/nc-gui-v2/components/smartsheet/Cell.vue
  5. 9
      packages/nc-gui-v2/composables/useGlobal/actions.ts
  6. 38
      packages/nc-gui-v2/composables/useViewFilters.ts

2
packages/nc-gui-v2/components.d.ts vendored

@ -137,6 +137,7 @@ declare module '@vue/runtime-core' {
MdiFileEyeOutline: typeof import('~icons/mdi/file-eye-outline')['default'] MdiFileEyeOutline: typeof import('~icons/mdi/file-eye-outline')['default']
MdiFilePlusOutline: typeof import('~icons/mdi/file-plus-outline')['default'] MdiFilePlusOutline: typeof import('~icons/mdi/file-plus-outline')['default']
MdiFileUploadOutline: typeof import('~icons/mdi/file-upload-outline')['default'] MdiFileUploadOutline: typeof import('~icons/mdi/file-upload-outline')['default']
MdiFilterOutline: typeof import('~icons/mdi/filter-outline')['default']
MdiFlag: typeof import('~icons/mdi/flag')['default'] MdiFlag: typeof import('~icons/mdi/flag')['default']
MdiFlashOutline: typeof import('~icons/mdi/flash-outline')['default'] MdiFlashOutline: typeof import('~icons/mdi/flash-outline')['default']
MdiFolder: typeof import('~icons/mdi/folder')['default'] MdiFolder: typeof import('~icons/mdi/folder')['default']
@ -163,6 +164,7 @@ declare module '@vue/runtime-core' {
MdiNotebookCheckOutline: typeof import('~icons/mdi/notebook-check-outline')['default'] MdiNotebookCheckOutline: typeof import('~icons/mdi/notebook-check-outline')['default']
MdiNumeric: typeof import('~icons/mdi/numeric')['default'] MdiNumeric: typeof import('~icons/mdi/numeric')['default']
MdiOpenInNew: typeof import('~icons/mdi/open-in-new')['default'] MdiOpenInNew: typeof import('~icons/mdi/open-in-new')['default']
MdiPencil: typeof import('~icons/mdi/pencil')['default']
MdiPlus: typeof import('~icons/mdi/plus')['default'] MdiPlus: typeof import('~icons/mdi/plus')['default']
MdiPlusBoxOutline: typeof import('~icons/mdi/plus-box-outline')['default'] MdiPlusBoxOutline: typeof import('~icons/mdi/plus-box-outline')['default']
MdiPlusOutline: typeof import('~icons/mdi/plus-outline')['default'] MdiPlusOutline: typeof import('~icons/mdi/plus-outline')['default']

26
packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilterMenu.vue

@ -1,16 +1,17 @@
<script setup lang="ts"> <script setup lang="ts">
import { watchEffect } from '@vue/runtime-core'
import type ColumnFilter from './ColumnFilter.vue' import type ColumnFilter from './ColumnFilter.vue'
import { ActiveViewInj, IsLockedInj, IsPublicInj } from '~/context' import { ActiveViewInj, IsLockedInj, IsPublicInj, computed, inject, ref, useGlobal, useViewFilters, watchEffect } from '#imports'
import MdiFilterIcon from '~icons/mdi/filter-outline'
import MdiMenuDownIcon from '~icons/mdi/menu-down' const isLocked = inject(IsLockedInj, ref(false))
const isLocked = inject(IsLockedInj)
const activeView = inject(ActiveViewInj) const activeView = inject(ActiveViewInj)
const isPublic = inject(IsPublicInj)
const isPublic = inject(IsPublicInj, ref(false))
const { filterAutoSave } = useGlobal() const { filterAutoSave } = useGlobal()
const filterComp = ref<typeof ColumnFilter>()
// todo: avoid duplicate api call by keeping a filter store // todo: avoid duplicate api call by keeping a filter store
const { filters, loadFilters } = useViewFilters( const { filters, loadFilters } = useViewFilters(
activeView, activeView,
@ -19,17 +20,16 @@ const { filters, loadFilters } = useViewFilters(
) )
const filtersLength = ref(0) const filtersLength = ref(0)
watchEffect(async () => { watchEffect(async () => {
if (activeView?.value) { if (activeView?.value) {
await loadFilters() await loadFilters()
filtersLength.value = filters?.value?.length ?? 0
filtersLength.value = filters.value.length || 0
} }
}) })
const filterComp = ref<typeof ColumnFilter>()
const applyChanges = async () => { const applyChanges = async () => await filterComp.value?.applyChanges()
await filterComp?.value?.applyChanges()
}
</script> </script>
<template> <template>
@ -37,10 +37,10 @@ const applyChanges = async () => {
<div :class="{ 'nc-badge nc-active-btn': filtersLength }"> <div :class="{ 'nc-badge nc-active-btn': filtersLength }">
<a-button v-t="['c:filter']" class="nc-filter-menu-btn nc-toolbar-btn txt-sm" :disabled="isLocked"> <a-button v-t="['c:filter']" class="nc-filter-menu-btn nc-toolbar-btn txt-sm" :disabled="isLocked">
<div class="flex align-center gap-1"> <div class="flex align-center gap-1">
<MdiFilterIcon /> <MdiFilterOutline />
<!-- Filter --> <!-- Filter -->
<span class="text-capitalize !text-sm font-weight-medium">{{ $t('activity.filter') }}</span> <span class="text-capitalize !text-sm font-weight-medium">{{ $t('activity.filter') }}</span>
<MdiMenuDownIcon class="text-grey" /> <MdiMenuDown class="text-grey" />
</div> </div>
</a-button> </a-button>
</div> </div>

25
packages/nc-gui-v2/components/smartsheet-toolbar/FieldsMenu.vue

@ -1,14 +1,31 @@
<script setup lang="ts"> <script setup lang="ts">
import Draggable from 'vuedraggable' import Draggable from 'vuedraggable'
import { ActiveViewInj, FieldsInj, IsLockedInj, IsPublicInj, MetaInj, ReloadViewDataHookInj } from '~/context' import {
import { computed, inject, useNuxtApp, useViewColumns, watch } from '#imports' ActiveViewInj,
FieldsInj,
IsLockedInj,
IsPublicInj,
MetaInj,
ReloadViewDataHookInj,
computed,
inject,
ref,
useNuxtApp,
useViewColumns,
watch,
} from '#imports'
const meta = inject(MetaInj)! const meta = inject(MetaInj)!
const activeView = inject(ActiveViewInj)! const activeView = inject(ActiveViewInj)!
const reloadDataHook = inject(ReloadViewDataHookInj)! const reloadDataHook = inject(ReloadViewDataHookInj)!
const rootFields = inject(FieldsInj) const rootFields = inject(FieldsInj)
const isLocked = inject(IsLockedInj)
const isPublic = inject(IsPublicInj) const isLocked = inject(IsLockedInj, ref(false))
const isPublic = inject(IsPublicInj, ref(false))
const { $e } = useNuxtApp() const { $e } = useNuxtApp()

8
packages/nc-gui-v2/components/smartsheet/Cell.vue

@ -9,7 +9,9 @@ import {
IsLockedInj, IsLockedInj,
IsPublicInj, IsPublicInj,
computed, computed,
inject,
provide, provide,
ref,
toRef, toRef,
useColumn, useColumn,
useDebounceFn, useDebounceFn,
@ -42,11 +44,11 @@ provide(EditModeInj, useVModel(props, 'editEnabled', emit))
provide(ActiveCellInj, active) provide(ActiveCellInj, active)
const isForm = inject(IsFormInj) const isForm = inject(IsFormInj, ref(false))
const isPublic = inject(IsPublicInj) const isPublic = inject(IsPublicInj, ref(false))
const isLocked = inject(IsLockedInj) const isLocked = inject(IsLockedInj, ref(false))
let changed = $ref(false) let changed = $ref(false)

9
packages/nc-gui-v2/composables/useGlobal/actions.ts

@ -1,11 +1,10 @@
import { message } from 'ant-design-vue' import { message } from 'ant-design-vue'
import { Api } from 'nocodb-sdk'
import type { Actions, State } from './types' import type { Actions, State } from './types'
import { useNuxtApp } from '#imports'
export function useGlobalActions(state: State): Actions { export function useGlobalActions(state: State): Actions {
// todo replace with just `new Api()`? Would solve recursion issues /** detached api instance, will not trigger global loading */
/** we have to use the globally injected api instance, otherwise we run into recursion as `useApi` calls `useGlobal` */ const api = new Api()
const { $api } = useNuxtApp()
/** Sign out by deleting the token from localStorage */ /** Sign out by deleting the token from localStorage */
const signOut: Actions['signOut'] = () => { const signOut: Actions['signOut'] = () => {
@ -30,7 +29,7 @@ export function useGlobalActions(state: State): Actions {
/** manually try to refresh token */ /** manually try to refresh token */
const refreshToken = async () => { const refreshToken = async () => {
$api.instance api.instance
.post('/auth/refresh-token', null, { .post('/auth/refresh-token', null, {
withCredentials: true, withCredentials: true,
}) })

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

@ -1,6 +1,17 @@
import type { ViewType } from 'nocodb-sdk' import type { ViewType } from 'nocodb-sdk'
import type { ComputedRef, Ref } from 'vue' import type { ComputedRef, Ref } from 'vue'
import { IsPublicInj, ReloadViewDataHookInj, useMetas, useNuxtApp, useUIPermission } from '#imports' import {
IsPublicInj,
ReloadViewDataHookInj,
computed,
inject,
ref,
useMetas,
useNuxtApp,
useSharedView,
useUIPermission,
watch,
} from '#imports'
import type { Filter } from '~/lib' import type { Filter } from '~/lib'
export function useViewFilters( export function useViewFilters(
@ -17,12 +28,15 @@ export function useViewFilters(
const _filters = ref<Filter[]>([]) const _filters = ref<Filter[]>([])
const isPublic = inject(IsPublicInj, ref(false)) const isPublic = inject(IsPublicInj, ref(false))
const { $api } = useNuxtApp() const { $api } = useNuxtApp()
const { isUIAllowed } = useUIPermission() const { isUIAllowed } = useUIPermission()
const { metas } = useMetas() const { metas } = useMetas()
const filters = computed({ const filters = computed({
get: () => (isPublic.value ? siblingFilters || nestedFilters.value : _filters.value), get: () => (isPublic.value ? siblingFilters || nestedFilters.value : _filters.value) ?? [],
set: (value) => { set: (value) => {
if (isPublic.value) { if (isPublic.value) {
if (siblingFilters) { if (siblingFilters) {
@ -94,6 +108,7 @@ export function useViewFilters(
// if shared or sync permission not allowed simply remove it from array // if shared or sync permission not allowed simply remove it from array
if (isPublic.value || !isUIAllowed('filterSync')) { if (isPublic.value || !isUIAllowed('filterSync')) {
filters.value.splice(i, 1) filters.value.splice(i, 1)
reloadData?.() reloadData?.()
} else { } else {
if (filter.id) { if (filter.id) {
@ -103,7 +118,9 @@ export function useViewFilters(
// if auto-apply enabled invoke delete api and remove from array // if auto-apply enabled invoke delete api and remove from array
} else { } else {
await $api.dbTableFilter.delete(filter.id) await $api.dbTableFilter.delete(filter.id)
reloadData?.() reloadData?.()
filters.value.splice(i, 1) filters.value.splice(i, 1)
} }
// if not synced yet remove it from array // if not synced yet remove it from array
@ -115,11 +132,14 @@ export function useViewFilters(
const saveOrUpdate = async (filter: Filter, i: number, force = false) => { const saveOrUpdate = async (filter: Filter, i: number, force = false) => {
if (isPublic.value) { if (isPublic.value) {
filters.value[i] = { ...filter } as any filters.value[i] = { ...filter }
filters.value = [...filters.value] filters.value = [...filters.value]
return return
} }
if (!view?.value) return if (!view?.value) return
if (!isUIAllowed('filterSync')) { if (!isUIAllowed('filterSync')) {
// skip // skip
} else if (!autoApply?.value && !force) { } else if (!autoApply?.value && !force) {
@ -136,12 +156,11 @@ export function useViewFilters(
fk_parent_id: parentId, fk_parent_id: parentId,
})) as any })) as any
} }
reloadData?.() reloadData?.()
} }
const addFilter = () => { const addFilter = () => filters.value.push(placeholderFilter)
filters.value.push(placeholderFilter)
}
const addFilterGroup = async () => { const addFilterGroup = async () => {
const child = placeholderFilter const child = placeholderFilter
@ -150,10 +169,13 @@ export function useViewFilters(
status: 'create', status: 'create',
logical_op: 'and', logical_op: 'and',
} }
if (isPublic.value) placeHolderGroupFilter.children = [child] if (isPublic.value) placeHolderGroupFilter.children = [child]
filters.value.push(placeHolderGroupFilter) filters.value.push(placeHolderGroupFilter)
const index = filters.value.length - 1 const index = filters.value.length - 1
await saveOrUpdate(filters.value[index], index, true) await saveOrUpdate(filters.value[index], index, true)
} }
@ -167,9 +189,7 @@ export function useViewFilters(
return metas?.value?.[view?.value?.fk_model_id as string]?.columns?.length || 0 return metas?.value?.[view?.value?.fk_model_id as string]?.columns?.length || 0
}, },
async (nextColsLength, oldColsLength) => { async (nextColsLength, oldColsLength) => {
if (nextColsLength < oldColsLength) { if (nextColsLength < oldColsLength) await loadFilters()
await loadFilters()
}
}, },
) )

Loading…
Cancel
Save