Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exclude field ids #608

Merged
merged 4 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Reflector } from '@nestjs/core';
import { type PermissionAction } from '@teable/core';
import { ClsService } from 'nestjs-cls';
import type { IClsStore } from '../../../types/cls';
import { IS_DISABLED_PERMISSION } from '../decorators/disabled-permisison.decorator';
import { IS_DISABLED_PERMISSION } from '../decorators/disabled-permission.decorator';
import { PERMISSIONS_KEY } from '../decorators/permissions.decorator';
import { IS_PUBLIC_KEY } from '../decorators/public.decorator';
import type { IResourceMeta } from '../decorators/resource_meta.decorator';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@ export class SelectionService {
}

private async columnSelectionToIds(tableId: string, query: IRangesToIdQuery): Promise<string[]> {
const { type, viewId, ranges } = query;
const { type, viewId, ranges, excludeFieldIds } = query;
const result = await this.fieldService.getDocIdsByQuery(tableId, {
viewId,
filterHidden: true,
excludeFieldIds,
});

if (type === RangeType.Rows) {
Expand Down Expand Up @@ -657,6 +658,7 @@ export class SelectionService {
const fields = await this.fieldService.getFieldInstances(tableId, {
viewId,
filterHidden: true,
excludeFieldIds: rangesRo.excludeFieldIds,
});

const tableSize: [number, number] = [fields.length, rowCountInView];
Expand Down
25 changes: 17 additions & 8 deletions apps/nestjs-backend/src/share-db/share-db.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ export class ShareDbAdapter extends ShareDb.DB {
projection,
undefined,
(error, snapshots) => {
if (error) {
return callback(error, []);
}
callback(
error,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Expand Down Expand Up @@ -185,6 +188,7 @@ export class ShareDbAdapter extends ShareDb.DB {
callback(null, this.snapshots2Map(snapshots));
}
} catch (err) {
this.logger.error(err);
callback(exceptionParse(err as Error));
}
}
Expand All @@ -193,16 +197,21 @@ export class ShareDbAdapter extends ShareDb.DB {
collection: string,
id: string,
projection: IProjection | undefined,
options: unknown,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
options: any,
callback: (err: unknown, data?: Snapshot) => void
) {
this.getSnapshotBulk(collection, [id], projection, options, (err, data) => {
if (err) {
callback(err);
} else {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
callback(null, data![id]);
}
await this.cls.runWith(this.cls.get(), async () => {
this.cls.set('cookie', options.cookie);
this.cls.set('shareViewId', options.shareId);
this.getSnapshotBulk(collection, [id], projection, options, (err, data) => {
if (err) {
callback(err);
} else {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
callback(null, data![id]);
}
});
});
}

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/models/field/field.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ export const getFieldsQuerySchema = z.object({
description: 'The id of the view.',
}),
filterHidden: z.coerce.boolean().optional(),
filterDenied: z.coerce.boolean().optional(),
excludeFieldIds: z.array(z.string().startsWith(IdPrefix.Field)).optional(),
});

Expand Down