Skip to content

Commit

Permalink
fix(components/ag-grid): address deprecation warnings (#2788)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhwhite authored Oct 1, 2024
1 parent 92caefc commit c9695da
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export class DemoComponent {
constructor() {
const gridOptions: GridOptions = {
columnDefs: this.#columnDefs,
rowSelection: 'multiple',
};

this.gridOptions = this.#agGridSvc.getGridOptions({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class DemoComponent {
constructor() {
const gridOptions: GridOptions = {
columnDefs: this.#columnDefs,
rowSelection: 'single',
selection: { mode: 'singleRow' },
};

this.gridOptions = this.#agGridSvc.getGridOptions({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ export class ViewGridComponent implements OnInit, OnDestroy {
this.gridOptions = this.#agGridSvc.getGridOptions({
gridOptions: {
columnDefs: this.#columnDefs,
rowSelection: 'multiple',
onGridReady: this.onGridReady.bind(this),
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ export class ViewGridComponent implements OnInit, OnDestroy {
this.gridOptions = this.#agGridSvc.getGridOptions({
gridOptions: {
columnDefs: this.#columnDefs,
rowSelection: 'single',
onGridReady: this.onGridReady.bind(this),
selection: { mode: 'singleRow' },
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class DemoComponent implements OnInit, OnDestroy {
onGridReady: (gridReadyEvent): void => {
this.onGridReady(gridReadyEvent);
},
rowSelection: 'single',
selection: { mode: 'singleRow' },
pagination: true,
suppressPaginationPanel: true,
paginationPageSize: this.pageSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,6 @@ export class EditComplexCellsComponent implements OnInit {
onGridSizeChanged: () => {
this.sizeGrid();
},
rowSelection: 'multiple',
suppressColumnVirtualisation: true,
stopEditingWhenCellsLoseFocus: false,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,28 @@ describe('SkyAgGridService', () => {
?.enableCellTextSelection,
).toBeFalsy();
});

it('should update selection options', () => {
expect(
agGridService.getGridOptions({
gridOptions: { rowSelection: 'single' },
}),
).toEqual(
jasmine.objectContaining({
selection: { mode: 'singleRow' },
}),
);

expect(
agGridService.getGridOptions({
gridOptions: { enableRangeSelection: true },
}),
).toEqual(
jasmine.objectContaining({
selection: { mode: 'cell' },
}),
);
});
});

describe('getEditableGridOptions', () => {
Expand All @@ -338,6 +360,7 @@ describe('SkyAgGridService', () => {
});

expect(editableGridOptions.rowSelection).toBeUndefined();
expect(editableGridOptions.selection).toBeUndefined();
});
});

Expand Down
32 changes: 25 additions & 7 deletions libs/components/ag-grid/src/lib/modules/ag-grid/ag-grid.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,21 @@ export class SkyAgGridService implements OnDestroy {
defaultGridOptions: GridOptions,
providedGridOptions: GridOptions,
): GridOptions {
if (
!providedGridOptions.selection &&
('rowSelection' in providedGridOptions ||
'enableRangeSelection' in providedGridOptions)
) {
if (providedGridOptions.rowSelection === 'single') {
providedGridOptions.selection = { mode: 'singleRow' };
}
if (providedGridOptions.enableRangeSelection) {
providedGridOptions.selection = { mode: 'cell' };
}
delete providedGridOptions.rowSelection;
delete providedGridOptions.enableRangeSelection;
}

const mergedGridOptions: GridOptions = {
...defaultGridOptions,
...providedGridOptions,
Expand Down Expand Up @@ -232,13 +247,14 @@ export class SkyAgGridService implements OnDestroy {
...defaultGridOptions.icons,
...providedGridOptions.icons,
},
selection: providedGridOptions.selection ?? defaultGridOptions.selection,
};

// Enable text selection unless explicitly disabled or conflicting with another setting.
if (
mergedGridOptions.enableCellTextSelection ||
(!('enableCellTextSelection' in mergedGridOptions) &&
!mergedGridOptions.enableRangeSelection &&
mergedGridOptions.selection?.mode !== 'cell' &&
!mergedGridOptions.columnDefs?.some((col: ColDef) => col.editable))
) {
mergedGridOptions.context ||= {};
Expand Down Expand Up @@ -516,11 +532,15 @@ export class SkyAgGridService implements OnDestroy {
},
loadingOverlayComponent: SkyAgGridLoadingComponent,
onCellFocused: () => this.#onCellFocused(),
rowMultiSelectWithClick: true,
rowSelection: 'multiple',
selection: {
mode: 'multiRow',
enableClickSelection: false,
enableMultiSelectWithClick: true,
checkboxes: false,
headerCheckbox: false,
},
singleClickEdit: true,
sortingOrder: ['desc', 'asc', null],
suppressRowClickSelection: true,
suppressDragLeaveHidesColumns: true,
};

Expand Down Expand Up @@ -597,9 +617,7 @@ export class SkyAgGridService implements OnDestroy {

#getDefaultEditableGridOptions(args: SkyGetGridOptionsArgs): GridOptions {
const defaultGridOptions = this.#getDefaultGridOptions(args);

defaultGridOptions.rowSelection = undefined;

delete defaultGridOptions.selection;
return defaultGridOptions;
}

Expand Down
2 changes: 2 additions & 0 deletions libs/components/ag-grid/src/lib/styles/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ $modernDarkThemeCompact: map.merge($modernDarkThemeBase, $modernThemeCompact);
.ag-theme-sky-data-entry-grid-modern-dark-compact {
@include ag-grid-extra.ag-grid-extra();

--ag-list-item-height: var(--ag-row-height);

.ag-header-cell {
cursor: initial;

Expand Down

0 comments on commit c9695da

Please sign in to comment.