-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat(lastViewAt): add recently view on company #15072
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
02586f5
feat(redis): introduce redis-backed `lastViewedAt` field and metadata…
AMoreaux a8092d0
feat(audit): add `Object Record Viewed` event tracking and optimize `…
AMoreaux 525d014
Merge remote-tracking branch 'origin/main' into feat/add-recently-view
AMoreaux 1951e60
chore(graphql): fix formatting inconsistencies and cleanup unused tes…
AMoreaux 5961867
feat(orm): add `storage
AMoreaux 50c20f4
Merge remote-tracking branch 'origin/main' into feat/add-recently-view
AMoreaux a57c4f0
refactor(frontend/server): remove `RecordShowContent` component and e…
AMoreaux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...database/typeorm/core/migrations/common/1760458320000-add-fieldmetadata-storage-column.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { type MigrationInterface, type QueryRunner } from 'typeorm'; | ||
|
|
||
| export class AddFieldMetadataStorageColumn1760458320000 | ||
| implements MigrationInterface | ||
| { | ||
| name = 'AddFieldMetadataStorageColumn1760458320000'; | ||
|
|
||
| public async up(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query( | ||
| `ALTER TABLE "core"."fieldMetadata" ADD COLUMN "storage" character varying`, | ||
| ); | ||
| } | ||
|
|
||
| public async down(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query( | ||
| `ALTER TABLE "core"."fieldMetadata" DROP COLUMN "storage"`, | ||
| ); | ||
| } | ||
| } |
255 changes: 255 additions & 0 deletions
255
...graphql/graphql-query-runner/graphql-query-parsers/__tests__/graphql-query.parser.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,255 @@ | ||
| import { faker } from '@faker-js/faker'; | ||
|
|
||
| import { GraphqlQueryParser } from 'src/engine/api/graphql/graphql-query-runner/graphql-query-parsers/graphql-query.parser'; | ||
| import { GraphqlQueryFilterConditionParser } from 'src/engine/api/graphql/graphql-query-runner/graphql-query-parsers/graphql-query-filter/graphql-query-filter-condition.parser'; | ||
| import { GraphqlQueryOrderFieldParser } from 'src/engine/api/graphql/graphql-query-runner/graphql-query-parsers/graphql-query-order/graphql-query-order.parser'; | ||
| import { GraphqlQuerySelectedFieldsParser } from 'src/engine/api/graphql/graphql-query-runner/graphql-query-parsers/graphql-query-selected-fields/graphql-selected-fields.parser'; | ||
| import { | ||
| GraphqlQueryRunnerException, | ||
| GraphqlQueryRunnerExceptionCode, | ||
| } from 'src/engine/api/graphql/graphql-query-runner/errors/graphql-query-runner.exception'; | ||
| import { type ObjectMetadataMaps } from 'src/engine/metadata-modules/types/object-metadata-maps'; | ||
| import { type ObjectMetadataItemWithFieldMaps } from 'src/engine/metadata-modules/types/object-metadata-item-with-field-maps'; | ||
| import { getMockObjectMetadataItemWithFieldsMaps } from 'src/utils/__test__/get-object-metadata-item-with-fields-maps.mock'; | ||
|
|
||
| // Minimal chainable query builder mock | ||
| const createQueryBuilderMock = () => { | ||
| const qb: any = { | ||
| withDeleted: jest.fn().mockReturnThis(), | ||
| orderBy: jest.fn().mockReturnThis(), | ||
| addOrderBy: jest.fn().mockReturnThis(), | ||
| }; | ||
|
|
||
| return qb; | ||
| }; | ||
|
|
||
| describe('GraphqlQueryParser', () => { | ||
| let objectMetadataMaps: ObjectMetadataMaps; | ||
| let objectMetadataItem: ObjectMetadataItemWithFieldMaps; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
|
|
||
| const nameSingular = 'mockObject'; | ||
| const objectId = faker.string.uuid(); | ||
|
|
||
| objectMetadataItem = getMockObjectMetadataItemWithFieldsMaps({ | ||
| id: objectId, | ||
| nameSingular, | ||
| namePlural: `${nameSingular}s`, | ||
| workspaceId: faker.string.uuid(), | ||
| fieldsById: {}, | ||
| fieldIdByJoinColumnName: {}, | ||
| fieldIdByName: {}, | ||
| indexMetadatas: [], | ||
| }); | ||
|
|
||
| objectMetadataMaps = { | ||
| byId: { [objectId]: objectMetadataItem }, | ||
| idByNameSingular: { [nameSingular]: objectId }, | ||
| }; | ||
| }); | ||
|
|
||
| describe('applyDeletedAtToBuilder', () => { | ||
| test('calls withDeleted when deletedAt filter at top-level', () => { | ||
| const qb = createQueryBuilderMock(); | ||
| const parser = new GraphqlQueryParser( | ||
| objectMetadataItem, | ||
| objectMetadataMaps, | ||
| ); | ||
|
|
||
| parser.applyDeletedAtToBuilder(qb as any, { deletedAt: null } as any); | ||
|
|
||
| expect(qb.withDeleted).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| test('calls withDeleted when deletedAt filter nested in object', () => { | ||
| const qb = createQueryBuilderMock(); | ||
| const parser = new GraphqlQueryParser( | ||
| objectMetadataItem, | ||
| objectMetadataMaps, | ||
| ); | ||
|
|
||
| parser.applyDeletedAtToBuilder( | ||
| qb as any, | ||
| { some: { deep: { path: { deletedAt: { $ne: null } } } } } as any, | ||
| ); | ||
|
|
||
| expect(qb.withDeleted).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| test('calls withDeleted when deletedAt filter present in array', () => { | ||
| const qb = createQueryBuilderMock(); | ||
| const parser = new GraphqlQueryParser( | ||
| objectMetadataItem, | ||
| objectMetadataMaps, | ||
| ); | ||
|
|
||
| parser.applyDeletedAtToBuilder( | ||
| qb as any, | ||
| [{ a: 1 }, { deletedAt: 1 }] as any, | ||
| ); | ||
|
|
||
| expect(qb.withDeleted).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| test('does not call withDeleted when deletedAt is absent', () => { | ||
| const qb = createQueryBuilderMock(); | ||
| const parser = new GraphqlQueryParser( | ||
| objectMetadataItem, | ||
| objectMetadataMaps, | ||
| ); | ||
|
|
||
| parser.applyDeletedAtToBuilder(qb as any, { foo: 'bar' } as any); | ||
|
|
||
| expect(qb.withDeleted).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('applyOrderToBuilder', () => { | ||
| test('delegates to orderBy with parsed order when not grouped', () => { | ||
| const qb = createQueryBuilderMock(); | ||
| const parser = new GraphqlQueryParser( | ||
| objectMetadataItem, | ||
| objectMetadataMaps, | ||
| ); | ||
|
|
||
| const parsed = { 't.name': 'ASC', 't.createdAt': 'DESC' } as any; | ||
| const orderSpy = jest | ||
| .spyOn(GraphqlQueryOrderFieldParser.prototype, 'parse') | ||
| .mockReturnValue(parsed); | ||
|
|
||
| const returned = parser.applyOrderToBuilder( | ||
| qb as any, | ||
| { name: 'AscNullsLast' } as any, | ||
| objectMetadataItem.nameSingular, | ||
| true, | ||
| ); | ||
|
|
||
| expect(orderSpy).toHaveBeenCalledWith( | ||
| { name: 'AscNullsLast' }, | ||
| objectMetadataItem.nameSingular, | ||
| true, | ||
| false, | ||
| ); | ||
| expect(qb.orderBy).toHaveBeenCalledWith(parsed); | ||
| expect(returned).toBe(qb); | ||
| }); | ||
|
|
||
| test('uses orderBy then addOrderBy when grouped', () => { | ||
| const qb = createQueryBuilderMock(); | ||
| const parser = new GraphqlQueryParser( | ||
| objectMetadataItem, | ||
| objectMetadataMaps, | ||
| ); | ||
|
|
||
| const parsedGrouped = { | ||
| 'COUNT(t.id)': { order: 'ASC', nulls: 'NULLS LAST' }, | ||
| 't.name': { order: 'DESC', nulls: undefined }, | ||
| } as const; | ||
|
|
||
| jest | ||
| .spyOn(GraphqlQueryOrderFieldParser.prototype, 'parse') | ||
| .mockReturnValue(parsedGrouped); | ||
|
|
||
| const returned = parser.applyOrderToBuilder( | ||
| qb as any, | ||
| { name: 'AscNullsLast' } as any, | ||
| objectMetadataItem.nameSingular, | ||
| true, | ||
| ); | ||
|
|
||
| const entries = Object.entries(parsedGrouped); | ||
|
|
||
| expect(qb.orderBy).toHaveBeenCalledWith( | ||
| entries[0][0], | ||
| entries[0][1].order, | ||
| entries[0][1].nulls, | ||
| ); | ||
| expect(qb.addOrderBy).toHaveBeenCalledWith( | ||
| entries[1][0], | ||
| entries[1][1].order, | ||
| entries[1][1].nulls, | ||
| ); | ||
| expect(returned).toBe(qb); | ||
| }); | ||
| }); | ||
|
|
||
| describe('applyFilterToBuilder', () => { | ||
| test('delegates to filter condition parser and returns its result', () => { | ||
| const qb = createQueryBuilderMock(); | ||
| const newQb = { ...createQueryBuilderMock(), marker: 'returned' } as any; | ||
| const parser = new GraphqlQueryParser( | ||
| objectMetadataItem, | ||
| objectMetadataMaps, | ||
| ); | ||
|
|
||
| const filterSpy = jest | ||
| .spyOn(GraphqlQueryFilterConditionParser.prototype, 'parse') | ||
| .mockReturnValue(newQb); | ||
|
|
||
| const result = parser.applyFilterToBuilder( | ||
| qb as any, | ||
| objectMetadataItem.nameSingular, | ||
| { id: { eq: '1' } } as any, | ||
| ); | ||
|
|
||
| expect(filterSpy).toHaveBeenCalledWith( | ||
| qb, | ||
| objectMetadataItem.nameSingular, | ||
| { id: { eq: '1' } }, | ||
| ); | ||
| expect(result).toBe(newQb); | ||
| }); | ||
| }); | ||
|
|
||
| describe('parseSelectedFields', () => { | ||
| test('throws when object metadata for parent is not found', () => { | ||
| const missingMaps: ObjectMetadataMaps = { | ||
| byId: {}, | ||
| idByNameSingular: {}, | ||
| }; | ||
| const parser = new GraphqlQueryParser(objectMetadataItem, missingMaps); | ||
|
|
||
| expect(() => | ||
| parser.parseSelectedFields(objectMetadataItem, { id: {} }, missingMaps), | ||
| ).toThrow(GraphqlQueryRunnerException); | ||
|
|
||
| try { | ||
| parser.parseSelectedFields(objectMetadataItem, { id: {} }, missingMaps); | ||
| } catch (e) { | ||
| const err = e as GraphqlQueryRunnerException; | ||
|
|
||
| expect(err.code).toBe( | ||
| GraphqlQueryRunnerExceptionCode.OBJECT_METADATA_NOT_FOUND, | ||
| ); | ||
| expect(err.message).toContain(objectMetadataItem.nameSingular); | ||
| } | ||
| }); | ||
|
|
||
| test('delegates to GraphqlQuerySelectedFieldsParser when metadata exists', () => { | ||
| const parser = new GraphqlQueryParser( | ||
| objectMetadataItem, | ||
| objectMetadataMaps, | ||
| ); | ||
| const selectedFieldsResult = { | ||
| selectedColumns: ['t.id'], | ||
| selectedRelations: {}, | ||
| selectedAggregates: {}, | ||
| } as any; | ||
|
|
||
| const selectedSpy = jest | ||
| .spyOn(GraphqlQuerySelectedFieldsParser.prototype, 'parse') | ||
| .mockReturnValue(selectedFieldsResult); | ||
|
|
||
| const result = parser.parseSelectedFields( | ||
| objectMetadataItem, | ||
| { id: {} }, | ||
| objectMetadataMaps, | ||
| ); | ||
|
|
||
| expect(selectedSpy).toHaveBeenCalled(); | ||
| expect(result).toBe(selectedFieldsResult); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already track pageviews, can't we infer it from that or do something smarter rather than send 2 extremely similar track events?
We could either stop tracking unstructured pageviews and only store events like that ; or we could eventually let the endpoint support an array and send 2 events at once...? I think I prefer solution 1