Browse Source

fix: add base order on creating new base

pull/7528/head
Ramesh Mane 11 months ago
parent
commit
7f0db243e9
  1. 2
      packages/nc-gui/components/dashboard/TreeView/index.vue
  2. 25
      packages/nc-gui/store/bases.ts
  3. 5
      packages/nocodb/src/models/Base.ts
  4. 4
      packages/nocodb/src/services/bases.service.ts

2
packages/nc-gui/components/dashboard/TreeView/index.vue

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import Draggable from 'vuedraggable'
import type { TableType } from 'nocodb-sdk' import type { TableType } from 'nocodb-sdk'
import ProjectWrapper from './ProjectWrapper.vue' import ProjectWrapper from './ProjectWrapper.vue'
import { import {

25
packages/nc-gui/store/bases.ts

@ -9,6 +9,8 @@ import type { NcProject, User } from '#imports'
export const useBases = defineStore('basesStore', () => { export const useBases = defineStore('basesStore', () => {
const { $api } = useNuxtApp() const { $api } = useNuxtApp()
const { isUIAllowed } = useRoles()
const bases = ref<Map<string, NcProject>>(new Map()) const bases = ref<Map<string, NcProject>>(new Map())
const basesList = computed<NcProject[]>(() => const basesList = computed<NcProject[]>(() =>
@ -150,6 +152,8 @@ export const useBases = defineStore('basesStore', () => {
}) })
return acc return acc
}, new Map()) }, new Map())
await updateNullBaseOrder()
} catch (e) { } catch (e) {
console.error(e) console.error(e)
message.error(e.message) message.error(e.message)
@ -300,6 +304,27 @@ export const useBases = defineStore('basesStore', () => {
await navigateTo(`/nc/${baseId}`) await navigateTo(`/nc/${baseId}`)
} }
async function updateNullBaseOrder() {
if (!isUIAllowed('baseMove')) return
const basesArray = Array.from(bases.value.values())
const isOrderNullPresent = basesArray.some((base) => base.order === null)
if (isOrderNullPresent) {
const orderUpdateBasesList = basesArray.map((base, i) => {
bases.value.set(base.id!, { ...base, order: i + 1 })
return {
id: base.id,
order: i + 1,
}
})
for (const orderUpdateBase of orderUpdateBasesList) {
await api.base.update(orderUpdateBase.id!, { order: orderUpdateBase.order })
}
}
}
onMounted(() => { onMounted(() => {
if (!activeProjectId.value) return if (!activeProjectId.value) return
if (isProjectPopulated(activeProjectId.value)) return if (isProjectPopulated(activeProjectId.value)) return

5
packages/nocodb/src/models/Base.ts

@ -57,6 +57,11 @@ export default class Base implements BaseType {
'order', 'order',
]); ]);
if (!insertObj.order) {
// get order value
insertObj.order = await ncMeta.metaGetNextOrder(MetaTable.PROJECT, {});
}
const { id: baseId } = await ncMeta.metaInsert2( const { id: baseId } = await ncMeta.metaInsert2(
null, null,
null, null,

4
packages/nocodb/src/services/bases.service.ts

@ -196,10 +196,6 @@ export class BasesService {
baseBody.title = DOMPurify.sanitize(baseBody.title); baseBody.title = DOMPurify.sanitize(baseBody.title);
baseBody.slug = baseBody.title; baseBody.slug = baseBody.title;
const bases = await Base.list(param);
console.log('list', bases);
const base = await Base.createProject(baseBody); const base = await Base.createProject(baseBody);
// TODO: create n:m instances here // TODO: create n:m instances here

Loading…
Cancel
Save