Skip to content

Commit 6d9d939

Browse files
feat: LEAP-1356: Add custom button props (#6787)
Co-authored-by: Gondragos <[email protected]> Co-authored-by: MihajloHoma <[email protected]>
1 parent 054bfe1 commit 6d9d939

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

Diff for: web/libs/datamanager/src/components/Common/Table/TableRow/TableRow.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const TableRow = observer(({ data, even, style, wrapperStyle, onClick, st
6161

6262
return (
6363
<div className={rowWrapperCN.mod(mods).toString()} style={wrapperStyle} onClick={(e) => onClick?.(data, e)}>
64-
<div className={tableRowCN.toString()} style={style}>
64+
<div className={tableRowCN.toString()} style={style} data-leave={true}>
6565
{columns.map((col) => {
6666
return <CellRenderer key={col.id} col={col} data={data} cellViews={cellViews} decoration={decoration} />;
6767
})}

Diff for: web/libs/datamanager/src/components/Common/Tabs/Tabs.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const Tabs = ({
6161
</Droppable>
6262
</DragDropContext>
6363
{allowedActions.add !== false && (
64-
<Button className={tabsCN.elem("add").toString()} type="text" onClick={onAdd} icon={addIcon} />
64+
<Button className={tabsCN.elem("add").toString()} type="text" onClick={onAdd} icon={addIcon} data-leave />
6565
)}
6666
</span>
6767
<span className={tabsCN.elem("extra").toString()}>{tabBarExtraContent}</span>
@@ -140,6 +140,7 @@ export const TabsItem = ({
140140
.toString()}
141141
onClick={() => switchTab?.(tab)}
142142
title={currentTitle}
143+
data-leave
143144
>
144145
{renameMode ? (
145146
<Input

Diff for: web/libs/datamanager/src/components/Common/Tabs/TabsMenu.jsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ export const TabsMenu = ({ onClick, editable = true, closable = true, clonable =
1515
title: "Duplicate",
1616
enabled: !virtual && clonable,
1717
action: () => onClick("duplicate"),
18+
willLeave: true,
1819
},
1920
{
2021
key: "save",
2122
title: "Save",
2223
enabled: virtual,
2324
action: () => onClick("save"),
25+
willLeave: true,
2426
},
2527
],
2628
[editable, closable, clonable, virtual],
@@ -32,7 +34,7 @@ export const TabsMenu = ({ onClick, editable = true, closable = true, clonable =
3234
<Menu size="medium" onClick={(e) => e.domEvent.stopPropagation()}>
3335
{items.map((item) =>
3436
item.enabled ? (
35-
<Menu.Item key={item.key} onClick={item.action}>
37+
<Menu.Item key={item.key} onClick={item.action} data-leave={item.willLeave}>
3638
{item.title}
3739
</Menu.Item>
3840
) : null,
@@ -41,7 +43,9 @@ export const TabsMenu = ({ onClick, editable = true, closable = true, clonable =
4143
{closable ? (
4244
<>
4345
{showDivider && <Menu.Divider />}
44-
<Menu.Item onClick={() => onClick("close")}>Close</Menu.Item>
46+
<Menu.Item onClick={() => onClick("close")} data-leave>
47+
Close
48+
</Menu.Item>
4549
</>
4650
) : null}
4751
</Menu>

Diff for: web/libs/editor/src/components/BottomBar/Controls.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ const ControlButton = observer(({ button, disabled, onClick }: ControlButtonProp
4949

5050
return (
5151
<ButtonTooltip title={button.tooltip ?? ""}>
52-
<Button aria-label={button.ariaLabel} disabled={button.disabled || disabled} look={look} onClick={onClick}>
52+
<Button
53+
{...button.props}
54+
aria-label={button.ariaLabel}
55+
disabled={button.disabled || disabled}
56+
look={look}
57+
onClick={onClick}
58+
>
5359
{button.title}
5460
</Button>
5561
</ButtonTooltip>

Diff for: web/libs/editor/src/stores/CustomButton.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { applySnapshot, getSnapshot, type Instance, type SnapshotIn, types } from "mobx-state-tree";
1+
import { type Instance, type SnapshotIn, types } from "mobx-state-tree";
22
import { guidGenerator } from "../utils/unique";
33

44
export type CustomButtonType = Instance<typeof CustomButton>;
@@ -19,9 +19,14 @@ export const CustomButton = types
1919
tooltip: types.maybe(types.string),
2020
ariaLabel: types.maybe(types.string),
2121
disabled: types.maybe(types.boolean),
22+
props: types.maybe(types.frozen()),
2223
})
2324
.actions((self) => ({
2425
updateState(newState: CustomButtonSnType) {
25-
applySnapshot(self, Object.assign({}, getSnapshot(self), newState));
26+
for (const key in newState) {
27+
if (key in self) {
28+
self[key] = newState[key];
29+
}
30+
}
2631
},
2732
}));

0 commit comments

Comments
 (0)