-
Notifications
You must be signed in to change notification settings - Fork 260
fix(databases): redirect legacy collection links to tables #3196
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
Open
HarshMN2345
wants to merge
3
commits into
main
Choose a base branch
from
codex/sentry-legacy-collection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+153
−8
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
119 changes: 119 additions & 0 deletions
119
...t-[region]-[project]/databases/database-[database]/collection-[collection]/layout.test.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,119 @@ | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
| import type { DatabaseType } from '$database/(entity)/helpers/terminology'; | ||
| import { get } from 'svelte/store'; | ||
| import { load } from './+layout'; | ||
| import { load as loadRecord } from '../[...rest]/+page'; | ||
| import { databaseRowSheetOptions } from '../table-[table]/store'; | ||
| import { noSqlDocument } from './store'; | ||
|
|
||
| const { getEntity } = vi.hoisted(() => ({ getEntity: vi.fn() })); | ||
|
|
||
| vi.mock('./header.svelte', () => ({ default: {} })); | ||
| vi.mock('$database/(entity)', async () => { | ||
| const { toDatabaseType } = await import('$database/(entity)/helpers/terminology'); | ||
| return { | ||
| Breadcrumbs: {}, | ||
| toDatabaseType, | ||
| useDatabaseSdk: () => ({ getEntity }) | ||
| }; | ||
| }); | ||
|
|
||
| const params = { region: 'fra', project: 'project', database: 'database', collection: 'items' }; | ||
| const databasePath = '/console/project-fra-project/databases/database-database'; | ||
|
|
||
| function event(type: DatabaseType, suffix = '') { | ||
| return { | ||
| params, | ||
| depends: vi.fn(), | ||
| parent: async () => ({ database: { $id: params.database, type } }), | ||
| url: new URL(`https://console.example${databasePath}/collection-items${suffix}`) | ||
| } as unknown as Parameters<typeof load>[0]; | ||
| } | ||
|
|
||
| function recordEvent(type: DatabaseType, rest: string) { | ||
| return { | ||
| ...event(type), | ||
| params: { ...params, rest }, | ||
| url: new URL(`https://console.example${databasePath}/${rest}?limit=50`) | ||
| } as unknown as Parameters<typeof loadRecord>[0]; | ||
| } | ||
|
|
||
| describe('collection layout', () => { | ||
| beforeEach(() => { | ||
| getEntity.mockReset(); | ||
| databaseRowSheetOptions.update((options) => ({ ...options, show: false, rowId: null })); | ||
| noSqlDocument.reset(); | ||
| }); | ||
|
|
||
| it.each([ | ||
| ['legacy', ''], | ||
| ['legacy', '/indexes?search=name'], | ||
| ['legacy', '/settings'], | ||
| ['legacy', '/export'], | ||
| ['tablesdb', '?limit=50&query=%5B%5D'] | ||
| ] as const)('redirects %s collection links to the table page (%s)', async (type, suffix) => { | ||
| await expect(load(event(type, suffix))).rejects.toMatchObject({ | ||
| status: 308, | ||
| location: `${databasePath}/table-items${suffix}` | ||
| }); | ||
| }); | ||
|
|
||
| it.each(['documentsdb', 'vectorsdb'] as const)('loads a %s collection', async (type) => { | ||
| const collection = { $id: params.collection, name: 'Items' }; | ||
| getEntity.mockResolvedValue(collection); | ||
|
|
||
| const result = await load(event(type)); | ||
|
|
||
| expect(result).toMatchObject({ collection }); | ||
| }); | ||
|
|
||
| it.each(['legacy', 'tablesdb'] as const)( | ||
| 'opens the requested row after following a %s document link', | ||
| async (type) => { | ||
| await expect( | ||
| loadRecord(recordEvent(type, 'collection-items/document-record')) | ||
| ).rejects.toMatchObject({ | ||
| status: 308, | ||
| location: `${databasePath}/collection-items?limit=50` | ||
| }); | ||
| await expect(load(event(type, '?limit=50'))).rejects.toMatchObject({ | ||
| status: 308, | ||
| location: `${databasePath}/table-items?limit=50` | ||
| }); | ||
|
|
||
| expect(get(databaseRowSheetOptions)).toMatchObject({ | ||
| rowId: 'record', | ||
| show: true, | ||
| title: 'Update row' | ||
| }); | ||
| expect(get(noSqlDocument).documentId).toBeNull(); | ||
| } | ||
| ); | ||
|
|
||
| it.each(['documentsdb', 'vectorsdb'] as const)( | ||
| 'keeps a %s document link on the collection sheet', | ||
| async (type) => { | ||
| await expect( | ||
| loadRecord(recordEvent(type, 'collection-items/document-record')) | ||
| ).rejects.toMatchObject({ | ||
| status: 308, | ||
| location: `${databasePath}/collection-items?limit=50` | ||
| }); | ||
|
|
||
| expect(get(noSqlDocument).documentId).toBe('record'); | ||
| expect(get(databaseRowSheetOptions).show).toBe(false); | ||
| } | ||
| ); | ||
|
|
||
| it('keeps table row links working', async () => { | ||
| await expect( | ||
| loadRecord(recordEvent('tablesdb', 'table-items/row-record')) | ||
| ).rejects.toMatchObject({ | ||
| status: 308, | ||
| location: `${databasePath}/table-items?limit=50` | ||
| }); | ||
|
|
||
| expect(get(databaseRowSheetOptions)).toMatchObject({ rowId: 'record', show: true }); | ||
| expect(get(noSqlDocument).documentId).toBeNull(); | ||
| }); | ||
| }); | ||
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.
Uh oh!
There was an error while loading. Please reload this page.