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

feat: Column.excludeFieldFromQuery, exclude field but keep fields array #1217

Merged
merged 5 commits into from
Nov 25, 2023
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
5 changes: 4 additions & 1 deletion packages/common/src/interfaces/column.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ export interface Column<T = any> {
/** Default to false, which leads to exclude the column title from the Grid Menu. */
excludeFromGridMenu?: boolean;

/** Defaults to false, which leads to exclude the field from the query (typically a backend service query) */
/** Defaults to false, which leads to exclude the `field` property, but still includes the `fields` property, from the query (typically a backend service query) */
excludeFieldFromQuery?: boolean;

/** Defaults to false, which leads to exclude the `field` (and `fields`) from the query (typically a backend service query) */
excludeFromQuery?: boolean;

/** Defaults to false, which leads to exclude the column from getting a header menu. For example, the checkbox row selection should not have a header menu. */
Expand Down
14 changes: 14 additions & 0 deletions packages/graphql/src/services/__tests__/graphql.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,20 @@ describe('GraphqlService', () => {
expect(removeSpaces(query)).toBe(removeSpaces(expectation));
});

it('should exclude a column field, and expect a query string without it, but still include any fields specified', () => {
const expectation = `query{ users(first:10, offset:0){ totalCount, nodes{ id, field1, field3, field4, field5 }}}`;
const columns = [
{ id: 'field1', field: 'field1', width: 100 },
{ id: 'field2', field: 'field2', fields: ['field3', 'field4', 'field5'], width: 100, excludeFieldFromQuery: true }
];
jest.spyOn(gridStub, 'getColumns').mockReturnValue(columns);

service.init({ datasetName: 'users' }, paginationOptions, gridStub);
const query = service.buildQuery();

expect(removeSpaces(query)).toBe(removeSpaces(expectation));
});

it('should use default pagination "first" option when "paginationOptions" is not provided', () => {
const expectation = `query{ users(first:${DEFAULT_ITEMS_PER_PAGE}, offset:0){ totalCount, nodes{ id, field1 }}}`;
const columns = [{ id: 'field1', field: 'field1', width: 100 }, { id: 'field2', field: 'field2', width: 100, excludeFromQuery: true }];
Expand Down
4 changes: 3 additions & 1 deletion packages/graphql/src/services/graphql.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ export class GraphqlService implements BackendService {
const columnIds: string[] = [];
if (columnDefinitions && Array.isArray(columnDefinitions)) {
for (const column of columnDefinitions) {
columnIds.push(column.field);
if (!column.excludeFieldFromQuery) {
columnIds.push(column.field);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you apply the same logic in the OData Service as well, they should have the same feature as much as possible

}

// if extra "fields" are passed, also push them to columnIds
if (column.fields) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ describe('GridOdataService', () => {

it('should use default pagination "$top" option when "paginationOptions" is not provided', () => {
const expectation = `$top=${DEFAULT_ITEMS_PER_PAGE}`;
const columns = [{ id: 'field1', field: 'field1', width: 100 }, { id: 'field2', field: 'field2', width: 100, excludeFromQuery: true }];
const columns = [
{ id: 'field1', field: 'field1', width: 100 },
{ id: 'field2', field: 'field2', width: 100, excludeFromQuery: true },
{ id: 'field3', field: 'field3', fields: ['field4', 'field5', 'field6'], width: 100, excludeFieldFromQuery: true }
];
jest.spyOn(gridStub, 'getColumns').mockReturnValue(columns);

service.init(null as any, undefined, gridStub);
Expand Down