Skip to content

Commit

Permalink
fix: exclude field ids (#608)
Browse files Browse the repository at this point in the history
* fix: add missing parameters

* chore: rename error words

* chore: optimize some bugs and parameters

* fix: getSnapshot trigger getSnapshotBulk
  • Loading branch information
boris-w committed May 20, 2024
1 parent 6a85eb7 commit 6ea342b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
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

0 comments on commit 6ea342b

Please sign in to comment.