diff --git a/packages/pluggableWidgets/datagrid-web/src/Datagrid.tsx b/packages/pluggableWidgets/datagrid-web/src/Datagrid.tsx index 3eeddd6be1..dff3b1000e 100644 --- a/packages/pluggableWidgets/datagrid-web/src/Datagrid.tsx +++ b/packages/pluggableWidgets/datagrid-web/src/Datagrid.tsx @@ -4,7 +4,7 @@ import { ReactElement } from "react"; import { DatagridContainerProps } from "../typings/DatagridProps"; import { Widget } from "./components/Widget"; import { useDataExport } from "./features/data-export/useDataExport"; -import { useDataGridJSActions } from "./helpers/useDataGridJSActions"; +import { useDataGridJSActions } from "./model/hooks/useDataGridJSActions"; import { useColumnsStore, useExportProgressService } from "./model/hooks/injection-hooks"; import { useDatagridContainer } from "./model/hooks/useDatagridContainer"; diff --git a/packages/pluggableWidgets/datagrid-web/src/helpers/state/ColumnGroupStore.ts b/packages/pluggableWidgets/datagrid-web/src/helpers/state/ColumnGroupStore.ts index 66d4ebc49c..bec11bb301 100644 --- a/packages/pluggableWidgets/datagrid-web/src/helpers/state/ColumnGroupStore.ts +++ b/packages/pluggableWidgets/datagrid-web/src/helpers/state/ColumnGroupStore.ts @@ -129,7 +129,6 @@ export class ColumnGroupStore implements IColumnGroupStore, IColumnParentStore, const columnTarget = this._allColumnsById.get(target)!; columnSource.orderWeight = columnTarget.orderWeight + (placement === "after" ? 1 : -1); - // normalize columns this._allColumnsOrdered.forEach((column, idx) => { column.orderWeight = idx * 10; }); @@ -144,7 +143,6 @@ export class ColumnGroupStore implements IColumnGroupStore, IColumnParentStore, } get loaded(): boolean { - // check if all columns loaded, then we can render return this._allColumns.every(c => c.loaded); } @@ -155,12 +153,12 @@ export class ColumnGroupStore implements IColumnGroupStore, IColumnParentStore, get availableColumns(): ColumnStore[] { // columns that are not hidden by visibility expression // visible field name is misleading, it means available - return [...this._allColumnsOrdered].filter(column => column.isAvailable); + return this._allColumnsOrdered.filter(column => column.isAvailable); } get visibleColumns(): ColumnStore[] { // list of columns that are available and not in the set of hidden columns - return [...this.availableColumns].filter(column => !column.isHidden); + return this.availableColumns.filter(column => !column.isHidden); } get sortInstructions(): SortInstruction[] | undefined { diff --git a/packages/pluggableWidgets/datagrid-web/src/helpers/state/ColumnsSortingStore.ts b/packages/pluggableWidgets/datagrid-web/src/helpers/state/ColumnsSortingStore.ts index 0cc2dbf1c2..2a20f8f634 100644 --- a/packages/pluggableWidgets/datagrid-web/src/helpers/state/ColumnsSortingStore.ts +++ b/packages/pluggableWidgets/datagrid-web/src/helpers/state/ColumnsSortingStore.ts @@ -23,27 +23,20 @@ export class ColumnsSortingStore implements IColumnSortingStore { getDirection(columnId: ColumnId): [SortDirection, number] | undefined { const ruleIndex = this.rules.findIndex(r => r[0] === columnId); - if (ruleIndex === -1) { - return undefined; - } - const [, dir] = this.rules.at(ruleIndex)!; - - return [dir, ruleIndex + 1]; + const rule = this.rules[ruleIndex]; + return rule ? [rule[1], ruleIndex + 1] : undefined; } toggleSort(columnId: ColumnId): void { const [[cId, dir] = []] = this.rules; if (!cId || cId !== columnId) { - // was not sorted or sorted by a different column this.rules = [[columnId, "asc"]]; return; } if (dir === "asc") { - // sorted by asc, flip to desc this.rules = [[columnId, "desc"]]; return; } - // sorted by desc, disable this.rules = []; } } diff --git a/packages/pluggableWidgets/datagrid-web/src/helpers/state/GridPersonalizationStore.ts b/packages/pluggableWidgets/datagrid-web/src/helpers/state/GridPersonalizationStore.ts index 3fb794c59e..bb6dd81782 100644 --- a/packages/pluggableWidgets/datagrid-web/src/helpers/state/GridPersonalizationStore.ts +++ b/packages/pluggableWidgets/datagrid-web/src/helpers/state/GridPersonalizationStore.ts @@ -17,6 +17,8 @@ import { AttributePersonalizationStorage } from "../storage/AttributePersonaliza import { LocalStoragePersonalizationStorage } from "../storage/LocalStoragePersonalizationStorage"; import { PersonalizationStorage } from "../storage/PersonalizationStorage"; +const SCHEMA_VERSION: GridPersonalizationStorageSettings["schemaVersion"] = 3; + type RequiredProps = Pick< DatagridContainerProps, "name" | "configurationStorageType" | "storeFiltersInPersonalization" | "configurationAttribute" @@ -25,7 +27,6 @@ type RequiredProps = Pick< export class GridPersonalizationStore implements SetupComponent { private readonly gridName: string; private readonly gridColumnsHash: string; - private readonly schemaVersion: GridPersonalizationStorageSettings["schemaVersion"] = 3; private readonly storeFilters: boolean; private readonly storage: PersonalizationStorage; @@ -140,7 +141,7 @@ export class GridPersonalizationStore implements SetupComponent { "name" in settings && "settingsHash" in settings && "schemaVersion" in settings && - settings.schemaVersion === this.schemaVersion + settings.schemaVersion === SCHEMA_VERSION ); } @@ -188,7 +189,7 @@ function toStorageFormat( return { name: gridName, - schemaVersion: 3, + schemaVersion: SCHEMA_VERSION, settingsHash: gridColumnsHash, columns: columnsSettings.map(c => ({ columnId: c.columnId, diff --git a/packages/pluggableWidgets/datagrid-web/src/helpers/state/column/ColumnFilterStore.tsx b/packages/pluggableWidgets/datagrid-web/src/helpers/state/column/ColumnFilterStore.tsx index a811b764a4..a7a2d93b73 100644 --- a/packages/pluggableWidgets/datagrid-web/src/helpers/state/column/ColumnFilterStore.tsx +++ b/packages/pluggableWidgets/datagrid-web/src/helpers/state/column/ColumnFilterStore.tsx @@ -23,7 +23,7 @@ const { Provider } = getGlobalFilterContextObject(); export class ColumnFilterStore implements IColumnFilterStore { private _widget: ReactNode; - private _error: APIError | null; + private _error: APIError | null = null; private _filterStore: FilterStore | null = null; private _context: FilterAPI; private _filterHost: ObservableFilterHost; @@ -31,15 +31,11 @@ export class ColumnFilterStore implements IColumnFilterStore { constructor(props: ColumnsType, info: StaticInfo, filterHost: ObservableFilterHost) { this._filterHost = filterHost; this._widget = props.filter; - const storeResult = this.createFilterStore(props, null); - if (storeResult === null) { - this._error = this._filterStore = null; - } else if (storeResult.hasError) { + const storeResult = this.createFilterStore(props); + if (storeResult?.hasError) { this._error = storeResult.error; - this._filterStore = null; } else { - this._error = null; - this._filterStore = storeResult.value; + this._filterStore = storeResult?.value ?? null; } this._context = this.createContext(this._filterStore, info); @@ -56,12 +52,9 @@ export class ColumnFilterStore implements IColumnFilterStore { return disposeAll; } - private createFilterStore( - props: ColumnsType, - dsViewState: FilterCondition | null - ): ReturnType | null { + private createFilterStore(props: ColumnsType): ReturnType | null { if (isListAttributeValue(props.attribute)) { - return attrgroupFilterStore(props.attribute.type, props.attribute, dsViewState); + return attrgroupFilterStore(props.attribute.type, props.attribute, null); } return null; diff --git a/packages/pluggableWidgets/datagrid-web/src/helpers/state/column/ColumnStore.tsx b/packages/pluggableWidgets/datagrid-web/src/helpers/state/column/ColumnStore.tsx index 9cbd7e2459..f7a2121aec 100644 --- a/packages/pluggableWidgets/datagrid-web/src/helpers/state/column/ColumnStore.tsx +++ b/packages/pluggableWidgets/datagrid-web/src/helpers/state/column/ColumnStore.tsx @@ -95,7 +95,6 @@ export class ColumnStore implements GridColumn { this._dynamicText = props.dynamicText; } - // old props get alignment(): AlignmentEnum { return this.baseInfo.alignment; } @@ -112,7 +111,6 @@ export class ColumnStore implements GridColumn { return this.baseInfo.draggable; } - // hiding get canHide(): boolean { return this.baseInfo.hidable; } @@ -121,7 +119,6 @@ export class ColumnStore implements GridColumn { this.isHidden = !this.isHidden; } - // size get canResize(): boolean { // column is not resizable if it is at the end of the grid return this.baseInfo.resizable && !this.parentStore.isLastVisible(this); @@ -131,7 +128,6 @@ export class ColumnStore implements GridColumn { this.size = size; } - // sorting get canSort(): boolean { return this.baseInfo.sortable && !!this._attribute?.sortable; } diff --git a/packages/pluggableWidgets/datagrid-web/src/helpers/storage/AttributePersonalizationStorage.ts b/packages/pluggableWidgets/datagrid-web/src/helpers/storage/AttributePersonalizationStorage.ts index a55eb84965..df65fc7602 100644 --- a/packages/pluggableWidgets/datagrid-web/src/helpers/storage/AttributePersonalizationStorage.ts +++ b/packages/pluggableWidgets/datagrid-web/src/helpers/storage/AttributePersonalizationStorage.ts @@ -39,7 +39,7 @@ export class AttributePersonalizationStorage implements PersonalizationStorage { } } - updateSettings(newSettings: any): void { + updateSettings(newSettings: unknown): void { // Prevent saving empty string or null to the attribute newSettings = newSettings === "" || newSettings === null ? undefined : newSettings; if (this._storageAttr && !this._storageAttr.readOnly) { diff --git a/packages/pluggableWidgets/datagrid-web/src/helpers/storage/LocalStoragePersonalizationStorage.ts b/packages/pluggableWidgets/datagrid-web/src/helpers/storage/LocalStoragePersonalizationStorage.ts index dc061cc762..110da191d3 100644 --- a/packages/pluggableWidgets/datagrid-web/src/helpers/storage/LocalStoragePersonalizationStorage.ts +++ b/packages/pluggableWidgets/datagrid-web/src/helpers/storage/LocalStoragePersonalizationStorage.ts @@ -9,7 +9,7 @@ export class LocalStoragePersonalizationStorage implements PersonalizationStorag return data ? JSON.parse(data) : undefined; } - updateSettings(newSettings: any): void { + updateSettings(newSettings: unknown): void { const newSettingsJson = JSON.stringify(newSettings); if (localStorage.getItem(this.key) !== newSettingsJson) { localStorage.setItem(this.key, newSettingsJson); diff --git a/packages/pluggableWidgets/datagrid-web/src/helpers/storage/PersonalizationStorage.ts b/packages/pluggableWidgets/datagrid-web/src/helpers/storage/PersonalizationStorage.ts index 4b6f170c54..2482924fba 100644 --- a/packages/pluggableWidgets/datagrid-web/src/helpers/storage/PersonalizationStorage.ts +++ b/packages/pluggableWidgets/datagrid-web/src/helpers/storage/PersonalizationStorage.ts @@ -4,6 +4,6 @@ type RequiredProps = Pick; export interface PersonalizationStorage { settings: unknown; - updateSettings(newSettings: any): void; + updateSettings(newSettings: unknown): void; updateProps?(props: RequiredProps): void; } diff --git a/packages/pluggableWidgets/datagrid-web/src/helpers/useDataGridJSActions.ts b/packages/pluggableWidgets/datagrid-web/src/model/hooks/useDataGridJSActions.ts similarity index 83% rename from packages/pluggableWidgets/datagrid-web/src/helpers/useDataGridJSActions.ts rename to packages/pluggableWidgets/datagrid-web/src/model/hooks/useDataGridJSActions.ts index 78f70a245e..9b7d4428bc 100644 --- a/packages/pluggableWidgets/datagrid-web/src/helpers/useDataGridJSActions.ts +++ b/packages/pluggableWidgets/datagrid-web/src/model/hooks/useDataGridJSActions.ts @@ -1,5 +1,5 @@ import { useOnClearSelectionEvent, useOnResetFiltersEvent } from "@mendix/widget-plugin-external-events/hooks"; -import { useDatagridConfig, useSelectActions } from "../model/hooks/injection-hooks"; +import { useDatagridConfig, useSelectActions } from "./injection-hooks"; export function useDataGridJSActions(): void { const info = useDatagridConfig(); diff --git a/packages/pluggableWidgets/datagrid-web/src/typings/GridColumn.ts b/packages/pluggableWidgets/datagrid-web/src/typings/GridColumn.ts index 75ee8b4551..3d26ebe0c6 100644 --- a/packages/pluggableWidgets/datagrid-web/src/typings/GridColumn.ts +++ b/packages/pluggableWidgets/datagrid-web/src/typings/GridColumn.ts @@ -21,17 +21,14 @@ export interface GridColumn { isAvailable: boolean; wrapText: boolean; - // hiding canHide: boolean; isHidden: boolean; toggleHidden(): void; - // sorting canSort: boolean; sortDir: SortDirection | undefined; toggleSort(): void; - // sizing canResize: boolean; size: number | undefined; setSize(size: number): void;