Browse Source

Merge branch 'develop' into fix/3156-bulk

pull/3172/head
Pranav C 2 years ago committed by GitHub
parent
commit
6173662bbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      packages/nc-gui-v2/components/cell/DatePicker.vue
  2. 12
      packages/nc-gui-v2/components/cell/DateTimePicker.vue
  3. 17
      packages/nc-gui-v2/components/cell/Json.vue
  4. 10
      packages/nc-gui-v2/components/cell/MultiSelect.vue
  5. 10
      packages/nc-gui-v2/components/cell/SingleSelect.vue
  6. 9
      packages/nc-gui-v2/components/cell/TimePicker.vue
  7. 10
      packages/nc-gui-v2/components/cell/YearPicker.vue
  8. 2
      packages/nc-gui-v2/components/dashboard/GithubStarButton.vue
  9. 50
      packages/nc-gui-v2/components/shared-view/AskPassword.vue
  10. 85
      packages/nc-gui-v2/components/shared-view/Form.vue
  11. 32
      packages/nc-gui-v2/components/shared-view/Grid.vue
  12. 8
      packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilter.vue
  13. 5
      packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilterMenu.vue
  14. 2
      packages/nc-gui-v2/components/smartsheet-toolbar/FieldsMenu.vue
  15. 38
      packages/nc-gui-v2/components/smartsheet-toolbar/MoreActions.vue
  16. 19
      packages/nc-gui-v2/components/smartsheet/Form.vue
  17. 29
      packages/nc-gui-v2/components/smartsheet/Grid.vue
  18. 10
      packages/nc-gui-v2/components/smartsheet/Toolbar.vue
  19. 4
      packages/nc-gui-v2/components/smartsheet/sidebar/index.vue
  20. 2
      packages/nc-gui-v2/components/tabs/auth/user-management/UsersModal.vue
  21. 6
      packages/nc-gui-v2/components/virtual-cell/BelongsTo.vue
  22. 6
      packages/nc-gui-v2/components/virtual-cell/HasMany.vue
  23. 6
      packages/nc-gui-v2/components/virtual-cell/ManyToMany.vue
  24. 8
      packages/nc-gui-v2/components/virtual-cell/components/ItemChip.vue
  25. 30
      packages/nc-gui-v2/components/virtual-cell/components/ListChildItems.vue
  26. 8
      packages/nc-gui-v2/components/virtual-cell/components/ListItems.vue
  27. 8
      packages/nc-gui-v2/composables/useGridViewColumnWidth.ts
  28. 9
      packages/nc-gui-v2/composables/useLTARStore.ts
  29. 10
      packages/nc-gui-v2/composables/useMetas.ts
  30. 24
      packages/nc-gui-v2/composables/useProject.ts
  31. 108
      packages/nc-gui-v2/composables/useSharedView.ts
  32. 7
      packages/nc-gui-v2/composables/useSmartsheetRowStore.ts
  33. 58
      packages/nc-gui-v2/composables/useViewColumns.ts
  34. 38
      packages/nc-gui-v2/composables/useViewData.ts
  35. 73
      packages/nc-gui-v2/composables/useViewFilters.ts
  36. 47
      packages/nc-gui-v2/composables/useViewSorts.ts
  37. 3
      packages/nc-gui-v2/context/index.ts
  38. 37
      packages/nc-gui-v2/layouts/shared-view.vue
  39. 15
      packages/nc-gui-v2/lib/types.ts
  40. 45
      packages/nc-gui-v2/pages/[projectType]/[projectId]/index.vue
  41. 39
      packages/nc-gui-v2/pages/[projectType]/form/[viewId].vue
  42. 32
      packages/nc-gui-v2/pages/[projectType]/view/[viewId].vue
  43. 5
      packages/nc-gui-v2/utils/urlUtils.ts

10
packages/nc-gui-v2/components/cell/DatePicker.vue

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { ColumnInj, EditModeInj, computed, inject, ref, watch } from '#imports' import { ColumnInj, ReadonlyInj, computed, inject, ref, watch } from '#imports'
interface Props { interface Props {
modelValue?: string | null modelValue?: string | null
@ -12,7 +12,7 @@ const emit = defineEmits(['update:modelValue'])
const columnMeta = inject(ColumnInj, null)! const columnMeta = inject(ColumnInj, null)!
const editEnabled = inject(EditModeInj)! const readOnly = inject(ReadonlyInj, false)
let isDateInvalid = $ref(false) let isDateInvalid = $ref(false)
@ -55,7 +55,7 @@ watch(
{ flush: 'post' }, { flush: 'post' },
) )
const placeholder = computed(() => (isDateInvalid ? 'Invalid date' : editEnabled.value ? 'Select date' : '')) const placeholder = computed(() => (isDateInvalid ? 'Invalid date' : readOnly ? 'Select date' : ''))
</script> </script>
<template> <template>
@ -65,10 +65,10 @@ const placeholder = computed(() => (isDateInvalid ? 'Invalid date' : editEnabled
class="!w-full px-1" class="!w-full px-1"
:format="dateFormat" :format="dateFormat"
:placeholder="placeholder" :placeholder="placeholder"
:allow-clear="!editEnabled" :allow-clear="!readOnly"
:input-read-only="true" :input-read-only="true"
:dropdown-class-name="randomClass" :dropdown-class-name="randomClass"
:open="editEnabled ? false : open" :open="readOnly ? false : open"
@click="open = !open" @click="open = !open"
> >
<template #suffixIcon></template> <template #suffixIcon></template>

12
packages/nc-gui-v2/components/cell/DateTimePicker.vue

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { EditModeInj } from '~/context' import { ReadonlyInj } from '#imports'
interface Props { interface Props {
modelValue: string | null | undefined modelValue: string | null | undefined
@ -12,7 +12,7 @@ const emit = defineEmits(['update:modelValue'])
const { isMysql } = useProject() const { isMysql } = useProject()
const editEnabled = inject(EditModeInj) const readOnly = inject(ReadonlyInj, false)
let isDateInvalid = $ref(false) let isDateInvalid = $ref(false)
@ -64,12 +64,12 @@ watch(
:bordered="false" :bordered="false"
class="!w-full px-1" class="!w-full px-1"
format="YYYY-MM-DD HH:mm" format="YYYY-MM-DD HH:mm"
:placeholder="isDateInvalid ? 'Invalid date' : !editEnabled ? 'Select date and time' : ''" :placeholder="isDateInvalid ? 'Invalid date' : !readOnly ? 'Select date and time' : ''"
:allow-clear="!editEnabled" :allow-clear="!readOnly"
:input-read-only="true" :input-read-only="true"
:dropdown-class-name="randomClass" :dropdown-class-name="randomClass"
:open="editEnabled ? false : open" :open="readOnly ? false : open"
:disabled="!editEnabled" :disabled="readOnly"
@click="open = !open" @click="open = !open"
@ok="open = !open" @ok="open = !open"
> >

17
packages/nc-gui-v2/components/cell/Json.vue

@ -2,7 +2,7 @@
import { Modal as AModal } from 'ant-design-vue' import { Modal as AModal } from 'ant-design-vue'
import Editor from '~/components/monaco/Editor.vue' import Editor from '~/components/monaco/Editor.vue'
import { ReadonlyInj, computed, inject, ref, useVModel, watch } from '#imports' import { ReadonlyInj, computed, inject, ref, useVModel, watch } from '#imports'
import { EditModeInj } from '~/context' import { EditModeInj, IsFormInj } from '~/context'
interface Props { interface Props {
modelValue: string | Record<string, any> | undefined modelValue: string | Record<string, any> | undefined
@ -18,22 +18,29 @@ const emits = defineEmits<Emits>()
const editEnabled = inject(EditModeInj, ref(false)) const editEnabled = inject(EditModeInj, ref(false))
const isForm = inject(IsFormInj, ref(false))
const readonly = inject(ReadonlyInj) const readonly = inject(ReadonlyInj)
const vModel = useVModel(props, 'modelValue', emits) const vModel = useVModel(props, 'modelValue', emits)
const localValueState = ref<string | undefined>() const localValueState = ref<string | undefined>()
let error = $ref<string | undefined>()
let isExpanded = $ref(false)
const localValue = computed<string | Record<string, any> | undefined>({ const localValue = computed<string | Record<string, any> | undefined>({
get: () => localValueState.value, get: () => localValueState.value,
set: (val: undefined | string | Record<string, any>) => { set: (val: undefined | string | Record<string, any>) => {
localValueState.value = typeof val === 'object' ? JSON.stringify(val, null, 2) : val localValueState.value = typeof val === 'object' ? JSON.stringify(val, null, 2) : val
/** if form and not expanded then sync directly */
if (isForm.value && !isExpanded) {
vModel.value = val
}
}, },
}) })
let error = $ref<string | undefined>()
let isExpanded = $ref(false)
const clear = () => { const clear = () => {
error = undefined error = undefined
@ -98,7 +105,7 @@ watch(editEnabled, () => {
<CilFullscreen v-else class="h-2.5" /> <CilFullscreen v-else class="h-2.5" />
</a-button> </a-button>
<div class="flex flex-row"> <div v-if="!isForm || isExpanded" class="flex flex-row">
<a-button type="text" size="small" :onclick="clear"><div class="text-xs">Cancel</div></a-button> <a-button type="text" size="small" :onclick="clear"><div class="text-xs">Cancel</div></a-button>
<a-button type="primary" size="small" :disabled="!!error || localValue === vModel"> <a-button type="primary" size="small" :disabled="!!error || localValue === vModel">

10
packages/nc-gui-v2/components/cell/MultiSelect.vue

@ -4,7 +4,7 @@ import type { SelectOptionsType } from 'nocodb-sdk'
import { import {
ActiveCellInj, ActiveCellInj,
ColumnInj, ColumnInj,
EditModeInj, ReadonlyInj,
computed, computed,
h, h,
inject, inject,
@ -28,7 +28,7 @@ const { isMysql } = useProject()
const column = inject(ColumnInj)! const column = inject(ColumnInj)!
const editEnabled = inject(EditModeInj)! const readOnly = inject(ReadonlyInj)!
const active = inject(ActiveCellInj, ref(false)) const active = inject(ActiveCellInj, ref(false))
@ -129,12 +129,12 @@ watch(isOpen, (n, _o) => {
v-model:value="vModel" v-model:value="vModel"
mode="multiple" mode="multiple"
class="w-full" class="w-full"
placeholder="Select an option" :placeholder="!readOnly ? 'Select an option' : ''"
:bordered="false" :bordered="false"
show-arrow :show-arrow="!readOnly"
:show-search="false" :show-search="false"
:open="isOpen" :open="isOpen"
:disabled="!editEnabled" :disabled="readOnly"
@keydown="handleKeys" @keydown="handleKeys"
@click="isOpen = !isOpen" @click="isOpen = !isOpen"
> >

10
packages/nc-gui-v2/components/cell/SingleSelect.vue

@ -1,7 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { Select as AntSelect } from 'ant-design-vue' import type { Select as AntSelect } from 'ant-design-vue'
import type { SelectOptionsType } from 'nocodb-sdk' import type { SelectOptionsType } from 'nocodb-sdk'
import { ActiveCellInj, ColumnInj, EditModeInj, computed, inject, ref, useEventListener, watch } from '#imports' import { ActiveCellInj, ColumnInj, ReadonlyInj, computed, inject, ref, useEventListener, watch } from '#imports'
interface Props { interface Props {
modelValue?: string | undefined modelValue?: string | undefined
@ -13,7 +13,7 @@ const emit = defineEmits(['update:modelValue'])
const column = inject(ColumnInj)! const column = inject(ColumnInj)!
const editEnabled = inject(EditModeInj)! const readOnly = inject(ReadonlyInj)!
const active = inject(ActiveCellInj, ref(false)) const active = inject(ActiveCellInj, ref(false))
@ -69,11 +69,11 @@ watch(isOpen, (n, _o) => {
v-model:value="vModel" v-model:value="vModel"
class="w-full" class="w-full"
:allow-clear="!column.rqd && active" :allow-clear="!column.rqd && active"
placeholder="Select an option" :placeholder="!readOnly ? 'Select an option' : ''"
:bordered="false" :bordered="false"
:open="isOpen" :open="isOpen"
:disabled="!editEnabled" :disabled="readOnly"
:show-arrow="active || vModel === null" :show-arrow="!readOnly && (active || vModel === null)"
@select="isOpen = false" @select="isOpen = false"
@keydown="handleKeys" @keydown="handleKeys"
@click="isOpen = !isOpen" @click="isOpen = !isOpen"

9
packages/nc-gui-v2/components/cell/TimePicker.vue

@ -1,7 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { onClickOutside } from '@vueuse/core' import { onClickOutside } from '@vueuse/core'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { EditModeInj } from '~/context'
interface Props { interface Props {
modelValue?: string | null | undefined modelValue?: string | null | undefined
@ -13,7 +12,7 @@ const emit = defineEmits(['update:modelValue'])
const { isMysql } = useProject() const { isMysql } = useProject()
const editEnabled = inject(EditModeInj) const readOnly = inject(ReadonlyInj, false)
let isTimeInvalid = $ref(false) let isTimeInvalid = $ref(false)
@ -76,10 +75,10 @@ watch(
use12-hours use12-hours
format="HH:mm" format="HH:mm"
class="!w-full px-1" class="!w-full px-1"
:placeholder="isTimeInvalid ? 'Invalid time' : !readOnlyMode ? 'Select time' : ''" :placeholder="isTimeInvalid ? 'Invalid time' : !readOnly ? 'Select time' : ''"
:allow-clear="!editEnabled" :allow-clear="!readOnly"
:input-read-only="true" :input-read-only="true"
:open="editEnabled ? false : open" :open="readOnly ? false : open"
:popup-class-name="randomClass" :popup-class-name="randomClass"
@click="open = !open" @click="open = !open"
@ok="open = !open" @ok="open = !open"

10
packages/nc-gui-v2/components/cell/YearPicker.vue

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { EditModeInj, computed, inject, onClickOutside, ref, watch } from '#imports' import { computed, inject, onClickOutside, ref, watch } from '#imports'
interface Props { interface Props {
modelValue?: number | string | null modelValue?: number | string | null
@ -10,7 +10,7 @@ const { modelValue } = defineProps<Props>()
const emit = defineEmits(['update:modelValue']) const emit = defineEmits(['update:modelValue'])
const editEnabled = inject(EditModeInj)! const readOnly = inject(ReadonlyInj, false)
let isYearInvalid = $ref(false) let isYearInvalid = $ref(false)
@ -53,7 +53,7 @@ watch(
{ flush: 'post' }, { flush: 'post' },
) )
const placeholder = computed(() => (isYearInvalid ? 'Invalid year' : editEnabled.value ? 'Select year' : '')) const placeholder = computed(() => (isYearInvalid ? 'Invalid year' : readOnly ? 'Select year' : ''))
</script> </script>
<template> <template>
@ -63,9 +63,9 @@ const placeholder = computed(() => (isYearInvalid ? 'Invalid year' : editEnabled
:bordered="false" :bordered="false"
class="!w-full px-1" class="!w-full px-1"
:placeholder="placeholder" :placeholder="placeholder"
:allow-clear="!editEnabled" :allow-clear="!readOnly"
:input-read-only="true" :input-read-only="true"
:open="editEnabled ? false : open" :open="readOnly ? false : open"
:dropdown-class-name="randomClass" :dropdown-class-name="randomClass"
@click="open = !open" @click="open = !open"
@change="open = !open" @change="open = !open"

2
packages/nc-gui-v2/components/dashboard/GithubStarButton.vue

@ -3,7 +3,7 @@ import GithubButton from 'vue-github-button'
</script> </script>
<template> <template>
<GithubButton href="https://github.com/nocodb/nocodb" data-icon="octicon-star" :data-show-count="true" data-size="large" <GithubButton href="https://github.com/nocodb/nocodb" data-icon="octicon-star" data-show-count="true" data-size="large"
>Star</GithubButton >Star</GithubButton
> >
</template> </template>

50
packages/nc-gui-v2/components/shared-view/AskPassword.vue

@ -0,0 +1,50 @@
<script setup lang="ts">
import { message } from 'ant-design-vue'
import { extractSdkResponseErrorMsg } from '~/utils'
interface Props {
modelValue: boolean
}
const props = defineProps<Props>()
const emit = defineEmits(['update:modelValue'])
const route = useRoute()
const { loadSharedView } = useSharedView()
const formState = ref({ password: undefined })
const vModel = useVModel(props, 'modelValue', emit)
const onFinish = async () => {
try {
await loadSharedView(route.params.viewId as string, formState.value.password)
vModel.value = false
} catch (e: any) {
console.error(e)
message.error(await extractSdkResponseErrorMsg(e))
}
}
</script>
<template>
<a-modal
v-model:visible="vModel"
:closable="false"
width="28rem"
centered
:footer="null"
:mask-closable="false"
@close="vModel = false"
>
<div class="w-full flex flex-col">
<a-typography-title :level="4">This shared view is protected</a-typography-title>
<a-form ref="formRef" :model="formState" class="mt-2" @finish="onFinish">
<a-form-item name="password" :rules="[{ required: true, message: 'Password is required' }]">
<a-input-password v-model:value="formState.password" placeholder="Enter password" />
</a-form-item>
<a-button type="primary" html-type="submit">Unlock</a-button>
</a-form>
</div>
</a-modal>
</template>
<style scoped lang="scss"></style>

85
packages/nc-gui-v2/components/shared-view/Form.vue

@ -0,0 +1,85 @@
<script setup lang="ts">
import { RelationTypes, UITypes, isVirtualCol } from 'nocodb-sdk'
import { FieldsInj, MetaInj } from '#imports'
const fields = inject(FieldsInj, ref([]))
const meta = inject(MetaInj)
const { sharedView } = useSharedView()
const formState = ref(fields.value.reduce((a, v) => ({ ...a, [v.title]: undefined }), {}))
function isRequired(_columnObj: Record<string, any>, required = false) {
let columnObj = _columnObj
if (
columnObj.uidt === UITypes.LinkToAnotherRecord &&
columnObj.colOptions &&
columnObj.colOptions.type === RelationTypes.BELONGS_TO
) {
columnObj = fields.value.find((c: Record<string, any>) => c.id === columnObj.colOptions.fk_child_column_id) as Record<
string,
any
>
}
return required || (columnObj && columnObj.rqd && !columnObj.cdf)
}
useSmartsheetStoreOrThrow()
useProvideSmartsheetRowStore(meta, formState)
const formRef = ref()
</script>
<template>
<div class="flex flex-col my-4 space-y-2 mx-32 items-center">
<div class="flex w-2/3 flex-col mt-10">
<div class="flex flex-col items-start px-14 py-8 bg-gray-50 rounded-md w-full">
<a-typography-title class="border-b-1 border-gray-100 w-full pb-3" :level="1">
{{ sharedView.view.heading }}
</a-typography-title>
<a-typography class="pl-1 text-sm">{{ sharedView.view.subheading }}</a-typography>
</div>
<a-form ref="formRef" :model="formState" class="mt-8 pb-12 mb-8 px-3 bg-gray-50 rounded-md">
<div v-for="(field, index) in fields" :key="index" class="flex flex-col mt-4 px-10 pt-6 space-y-2">
<div class="flex">
<SmartsheetHeaderVirtualCell
v-if="isVirtualCol(field)"
:column="{ ...field, title: field.label || field.title }"
:required="isRequired(field, field.required)"
:hide-menu="true"
/>
<SmartsheetHeaderCell
v-else
:column="{ ...field, title: field.label || field.title }"
:required="isRequired(field, field.required)"
:hide-menu="true"
/>
</div>
<a-form-item
v-if="isVirtualCol(field)"
class="ma-0 gap-0 pa-0"
:name="field.title"
:rules="[{ required: field.required, message: `${field.title} is required` }]"
>
<SmartsheetVirtualCell v-model="formState[field.title]" class="nc-input" :column="field" />
</a-form-item>
<a-form-item
v-else
class="ma-0 gap-0 pa-0"
:name="field.title"
:rules="[{ required: field.required, message: `${field.title} is required` }]"
>
<SmartsheetCell v-model="formState[field.title]" class="nc-input" :column="field" :edit-enabled="true" />
</a-form-item>
</div>
</a-form>
</div>
</div>
</template>
<style scoped lang="scss">
.nc-input {
@apply w-full !bg-white rounded px-2 py-2 min-h-[40px] mt-2 mb-2 flex align-center border-solid border-1 border-primary;
}
</style>

32
packages/nc-gui-v2/components/shared-view/Grid.vue

@ -0,0 +1,32 @@
<script setup lang="ts">
import type { Ref } from 'vue'
import type { TableType } from 'nocodb-sdk'
import { ActiveViewInj, FieldsInj, IsPublicInj, MetaInj, ReadonlyInj, ReloadViewDataHookInj } from '~/context'
const { sharedView, meta, columns } = useSharedView()
const reloadEventHook = createEventHook<void>()
provide(ReloadViewDataHookInj, reloadEventHook)
provide(ReadonlyInj, ref(true))
provide(MetaInj, meta)
provide(ActiveViewInj, sharedView)
provide(FieldsInj, columns)
provide(IsPublicInj, ref(true))
useProvideSmartsheetStore(sharedView as Ref<TableType>, meta)
</script>
<template>
<div class="nc-container flex flex-col h-full mt-4 px-6">
<SmartsheetToolbar />
<SmartsheetGrid class="px-3" />
</div>
</template>
<style scoped>
.nc-container {
height: calc(100% - var(--header-height));
flex: 1 1 100%;
}
</style>

8
packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilter.vue

@ -8,13 +8,15 @@ import { comparisonOpList } from '~/utils/filterUtils'
import { ActiveViewInj, MetaInj, ReloadViewDataHookInj } from '~/context' import { ActiveViewInj, MetaInj, ReloadViewDataHookInj } from '~/context'
import MdiDeleteIcon from '~icons/mdi/close-box' import MdiDeleteIcon from '~icons/mdi/close-box'
import MdiAddIcon from '~icons/mdi/plus' import MdiAddIcon from '~icons/mdi/plus'
import type { Filter } from '~/lib/types'
const { const {
nested = false, nested = false,
parentId, parentId,
autoSave = true, autoSave = true,
hookId = null, hookId = null,
} = defineProps<{ nested?: boolean; parentId?: string; autoSave: boolean; hookId?: string }>() modelValue,
} = defineProps<{ nested?: boolean; parentId?: string; autoSave: boolean; hookId?: string; modelValue?: Filter[] }>()
const emit = defineEmits(['update:filtersLength']) const emit = defineEmits(['update:filtersLength'])
@ -25,7 +27,6 @@ const activeView = inject(ActiveViewInj)
const reloadDataHook = inject(ReloadViewDataHookInj) const reloadDataHook = inject(ReloadViewDataHookInj)
// todo: replace with inject or get from state // todo: replace with inject or get from state
const shared = ref(false)
const { $e } = useNuxtApp() const { $e } = useNuxtApp()
@ -36,6 +37,7 @@ const { filters, deleteFilter, saveOrUpdate, loadFilters, addFilter, addFilterGr
() => { () => {
reloadDataHook?.trigger() reloadDataHook?.trigger()
}, },
modelValue,
) )
const filterUpdateCondition = (filter: FilterType, i: number) => { const filterUpdateCondition = (filter: FilterType, i: number) => {
@ -152,7 +154,7 @@ defineExpose({
<span class="col-span-3" /> <span class="col-span-3" />
<div class="col-span-5"> <div class="col-span-5">
<SmartsheetToolbarColumnFilter <SmartsheetToolbarColumnFilter
v-if="filter.id || shared" v-if="filter.id || filter.children"
ref="nestedFilters" ref="nestedFilters"
v-model="filter.children" v-model="filter.children"
:parent-id="filter.id" :parent-id="filter.id"

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

@ -1,12 +1,13 @@
<script setup lang="ts"> <script setup lang="ts">
import { watchEffect } from '@vue/runtime-core' import { watchEffect } from '@vue/runtime-core'
import type ColumnFilter from './ColumnFilter.vue' import type ColumnFilter from './ColumnFilter.vue'
import { ActiveViewInj, IsLockedInj } from '~/context' import { ActiveViewInj, IsLockedInj, IsPublicInj } from '~/context'
import MdiFilterIcon from '~icons/mdi/filter-outline' import MdiFilterIcon from '~icons/mdi/filter-outline'
import MdiMenuDownIcon from '~icons/mdi/menu-down' import MdiMenuDownIcon from '~icons/mdi/menu-down'
const isLocked = inject(IsLockedInj) const isLocked = inject(IsLockedInj)
const activeView = inject(ActiveViewInj) const activeView = inject(ActiveViewInj)
const isPublic = inject(IsPublicInj)
const { filterAutoSave } = useGlobal() const { filterAutoSave } = useGlobal()
@ -50,7 +51,7 @@ const applyChanges = async () => {
:auto-save="filterAutoSave" :auto-save="filterAutoSave"
@update:filters-length="filtersLength = $event" @update:filters-length="filtersLength = $event"
> >
<div class="d-flex align-end mt-2 min-h-[30px]" @click.stop> <div v-if="!isPublic" class="d-flex align-end mt-2 min-h-[30px]" @click.stop>
<a-checkbox id="col-filter-checkbox" v-model:checked="filterAutoSave" class="col-filter-checkbox" hide-details dense> <a-checkbox id="col-filter-checkbox" v-model:checked="filterAutoSave" class="col-filter-checkbox" hide-details dense>
<span class="text-grey text-xs"> <span class="text-grey text-xs">
{{ $t('msg.info.filterAutoApply') }} {{ $t('msg.info.filterAutoApply') }}

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

@ -21,7 +21,7 @@ const {
showAll, showAll,
hideAll, hideAll,
saveOrUpdate, saveOrUpdate,
} = useViewColumns(activeView, meta, false, () => reloadDataHook.trigger()) } = useViewColumns(activeView, meta, () => reloadDataHook.trigger())
watch( watch(
() => (activeView.value as any)?.id, () => (activeView.value as any)?.id,

38
packages/nc-gui-v2/components/smartsheet-toolbar/MoreActions.vue

@ -6,6 +6,8 @@ import FileSaver from 'file-saver'
import { message } from 'ant-design-vue' import { message } from 'ant-design-vue'
import { import {
ActiveViewInj, ActiveViewInj,
FieldsInj,
IsPublicInj,
MetaInj, MetaInj,
extractSdkResponseErrorMsg, extractSdkResponseErrorMsg,
inject, inject,
@ -22,7 +24,7 @@ enum ExportTypes {
const sharedViewListDlg = ref(false) const sharedViewListDlg = ref(false)
const publicViewId = null const isPublicView = inject(IsPublicInj, ref(false))
const isView = false const isView = false
@ -33,7 +35,7 @@ const { project } = useProject()
const { $api } = useNuxtApp() const { $api } = useNuxtApp()
const meta = inject(MetaInj) const meta = inject(MetaInj)
const fields = inject(FieldsInj, ref([]))
const selectedView = inject(ActiveViewInj) const selectedView = inject(ActiveViewInj)
const showWebhookDrawer = ref(false) const showWebhookDrawer = ref(false)
@ -46,31 +48,13 @@ const exportFile = async (exportType: ExportTypes) => {
let offset = 0 let offset = 0
let c = 1 let c = 1
const responseType = exportType === ExportTypes.EXCEL ? 'base64' : 'blob' const responseType = exportType === ExportTypes.EXCEL ? 'base64' : 'blob'
try { try {
while (!isNaN(offset) && offset > -1) { while (!isNaN(offset) && offset > -1) {
let res let res
if (publicViewId) { if (isPublicView.value) {
// TODO: pending for shared view const { exportFile: sharedViewExportFile } = useSharedView()
// const { data, headers } = await $api.public.csvExport(publicViewId, exportType, { res = await sharedViewExportFile(fields.value, offset, exportType, responseType)
// format: responseType,
// query: {
// fields:
// queryParams && queryParams.fieldsOrder && queryParams.fieldsOrder.filter((c: number) => queryParams.showFields[c]),
// offset,
// sortArrJson: JSON.stringify(
// reqPayload &&
// reqPayload.sorts &&
// reqPayload.sorts.map(({ fk_column_id, direction }) => ({
// direction,
// fk_column_id,
// })),
// ),
// filterArrJson: JSON.stringify(reqPayload && reqPayload.filters),
// },
// headers: {
// 'xc-password': reqPayload && reqPayload.password,
// },
// } as Record<string, any>)
} else { } else {
res = await $api.dbViewRow.export( res = await $api.dbViewRow.export(
'noco', 'noco',
@ -137,7 +121,7 @@ const exportFile = async (exportType: ExportTypes) => {
</div> </div>
<div <div
v-if="isUIAllowed('csvImport') && !isView" v-if="isUIAllowed('csvImport') && !isView && !isPublicView"
v-t="['a:actions:upload-csv']" v-t="['a:actions:upload-csv']"
class="nc-menu-item" class="nc-menu-item"
@click="quickImportDialog = true" @click="quickImportDialog = true"
@ -148,7 +132,7 @@ const exportFile = async (exportType: ExportTypes) => {
</div> </div>
<div <div
v-if="isUIAllowed('SharedViewList') && !isView" v-if="isUIAllowed('SharedViewList') && !isView && !isPublicView"
v-t="['a:actions:shared-view-list']" v-t="['a:actions:shared-view-list']"
class="nc-menu-item" class="nc-menu-item"
@click="sharedViewListDlg = true" @click="sharedViewListDlg = true"
@ -159,7 +143,7 @@ const exportFile = async (exportType: ExportTypes) => {
</div> </div>
<div <div
v-if="isUIAllowed('webhook') && !isView" v-if="isUIAllowed('webhook') && !isView && !isPublicView"
v-t="['c:actions:webhook']" v-t="['c:actions:webhook']"
class="nc-menu-item" class="nc-menu-item"
@click="showWebhookDrawer = true" @click="showWebhookDrawer = true"

19
packages/nc-gui-v2/components/smartsheet/Form.vue

@ -42,7 +42,7 @@ const secondsRemain = ref(0)
const isEditable = isUIAllowed('editFormView' as Permission) const isEditable = isUIAllowed('editFormView' as Permission)
const meta = inject(MetaInj) const meta = inject(MetaInj)!
const view = inject(ActiveViewInj) const view = inject(ActiveViewInj)
@ -53,6 +53,15 @@ const { showAll, hideAll, saveOrUpdate } = useViewColumns(view, meta as any, fal
setFormData() setFormData()
}) })
const { syncLTARRefs } = useProvideSmartsheetRowStore(
meta,
ref({
row: formState,
oldRow: {},
rowMeta: { new: true },
}),
)
const columns = computed(() => meta?.value?.columns || []) const columns = computed(() => meta?.value?.columns || [])
const localColumns = ref<Record<string, any>[]>([]) const localColumns = ref<Record<string, any>[]>([])
@ -92,7 +101,11 @@ async function submitForm() {
return return
} }
await insertRow(formState) const insertedRowData = await insertRow(formState)
if (insertedRowData) {
await syncLTARRefs(insertedRowData)
}
submitted.value = true submitted.value = true
} }
@ -527,6 +540,7 @@ onMounted(async () => {
class="nc-input" class="nc-input"
:class="`nc-form-input-${element.title.replaceAll(' ', '')}`" :class="`nc-form-input-${element.title.replaceAll(' ', '')}`"
:column="element" :column="element"
@click.stop.prevent
/> />
</a-form-item> </a-form-item>
@ -542,6 +556,7 @@ onMounted(async () => {
:class="`nc-form-input-${element.title.replaceAll(' ', '')}`" :class="`nc-form-input-${element.title.replaceAll(' ', '')}`"
:column="element" :column="element"
:edit-enabled="true" :edit-enabled="true"
@click.stop.prevent
/> />
</a-form-item> </a-form-item>

29
packages/nc-gui-v2/components/smartsheet/Grid.vue

@ -23,8 +23,10 @@ import {
IsFormInj, IsFormInj,
IsGridInj, IsGridInj,
IsLockedInj, IsLockedInj,
IsPublicInj,
MetaInj, MetaInj,
PaginationDataInj, PaginationDataInj,
ReadonlyInj,
ReloadViewDataHookInj, ReloadViewDataHookInj,
} from '~/context' } from '~/context'
import { NavigateDir } from '~/lib' import { NavigateDir } from '~/lib'
@ -34,10 +36,12 @@ const meta = inject(MetaInj)
const view = inject(ActiveViewInj) const view = inject(ActiveViewInj)
const isPublicView = inject(IsPublicInj, ref(false))
// keep a root fields variable and will get modified from // keep a root fields variable and will get modified from
// fields menu and get used in grid and gallery // fields menu and get used in grid and gallery
const fields = inject(FieldsInj, ref([])) const fields = inject(FieldsInj, ref([]))
const readonly = inject(ReadonlyInj, ref(false))
const isLocked = inject(IsLockedInj, false) const isLocked = inject(IsLockedInj, false)
const reloadViewDataHook = inject(ReloadViewDataHookInj) const reloadViewDataHook = inject(ReloadViewDataHookInj)
@ -45,8 +49,6 @@ const reloadViewDataHook = inject(ReloadViewDataHookInj)
const { isUIAllowed } = useUIPermission() const { isUIAllowed } = useUIPermission()
// todo: get from parent ( inject or use prop ) // todo: get from parent ( inject or use prop )
const isPublicView = false
const isView = false const isView = false
const selected = reactive<{ row: number | null; col: number | null }>({ row: null, col: null }) const selected = reactive<{ row: number | null; col: number | null }>({ row: null, col: null })
@ -80,7 +82,6 @@ const {
} = useViewData(meta, view as any, xWhere) } = useViewData(meta, view as any, xWhere)
const { loadGridViewColumns, updateWidth, resizingColWidth, resizingCol } = useGridViewColumnWidth(view as any) const { loadGridViewColumns, updateWidth, resizingColWidth, resizingCol } = useGridViewColumnWidth(view as any)
onMounted(loadGridViewColumns) onMounted(loadGridViewColumns)
provide(IsFormInj, ref(false)) provide(IsFormInj, ref(false))
@ -149,7 +150,7 @@ const clearCell = async (ctx: { row: number; col: number }) => {
const { copy } = useClipboard() const { copy } = useClipboard()
const makeEditable = (row: Row, col: ColumnType) => { const makeEditable = (row: Row, col: ColumnType) => {
if (isPublicView || editEnabled || isView) { if (isPublicView.value || editEnabled || isView) {
return return
} }
if (!isPkAvail.value && !row.rowMeta.new) { if (!isPkAvail.value && !row.rowMeta.new) {
@ -323,14 +324,14 @@ const expandForm = (row: Row, state: Record<string, any>) => {
@xcresized="resizingCol = null" @xcresized="resizingCol = null"
> >
<div class="w-full h-full bg-gray-100 flex items-center"> <div class="w-full h-full bg-gray-100 flex items-center">
<SmartsheetHeaderVirtualCell v-if="isVirtualCol(col)" :column="col" /> <SmartsheetHeaderVirtualCell v-if="isVirtualCol(col)" :column="col" :hide-menu="readonly" />
<SmartsheetHeaderCell v-else :column="col" /> <SmartsheetHeaderCell v-else :column="col" :hide-menu="readonly" />
</div> </div>
</th> </th>
<!-- v-if="!isLocked && !isVirtual && !isPublicView && _isUIAllowed('add-column')" --> <!-- v-if="!isLocked && !isVirtual && !isPublicView && _isUIAllowed('add-column')" -->
<th <th
v-if="isUIAllowed('add-column')" v-if="!readonly && isUIAllowed('add-column')"
v-t="['c:column:add']" v-t="['c:column:add']"
class="cursor-pointer" class="cursor-pointer"
@click.stop="addColumnDropdown = true" @click.stop="addColumnDropdown = true"
@ -359,17 +360,18 @@ const expandForm = (row: Row, state: Record<string, any>) => {
<tr class="nc-grid-row"> <tr class="nc-grid-row">
<td key="row-index" class="caption nc-grid-cell pl-5 pr-1"> <td key="row-index" class="caption nc-grid-cell pl-5 pr-1">
<div class="align-center flex gap-1 min-w-[55px]"> <div class="align-center flex gap-1 min-w-[55px]">
<div class="nc-row-no text-xs text-gray-500" :class="{ hidden: row.rowMeta.selected }"> <div v-if="!readonly" class="nc-row-no text-xs text-gray-500" :class="{ hidden: row.rowMeta.selected }">
{{ rowIndex + 1 }} {{ rowIndex + 1 }}
</div> </div>
<div <div
v-if="!readonly"
:class="{ hidden: !row.rowMeta.selected, flex: row.rowMeta.selected }" :class="{ hidden: !row.rowMeta.selected, flex: row.rowMeta.selected }"
class="nc-row-expand-and-checkbox" class="nc-row-expand-and-checkbox"
> >
<a-checkbox v-model:checked="row.rowMeta.selected" /> <a-checkbox v-model:checked="row.rowMeta.selected" />
</div> </div>
<span class="flex-1" /> <span class="flex-1" />
<div class="nc-expand" :class="{ 'nc-comment': row.rowMeta?.commentCount }"> <div v-if="!readonly" class="nc-expand" :class="{ 'nc-comment': row.rowMeta?.commentCount }">
<span <span
v-if="row.rowMeta?.commentCount" v-if="row.rowMeta?.commentCount"
class="py-1 px-3 rounded-full text-xs cursor-pointer select-none transform hover:(scale-110)" class="py-1 px-3 rounded-full text-xs cursor-pointer select-none transform hover:(scale-110)"
@ -416,7 +418,12 @@ const expandForm = (row: Row, state: Record<string, any>) => {
v-else v-else
v-model="row.row[columnObj.title]" v-model="row.row[columnObj.title]"
:column="columnObj" :column="columnObj"
:edit-enabled="editEnabled && selected.col === colIndex && selected.row === rowIndex" :edit-enabled="
isUIAllowed('xcDatatableEditable') &&
editEnabled &&
selected.col === colIndex &&
selected.row === rowIndex
"
:row-index="rowIndex" :row-index="rowIndex"
:active="selected.col === colIndex && selected.row === rowIndex" :active="selected.col === colIndex && selected.row === rowIndex"
@update:edit-enabled="editEnabled = false" @update:edit-enabled="editEnabled = false"

10
packages/nc-gui-v2/components/smartsheet/Toolbar.vue

@ -1,7 +1,9 @@
<script setup lang="ts"> <script setup lang="ts">
import { useSmartsheetStoreOrThrow } from '~/composables' import { IsPublicInj, useSmartsheetStoreOrThrow } from '#imports'
const { isGrid, isForm, isGallery } = useSmartsheetStoreOrThrow() const { isGrid, isForm, isGallery } = useSmartsheetStoreOrThrow()
const { allowCSVDownload } = useSharedView()
const isPublic = inject(IsPublicInj, ref(false))
</script> </script>
<template> <template>
@ -12,11 +14,11 @@ const { isGrid, isForm, isGallery } = useSmartsheetStoreOrThrow()
<SmartsheetToolbarSortListMenu v-if="isGrid || isGallery" /> <SmartsheetToolbarSortListMenu v-if="isGrid || isGallery" />
<SmartsheetToolbarShareView v-if="isForm || isGrid" /> <SmartsheetToolbarShareView v-if="(isForm || isGrid) && !isPublic" />
<SmartsheetToolbarMoreActions v-if="isGrid" /> <SmartsheetToolbarMoreActions v-if="(isGrid && !isPublic) || (isGrid && isPublic && allowCSVDownload)" />
<div class="flex-1" /> <div class="flex-1" />
<SmartsheetToolbarSearchData v-if="isGrid || isGallery" class="shrink mr-2" /> <SmartsheetToolbarSearchData v-if="(isGrid || isGallery) && !isPublic" class="shrink mr-2" />
</div> </div>
</template> </template>

4
packages/nc-gui-v2/components/smartsheet/sidebar/index.vue

@ -97,13 +97,13 @@ function onCreate(view: GridType | FormType | KanbanType | GalleryType) {
> >
<MaterialSymbolsChevronRightRounded <MaterialSymbolsChevronRightRounded
v-if="sidebarOpen" v-if="sidebarOpen"
class="transform group-hover:(scale-115 text-pink-500) text-xl text-gray-400" class="transform group-hover:(scale-115 text-pink-500) text-xl text-gray-400 nc-right-sidebar-toggle"
@click="sidebarOpen = false" @click="sidebarOpen = false"
/> />
<MaterialSymbolsChevronLeftRounded <MaterialSymbolsChevronLeftRounded
v-else v-else
class="transform group-hover:(scale-115 text-pink-500) text-xl text-gray-400" class="transform group-hover:(scale-115 text-pink-500) text-xl text-gray-400 nc-right-sidebar-toggle"
@click="sidebarOpen = true" @click="sidebarOpen = true"
/> />
</div> </div>

2
packages/nc-gui-v2/components/tabs/auth/user-management/UsersModal.vue

@ -85,7 +85,6 @@ const saveUser = async () => {
project_id: project.value.id, project_id: project.value.id,
projectName: project.value.title, projectName: project.value.title,
}) })
emit('reload')
emit('closed') emit('closed')
} else { } else {
const res = await $api.auth.projectUserAdd(project.value.id, { const res = await $api.auth.projectUserAdd(project.value.id, {
@ -96,6 +95,7 @@ const saveUser = async () => {
}) })
usersData.invitationToken = res.invite_token usersData.invitationToken = res.invite_token
} }
emit('reload')
message.success('Successfully updated the user details') message.success('Successfully updated the user details')
} catch (e: any) { } catch (e: any) {
console.error(e) console.error(e)

6
packages/nc-gui-v2/components/virtual-cell/BelongsTo.vue

@ -5,7 +5,7 @@ import {
ActiveCellInj, ActiveCellInj,
CellValueInj, CellValueInj,
ColumnInj, ColumnInj,
EditModeInj, ReadonlyInj,
ReloadViewDataHookInj, ReloadViewDataHookInj,
RowInj, RowInj,
defineAsyncComponent, defineAsyncComponent,
@ -31,7 +31,7 @@ const row = inject(RowInj)!
const active = inject(ActiveCellInj)! const active = inject(ActiveCellInj)!
const editEnabled = inject(EditModeInj) const readonly = inject(ReadonlyInj, false)
const listItemsDlg = ref(false) const listItemsDlg = ref(false)
@ -72,7 +72,7 @@ const unlinkRef = async (rec: Record<string, any>) => {
<ItemChip :item="value" :value="value[relatedTablePrimaryValueProp]" @unlink="unlinkRef(value)" /> <ItemChip :item="value" :value="value[relatedTablePrimaryValueProp]" @unlink="unlinkRef(value)" />
</template> </template>
</div> </div>
<div v-if="editEnabled" class="flex-1 flex justify-end gap-1 min-h-[30px] align-center"> <div v-if="!readonly" class="flex-1 flex justify-end gap-1 min-h-[30px] align-center">
<component <component
:is="addIcon" :is="addIcon"
class="text-sm nc-action-icon text-gray-500/50 hover:text-gray-500 select-none group-hover:(text-gray-500)" class="text-sm nc-action-icon text-gray-500/50 hover:text-gray-500 select-none group-hover:(text-gray-500)"

6
packages/nc-gui-v2/components/virtual-cell/HasMany.vue

@ -4,8 +4,8 @@ import type { Ref } from 'vue'
import { import {
CellValueInj, CellValueInj,
ColumnInj, ColumnInj,
EditModeInj,
IsFormInj, IsFormInj,
ReadonlyInj,
ReloadViewDataHookInj, ReloadViewDataHookInj,
RowInj, RowInj,
computed, computed,
@ -32,7 +32,7 @@ const reloadTrigger = inject(ReloadViewDataHookInj)!
const isForm = inject(IsFormInj) const isForm = inject(IsFormInj)
const editEnabled = inject(EditModeInj) const readonly = inject(ReadonlyInj, false)
const listItemsDlg = ref(false) const listItemsDlg = ref(false)
@ -94,7 +94,7 @@ const unlinkRef = async (rec: Record<string, any>) => {
@click="childListDlg = true" @click="childListDlg = true"
/> />
<MdiPlus <MdiPlus
v-if="editEnabled" v-if="!readonly"
class="select-none text-sm nc-action-icon text-gray-500/50 hover:text-gray-500" class="select-none text-sm nc-action-icon text-gray-500/50 hover:text-gray-500"
@click="listItemsDlg = true" @click="listItemsDlg = true"
/> />

6
packages/nc-gui-v2/components/virtual-cell/ManyToMany.vue

@ -4,8 +4,8 @@ import type { Ref } from 'vue'
import { import {
CellValueInj, CellValueInj,
ColumnInj, ColumnInj,
EditModeInj,
IsFormInj, IsFormInj,
ReadonlyInj,
ReloadViewDataHookInj, ReloadViewDataHookInj,
RowInj, RowInj,
computed, computed,
@ -31,7 +31,7 @@ const reloadTrigger = inject(ReloadViewDataHookInj)!
const isForm = inject(IsFormInj) const isForm = inject(IsFormInj)
const editEnabled = inject(EditModeInj) const readonly = inject(ReadonlyInj, false)
const listItemsDlg = ref(false) const listItemsDlg = ref(false)
@ -92,7 +92,7 @@ const unlinkRef = async (rec: Record<string, any>) => {
<MdiArrowExpand class="text-sm nc-action-icon text-gray-500/50 hover:text-gray-500" @click="childListDlg = true" /> <MdiArrowExpand class="text-sm nc-action-icon text-gray-500/50 hover:text-gray-500" @click="childListDlg = true" />
<MdiPlus <MdiPlus
v-if="editEnabled" v-if="!readonly"
class="text-sm nc-action-icon text-gray-500/50 hover:text-gray-500" class="text-sm nc-action-icon text-gray-500/50 hover:text-gray-500"
@click="listItemsDlg = true" @click="listItemsDlg = true"
/> />

8
packages/nc-gui-v2/components/virtual-cell/components/ItemChip.vue

@ -1,5 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import { ActiveCellInj, EditModeInj, IsFormInj, defineAsyncComponent, inject, ref, useLTARStoreOrThrow } from '#imports' import { ActiveCellInj, IsFormInj, ReadonlyInj, defineAsyncComponent, inject, ref, useLTARStoreOrThrow } from '#imports'
interface Props { interface Props {
value?: string | number | boolean value?: string | number | boolean
@ -14,7 +14,7 @@ const ExpandedForm: any = defineAsyncComponent(() => import('../../smartsheet/ex
const { relatedTableMeta } = useLTARStoreOrThrow()! const { relatedTableMeta } = useLTARStoreOrThrow()!
const editEnabled = inject(EditModeInj)! const readonly = inject(ReadonlyInj, false)
const active = inject(ActiveCellInj, ref(false)) const active = inject(ActiveCellInj, ref(false))
@ -37,13 +37,13 @@ export default {
> >
<span class="name">{{ value }}</span> <span class="name">{{ value }}</span>
<div v-show="active || isForm" v-if="editEnabled" class="flex align-center"> <div v-show="active || isForm" v-if="!readonly" class="flex align-center">
<MdiCloseThick class="unlink-icon text-xs text-gray-500/50 group-hover:text-gray-500" @click.stop="emit('unlink')" /> <MdiCloseThick class="unlink-icon text-xs text-gray-500/50 group-hover:text-gray-500" @click.stop="emit('unlink')" />
</div> </div>
<Suspense> <Suspense>
<ExpandedForm <ExpandedForm
v-if="editEnabled" v-if="!readonly"
v-model="expandedFormDlg" v-model="expandedFormDlg"
:row="{ row: item }" :row="{ row: item }"
:meta="relatedTableMeta" :meta="relatedTableMeta"

30
packages/nc-gui-v2/components/virtual-cell/components/ListChildItems.vue

@ -3,8 +3,8 @@ import { Empty, Modal } from 'ant-design-vue'
import type { ColumnType } from 'nocodb-sdk' import type { ColumnType } from 'nocodb-sdk'
import { import {
ColumnInj, ColumnInj,
EditModeInj,
IsFormInj, IsFormInj,
ReadonlyInj,
computed, computed,
useLTARStoreOrThrow, useLTARStoreOrThrow,
useSmartsheetRowStoreOrThrow, useSmartsheetRowStoreOrThrow,
@ -24,7 +24,7 @@ const isForm = inject(IsFormInj, ref(false))
const column = inject(ColumnInj) const column = inject(ColumnInj)
const editEnabled = inject(EditModeInj) const readonly = inject(ReadonlyInj, false)
const { const {
childrenList, childrenList,
@ -43,7 +43,7 @@ const { isNew, state, removeLTARRef } = useSmartsheetRowStoreOrThrow()
watch( watch(
[vModel, isForm], [vModel, isForm],
(nextVal) => { (nextVal) => {
if (nextVal[0] || nextVal[1]) { if ((nextVal[0] || nextVal[1]) && !isNew.value) {
loadChildrenList() loadChildrenList()
} }
}, },
@ -59,6 +59,12 @@ const unlinkRow = async (row: Record<string, any>) => {
} }
} }
const unlinkIfNewRow = async (row: Record<string, any>) => {
if (isNew.value) {
removeLTARRef(row, column?.value as ColumnType)
}
}
const container = computed(() => const container = computed(() =>
isForm?.value isForm?.value
? h('div', { ? h('div', {
@ -79,7 +85,7 @@ const expandedFormRow = ref()
<MdiReload v-if="!isForm" class="cursor-pointer text-gray-500" @click="loadChildrenList" /> <MdiReload v-if="!isForm" class="cursor-pointer text-gray-500" @click="loadChildrenList" />
<a-button v-if="editEnabled" type="primary" ghost class="!text-xs" size="small" @click="emit('attachRecord')"> <a-button v-if="!readonly" type="primary" ghost class="!text-xs" size="small" @click="emit('attachRecord')">
<div class="flex align-center gap-1"> <div class="flex align-center gap-1">
<MdiLinkVariantRemove class="text-xs" type="primary" @click="unlinkRow(row)" /> <MdiLinkVariantRemove class="text-xs" type="primary" @click="unlinkRow(row)" />
Link to '{{ meta.title }}' Link to '{{ meta.title }}'
@ -101,18 +107,19 @@ const expandedFormRow = ref()
> >
<div class="flex align-center"> <div class="flex align-center">
<div class="flex-grow overflow-hidden min-w-0"> <div class="flex-grow overflow-hidden min-w-0">
{{ row[relatedTablePrimaryValueProp] {{ row[relatedTablePrimaryValueProp] }}
}}<span class="text-gray-400 text-[11px] ml-1">(Primary key : {{ getRelatedTableRowId(row) }})</span> <span class="text-gray-400 text-[11px] ml-1">(Primary key : {{ getRelatedTableRowId(row) }})</span>
</div> </div>
<div class="flex-1"></div> <div class="flex-1"></div>
<div v-if="editEnabled" class="flex gap-2"> <div v-if="!readonly" class="flex gap-2">
<MdiLinkVariantRemove <MdiLinkVariantRemove
class="text-xs text-grey hover:(!text-red-500) cursor-pointer" class="text-xs text-grey hover:(!text-red-500) cursor-pointer"
@click.stop="unlinkRow(row)" @click.stop="unlinkRow(row)"
/> />
<MdiDeleteOutline <MdiDeleteOutline
v-if="!readonly"
class="text-xs text-grey hover:(!text-red-500) cursor-pointer" class="text-xs text-grey hover:(!text-red-500) cursor-pointer"
@click.stop="deleteRelatedRow(row)" @click.stop="deleteRelatedRow(row, unlinkIfNewRow)"
/> />
</div> </div>
</div> </div>
@ -128,7 +135,12 @@ const expandedFormRow = ref()
show-less-items show-less-items
/> />
</template> </template>
<a-empty v-else class="my-10" :image="Empty.PRESENTED_IMAGE_SIMPLE" /> <a-empty
v-else
:class="{ 'my-10': !isForm, 'my-1 !text-xs': isForm }"
:image="Empty.PRESENTED_IMAGE_SIMPLE"
:image-style="isForm ? { height: '20px' } : {}"
/>
</div> </div>
<Suspense> <Suspense>

8
packages/nc-gui-v2/components/virtual-cell/components/ListItems.vue

@ -47,8 +47,12 @@ const linkRow = async (row: Record<string, any>) => {
vModel.value = false vModel.value = false
} }
watch(vModel, () => { /** reload list on modal open */
if (vModel.value) { watch(vModel, (nextVal, prevVal) => {
if (nextVal && !prevVal) {
/** reset query and limit */
childrenExcludedListPagination.query = ''
childrenExcludedListPagination.page = 1
loadChildrenExcludedList() loadChildrenExcludedList()
} }
}) })

8
packages/nc-gui-v2/composables/useGridViewColumnWidth.ts

@ -3,6 +3,7 @@ import type { ColumnType, GridColumnType, GridType } from 'nocodb-sdk'
import type { Ref } from 'vue' import type { Ref } from 'vue'
import { useMetas } from './useMetas' import { useMetas } from './useMetas'
import { useUIPermission } from './useUIPermission' import { useUIPermission } from './useUIPermission'
import { IsPublicInj } from '~/context'
export function useGridViewColumnWidth(view: Ref<(GridType & { id?: string }) | undefined>) { export function useGridViewColumnWidth(view: Ref<(GridType & { id?: string }) | undefined>) {
const { css, load: loadCss, unload: unloadCss } = useStyleTag('') const { css, load: loadCss, unload: unloadCss } = useStyleTag('')
@ -13,6 +14,7 @@ export function useGridViewColumnWidth(view: Ref<(GridType & { id?: string }) |
const gridViewCols = ref<Record<string, GridColumnType>>({}) const gridViewCols = ref<Record<string, GridColumnType>>({})
const resizingCol = ref('') const resizingCol = ref('')
const resizingColWidth = ref('200px') const resizingColWidth = ref('200px')
const isPublic = inject(IsPublicInj, ref(false))
const columns = computed<ColumnType[]>(() => metas?.value?.[(view?.value as any)?.fk_model_id as string]?.columns) const columns = computed<ColumnType[]>(() => metas?.value?.[(view?.value as any)?.fk_model_id as string]?.columns)
@ -35,8 +37,8 @@ export function useGridViewColumnWidth(view: Ref<(GridType & { id?: string }) |
) )
const loadGridViewColumns = async () => { const loadGridViewColumns = async () => {
if (!view.value?.id) return if (!view.value?.id && !isPublic.value) return
const colsData: GridColumnType[] = await $api.dbView.gridColumnsList(view.value.id) const colsData: GridColumnType[] = isPublic.value ? columns.value : await $api.dbView.gridColumnsList(view.value.id)
gridViewCols.value = colsData.reduce<Record<string, GridColumnType>>( gridViewCols.value = colsData.reduce<Record<string, GridColumnType>>(
(o, col) => ({ (o, col) => ({
...o, ...o,
@ -56,7 +58,7 @@ export function useGridViewColumnWidth(view: Ref<(GridType & { id?: string }) |
} }
// sync with server if allowed // sync with server if allowed
if (isUIAllowed('gridColUpdate') && gridViewCols.value[id]?.id) { if (!isPublic.value && isUIAllowed('gridColUpdate') && gridViewCols.value[id]?.id) {
$api.dbView.gridColumnUpdate(gridViewCols.value[id].id as string, { $api.dbView.gridColumnUpdate(gridViewCols.value[id].id as string, {
width, width,
}) })

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

@ -139,7 +139,7 @@ const [useProvideLTARStore, useLTARStore] = useInjectionState(
} }
} }
const deleteRelatedRow = async (row: Record<string, any>) => { const deleteRelatedRow = async (row: Record<string, any>, onSuccess?: (row: Record<string, any>) => void) => {
Modal.confirm({ Modal.confirm({
title: 'Do you want to delete the record?', title: 'Do you want to delete the record?',
type: 'warning', type: 'warning',
@ -148,7 +148,12 @@ const [useProvideLTARStore, useLTARStore] = useInjectionState(
try { try {
$api.dbTableRow.delete(NOCO, project.value.id as string, relatedTableMeta.value.id as string, id as string) $api.dbTableRow.delete(NOCO, project.value.id as string, relatedTableMeta.value.id as string, id as string)
reloadData?.() reloadData?.()
await loadChildrenList()
/** reload child list if not a new row */
if (!isNewRow?.value) {
await loadChildrenList()
}
onSuccess?.(row)
} catch (e: any) { } catch (e: any) {
message.error(`Delete failed: ${await extractSdkResponseErrorMsg(e)}`) message.error(`Delete failed: ${await extractSdkResponseErrorMsg(e)}`)
} }

10
packages/nc-gui-v2/composables/useMetas.ts

@ -12,6 +12,14 @@ export function useMetas() {
const metas = useState<{ [idOrTitle: string]: TableType | any }>('metas', () => ({})) const metas = useState<{ [idOrTitle: string]: TableType | any }>('metas', () => ({}))
const loadingState = useState<Record<string, boolean>>('metas-loading-state', () => ({})) const loadingState = useState<Record<string, boolean>>('metas-loading-state', () => ({}))
const setMeta = async (model: any) => {
metas.value = {
...metas.value,
[model.id!]: model,
[model.title]: model,
}
}
const getMeta = async (tableIdOrTitle: string, force = false): Promise<TableType | TableInfoType | null> => { const getMeta = async (tableIdOrTitle: string, force = false): Promise<TableType | TableInfoType | null> => {
if (!tableIdOrTitle) return null if (!tableIdOrTitle) return null
/** wait until loading is finished if requesting same meta */ /** wait until loading is finished if requesting same meta */
@ -83,5 +91,5 @@ export function useMetas() {
} }
} }
return { getMeta, clearAllMeta, metas, removeMeta } return { getMeta, clearAllMeta, metas, removeMeta, setMeta }
} }

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

@ -2,6 +2,7 @@ import { SqlUiFactory } from 'nocodb-sdk'
import type { OracleUi, ProjectType, TableType } from 'nocodb-sdk' import type { OracleUi, ProjectType, TableType } from 'nocodb-sdk'
import type { MaybeRef } from '@vueuse/core' import type { MaybeRef } from '@vueuse/core'
import { useNuxtApp, useRoute, useState } from '#app' import { useNuxtApp, useRoute, useState } from '#app'
import type { ProjectMetaInfo } from '~/lib'
import { USER_PROJECT_ROLES } from '~/lib' import { USER_PROJECT_ROLES } from '~/lib'
export function useProject(projectId?: MaybeRef<string>) { export function useProject(projectId?: MaybeRef<string>) {
@ -13,10 +14,17 @@ export function useProject(projectId?: MaybeRef<string>) {
const tables = useState<TableType[]>('tables', () => [] as TableType[]) const tables = useState<TableType[]>('tables', () => [] as TableType[])
const route = useRoute() const route = useRoute()
const { includeM2M } = useGlobal() const { includeM2M } = useGlobal()
const projectMetaInfo = useState<ProjectMetaInfo | undefined>('projectMetaInfo')
// todo: refactor path param name and variable name // todo: refactor path param name and variable name
const projectType = $computed(() => route.params.projectType as string) const projectType = $computed(() => route.params.projectType as string)
async function loadProjectMetaInfo(force?: boolean) {
if (!projectMetaInfo.value || force) {
const data = await $api.project.metaGet(project.value.id!, {}, {})
projectMetaInfo.value = data
}
}
async function loadProjectRoles() { async function loadProjectRoles() {
projectRoles.value = {} projectRoles.value = {}
@ -59,5 +67,17 @@ export function useProject(projectId?: MaybeRef<string>) {
) )
const isSharedBase = computed(() => projectType === 'base') const isSharedBase = computed(() => projectType === 'base')
return { project, tables, loadProjectRoles, loadProject, loadTables, isMysql, isPg, sqlUi, isSharedBase } return {
project,
tables,
loadProjectRoles,
loadProject,
loadTables,
isMysql,
isPg,
sqlUi,
isSharedBase,
loadProjectMetaInfo,
projectMetaInfo,
}
} }

108
packages/nc-gui-v2/composables/useSharedView.ts

@ -0,0 +1,108 @@
import type { ColumnType, ExportTypes, FilterType, PaginatedType, SortType, TableType, ViewType } from 'nocodb-sdk'
import { UITypes } from 'nocodb-sdk'
import { useNuxtApp } from '#app'
export function useSharedView() {
const nestedFilters = useState<(FilterType & { status?: 'update' | 'delete' | 'create'; parentId?: string })[]>(
'nestedFilters',
() => [],
)
const paginationData = useState<PaginatedType>('paginationData', () => ({ page: 1, pageSize: 25 }))
const sharedView = useState<ViewType>('sharedView')
const sorts = useState<SortType[]>('sorts', () => [])
const password = useState<string | undefined>('password')
const allowCSVDownload = useState<boolean>('allowCSVDownload', () => false)
const meta = ref<TableType>(sharedView.value?.model)
const columns = ref<ColumnType[]>(sharedView.value?.model?.columns)
const formColumns = computed(
() =>
columns.value
.filter(
(f: Record<string, any>) =>
f.show && f.uidt !== UITypes.Rollup && f.uidt !== UITypes.Lookup && f.uidt !== UITypes.Formula,
)
.sort((a: Record<string, any>, b: Record<string, any>) => a.order - b.order)
.map((c: Record<string, any>) => ({ ...c, required: !!(c.required || 0) })) ?? [],
)
const { $api } = useNuxtApp()
const { setMeta } = useMetas()
const loadSharedView = async (viewId: string, localPassword: string | undefined = undefined) => {
const viewMeta = await $api.public.sharedViewMetaGet(viewId, {
headers: {
'xc-password': localPassword ?? password.value,
},
})
allowCSVDownload.value = JSON.parse(viewMeta.meta).allowCSVDownload
if (localPassword) password.value = localPassword
sharedView.value = viewMeta
meta.value = viewMeta.model
columns.value = viewMeta.model.columns
setMeta(viewMeta.model)
const relatedMetas = { ...viewMeta.relatedMetas }
Object.keys(relatedMetas).forEach((key) => setMeta(relatedMetas[key]))
}
const fetchSharedViewData = async () => {
const page = paginationData.value.page || 1
const pageSize = paginationData.value.pageSize || 25
const { data } = await $api.public.dataList(
sharedView?.value?.uuid,
{
offset: (page - 1) * pageSize,
filterArrJson: JSON.stringify(nestedFilters.value),
sortArrJson: JSON.stringify(sorts.value),
} as any,
{
headers: {
'xc-password': password.value,
},
},
)
return data
}
const exportFile = async (
fields: any[],
offset: number,
type: ExportTypes.EXCEL | ExportTypes.CSV,
responseType: 'base64' | 'blob',
) => {
return await $api.public.csvExport(sharedView.value?.uuid, type, {
format: responseType as any,
query: {
fields: fields.map((field) => field.title),
offset,
sortArrJson: JSON.stringify(sorts.value),
filterArrJson: JSON.stringify(nestedFilters.value),
},
headers: {
'xc-password': password.value,
},
})
}
return {
sharedView,
loadSharedView,
meta,
columns,
nestedFilters,
fetchSharedViewData,
paginationData,
sorts,
exportFile,
formColumns,
allowCSVDownload,
}
}

7
packages/nc-gui-v2/composables/useSmartsheetRowStore.ts

@ -5,7 +5,7 @@ import type { Ref } from 'vue'
import type { Row } from './useViewData' import type { Row } from './useViewData'
import { useInjectionState, useMetas, useNuxtApp, useProject, useVirtualCell } from '#imports' import { useInjectionState, useMetas, useNuxtApp, useProject, useVirtualCell } from '#imports'
import { NOCO } from '~/lib' import { NOCO } from '~/lib'
import { extractPkFromRow, extractSdkResponseErrorMsg } from '~/utils' import { deepCompare, extractPkFromRow, extractSdkResponseErrorMsg } from '~/utils'
const [useProvideSmartsheetRowStore, useSmartsheetRowStore] = useInjectionState((meta: Ref<TableType>, row: Ref<Row>) => { const [useProvideSmartsheetRowStore, useSmartsheetRowStore] = useInjectionState((meta: Ref<TableType>, row: Ref<Row>) => {
const { $api } = useNuxtApp() const { $api } = useNuxtApp()
@ -23,6 +23,11 @@ const [useProvideSmartsheetRowStore, useSmartsheetRowStore] = useInjectionState(
const { isHm, isMm, isBt } = $(useVirtualCell(ref(column))) const { isHm, isMm, isBt } = $(useVirtualCell(ref(column)))
if (isHm || isMm) { if (isHm || isMm) {
state.value[column.title!] = state.value[column.title!] || [] state.value[column.title!] = state.value[column.title!] || []
if (state.value[column.title!]!.find((ln: Record<string, any>) => deepCompare(ln, value))) {
return message.info('This value is already in the list')
}
state.value[column.title!]!.push(value) state.value[column.title!]!.push(value)
} else if (isBt) { } else if (isBt) {
state.value[column.title!] = value state.value[column.title!] = value

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

@ -3,13 +3,10 @@ import type { ColumnType, TableType, ViewType } from 'nocodb-sdk'
import { watch } from 'vue' import { watch } from 'vue'
import type { ComputedRef, Ref } from 'vue' import type { ComputedRef, Ref } from 'vue'
import { useNuxtApp } from '#app' import { useNuxtApp } from '#app'
import { IsPublicInj } from '#imports'
export function useViewColumns( export function useViewColumns(view: Ref<ViewType> | undefined, meta: ComputedRef<TableType>, reloadData?: () => void) {
view: Ref<ViewType> | undefined, const isPublic = inject(IsPublicInj, ref(false))
meta: ComputedRef<TableType>,
isPublic = false,
reloadData?: () => void,
) {
const fields = ref< const fields = ref<
{ {
order: number order: number
@ -31,7 +28,7 @@ export function useViewColumns(
let order = 1 let order = 1
if (view.value?.id) { if (view.value?.id) {
const data = (await $api.dbViewColumn.list(view.value.id)) as any[] const data = (isPublic.value ? meta.value?.columns : await $api.dbViewColumn.list(view.value.id)) as any[]
const fieldById = data.reduce<Record<string, any>>((acc, curr) => { const fieldById = data.reduce<Record<string, any>>((acc, curr) => {
curr.show = !!curr.show curr.show = !!curr.show
@ -54,12 +51,19 @@ export function useViewColumns(
} }
}) })
.sort((a, b) => a.order - b.order) .sort((a, b) => a.order - b.order)
} else if (isPublic) {
fields.value = meta.value.columns as any
} }
} }
const showAll = async (ignoreIds?: any) => { const showAll = async (ignoreIds?: any) => {
if (isPublic.value) {
fields.value = fields.value?.map((field) => ({
...field,
show: true,
}))
reloadData?.()
return
}
if (view?.value?.id) { if (view?.value?.id) {
if (ignoreIds) { if (ignoreIds) {
await $api.dbView.showAllColumn(view.value.id, { await $api.dbView.showAllColumn(view.value.id, {
@ -74,6 +78,14 @@ export function useViewColumns(
reloadData?.() reloadData?.()
} }
const hideAll = async (ignoreIds?: any) => { const hideAll = async (ignoreIds?: any) => {
if (isPublic.value) {
fields.value = fields.value?.map((field) => ({
...field,
show: false,
}))
reloadData?.()
return
}
if (view?.value?.id) { if (view?.value?.id) {
if (ignoreIds) { if (ignoreIds) {
await $api.dbView.hideAllColumn(view.value.id, { await $api.dbView.hideAllColumn(view.value.id, {
@ -89,6 +101,22 @@ export function useViewColumns(
} }
const saveOrUpdate = async (field: any, index: number) => { const saveOrUpdate = async (field: any, index: number) => {
if (isPublic && fields.value) {
fields.value[index] = field
meta.value.columns = meta.value?.columns?.map((column) => {
if (column.id === field.fk_column_id) {
return {
...column,
...field,
}
}
return column
})
reloadData?.()
return
}
if (isUIAllowed('fieldsSync')) { if (isUIAllowed('fieldsSync')) {
if (field.id && view?.value?.id) { if (field.id && view?.value?.id) {
await $api.dbViewColumn.update(view.value.id, field.id, field) await $api.dbViewColumn.update(view.value.id, field.id, field)
@ -118,11 +146,13 @@ export function useViewColumns(
}, },
set(v: boolean) { set(v: boolean) {
if (view?.value?.id) { if (view?.value?.id) {
$api.dbView if (!isPublic.value) {
.update(view.value.id, { $api.dbView
show_system_fields: v, .update(view.value.id, {
}) show_system_fields: v,
.finally(() => reloadData?.()) })
.finally(() => reloadData?.())
}
;(view.value as any).show_system_fields = v ;(view.value as any).show_system_fields = v
} }
}, },

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

@ -1,7 +1,8 @@
import type { Api, ColumnType, FormType, GalleryType, PaginatedType, TableType, ViewType } from 'nocodb-sdk' import type { Api, ColumnType, FormType, GalleryType, PaginatedType, TableType, ViewType } from 'nocodb-sdk'
import type { ComputedRef, Ref } from 'vue' import type { ComputedRef, Ref } from 'vue'
import { message } from 'ant-design-vue' import { message } from 'ant-design-vue'
import { NOCO, computed, extractPkFromRow, extractSdkResponseErrorMsg, ref, useNuxtApp, useProject } from '#imports' import { useNuxtApp } from '#app'
import { IsPublicInj, NOCO, extractPkFromRow, extractSdkResponseErrorMsg, useProject } from '#imports'
const formatData = (list: Record<string, any>[]) => const formatData = (list: Record<string, any>[]) =>
list.map((row) => ({ list.map((row) => ({
@ -29,17 +30,30 @@ export function useViewData(
throw new Error('Table meta is not available') throw new Error('Table meta is not available')
} }
const formattedData = ref<Row[]>([]) const _paginationData = ref<PaginatedType>({ page: 1, pageSize: 25 })
const paginationData = ref<PaginatedType>({ page: 1, pageSize: 25 })
const aggCommentCount = ref<{ row_id: string; count: number }[]>([]) const aggCommentCount = ref<{ row_id: string; count: number }[]>([])
const galleryData = ref<GalleryType>() const galleryData = ref<GalleryType>()
const formColumnData = ref<FormType>() const formColumnData = ref<FormType>()
// todo: missing properties on FormType (success_msg, show_blank_form, // todo: missing properties on FormType (success_msg, show_blank_form,
const formViewData = ref<FormType & { success_msg?: string; show_blank_form?: boolean }>() const formViewData = ref<FormType & { success_msg?: string; show_blank_form?: boolean }>()
const formattedData = ref<Row[]>([])
const isPublic = inject(IsPublicInj, ref(false))
const { project } = useProject() const { project } = useProject()
const { fetchSharedViewData, paginationData: sharedPaginationData } = useSharedView()
const { $api } = useNuxtApp() const { $api } = useNuxtApp()
const paginationData = computed({
get: () => (isPublic.value ? sharedPaginationData.value : _paginationData.value),
set: (value) => {
if (isPublic.value) {
sharedPaginationData.value = value
} else {
_paginationData.value = value
}
},
})
const selectedAllRecords = computed({ const selectedAllRecords = computed({
get() { get() {
return !!formattedData.value.length && formattedData.value.every((row: Row) => row.rowMeta.selected) return !!formattedData.value.length && formattedData.value.every((row: Row) => row.rowMeta.selected)
@ -68,9 +82,7 @@ export function useViewData(
/** load row comments count */ /** load row comments count */
const loadAggCommentsCount = async () => { const loadAggCommentsCount = async () => {
// todo: handle in public api // todo: handle in public api
// if (this.isPublicView) { if (isPublic.value) return
// return;
// }
const ids = formattedData.value const ids = formattedData.value
?.filter(({ rowMeta: { new: isNew } }) => !isNew) ?.filter(({ rowMeta: { new: isNew } }) => !isNew)
@ -92,11 +104,14 @@ export function useViewData(
} }
const loadData = async (params: Parameters<Api<any>['dbViewRow']['list']>[4] = {}) => { const loadData = async (params: Parameters<Api<any>['dbViewRow']['list']>[4] = {}) => {
if (!project?.value?.id || !meta?.value?.id || !viewMeta?.value?.id) return if ((!project?.value?.id || !meta?.value?.id || !viewMeta?.value?.id) && !isPublic.value) return
const response = await $api.dbViewRow.list('noco', project.value.id, meta.value.id, viewMeta.value.id, {
...params, const response = !isPublic.value
where: where?.value, ? await $api.dbViewRow.list('noco', project.value.id!, meta.value.id!, viewMeta!.value.id, {
}) ...params,
where: where?.value,
})
: await fetchSharedViewData()
formattedData.value = formatData(response.list) formattedData.value = formatData(response.list)
paginationData.value = response.pageInfo paginationData.value = response.pageInfo
@ -133,6 +148,7 @@ export function useViewData(
}) })
await syncCount() await syncCount()
return insertedData
} catch (error: any) { } catch (error: any) {
message.error(await extractSdkResponseErrorMsg(error)) message.error(await extractSdkResponseErrorMsg(error))
} }

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

@ -1,22 +1,53 @@
import type { FilterType, ViewType } from 'nocodb-sdk' import type { ViewType } from 'nocodb-sdk'
import type { ComputedRef, Ref } from 'vue' import type { ComputedRef, Ref } from 'vue'
import { useNuxtApp, useUIPermission } from '#imports' import { IsPublicInj, ReloadViewDataHookInj, useMetas, useNuxtApp, useUIPermission } from '#imports'
import { useMetas } from '~/composables/useMetas' import type { Filter } from '~/lib'
export function useViewFilters( export function useViewFilters(
view: Ref<ViewType> | undefined, view: Ref<ViewType> | undefined,
parentId?: string, parentId?: string,
autoApply?: ComputedRef<boolean>, autoApply?: ComputedRef<boolean>,
reloadData?: () => void, reloadData?: () => void,
shared = false, siblingFilters?: Filter[],
) { ) {
const filters = ref<(FilterType & { status?: 'update' | 'delete' | 'create'; parentId?: string })[]>([]) const { nestedFilters } = useSharedView()
const reloadHook = inject(ReloadViewDataHookInj)
const _filters = ref<Filter[]>([])
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({
get: () => (isPublic.value ? siblingFilters || nestedFilters.value : _filters.value),
set: (value) => {
if (isPublic.value) {
if (siblingFilters) {
siblingFilters = value
} else {
nestedFilters.value = value
}
nestedFilters.value = [...nestedFilters.value]
reloadHook?.trigger()
} else {
_filters.value = value
}
},
})
const placeholderFilter: Filter = {
comparison_op: 'eq',
value: '',
status: 'create',
logical_op: 'and',
}
const loadFilters = async (hookId?: string) => { const loadFilters = async (hookId?: string) => {
if (isPublic.value) return
if (hookId) { if (hookId) {
if (parentId) { if (parentId) {
filters.value = await $api.dbTableFilter.childrenRead(parentId) filters.value = await $api.dbTableFilter.childrenRead(parentId)
@ -55,12 +86,13 @@ export function useViewFilters(
} }
} }
} }
reloadData?.() reloadData?.()
} }
const deleteFilter = async (filter: FilterType & { status: string }, i: number) => { const deleteFilter = async (filter: Filter, i: number) => {
// 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 (shared || !isUIAllowed('filterSync')) { if (isPublic.value || !isUIAllowed('filterSync')) {
filters.value.splice(i, 1) filters.value.splice(i, 1)
reloadData?.() reloadData?.()
} else { } else {
@ -81,9 +113,14 @@ export function useViewFilters(
} }
} }
const saveOrUpdate = async (filter: FilterType & { status?: string }, i: number, force = false) => { const saveOrUpdate = async (filter: Filter, i: number, force = false) => {
if (isPublic.value) {
filters.value[i] = { ...filter } as any
filters.value = [...filters.value]
return
}
if (!view?.value) return if (!view?.value) return
if (shared || !isUIAllowed('filterSync')) { if (!isUIAllowed('filterSync')) {
// skip // skip
} else if (!autoApply?.value && !force) { } else if (!autoApply?.value && !force) {
filter.status = filter.id ? 'update' : 'create' filter.status = filter.id ? 'update' : 'create'
@ -103,21 +140,19 @@ export function useViewFilters(
} }
const addFilter = () => { const addFilter = () => {
filters.value.push({ filters.value.push(placeholderFilter)
comparison_op: 'eq',
value: '',
status: 'create',
logical_op: 'and',
})
} }
const addFilterGroup = async (parentId?: string) => { const addFilterGroup = async () => {
filters.value.push({ const child = placeholderFilter
parentId, const placeHolderGroupFilter: Filter = {
is_group: true, is_group: true,
status: 'create', status: 'create',
logical_op: 'and', logical_op: 'and',
}) }
if (isPublic.value) placeHolderGroupFilter.children = [child]
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)
} }

47
packages/nc-gui-v2/composables/useViewSorts.ts

@ -1,18 +1,39 @@
import type { GalleryType, GridType, KanbanType, SortType } from 'nocodb-sdk' import type { GalleryType, GridType, KanbanType, SortType } from 'nocodb-sdk'
import type { Ref } from 'vue' import type { Ref } from 'vue'
import { useNuxtApp } from '#imports' import { IsPublicInj, ReloadViewDataHookInj, useNuxtApp } from '#imports'
export function useViewSorts( export function useViewSorts(
view: Ref<(GridType | KanbanType | GalleryType) & { id?: string }> | undefined, view: Ref<(GridType | KanbanType | GalleryType) & { id?: string }> | undefined,
reloadData?: () => void, reloadData?: () => void,
) { ) {
const sorts = ref<SortType[]>([]) const _sorts = ref<SortType[]>([])
const { sorts: sharedViewSorts, sharedView } = useSharedView()
const reloadHook = inject(ReloadViewDataHookInj)
const isPublic = inject(IsPublicInj, ref(false))
const sorts = computed<SortType[]>({
get: () => (isPublic.value ? sharedViewSorts.value : _sorts.value),
set: (value) => {
if (isPublic.value) {
sharedViewSorts.value = value
} else {
_sorts.value = value
}
reloadHook?.trigger()
},
})
const { $api } = useNuxtApp() const { $api } = useNuxtApp()
const { isUIAllowed } = useUIPermission() const { isUIAllowed } = useUIPermission()
const loadSorts = async () => { const loadSorts = async () => {
if (isPublic.value) {
const sharedSorts = sharedView.value?.sorts || []
sorts.value = [...sharedSorts]
return
}
if (!view?.value) return if (!view?.value) return
sorts.value = ((await $api.dbTableSort.list(view?.value?.id as string)) as any)?.sorts?.list sorts.value = ((await $api.dbTableSort.list(view?.value?.id as string)) as any)?.sorts?.list
} }
@ -20,6 +41,12 @@ export function useViewSorts(
const saveOrUpdate = async (sort: SortType, i: number) => { const saveOrUpdate = async (sort: SortType, i: number) => {
// TODO: // TODO:
// if (!this.shared && this._isUIAllowed('sortSync')) { // if (!this.shared && this._isUIAllowed('sortSync')) {
if (isPublic.value) {
sorts.value[i] = sort
sorts.value = [...sorts.value]
return
}
if (isUIAllowed('sortSync')) { if (isUIAllowed('sortSync')) {
if (sort.id) { if (sort.id) {
await $api.dbTableSort.update(sort.id, sort) await $api.dbTableSort.update(sort.id, sort)
@ -30,19 +57,23 @@ export function useViewSorts(
reloadData?.() reloadData?.()
} }
const addSort = () => { const addSort = () => {
sorts.value.push({ sorts.value = [
direction: 'asc', ...sorts.value,
}) {
direction: 'asc',
},
]
} }
const deleteSort = async (sort: SortType, i: number) => { const deleteSort = async (sort: SortType, i: number) => {
// TOOD: // TOOD:
// if (!this.shared && sort.id && this._isUIAllowed('sortSync')) { // if (!this.shared && sort.id && this._isUIAllowed('sortSync')) {
if (isUIAllowed('sortSync') && sort.id) {
if (isUIAllowed('sortSync') && sort.id && !isPublic.value) {
await $api.dbTableSort.delete(sort.id) await $api.dbTableSort.delete(sort.id)
} else {
sorts.value.splice(i, 1)
} }
sorts.value.splice(i, 1)
sorts.value = [...sorts.value]
} }
return { sorts, loadSorts, addSort, deleteSort, saveOrUpdate } return { sorts, loadSorts, addSort, deleteSort, saveOrUpdate }
} }

3
packages/nc-gui-v2/context/index.ts

@ -6,6 +6,7 @@ import type { Row } from '~/composables'
import type { TabItem } from '~/composables/useTabs' import type { TabItem } from '~/composables/useTabs'
export const ActiveCellInj: InjectionKey<Ref<boolean>> = Symbol('active-cell') export const ActiveCellInj: InjectionKey<Ref<boolean>> = Symbol('active-cell')
export const IsPublicInj: InjectionKey<Ref<boolean>> = Symbol('is-public')
export const RowInj: InjectionKey<Ref<Row>> = Symbol('row') export const RowInj: InjectionKey<Ref<Row>> = Symbol('row')
export const ColumnInj: InjectionKey<Ref<ColumnType & { meta: any }>> = Symbol('column-injection') export const ColumnInj: InjectionKey<Ref<ColumnType & { meta: any }>> = Symbol('column-injection')
export const MetaInj: InjectionKey<ComputedRef<TableType>> = Symbol('meta-injection') export const MetaInj: InjectionKey<ComputedRef<TableType>> = Symbol('meta-injection')
@ -18,7 +19,7 @@ export const IsGridInj: InjectionKey<boolean> = Symbol('is-grid-injection')
export const IsLockedInj: InjectionKey<boolean> = Symbol('is-locked-injection') export const IsLockedInj: InjectionKey<boolean> = Symbol('is-locked-injection')
export const CellValueInj: InjectionKey<Ref<any>> = Symbol('cell-value-injection') export const CellValueInj: InjectionKey<Ref<any>> = Symbol('cell-value-injection')
export const ActiveViewInj: InjectionKey<Ref<ViewType>> = Symbol('active-view-injection') export const ActiveViewInj: InjectionKey<Ref<ViewType>> = Symbol('active-view-injection')
export const ReadonlyInj: InjectionKey<any> = Symbol('readonly-injection') export const ReadonlyInj: InjectionKey<boolean> = Symbol('readonly-injection')
export const ReloadViewDataHookInj: InjectionKey<EventHook<void>> = Symbol('reload-view-data-injection') export const ReloadViewDataHookInj: InjectionKey<EventHook<void>> = Symbol('reload-view-data-injection')
export const FieldsInj: InjectionKey<Ref<any[]>> = Symbol('fields-injection') export const FieldsInj: InjectionKey<Ref<any[]>> = Symbol('fields-injection')
export const ViewListInj: InjectionKey<Ref<ViewType[]>> = Symbol('view-list-injection') export const ViewListInj: InjectionKey<Ref<ViewType[]>> = Symbol('view-list-injection')

37
packages/nc-gui-v2/layouts/shared-view.vue

@ -0,0 +1,37 @@
<script lang="ts" setup>
import { navigateTo } from '#app'
</script>
<script lang="ts">
export default {
name: 'SharedView',
}
</script>
<template>
<a-layout id="nc-app">
<a-layout class="!flex-col">
<a-layout-header class="flex !bg-primary items-center text-white pl-3 pr-4 shadow-lg">
<div class="transition-all duration-200 p-2 cursor-pointer transform hover:scale-105" @click="navigateTo('/')">
<img width="35" alt="NocoDB" src="~/assets/img/icons/512x512-trans.png" />
</div>
<div class="flex-1" />
</a-layout-header>
<div class="w-full overflow-hidden" style="height: calc(100% - var(--header-height))">
<slot />
</div>
</a-layout>
</a-layout>
</template>
<style lang="scss" scoped>
:deep(.ant-dropdown-menu-item-group-title) {
@apply border-b-1;
}
:deep(.ant-dropdown-menu-item-group-list) {
@apply m-0;
}
</style>

15
packages/nc-gui-v2/lib/types.ts

@ -1,5 +1,5 @@
import type { FilterType } from 'nocodb-sdk'
import type { Role } from './enums' import type { Role } from './enums'
export interface User { export interface User {
id: string id: string
email: string email: string
@ -10,4 +10,17 @@ export interface User {
project_id?: string project_id?: string
} }
export interface ProjectMetaInfo {
Node?: string
Arch?: string
Platform?: string
Docker?: boolean
Database?: string
ProjectOnRootDB?: string
RootDB?: string
PackageVersion?: string
}
export type Roles = Record<Role, boolean> export type Roles = Record<Role, boolean>
export type Filter = FilterType & { status?: 'update' | 'delete' | 'create'; parentId?: string; readOnly?: boolean }

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

@ -1,10 +1,12 @@
<script setup lang="ts"> <script setup lang="ts">
import { message } from 'ant-design-vue'
import { import {
navigateTo, navigateTo,
onKeyStroke, onKeyStroke,
openLink, openLink,
provideSidebar, provideSidebar,
ref, ref,
useClipboard,
useElementHover, useElementHover,
useProject, useProject,
useRoute, useRoute,
@ -12,15 +14,18 @@ import {
useUIPermission, useUIPermission,
} from '#imports' } from '#imports'
import { TabType } from '~/composables' import { TabType } from '~/composables'
const route = useRoute() const route = useRoute()
const { project, loadProject, loadTables, isSharedBase } = useProject() const { appInfo, token } = useGlobal()
const { project, loadProject, loadTables, isSharedBase, loadProjectMetaInfo, projectMetaInfo } = useProject()
const { addTab, clearTabs } = useTabs() const { addTab, clearTabs } = useTabs()
const { isUIAllowed } = useUIPermission() const { isUIAllowed } = useUIPermission()
const { copy } = useClipboard()
// create a new sidebar state // create a new sidebar state
const { isOpen, toggle } = provideSidebar({ isOpen: true }) const { isOpen, toggle } = provideSidebar({ isOpen: true })
@ -57,6 +62,31 @@ await loadProject()
await loadTables() await loadTables()
const isHovered = useElementHover(sidebar) const isHovered = useElementHover(sidebar)
const copyProjectInfo = async () => {
try {
await loadProjectMetaInfo()
copy(
Object.entries(projectMetaInfo.value!)
.map(([k, v]) => `${k}: **${v}**`)
.join('\n'),
)
message.info('Copied project info to clipboard')
} catch (e: any) {
console.log(e)
message.error(e.message)
}
}
const copyAuthToken = async () => {
try {
copy(token.value!)
message.info('Copied auth token to clipboard')
} catch (e: any) {
console.log(e)
message.error(e.message)
}
}
</script> </script>
<template> <template>
@ -141,7 +171,7 @@ const isHovered = useElementHover(sidebar)
</template> </template>
<a-menu-item key="copy"> <a-menu-item key="copy">
<div class="nc-project-menu-item group"> <div class="nc-project-menu-item group" @click.stop="copyProjectInfo">
<MdiContentCopy class="group-hover:text-pink-500 nc-copy-project-info" /> <MdiContentCopy class="group-hover:text-pink-500 nc-copy-project-info" />
Copy Project Info Copy Project Info
</div> </div>
@ -152,13 +182,20 @@ const isHovered = useElementHover(sidebar)
v-if="isUIAllowed('apiDocs')" v-if="isUIAllowed('apiDocs')"
v-t="['e:api-docs']" v-t="['e:api-docs']"
class="nc-project-menu-item group" class="nc-project-menu-item group"
@click.stop="openLink(`/api/v1/db/meta/projects/${route.params.projectId}/swagger`)" @click.stop="openLink(`/api/v1/db/meta/projects/${route.params.projectId}/swagger`, appInfo.ncSiteUrl)"
> >
<MdiApi class="group-hover:text-pink-500 nc-swagger-api-docs" /> <MdiApi class="group-hover:text-pink-500 nc-swagger-api-docs" />
Swagger: Rest APIs Swagger: Rest APIs
</div> </div>
</a-menu-item> </a-menu-item>
<a-menu-item key="copy">
<div v-t="['a:navbar:user:copy-auth-token']" class="nc-project-menu-item group" @click.stop="copyAuthToken">
<MdiContentCopy class="group-hover:text-pink-500 nc-copy-project-info" />
Copy Auth Token
</div>
</a-menu-item>
<a-menu-divider /> <a-menu-divider />
<a-menu-item key="teamAndSettings"> <a-menu-item key="teamAndSettings">

39
packages/nc-gui-v2/pages/[projectType]/form/[viewId].vue

@ -0,0 +1,39 @@
<script setup lang="ts">
import type { Ref } from 'vue'
import type { TableType } from 'nocodb-sdk'
import { ActiveViewInj, FieldsInj, IsPublicInj, MetaInj, ReloadViewDataHookInj, useRoute } from '#imports'
definePageMeta({
requiresAuth: false,
})
const route = useRoute()
const reloadEventHook = createEventHook<void>()
const { sharedView, loadSharedView, meta, formColumns } = useSharedView()
await loadSharedView(route.params.viewId as string)
provide(ReloadViewDataHookInj, reloadEventHook)
provide(MetaInj, meta)
provide(ActiveViewInj, sharedView)
provide(FieldsInj, formColumns)
provide(IsPublicInj, ref(true))
useProvideSmartsheetStore(sharedView as Ref<TableType>, meta)
</script>
<template>
<NuxtLayout id="content" class="flex">
<div class="nc-container flex flex-col h-full mt-2 px-6">
<SharedViewForm />
</div>
</NuxtLayout>
</template>
<style scoped>
.nc-container {
height: calc(100% - var(--header-height));
flex: 1 1 100%;
}
</style>

32
packages/nc-gui-v2/pages/[projectType]/view/[viewId].vue

@ -0,0 +1,32 @@
<script setup lang="ts">
import { ReadonlyInj, ReloadViewDataHookInj, useRoute } from '#imports'
definePageMeta({
requiresAuth: false,
layout: 'shared-view',
})
const route = useRoute()
const reloadEventHook = createEventHook<void>()
provide(ReloadViewDataHookInj, reloadEventHook)
provide(ReadonlyInj, ref(true))
const { loadSharedView } = useSharedView()
const showPassword = ref(false)
try {
await loadSharedView(route.params.viewId as string)
} catch (e) {
showPassword.value = true
}
</script>
<template>
<NuxtLayout id="content" class="flex" name="shared-view">
<div v-if="showPassword">
<SharedViewAskPassword v-model="showPassword" />
</div>
<SharedViewGrid v-else />
</NuxtLayout>
</template>

5
packages/nc-gui-v2/utils/urlUtils.ts

@ -24,6 +24,7 @@ export const isValidURL = (str: string) => {
return !!pattern.test(str) return !!pattern.test(str)
} }
export const openLink = (url: string, target = '_blank') => { export const openLink = (path: string, baseURL: string, target = '_blank') => {
window.open(url, target) const url = new URL(path, baseURL)
window.open(url.href, target)
} }

Loading…
Cancel
Save