Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/pluggableWidgets/datagrid-web/src/Datagrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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";

Check warning on line 7 in packages/pluggableWidgets/datagrid-web/src/Datagrid.tsx

View workflow job for this annotation

GitHub Actions / Run code quality check

`./model/hooks/useDataGridJSActions` import should occur after import of `./model/hooks/useDatagridContainer`
import { useColumnsStore, useExportProgressService } from "./model/hooks/injection-hooks";
import { useDatagridContainer } from "./model/hooks/useDatagridContainer";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand All @@ -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);
}

Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;

Expand Down Expand Up @@ -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
);
}

Expand Down Expand Up @@ -188,7 +189,7 @@ function toStorageFormat(

return {
name: gridName,
schemaVersion: 3,
schemaVersion: SCHEMA_VERSION,
settingsHash: gridColumnsHash,
columns: columnsSettings.map(c => ({
columnId: c.columnId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,19 @@ 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;

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);

Expand All @@ -56,12 +52,9 @@ export class ColumnFilterStore implements IColumnFilterStore {
return disposeAll;
}

private createFilterStore(
props: ColumnsType,
dsViewState: FilterCondition | null
): ReturnType<typeof attrgroupFilterStore> | null {
private createFilterStore(props: ColumnsType): ReturnType<typeof attrgroupFilterStore> | null {
if (isListAttributeValue(props.attribute)) {
return attrgroupFilterStore(props.attribute.type, props.attribute, dsViewState);
return attrgroupFilterStore(props.attribute.type, props.attribute, null);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ export class ColumnStore implements GridColumn {
this._dynamicText = props.dynamicText;
}

// old props
get alignment(): AlignmentEnum {
return this.baseInfo.alignment;
}
Expand All @@ -112,7 +111,6 @@ export class ColumnStore implements GridColumn {
return this.baseInfo.draggable;
}

// hiding
get canHide(): boolean {
return this.baseInfo.hidable;
}
Expand All @@ -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);
Expand All @@ -131,7 +128,6 @@ export class ColumnStore implements GridColumn {
this.size = size;
}

// sorting
get canSort(): boolean {
return this.baseInfo.sortable && !!this._attribute?.sortable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ type RequiredProps = Pick<DatagridContainerProps, "configurationAttribute">;

export interface PersonalizationStorage {
settings: unknown;
updateSettings(newSettings: any): void;
updateSettings(newSettings: unknown): void;
updateProps?(props: RequiredProps): void;
}
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading