Skip to content

Commit

Permalink
fix(code-examples): satisfy ESLint rules for action button and AG Gri…
Browse files Browse the repository at this point in the history
…d code examples (#2423)
  • Loading branch information
Blackbaud-SteveBrush committed Jul 2, 2024
1 parent 864bab8 commit aef0a9a
Show file tree
Hide file tree
Showing 42 changed files with 312 additions and 196 deletions.
2 changes: 1 addition & 1 deletion apps/code-examples/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class AppComponent {
});

const themeSettings = new SkyThemeSettings(
SkyTheme.presets['modern'],
SkyTheme.presets.modern,
SkyThemeMode.presets.light,
);

Expand Down
2 changes: 1 addition & 1 deletion apps/code-examples/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AppComponent } from './app.component';

@NgModule({
declarations: [AppComponent],
imports: [BrowserAnimationsModule, BrowserModule, AppRoutingModule],
imports: [AppRoutingModule, BrowserAnimationsModule, BrowserModule],
providers: [SkyThemeService],
bootstrap: [AppComponent],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { SkyDropdownModule } from '@skyux/popovers';
import { ICellRendererAngularComp } from 'ag-grid-angular';
import { ICellRendererParams } from 'ag-grid-community';

import { AgGridDemoRow } from './data';

@Component({
standalone: true,
selector: 'app-context-menu',
Expand All @@ -12,15 +14,15 @@ import { ICellRendererParams } from 'ag-grid-community';
imports: [SkyDropdownModule],
})
export class ContextMenuComponent implements ICellRendererAngularComp {
public contextMenuAriaLabel = '';
public deleteAriaLabel = '';
public markInactiveAriaLabel = '';
public moreInfoAriaLabel = '';
protected contextMenuAriaLabel = '';
protected deleteAriaLabel = '';
protected markInactiveAriaLabel = '';
protected moreInfoAriaLabel = '';

#name = '';
#name: string | undefined;

public agInit(params: ICellRendererParams): void {
this.#name = params.data && params.data.name;
public agInit(params: ICellRendererParams<AgGridDemoRow>): void {
this.#name = params.data?.name;
this.contextMenuAriaLabel = `Context menu for ${this.#name}`;
this.deleteAriaLabel = `Delete ${this.#name}`;
this.markInactiveAriaLabel = `Mark ${this.#name} inactive`;
Expand All @@ -32,6 +34,6 @@ export class ContextMenuComponent implements ICellRendererAngularComp {
}

protected actionClicked(action: string): void {
alert(`${action} clicked for ${this.#name}`);
console.error(`${action} clicked for ${this.#name}`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export interface AgGridDemoRow {
jobTitle?: AutocompleteOption;
}

export const AG_GRID_DEMO_DATA = [
export const AG_GRID_DEMO_DATA: AgGridDemoRow[] = [
{
selected: true,
name: 'Billy Bob',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ export class DemoComponent {
field: 'endDate',
headerName: 'End date',
type: SkyCellType.Date,
valueFormatter: this.#endDateFormatter,
valueFormatter: (params: ValueFormatterParams<AgGridDemoRow, Date>) =>
this.#endDateFormatter(params),
},
{
field: 'department',
Expand Down Expand Up @@ -127,7 +128,9 @@ export class DemoComponent {
constructor() {
const gridOptions: GridOptions = {
columnDefs: this.#columnDefs,
onGridReady: (gridReadyEvent): void => this.onGridReady(gridReadyEvent),
onGridReady: (gridReadyEvent): void => {
this.onGridReady(gridReadyEvent);
},
};

this.gridOptions = this.#agGridSvc.getEditableGridOptions({
Expand Down Expand Up @@ -165,7 +168,7 @@ export class DemoComponent {
if (result.reason === 'cancel' || result.reason === 'close') {
alert('Edits canceled!');
} else {
this.gridData = result.data;
this.gridData = result.data as AgGridDemoRow[];

if (this.#gridApi) {
this.#gridApi.refreshCells();
Expand All @@ -192,11 +195,13 @@ export class DemoComponent {
}
}

#endDateFormatter(params: ValueFormatterParams): string {
const dateConfig = { year: 'numeric', month: '2-digit', day: '2-digit' };

#endDateFormatter(params: ValueFormatterParams<AgGridDemoRow, Date>): string {
return params.value
? params.value.toLocaleDateString('en-us', dateConfig)
? params.value.toLocaleDateString('en-us', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
})
: 'N/A';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class EditModalComponent {
type: SkyCellType.Date,
editable: true,
cellEditorParams: (
params: ICellEditorParams,
params: ICellEditorParams<AgGridDemoRow>,
): { skyComponentProperties: SkyAgGridDatepickerProperties } => {
return { skyComponentProperties: { minDate: params.data.startDate } };
},
Expand All @@ -107,7 +107,7 @@ export class EditModalComponent {
type: SkyCellType.Autocomplete,
editable: true,
cellEditorParams: (
params: ICellEditorParams,
params: ICellEditorParams<AgGridDemoRow>,
): { skyComponentProperties: SkyAgGridAutocompleteProperties } => {
return {
skyComponentProperties: {
Expand All @@ -132,12 +132,9 @@ export class EditModalComponent {
type: SkyCellType.Autocomplete,
editable: true,
cellEditorParams: (
params: ICellEditorParams,
params: ICellEditorParams<AgGridDemoRow>,
): { skyComponentProperties: SkyAgGridAutocompleteProperties } => {
const selectedDepartment: string =
params.data &&
params.data.department &&
params.data.department.name;
const selectedDepartment = params.data?.department?.name;

const editParams: {
skyComponentProperties: SkyAgGridAutocompleteProperties;
Expand Down Expand Up @@ -178,7 +175,9 @@ export class EditModalComponent {

this.gridOptions = {
columnDefs: this.#columnDefs,
onGridReady: (gridReadyEvent): void => this.onGridReady(gridReadyEvent),
onGridReady: (gridReadyEvent): void => {
this.onGridReady(gridReadyEvent);
},
};

this.gridOptions = this.#agGridSvc.getEditableGridOptions({
Expand All @@ -196,15 +195,15 @@ export class EditModalComponent {

#departmentSelectionChange(
change: SkyAutocompleteSelectionChange,
node: IRowNode,
node: IRowNode<AgGridDemoRow>,
): void {
if (change.selectedItem && change.selectedItem !== node.data.department) {
if (change.selectedItem && change.selectedItem !== node.data?.department) {
this.#clearJobTitle(node);
}
}

#clearJobTitle(node: IRowNode | null): void {
if (node) {
#clearJobTitle(node: IRowNode<AgGridDemoRow> | null): void {
if (node?.data) {
node.data.jobTitle = undefined;
this.#changeDetectorRef.markForCheck();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { SkyDropdownModule } from '@skyux/popovers';
import { ICellRendererAngularComp } from 'ag-grid-angular';
import { ICellRendererParams } from 'ag-grid-community';

import { AgGridDemoRow } from './data';

@Component({
standalone: true,
selector: 'app-context-menu',
Expand All @@ -17,10 +19,10 @@ export class ContextMenuComponent implements ICellRendererAngularComp {
public markInactiveAriaLabel = '';
public moreInfoAriaLabel = '';

#name = '';
#name: string | undefined;

public agInit(params: ICellRendererParams): void {
this.#name = params.data && params.data.name;
public agInit(params: ICellRendererParams<AgGridDemoRow>): void {
this.#name = params.data?.name;
this.contextMenuAriaLabel = `Context menu for ${this.#name}`;
this.deleteAriaLabel = `Delete ${this.#name}`;
this.markInactiveAriaLabel = `Mark ${this.#name} inactive`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { SkyModalConfigurationInterface, SkyModalService } from '@skyux/modals';

import { Subject, takeUntil } from 'rxjs';

import { AG_GRID_DEMO_DATA } from './data';
import { AG_GRID_DEMO_DATA, AgGridDemoRow } from './data';
import { EditModalContext } from './edit-modal-context';
import { EditModalComponent } from './edit-modal.component';
import { FilterModalComponent } from './filter-modal.component';
Expand Down Expand Up @@ -130,7 +130,7 @@ export class DemoComponent implements OnInit, OnDestroy {
if (result.reason === 'cancel' || result.reason === 'close') {
alert('Edits canceled!');
} else {
this.items = result.data;
this.items = result.data as AgGridDemoRow[];
alert('Saving data!');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class EditModalComponent {
type: SkyCellType.Date,
editable: true,
cellEditorParams: (
params: ICellEditorParams,
params: ICellEditorParams<AgGridDemoRow>,
): { skyComponentProperties: SkyAgGridDatepickerProperties } => {
return {
skyComponentProperties: {
Expand All @@ -86,7 +86,7 @@ export class EditModalComponent {
type: SkyCellType.Autocomplete,
editable: true,
cellEditorParams: (
params: ICellEditorParams,
params: ICellEditorParams<AgGridDemoRow>,
): { skyComponentProperties: SkyAgGridAutocompleteProperties } => {
return {
skyComponentProperties: {
Expand All @@ -109,12 +109,9 @@ export class EditModalComponent {
type: SkyCellType.Autocomplete,
editable: true,
cellEditorParams: (
params: ICellEditorParams,
params: ICellEditorParams<AgGridDemoRow>,
): { skyComponentProperties: SkyAgGridAutocompleteProperties } => {
const selectedDepartment: string =
params.data &&
params.data.department &&
params.data.department.name;
const selectedDepartment = params.data?.department?.name;

const editParams: {
skyComponentProperties: SkyAgGridAutocompleteProperties;
Expand Down Expand Up @@ -155,7 +152,9 @@ export class EditModalComponent {

const gridOptions: GridOptions = {
columnDefs: this.#columnDefs,
onGridReady: (gridReadyEvent): void => this.onGridReady(gridReadyEvent),
onGridReady: (gridReadyEvent): void => {
this.onGridReady(gridReadyEvent);
},
};

this.gridOptions = this.#agGridService.getEditableGridOptions({
Expand All @@ -173,15 +172,15 @@ export class EditModalComponent {

#departmentSelectionChange(
change: SkyAutocompleteSelectionChange,
node: IRowNode,
node: IRowNode<AgGridDemoRow>,
): void {
if (change.selectedItem && change.selectedItem !== node.data.department) {
if (change.selectedItem && change.selectedItem !== node.data?.department) {
this.#clearJobTitle(node);
}
}

#clearJobTitle(node: IRowNode | null): void {
if (node) {
#clearJobTitle(node: IRowNode<AgGridDemoRow> | null): void {
if (node?.data) {
node.data.jobTitle = undefined;

if (this.#gridApi) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
import { SkyCheckboxModule } from '@skyux/forms';
import { SkyModalInstance, SkyModalModule } from '@skyux/modals';

import { Filters } from './filters';

@Component({
standalone: true,
selector: 'app-filter-modal',
Expand All @@ -30,10 +32,10 @@ export class FilterModalComponent {

constructor() {
if (this.#context.filterData?.filters) {
const filters = this.#context.filterData.filters;
const filters = this.#context.filterData.filters as Filters;

this.jobTitle = filters.jobTitle || 'any';
this.hideSales = filters.hideSales || false;
this.jobTitle = filters.jobTitle ?? 'any';
this.hideSales = filters.hideSales ?? false;
}

this.#changeDetector.markForCheck();
Expand All @@ -46,7 +48,7 @@ export class FilterModalComponent {
result.filters = {
jobTitle: this.jobTitle,
hideSales: this.hideSales,
};
} satisfies Filters;

this.#changeDetector.markForCheck();
this.#instance.save(result);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Filters {
jobTitle?: string;
hideSales?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { Subject, of, takeUntil } from 'rxjs';

import { ContextMenuComponent } from './context-menu.component';
import { AgGridDemoRow } from './data';
import { Filters } from './filters';

@Component({
standalone: true,
Expand Down Expand Up @@ -85,7 +86,8 @@ export class ViewGridComponent implements OnInit, OnDestroy {
field: 'endDate',
headerName: 'End date',
type: SkyCellType.Date,
valueFormatter: this.#endDateFormatter,
valueFormatter: (params: ValueFormatterParams<AgGridDemoRow, Date>) =>
this.#endDateFormatter(params),
},
{
field: 'department',
Expand Down Expand Up @@ -238,16 +240,21 @@ export class ViewGridComponent implements OnInit, OnDestroy {
this.#changeDetectorRef.markForCheck();
}

protected onRowSelected(rowSelectedEvent: RowSelectedEvent): void {
if (!rowSelectedEvent.data.selected) {
protected onRowSelected(
rowSelectedEvent: RowSelectedEvent<AgGridDemoRow>,
): void {
if (!rowSelectedEvent.data?.selected) {
this.#updateData();
}
}

#endDateFormatter(params: ValueFormatterParams): string {
const dateConfig = { year: 'numeric', month: '2-digit', day: '2-digit' };
#endDateFormatter(params: ValueFormatterParams<AgGridDemoRow, Date>): string {
return params.value
? params.value.toLocaleDateString('en-us', dateConfig)
? params.value.toLocaleDateString('en-us', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
})
: 'N/A';
}

Expand All @@ -256,11 +263,11 @@ export class ViewGridComponent implements OnInit, OnDestroy {
const filterData = this.#dataState.filterData;

if (filterData?.filters) {
const filters = filterData.filters;
const filters = filterData.filters as Filters;

filteredItems = items.filter((item) => {
return (
((filters.hideSales && item.department.name !== 'Sales') ||
(!!(filters.hideSales && item.department.name !== 'Sales') ||
!filters.hideSales) &&
((filters.jobTitle !== 'any' &&
item.jobTitle?.name === filters.jobTitle) ||
Expand All @@ -286,7 +293,7 @@ export class ViewGridComponent implements OnInit, OnDestroy {
property === 'name'
) {
const propertyText = item[property]?.toLowerCase();
if (propertyText.indexOf(searchText) > -1) {
if (propertyText.includes(searchText)) {
return true;
}
}
Expand All @@ -301,7 +308,7 @@ export class ViewGridComponent implements OnInit, OnDestroy {

#setInitialColumnOrder(): void {
const viewState = this.#dataState.getViewStateById(this.#viewId);
const visibleColumns = viewState?.displayedColumnIds || [];
const visibleColumns = viewState?.displayedColumnIds ?? [];

this.#columnDefs.sort((col1, col2) => {
const col1Index = visibleColumns.findIndex(
Expand Down
Loading

0 comments on commit aef0a9a

Please sign in to comment.