-
Notifications
You must be signed in to change notification settings - Fork 0
feat(ag-grid-angular-theme): added row (row group) state and store directives (#DS-5046) #195
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import { ChangeDetectionStrategy, Component, inject } from '@angular/core'; | ||
| import { | ||
| KbqAgGridRowFocusStateLocalStorageStore, | ||
| KbqAgGridRowFocusStateQueryParamsStore, | ||
| KbqAgGridThemeModule | ||
| } from '@koobiq/ag-grid-angular-theme'; | ||
| import { AgGridModule } from 'ag-grid-angular'; | ||
| import { AllCommunityModule, ColDef, GetRowIdFunc, ModuleRegistry } from 'ag-grid-community'; | ||
| import { DevRowData, devInjectRowData } from '../row-data'; | ||
|
|
||
| ModuleRegistry.registerModules([AllCommunityModule]); | ||
|
|
||
| const COLUMN_DEFS: ColDef[] = [ | ||
| { field: 'athlete', headerName: 'Athlete' }, | ||
| { field: 'age', headerName: 'Age' }, | ||
| { field: 'country', headerName: 'Country' }, | ||
| { field: 'year', headerName: 'Year' }, | ||
| { field: 'date', headerName: 'Date' }, | ||
| { field: 'sport', headerName: 'Sport' } | ||
| ]; | ||
|
|
||
| const DEFAULT_COL_DEF: ColDef = { | ||
| editable: true | ||
| }; | ||
|
|
||
| const GET_ROW_ID: GetRowIdFunc<DevRowData> = (params) => params.data.id; | ||
|
|
||
| const STATE_KEY = 'dev-ag-grid-row-focus-state'; | ||
|
|
||
| @Component({ | ||
| standalone: true, | ||
| imports: [AgGridModule, KbqAgGridThemeModule], | ||
| selector: 'dev-row-focus-state', | ||
| template: ` | ||
| <button type="button" (click)="rowFocusState.reset()">Reset state</button> | ||
| <ag-grid-angular | ||
| #rowFocusState="kbqAgGridRowFocusState" | ||
| data-testid="e2eScreenshotTarget" | ||
| kbqAgGridTheme | ||
| animateRows="false" | ||
| [getRowId]="getRowId" | ||
| [kbqAgGridRowFocusState]="stateKey" | ||
| [kbqAgGridRowFocusStateStore]="store" | ||
| [rowData]="rowData()" | ||
| [columnDefs]="columnDefs" | ||
| [defaultColDef]="defaultColDef" | ||
| /> | ||
| `, | ||
| styles: ` | ||
| ag-grid-angular { | ||
| height: 100%; | ||
| max-width: 2036px; | ||
| } | ||
| `, | ||
| changeDetection: ChangeDetectionStrategy.OnPush | ||
| }) | ||
| export class DevRowFocusState { | ||
| readonly rowData = devInjectRowData(); | ||
| readonly store = inject(KbqAgGridRowFocusStateLocalStorageStore); | ||
| readonly stateKey = STATE_KEY; | ||
| readonly columnDefs = COLUMN_DEFS; | ||
| readonly defaultColDef = DEFAULT_COL_DEF; | ||
| readonly getRowId = GET_ROW_ID; | ||
| } | ||
|
|
||
| @Component({ | ||
| standalone: true, | ||
| imports: [AgGridModule, KbqAgGridThemeModule], | ||
| selector: 'dev-row-focus-state-query-params', | ||
| template: ` | ||
| <button type="button" (click)="rowFocusState.reset()">Reset state</button> | ||
| <ag-grid-angular | ||
| #rowFocusState="kbqAgGridRowFocusState" | ||
| data-testid="e2eScreenshotTarget" | ||
| kbqAgGridTheme | ||
| animateRows="false" | ||
|
artembelik marked this conversation as resolved.
|
||
| [getRowId]="getRowId" | ||
| [kbqAgGridRowFocusState]="stateKey" | ||
| [kbqAgGridRowFocusStateStore]="store" | ||
| [rowData]="rowData()" | ||
| [columnDefs]="columnDefs" | ||
| [defaultColDef]="defaultColDef" | ||
| /> | ||
| `, | ||
| styles: ` | ||
| ag-grid-angular { | ||
| height: 100%; | ||
| max-width: 2036px; | ||
| } | ||
| `, | ||
| changeDetection: ChangeDetectionStrategy.OnPush | ||
| }) | ||
| export class DevRowFocusStateQueryParams { | ||
| readonly rowData = devInjectRowData(); | ||
| readonly store = inject(KbqAgGridRowFocusStateQueryParamsStore); | ||
| readonly stateKey = STATE_KEY; | ||
| readonly columnDefs = COLUMN_DEFS; | ||
| readonly defaultColDef = DEFAULT_COL_DEF; | ||
| readonly getRowId = GET_ROW_ID; | ||
| } | ||
105 changes: 105 additions & 0 deletions
105
dev/ag-grid-angular/src/tests/row-focus-state.playwright-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,105 @@ | ||
| import { expect, Page, test } from '@playwright/test'; | ||
| import { getCell, isCellFocused } from './utils/helpers'; | ||
|
|
||
| const rowFocusStateStorageKey = 'dev-ag-grid-row-focus-state'; | ||
| const rowFocusStateQueryParamKey = 'dev-ag-grid-row-focus-state'; | ||
|
|
||
| type StoredRowFocusState = { rowId: string; colId: string }; | ||
|
|
||
| const clearRowFocusState = async (page: Page): Promise<void> => { | ||
| await page.evaluate((key: string) => localStorage.removeItem(key), rowFocusStateStorageKey); | ||
| }; | ||
|
|
||
| const getRowFocusState = async (page: Page): Promise<StoredRowFocusState | null> => { | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
| return page.evaluate((key) => { | ||
| const stored = localStorage.getItem(key); | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
| return stored ? JSON.parse(stored) : null; | ||
| }, rowFocusStateStorageKey); | ||
| }; | ||
|
|
||
| const getRowFocusStateFromUrl = async (page: Page): Promise<StoredRowFocusState | null> => { | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
| return page.evaluate((key) => { | ||
| const item = new URLSearchParams(window.location.search).get(key); | ||
| if (!item) return null; | ||
|
|
||
| try { | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
| return JSON.parse(item); | ||
| } catch { | ||
| return null; | ||
| } | ||
| }, rowFocusStateQueryParamKey); | ||
| }; | ||
|
|
||
| const buildStateUrl = (state: StoredRowFocusState): string => { | ||
| const encoded = encodeURIComponent(JSON.stringify(state)); | ||
| return `/e2e/row-focus-state-query-params?${rowFocusStateQueryParamKey}=${encoded}`; | ||
| }; | ||
|
|
||
| test.describe('KbqAgGridRowFocusState', () => { | ||
| test.describe('KbqAgGridRowFocusStateLocalStorageStore', () => { | ||
| test('saves the active cell to localStorage when a cell is clicked', async ({ page }) => { | ||
| await page.goto('/e2e/row-focus-state'); | ||
| await clearRowFocusState(page); | ||
|
|
||
| await getCell(page, 0, 'athlete').click(); | ||
|
|
||
| await expect.poll(async () => (await getRowFocusState(page))?.colId).toBe('athlete'); | ||
| }); | ||
|
|
||
| test('restores the active cell from localStorage on page reload', async ({ page }) => { | ||
| await page.goto('/e2e/row-focus-state'); | ||
| await clearRowFocusState(page); | ||
|
|
||
| await getCell(page, 2, 'country').click(); | ||
| await expect.poll(async () => (await getRowFocusState(page))?.colId).toBe('country'); | ||
|
|
||
| await page.reload(); | ||
|
|
||
| await expect.poll(async () => isCellFocused(page, 2, 'country')).toBe(true); | ||
| }); | ||
|
|
||
| test('reset clears the active cell and stored state', async ({ page }) => { | ||
| await page.goto('/e2e/row-focus-state'); | ||
| await clearRowFocusState(page); | ||
|
|
||
| await getCell(page, 0, 'athlete').click(); | ||
| await expect.poll(async () => isCellFocused(page, 0, 'athlete')).toBe(true); | ||
|
|
||
| await page.getByRole('button', { name: 'Reset state' }).click(); | ||
|
|
||
| await expect.poll(async () => isCellFocused(page, 0, 'athlete')).toBe(false); | ||
| await expect.poll(async () => getRowFocusState(page)).toBeNull(); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('KbqAgGridRowFocusStateQueryParamsStore', () => { | ||
| test('saves the active cell to URL when a cell is clicked', async ({ page }) => { | ||
| await page.goto('/e2e/row-focus-state-query-params'); | ||
|
|
||
| await getCell(page, 0, 'athlete').click(); | ||
|
|
||
| await expect.poll(async () => (await getRowFocusStateFromUrl(page))?.colId).toBe('athlete'); | ||
| }); | ||
|
|
||
| test('restores the active cell from URL on page reload', async ({ page }) => { | ||
| await page.goto('/e2e/row-focus-state-query-params'); | ||
|
|
||
| await getCell(page, 2, 'country').click(); | ||
| await expect.poll(async () => (await getRowFocusStateFromUrl(page))?.colId).toBe('country'); | ||
|
|
||
| await page.reload(); | ||
|
|
||
| await expect.poll(async () => isCellFocused(page, 2, 'country')).toBe(true); | ||
| }); | ||
|
|
||
| test('applies pre-existing active cell from URL on page load', async ({ page }) => { | ||
| await page.goto(buildStateUrl({ rowId: '4f32fc42-54ea-4afe-bcb3-d3e15fff11a5', colId: 'athlete' })); | ||
|
|
||
| await expect.poll(async () => isCellFocused(page, 0, 'athlete')).toBe(true); | ||
| }); | ||
| }); | ||
| }); |
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.
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.