-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathV2.tsx
More file actions
133 lines (118 loc) · 3.59 KB
/
Copy pathV2.tsx
File metadata and controls
133 lines (118 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import { useGuideContext } from "@knocklabs/react-core";
import { Button } from "@telegraph/button";
import { Box, Stack } from "@telegraph/layout";
import { Minimize2, Undo2 } from "lucide-react";
import React from "react";
import { KnockButton } from "../KnockButton";
import { TOOLBAR_Z_INDEX } from "../shared";
import "../styles.css";
import { GuideContextDetails } from "./GuideContextDetails";
import { GuideRow } from "./GuideRow";
import {
DisplayOption,
GuidesListDisplaySelect,
} from "./GuidesListDisplaySelect";
import { detectToolbarParam } from "./helpers";
import {
InspectionResult,
useInspectGuideClientStore,
} from "./useInspectGuideClientStore";
const GuidesList = ({
guides,
displayOption,
}: {
guides: InspectionResult["guides"];
displayOption: DisplayOption;
}) => {
return guides.map((guide, idx) => {
const { isEligible, isQualified, selectable } = guide.annotation;
const isDisplayable = isEligible && isQualified;
const isDisplaying = isDisplayable && selectable.status === "returned";
if (displayOption === "only-displaying" && !isDisplaying) {
return null;
}
if (displayOption === "only-displayable" && !isDisplayable) {
return null;
}
if (displayOption === "all-eligible" && !isEligible) {
return null;
}
return <GuideRow key={guide.key} guide={guide} orderIndex={idx} />;
});
};
export const V2 = () => {
const { client } = useGuideContext();
const [guidesListDisplayOption, setGuidesListDisplayOption] =
React.useState<DisplayOption>("only-displayable");
const [isVisible, setIsVisible] = React.useState(detectToolbarParam());
const [isCollapsed, setIsCollapsed] = React.useState(true);
React.useEffect(() => {
if (!isVisible) {
return;
}
client.setDebug();
return () => {
client.unsetDebug();
};
}, [isVisible, client]);
const result = useInspectGuideClientStore();
if (!result) {
return null;
}
return (
<Box position="fixed" top="4" right="4" style={{ zIndex: TOOLBAR_Z_INDEX }}>
{isCollapsed ? (
<KnockButton onClick={() => setIsCollapsed(false)} />
) : (
<Stack
direction="column"
backgroundColor="surface-2"
shadow="2"
rounded="3"
border="px"
overflow="hidden"
style={{ width: "400px" }}
>
<Stack
w="full"
p="2"
justify="space-between"
direction="row"
style={{ boxSizing: "border-box" }}
>
<Box style={{ width: "220px" }}>
<GuidesListDisplaySelect
value={guidesListDisplayOption}
onChange={(opt) => setGuidesListDisplayOption(opt)}
/>
</Box>
<Stack gap="2">
<Button
onClick={() => setIsVisible(false)}
size="1"
variant="soft"
trailingIcon={{ icon: Undo2, "aria-hidden": true }}
>
Exit
</Button>
<Button
onClick={() => setIsCollapsed(true)}
size="1"
variant="soft"
leadingIcon={{ icon: Minimize2, alt: "Collapse guide toolbar" }}
/>
</Stack>
</Stack>
<Box w="full">
{result.error && <Box>{result.error}</Box>}
<GuideContextDetails />
<GuidesList
guides={result.guides}
displayOption={guidesListDisplayOption}
/>
</Box>
</Stack>
)}
</Box>
);
};