Skip to content

Commit 64c1364

Browse files
committed
feat: switch ui tile run menu to split action dropdown
No added functionality here, but paving the way for alternate run actions besides Run Once (what we had before as the default behavior of the run icon button). Signed-off-by: Nick Mitchell <[email protected]>
1 parent ac85bce commit 64c1364

File tree

2 files changed

+77
-19
lines changed

2 files changed

+77
-19
lines changed

pdl-live-react/src/view/masonry/MasonryTile.tsx

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { useCallback, useMemo } from "react"
1+
import { useMemo } from "react"
22

33
import {
4-
Button,
54
CardHeader,
65
CardTitle,
76
DescriptionList,
@@ -14,6 +13,7 @@ import {
1413
} from "@patternfly/react-core"
1514

1615
import Result from "../Result"
16+
import RunMenu from "./RunMenu"
1717
import Duration from "./Duration"
1818
import MasonryTileWrapper from "./MasonryTileWrapper"
1919
import BreadcrumbBarForBlockId from "../breadcrumbs/BreadcrumbBarForBlockId"
@@ -28,8 +28,6 @@ const gapSm = { default: "gapSm" as const }
2828
const nowrap = { default: "nowrap" as const }
2929
const center = { default: "alignItemsCenter" as const }
3030

31-
import RunIcon from "@patternfly/react-icons/dist/esm/icons/redo-icon"
32-
3331
export default function MasonryTile({
3432
sml,
3533
id,
@@ -48,12 +46,6 @@ export default function MasonryTile({
4846
block,
4947
run,
5048
}: Props) {
51-
const myRun = useCallback(() => {
52-
if (block && run) {
53-
run(block)
54-
}
55-
}, [block, run])
56-
5749
const actions = useMemo(
5850
() => ({
5951
actions: (
@@ -68,22 +60,15 @@ export default function MasonryTile({
6860
)}
6961
{tileActions.map((action) =>
7062
action === "run" ? (
71-
<Button
72-
key={action}
73-
icon={<RunIcon />}
74-
variant="plain"
75-
size="sm"
76-
isDisabled={!window.__TAURI_INTERNALS__}
77-
onClick={myRun}
78-
/>
63+
<RunMenu key="run" run={run} block={block} />
7964
) : (
8065
<></>
8166
),
8267
)}
8368
</>
8469
),
8570
}),
86-
[tileActions, myRun, start_nanos, end_nanos, timezone, sml],
71+
[tileActions, run, block, start_nanos, end_nanos, timezone, sml],
8772
)
8873

8974
const maxHeight =
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { useCallback, useMemo, useState } from "react"
2+
import {
3+
Dropdown,
4+
DropdownList,
5+
DropdownItem,
6+
MenuToggle,
7+
MenuToggleAction,
8+
} from "@patternfly/react-core"
9+
10+
import RunIcon from "@patternfly/react-icons/dist/esm/icons/redo-icon"
11+
12+
type Props = Pick<import("./Tile").default, "block"> & {
13+
run: import("./MasonryCombo").Runner
14+
}
15+
16+
/**
17+
* The Run split action dropdown placed in the upper right of each
18+
* MasonryTile.
19+
*/
20+
export default function RunMenu({ block, run }: Props) {
21+
const runOnce = useCallback(() => {
22+
if (block && run) {
23+
run(block)
24+
}
25+
}, [block, run])
26+
27+
const [isRunOpen, setIsRunOpen] = useState(false)
28+
const onRunToggle = useCallback(
29+
() => setIsRunOpen((open) => !open),
30+
[setIsRunOpen],
31+
)
32+
33+
const splitButtonItems = useMemo(
34+
() => [
35+
<MenuToggleAction
36+
key="split-action-run"
37+
aria-label="Run"
38+
onClick={runOnce}
39+
>
40+
<RunIcon />
41+
</MenuToggleAction>,
42+
],
43+
[runOnce],
44+
)
45+
46+
return (
47+
<Dropdown
48+
isOpen={isRunOpen}
49+
onSelect={onRunToggle}
50+
onOpenChange={setIsRunOpen}
51+
toggle={(toggleRef) => (
52+
<MenuToggle
53+
size="sm"
54+
ref={toggleRef}
55+
onClick={onRunToggle}
56+
isExpanded={isRunOpen}
57+
isDisabled={!window.__TAURI_INTERNALS__}
58+
splitButtonItems={splitButtonItems}
59+
/>
60+
)}
61+
>
62+
<DropdownList>
63+
<DropdownItem
64+
icon={<RunIcon />}
65+
description="Run this block once"
66+
onClick={runOnce}
67+
>
68+
Run Once
69+
</DropdownItem>
70+
</DropdownList>
71+
</Dropdown>
72+
)
73+
}

0 commit comments

Comments
 (0)