Skip to content

Commit 6303449

Browse files
committed
refactor: deprecate dg basic data
1 parent 487a931 commit 6303449

File tree

7 files changed

+50
-2
lines changed

7 files changed

+50
-2
lines changed

packages/pluggableWidgets/datagrid-web/src/helpers/state/GridBasicData.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type Props = Pick<
1010
type Gate = DerivedPropsGate<Props>;
1111

1212
/** This is basic data class, just a props mapper. Don't add any state or complex logic. */
13+
/** @deprecated use `TextsService` instead */
1314
export class GridBasicData {
1415
private gate: Gate;
1516

packages/pluggableWidgets/datagrid-web/src/model/configs/Datagrid.config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface DatagridConfig {
2222
columnsHidable: boolean;
2323
columnsResizable: boolean;
2424
columnsSortable: boolean;
25+
isInteractive: boolean;
2526
}
2627

2728
export function datagridConfig(props: DatagridContainerProps): DatagridConfig {
@@ -46,7 +47,8 @@ export function datagridConfig(props: DatagridContainerProps): DatagridConfig {
4647
columnsDraggable: props.columnsDraggable,
4748
columnsFilterable: props.columnsFilterable,
4849
columnsResizable: props.columnsResizable,
49-
columnsSortable: props.columnsSortable
50+
columnsSortable: props.columnsSortable,
51+
isInteractive: isInteractive(props)
5052
};
5153

5254
return Object.freeze(config);
@@ -71,3 +73,7 @@ function isSettingsStorageEnabled(props: DatagridContainerProps): boolean {
7173
if (props.configurationStorageType === "attribute" && props.configurationAttribute) return true;
7274
return false;
7375
}
76+
77+
function isInteractive(props: DatagridContainerProps): boolean {
78+
return props.itemSelection !== undefined || props.onClick !== undefined;
79+
}

packages/pluggableWidgets/datagrid-web/src/model/containers/Root.container.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { generateUUID } from "@mendix/widget-plugin-platform/framework/generate-
1616
import { Container, injected } from "brandi";
1717
import { visibleColumnsCountAtom } from "../models/columns.model";
1818
import { DatagridSetupService } from "../services/DatagridSetup.service";
19+
import { TextsService } from "../services/Texts.service";
1920
import { CORE_TOKENS as CORE } from "../tokens";
2021

2122
// datasource
@@ -39,6 +40,9 @@ injected(isCurrentPageSelectedAtom, CORE.mainGate);
3940
injected(selectedCountMultiAtom, CORE.mainGate);
4041
injected(selectionCounterTextsStore, CORE.mainGate, CORE.selection.selectedCount);
4142

43+
// other
44+
injected(TextsService, CORE.mainGate);
45+
4246
/**
4347
* Root container for bindings that can be shared down the hierarchy.
4448
* Declare only bindings that needs to be shared across multiple containers.
@@ -66,5 +70,6 @@ export class RootContainer extends Container {
6670
this.bind(CORE.selection.isCurrentPageSelected).toInstance(isCurrentPageSelectedAtom).inTransientScope();
6771
this.bind(CORE.selection.selectedCounterTextsStore).toInstance(selectionCounterTextsStore).inTransientScope();
6872
this.bind(CORE.selection.isAllItemsSelected).toInstance(isAllItemsSelectedAtom).inTransientScope();
73+
this.bind(CORE.texts).toInstance(TextsService).inTransientScope();
6974
}
7075
}

packages/pluggableWidgets/datagrid-web/src/model/hooks/injection-hooks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ export const [useQueryService] = createInjectionHooks(DG.query);
1515
export const [useVisibleColumnsCount] = createInjectionHooks(CORE.atoms.visibleColumnsCount);
1616
export const [useItemCount] = createInjectionHooks(CORE.atoms.itemCount);
1717
export const [useColumn] = createInjectionHooks(CORE.column);
18+
export const [useTexts] = createInjectionHooks(CORE.texts);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { DerivedPropsGate } from "@mendix/widget-plugin-mobx-kit/main";
2+
import { makeAutoObservable } from "mobx";
3+
import { MainGateProps } from "../../../typings/MainGateProps";
4+
5+
export class TextsService {
6+
constructor(private gate: DerivedPropsGate<MainGateProps>) {
7+
makeAutoObservable(this);
8+
}
9+
10+
private get props(): MainGateProps {
11+
return this.gate.props;
12+
}
13+
14+
get exportDialogLabel(): string | undefined {
15+
return this.props.exportDialogLabel?.value;
16+
}
17+
18+
get cancelExportLabel(): string | undefined {
19+
return this.props.cancelExportLabel?.value;
20+
}
21+
22+
get selectRowLabel(): string | undefined {
23+
return this.props.selectRowLabel?.value;
24+
}
25+
26+
get selectAllRowsLabel(): string | undefined {
27+
return this.props.selectAllRowsLabel?.value;
28+
}
29+
}

packages/pluggableWidgets/datagrid-web/src/model/tokens.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { DatagridConfig } from "./configs/Datagrid.config";
3232
import { DatagridSetupService } from "./services/DatagridSetup.service";
3333
import { DerivedLoaderController, DerivedLoaderControllerConfig } from "./services/DerivedLoaderController";
3434
import { PaginationConfig, PaginationController } from "./services/PaginationController";
35+
import { TextsService } from "./services/Texts.service";
3536

3637
/** Tokens to resolve dependencies from the container. */
3738

@@ -63,7 +64,9 @@ export const CORE_TOKENS = {
6364
}>("@store:selectedCounterTextsStore")
6465
},
6566

66-
setupService: token<DatagridSetupService>("DatagridSetupService")
67+
setupService: token<DatagridSetupService>("DatagridSetupService"),
68+
69+
texts: token<TextsService>("@srv:TextsService")
6770
};
6871

6972
/** Datagrid tokens. */

packages/pluggableWidgets/datagrid-web/typings/MainGateProps.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { DatagridContainerProps } from "./DatagridProps";
44
export type MainGateProps = Pick<
55
DatagridContainerProps,
66
| "allSelectedText"
7+
| "cancelExportLabel"
78
| "cancelSelectionLabel"
89
| "clearSelectionButtonLabel"
910
| "columns"
@@ -12,6 +13,7 @@ export type MainGateProps = Pick<
1213
| "datasource"
1314
| "emptyPlaceholder"
1415
| "enableSelectAll"
16+
| "exportDialogLabel"
1517
| "itemSelection"
1618
| "name"
1719
| "onSelectionChange"
@@ -23,6 +25,7 @@ export type MainGateProps = Pick<
2325
| "selectAllTemplate"
2426
| "selectAllText"
2527
| "selectionCounterPosition"
28+
| "selectRowLabel"
2629
| "showNumberOfRows"
2730
| "showPagingButtons"
2831
| "storeFiltersInPersonalization"

0 commit comments

Comments
 (0)