Skip to content

Commit 719c753

Browse files
committed
fixes
1 parent 8742c10 commit 719c753

File tree

9 files changed

+50
-20
lines changed

9 files changed

+50
-20
lines changed

packages/pluggableWidgets/gallery-web/src/components/GalleryItems.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export const GalleryItems = observer(function GalleryItems() {
1010
const texts = useTextsService();
1111
const focusController = useKeyNavFocus();
1212

13-
if (items.length === 0) {
14-
return <div>Empty</div>;
13+
if (items.length < 1) {
14+
return null;
1515
}
1616

1717
return (

packages/pluggableWidgets/gallery-web/src/components/ListItem.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useFocusTargetProps } from "@mendix/widget-plugin-grid/keyboard-navigation/useFocusTargetProps";
22
import classNames from "classnames";
33
import { ObjectItem } from "mendix";
4+
import { computed, trace } from "mobx";
45
import { observer } from "mobx-react-lite";
56
import { ReactElement, RefObject, useMemo } from "react";
67
import { getAriaProps } from "../features/item-interaction/get-item-aria-props";
@@ -20,8 +21,15 @@ export const ListItem = observer(function ListItem(props: ListItemProps): ReactE
2021
const itemVM = useGalleryItemVM();
2122
const getPosition = useLayoutService().getPositionFn;
2223

24+
const isSelected = computed(
25+
() => {
26+
trace();
27+
return selectActions.isSelected(item);
28+
},
29+
{ name: "[gallery]:@computed:ListItem:isSelected" }
30+
).get();
2331
const clickable = itemVM.hasOnClick(item) || selectActions.selectionType !== "None";
24-
const ariaProps = getAriaProps(item, selectActions, itemVM.label(item));
32+
const ariaProps = getAriaProps(selectActions.selectionType, isSelected, itemVM.label(item));
2533
const { columnIndex, rowIndex } = getPosition(itemIndex);
2634
const keyNavProps = useFocusTargetProps({ columnIndex: columnIndex ?? -1, rowIndex });
2735
const handlers = useMemo(() => eventsVM.getProps(item), [eventsVM, item]);

packages/pluggableWidgets/gallery-web/src/features/item-interaction/get-item-aria-props.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { SelectActionsService } from "@mendix/widget-plugin-grid/interfaces/SelectActionsService";
2-
import { ObjectItem } from "mendix";
1+
import { SelectionType } from "@mendix/widget-plugin-grid/selection";
32

43
type ListItemRole = "option" | "listitem";
54

@@ -10,11 +9,11 @@ type ListItemAriaProps = {
109
"aria-label": string | undefined;
1110
};
1211

13-
export function getAriaProps(item: ObjectItem, helper: SelectActionsService, label?: string): ListItemAriaProps {
14-
if (helper.selectionType === "Single" || helper.selectionType === "Multi") {
12+
export function getAriaProps(selectionType: SelectionType, isSelected: boolean, label?: string): ListItemAriaProps {
13+
if (selectionType === "Single" || selectionType === "Multi") {
1514
return {
1615
role: "option",
17-
"aria-selected": helper.isSelected(item),
16+
"aria-selected": isSelected,
1817
tabIndex: 0,
1918
"aria-label": label
2019
};

packages/pluggableWidgets/gallery-web/src/model/hooks/useGalleryContainer.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import { useConst } from "@mendix/widget-plugin-mobx-kit/react/useConst";
2+
import { useSetup } from "@mendix/widget-plugin-mobx-kit/react/useSetup";
3+
24
import { Container } from "brandi";
35
import { useEffect } from "react";
46
import { GalleryContainerProps } from "../../../typings/GalleryProps";
57
import { createGalleryContainer } from "../containers/createGalleryContainer";
8+
import { CORE_TOKENS as CORE } from "../tokens";
69

710
export function useGalleryContainer(props: GalleryContainerProps): Container {
811
const [container, mainProvider] = useConst(() => createGalleryContainer(props));
912

13+
// Run setup hooks on mount
14+
useSetup(() => container.get(CORE.setupService));
15+
1016
useEffect(() => mainProvider.setProps(props));
1117

1218
return container;

packages/pluggableWidgets/gallery-web/src/model/models/layout.model.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { VirtualGridLayout } from "@mendix/widget-plugin-grid/keyboard-navigation/VirtualGridLayout";
22
import { ComputedAtom } from "@mendix/widget-plugin-mobx-kit/main";
3-
import { computed } from "mobx";
3+
import { computed, trace } from "mobx";
44

55
/** @injectable */
66
export function layoutAtom(
@@ -10,7 +10,10 @@ export function layoutAtom(
1010
},
1111
pageSize: ComputedAtom<number>
1212
): ComputedAtom<VirtualGridLayout> {
13-
return computed(() => new VirtualGridLayout(layoutStore.numberOfRows, layoutStore.numberOfColumns, pageSize.get()));
13+
return computed(() => {
14+
trace()
15+
return new VirtualGridLayout(layoutStore.numberOfRows, layoutStore.numberOfColumns, pageSize.get())
16+
}, { name: '[gallery]:@computed:layoutAtom' });
1417
}
1518

1619
/** @injectable */

packages/pluggableWidgets/gallery-web/src/model/services/Layout.service.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getColumnAndRowBasedOnIndex, PositionInGrid } from "@mendix/widget-plugin-grid/selection";
22
import { ComputedAtom, SetupComponent, SetupComponentHost } from "@mendix/widget-plugin-mobx-kit/main";
3-
import { action, computed, makeAutoObservable } from "mobx";
3+
import { action, computed, makeAutoObservable, trace } from "mobx";
44
import { GalleryContainerProps } from "../../../typings/GalleryProps";
55

66
type Breakpoint = "desktop" | "tablet" | "phone";
@@ -18,13 +18,15 @@ export class LayoutService implements SetupComponent {
1818
this.width = window.innerWidth;
1919

2020
makeAutoObservable(this, {
21-
breakpoint: computed,
21+
setWidth: action,
2222
numberOfColumns: computed,
2323
numberOfRows: computed,
24-
getPositionFn: computed,
25-
setWidth: action,
2624
setup: false
2725
});
26+
27+
trace(this, "width");
28+
trace(this, "numberOfColumns");
29+
trace(this, "numberOfRows");
2830
}
2931

3032
setWidth(width: number): void {

packages/shared/widget-plugin-grid/src/core/models/datasource.model.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { computed } from "mobx";
88
export function itemCountAtom(
99
gate: DerivedPropsGate<{ datasource: { items?: { length: number } } }>
1010
): ComputedAtom<number> {
11-
return computed(() => gate.props.datasource.items?.length ?? -1);
11+
return computed(() => gate.props.datasource.items?.length ?? -1, { name: "plugin:@computed:itemCountAtom" });
1212
}
1313

1414
/**
@@ -36,7 +36,7 @@ export function offsetAtom(gate: DerivedPropsGate<{ datasource: { offset: number
3636
* @injectable
3737
*/
3838
export function limitAtom(gate: DerivedPropsGate<{ datasource: { limit: number } }>): ComputedAtom<number> {
39-
return computed(() => gate.props.datasource.limit);
39+
return computed(() => gate.props.datasource.limit, { name: 'plugin:@computed:limitAtom' });
4040
}
4141

4242
/**

packages/shared/widget-plugin-grid/src/keyboard-navigation/createFocusController.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ComputedAtom, SetupComponentHost } from "@mendix/widget-plugin-mobx-kit/main";
2-
import { reaction } from "mobx";
2+
import { reaction, trace } from "mobx";
33
import { FocusTargetController } from "./FocusTargetController";
44
import { PositionController } from "./PositionController";
55
import { VirtualGridLayout } from "./VirtualGridLayout";
@@ -13,8 +13,14 @@ export function createFocusController(
1313

1414
function setup(): void | (() => void) {
1515
return reaction(
16-
() => layout.get(),
17-
newLayout => controller.updateGridLayout(newLayout)
16+
() => {
17+
trace();
18+
return layout.get()
19+
},
20+
newLayout => {
21+
controller.updateGridLayout(newLayout)
22+
},
23+
{ name: "[plugin]:@reaction:createFocusController:layoutUpdate" }
1824
);
1925
}
2026

packages/shared/widget-plugin-grid/src/selection/helpers.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ import { Direction, MoveEvent1D, MoveEvent2D, MultiSelectionStatus, ScrollKeyCod
88

99
export class SingleSelectionHelper implements SingleSelectionService {
1010
type = "Single" as const;
11-
constructor(private selectionValue: SelectionSingleValue) {}
11+
constructor(private selectionValue: SelectionSingleValue) {
12+
type PrivateMembers = "selectionValue";
13+
makeObservable<this, PrivateMembers>(this, {
14+
selectionValue: observable.ref,
15+
updateProps: action
16+
});
17+
}
1218

1319
updateProps(value: SelectionSingleValue): void {
1420
this.selectionValue = value;

0 commit comments

Comments
 (0)