Skip to content

Commit bc4359b

Browse files
committed
feat: space layout
1 parent 8f40132 commit bc4359b

File tree

42 files changed

+1791
-433
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1791
-433
lines changed

apps/nestjs-backend/src/features/base/base.service.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
IUpdateBaseRo,
1313
IUpdateOrderRo,
1414
} from '@teable/openapi';
15+
import { keyBy } from 'lodash';
1516
import { ClsService } from 'nestjs-cls';
1617
import { IThresholdConfig, ThresholdConfig } from '../../configs/threshold.config';
1718
import { CustomHttpException } from '../../custom.exception';
@@ -20,6 +21,7 @@ import { IDbProvider } from '../../db-provider/db.provider.interface';
2021
import type { IClsStore } from '../../types/cls';
2122
import { getMaxLevelRole } from '../../utils/get-max-level-role';
2223
import { updateOrder } from '../../utils/update-order';
24+
import { getPublicFullStorageUrl } from '../attachments/plugins/utils';
2325
import { PermissionService } from '../auth/permission.service';
2426
import { CollaboratorService } from '../collaborator/collaborator.service';
2527
import { GraphService } from '../graph/graph.service';
@@ -52,6 +54,7 @@ export class BaseService {
5254
name: true,
5355
icon: true,
5456
spaceId: true,
57+
createdBy: true,
5558
},
5659
where: {
5760
id: baseId,
@@ -101,6 +104,8 @@ export class BaseService {
101104
order: true,
102105
spaceId: true,
103106
icon: true,
107+
createdBy: true,
108+
lastModifiedTime: true,
104109
},
105110
where: {
106111
deletedTime: null,
@@ -122,9 +127,24 @@ export class BaseService {
122127
},
123128
orderBy: [{ spaceId: 'asc' }, { order: 'asc' }],
124129
});
130+
131+
const createUserList = await this.prismaService.user.findMany({
132+
where: { id: { in: baseList.map((base) => base.createdBy) } },
133+
select: { id: true, name: true, avatar: true },
134+
});
135+
const createUserMap = keyBy(createUserList, 'id');
136+
125137
return baseList.map((base) => {
126138
const role = roleMap[base.id] || roleMap[base.spaceId];
127-
return { ...base, role };
139+
const createUser = createUserMap[base.createdBy];
140+
return {
141+
...base,
142+
role,
143+
createdUser: {
144+
...createUser,
145+
avatar: createUser?.avatar && getPublicFullStorageUrl(createUser.avatar),
146+
},
147+
};
128148
});
129149
}
130150

apps/nestjs-backend/src/features/space/space.service.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ import type {
1919
IUpdateSpaceRo,
2020
} from '@teable/openapi';
2121
import { ResourceType, CollaboratorType, PrincipalType, IntegrationType } from '@teable/openapi';
22-
import { map } from 'lodash';
22+
import { keyBy, map } from 'lodash';
2323
import { ClsService } from 'nestjs-cls';
2424
import { ThresholdConfig, IThresholdConfig } from '../../configs/threshold.config';
2525
import { CustomHttpException } from '../../custom.exception';
2626
import { PerformanceCache, PerformanceCacheService } from '../../performance-cache';
2727
import { generateIntegrationCacheKey } from '../../performance-cache/generate-keys';
2828
import type { IClsStore } from '../../types/cls';
29+
import { getPublicFullStorageUrl } from '../attachments/plugins/utils';
2930
import { PermissionService } from '../auth/permission.service';
3031
import { BaseService } from '../base/base.service';
3132
import { CollaboratorService } from '../collaborator/collaborator.service';
3233
import { SettingOpenApiService } from '../setting/open-api/setting-open-api.service';
3334
import { SettingService } from '../setting/setting.service';
34-
3535
@Injectable()
3636
export class SpaceService {
3737
constructor(
@@ -267,6 +267,8 @@ export class SpaceService {
267267
order: true,
268268
spaceId: true,
269269
icon: true,
270+
createdBy: true,
271+
lastModifiedTime: true,
270272
},
271273
where: {
272274
spaceId,
@@ -277,9 +279,23 @@ export class SpaceService {
277279
},
278280
});
279281

282+
const createUserList = await this.prismaService.user.findMany({
283+
where: { id: { in: baseList.map((base) => base.createdBy) } },
284+
select: { id: true, name: true, avatar: true },
285+
});
286+
const createUserMap = keyBy(createUserList, 'id');
287+
280288
return baseList.map((base) => {
281289
const role = roleMap[base.id] || roleMap[base.spaceId];
282-
return { ...base, role };
290+
const createUser = createUserMap[base.createdBy];
291+
return {
292+
...base,
293+
role,
294+
createdUser: {
295+
...createUser,
296+
avatar: createUser?.avatar && getPublicFullStorageUrl(createUser.avatar),
297+
},
298+
};
283299
});
284300
}
285301

apps/nestjs-backend/src/features/trash/trash.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ export class TrashService {
9090
}
9191

9292
async getTrash(trashRo: ITrashRo) {
93-
const { resourceType } = trashRo;
93+
const { resourceType, spaceId } = trashRo;
9494

9595
switch (resourceType) {
9696
case ResourceType.Space:
9797
return await this.getSpaceTrash();
9898
case ResourceType.Base:
99-
return await this.getBaseTrash();
99+
return await this.getBaseTrash(spaceId);
100100
default:
101101
throw new CustomHttpException(
102102
`Invalid resource type ${resourceType}`,
@@ -150,10 +150,10 @@ export class TrashService {
150150
};
151151
}
152152

153-
private async getBaseTrash() {
153+
private async getBaseTrash(spaceId?: string) {
154154
const { bases } = await this.getAuthorizedSpacesAndBases();
155155
const baseIds = bases.map((base) => base.id);
156-
const spaceIds = bases.map((base) => base.spaceId);
156+
const spaceIds = spaceId ? [spaceId] : bases.map((base) => base.spaceId);
157157
const baseIdMap = keyBy(bases, 'id');
158158

159159
const trashedSpaces = await this.prismaService.trash.findMany({

apps/nestjs-backend/src/features/user/last-visit/last-visit.service.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,33 @@ export class LastVisitService {
7979
};
8080
}
8181

82+
async spaceVisit(userId: string, parentResourceId: string) {
83+
const lastVisit = await this.prismaService.userLastVisit.findFirst({
84+
where: {
85+
userId,
86+
parentResourceId,
87+
resourceType: LastVisitResourceType.Space,
88+
},
89+
orderBy: {
90+
lastVisitTime: 'desc',
91+
},
92+
take: 1,
93+
select: {
94+
resourceId: true,
95+
resourceType: true,
96+
},
97+
});
98+
99+
if (lastVisit) {
100+
return {
101+
resourceId: lastVisit.resourceId,
102+
resourceType: lastVisit.resourceType as LastVisitResourceType,
103+
};
104+
}
105+
106+
return undefined;
107+
}
108+
82109
async tableVisit(userId: string, baseId: string): Promise<IUserLastVisitVo | undefined> {
83110
const knex = this.knex;
84111

@@ -404,6 +431,7 @@ export class LastVisitService {
404431
resourceIcon: 'b.icon',
405432
resourceRole: 'c.role_name',
406433
spaceId: 's.id',
434+
createBy: 'b.created_by',
407435
})
408436
.from('user_last_visit as ulv')
409437
.join('base as b', function () {
@@ -436,6 +464,7 @@ export class LastVisitService {
436464
resourceIcon: string;
437465
resourceRole: IRole;
438466
spaceId: string;
467+
createBy: string;
439468
}[]
440469
>(query.toQuery());
441470

@@ -449,6 +478,7 @@ export class LastVisitService {
449478
icon: result.resourceIcon,
450479
role: result.resourceRole,
451480
spaceId: result.spaceId,
481+
createdBy: result.createBy,
452482
},
453483
}));
454484

@@ -463,6 +493,8 @@ export class LastVisitService {
463493
params: IGetUserLastVisitRo
464494
): Promise<IUserLastVisitVo | undefined> {
465495
switch (params.resourceType) {
496+
case LastVisitResourceType.Space:
497+
return this.spaceVisit(userId, params.parentResourceId);
466498
case LastVisitResourceType.Table:
467499
return this.tableVisit(userId, params.parentResourceId);
468500
case LastVisitResourceType.View:
@@ -495,7 +527,6 @@ export class LastVisitService {
495527
resourceType: LastVisitResourceType.Base,
496528
resourceId,
497529
parentResourceId,
498-
maxRecords: 10,
499530
});
500531
return;
501532
}

apps/nestjs-backend/src/types/i18n.generated.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ export type I18nTranslations = {
241241
"import": string;
242242
"expand": string;
243243
"deleteTip": string;
244+
"select": string;
244245
};
245246
"quickAction": {
246247
"title": string;
@@ -846,6 +847,7 @@ export type I18nTranslations = {
846847
"resetTrashConfirm": string;
847848
"addToTrash": string;
848849
"description": string;
850+
"spaceTrash": string;
849851
};
850852
"pluginCenter": {
851853
"pluginUrlEmpty": string;
@@ -2693,6 +2695,14 @@ export type I18nTranslations = {
26932695
"title": string;
26942696
"description": string;
26952697
};
2698+
"baseList": {
2699+
"allBases": string;
2700+
"owner": string;
2701+
"lastOpened": string;
2702+
"enter": string;
2703+
"noTables": string;
2704+
"empty": string;
2705+
};
26962706
};
26972707
"system": {
26982708
"notFound": {

0 commit comments

Comments
 (0)