Browse Source

feat: base reorder

pull/7528/head
Ramesh Mane 5 months ago
parent
commit
c537442723
  1. 13
      packages/nc-gui/store/bases.ts
  2. 19
      packages/nocodb/src/models/Base.ts
  3. 5
      packages/nocodb/src/models/BaseUser.ts
  4. 12
      packages/nocodb/src/schema/swagger-v2.json
  5. 12
      packages/nocodb/src/schema/swagger.json
  6. 9
      packages/nocodb/src/services/bases.service.ts

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

@ -11,7 +11,7 @@ export const useBases = defineStore('basesStore', () => {
const bases = ref<Map<string, NcProject>>(new Map())
const basesList = computed<NcProject[]>(() => Array.from(bases.value.values()).sort((a, b) => a.updated_at - b.updated_at))
const basesList = computed<NcProject[]>(() => Array.from(bases.value.values()))
const basesUser = ref<Map<string, User[]>>(new Map())
const router = useRouter()
@ -214,8 +214,17 @@ export const useBases = defineStore('basesStore', () => {
}
const updateProject = async (baseId: string, baseUpdatePayload: BaseType) => {
const existingProject = bases.value.get(baseId) ?? ({} as any)
const base = {
...existingProject,
...baseUpdatePayload,
}
bases.value.set(baseId, base)
await api.base.update(baseId, baseUpdatePayload)
// todo: update base in store
await loadProject(baseId, true)
}

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

@ -54,6 +54,7 @@ export default class Base implements BaseType {
'status',
'meta',
'color',
'order',
]);
const { id: baseId } = await ncMeta.metaInsert2(
@ -110,12 +111,23 @@ export default class Base implements BaseType {
},
],
},
orderBy: {
order: 'asc',
},
});
await NocoCache.setList(CacheScope.PROJECT, [], baseList);
}
baseList = baseList.filter(
(p) => p.deleted === 0 || p.deleted === false || p.deleted === null,
);
baseList = baseList
.filter(
(p) => p.deleted === 0 || p.deleted === false || p.deleted === null,
)
.sort(
(a, b) =>
(a.order != null ? a.order : Infinity) -
(b.order != null ? b.order : Infinity),
);
const castedProjectList = baseList.map((m) => this.castType(m));
await Promise.all(castedProjectList.map((base) => base.getSources(ncMeta)));
@ -253,6 +265,7 @@ export default class Base implements BaseType {
'password',
'roles',
]);
console.log('basess', updateObj);
// get existing cache
const key = `${CacheScope.PROJECT}:${baseId}`;
let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);

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

@ -361,6 +361,11 @@ export default class BaseUser {
const castedProjectList = baseList
.filter((p) => !params?.type || p.type === params.type)
.sort(
(a, b) =>
(a.order != null ? a.order : Infinity) -
(b.order != null ? b.order : Infinity),
)
.map((m) => Base.castType(m));
await Promise.all(castedProjectList.map((base) => base.getSources(ncMeta)));

12
packages/nocodb/src/schema/swagger-v2.json

@ -1163,7 +1163,8 @@
"value": {
"color": "#24716E",
"meta": null,
"title": "My Base"
"title": "My Base",
"order": 1
}
}
}
@ -16011,7 +16012,8 @@
{
"color": "#24716E",
"meta": null,
"title": "My Base"
"title": "My Base",
"order": 1
}
],
"title": "Base Update Request Model",
@ -16048,6 +16050,12 @@
"items": {
"type": "string"
}
},
"order": {
"type": "number",
"description": "The order of the list of projects.",
"example": 1,
"minimum": 0
}
}
},

12
packages/nocodb/src/schema/swagger.json

@ -2785,7 +2785,8 @@
"value": {
"color": "#24716E",
"meta": null,
"title": "My Base"
"title": "My Base",
"order": 1
}
}
}
@ -21266,7 +21267,8 @@
{
"color": "#24716E",
"meta": null,
"title": "My Base"
"title": "My Base",
"order": 1
}
],
"title": "Base Update Request Model",
@ -21303,6 +21305,12 @@
"items": {
"type": "string"
}
},
"order": {
"type": "number",
"description": "The order of the list of projects.",
"example": 1,
"minimum": 0
}
}
},

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

@ -78,8 +78,13 @@ export class BasesService {
'meta',
'color',
'status',
'order',
]);
await this.validateProjectTitle(data, base);
console.log('base', data, param?.base);
if (data?.order !== undefined) {
data.order = !isNaN(+data.order) ? +data.order : 0;
}
const result = await Base.update(param.baseId, data);
@ -191,6 +196,10 @@ export class BasesService {
baseBody.title = DOMPurify.sanitize(baseBody.title);
baseBody.slug = baseBody.title;
const bases = await Base.list(param);
console.log('list', bases);
const base = await Base.createProject(baseBody);
// TODO: create n:m instances here

Loading…
Cancel
Save