-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathGuideRowDetails.tsx
More file actions
178 lines (169 loc) · 4.67 KB
/
GuideRowDetails.tsx
File metadata and controls
178 lines (169 loc) · 4.67 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import { Box, Stack } from "@telegraph/layout";
import { Tooltip } from "@telegraph/tooltip";
import { Text } from "@telegraph/typography";
import {
StatusColor,
GuideAnnotatedStatusDot as StatusDot,
} from "./GuideAnnotatedStatusDot";
import { ERROR_MESSAGE } from "./helpers";
import {
AnnotatedGuide,
UncommittedGuide,
isUncommittedGuide,
} from "./useInspectGuideClientStore";
const CardContainer = ({
title,
children,
}: {
title: string;
children: React.ReactNode;
}) => (
<Stack
direction="column"
justify="flex-start"
gap="1"
px="1_5"
py="1"
rounded="2"
bg="surface-1"
border="px"
borderColor="gray-4"
style={{ flex: 1 }}
>
<Text as="span" size="0" color="gray" weight="medium">
{title}
</Text>
<Stack direction="column" gap="1" mt="1">
{children}
</Stack>
</Stack>
);
const StatusRow = ({
label,
value,
color,
tooltip,
}: {
label: string;
value: string;
color: StatusColor;
tooltip?: React.ReactNode;
}) => {
return (
<Stack align="center" gap="1">
<Tooltip enabled={!!tooltip} label={tooltip} delayDuration={500}>
<Stack as="span" align="center" gap="1" display="inline-flex">
<StatusDot color={color} tooltip={`${label}: ${value}`} />
<Text as="span" size="1" weight="medium">
{label}:
</Text>
<Text as="span" size="1" weight="medium" color={color}>
{value}
</Text>
</Stack>
</Tooltip>
</Stack>
);
};
export type StatusSummary = {
color: StatusColor;
label: string;
description: string;
};
export const getSelectableStatusSummary = (
status: "returned" | "throttled" | "queried" | undefined,
): StatusSummary => {
switch (status) {
case "returned":
return {
label: "Ready to display",
color: "blue",
description: "This guide is queried and ready to display",
};
case "throttled":
return {
label: "Throttled",
color: "yellow",
description:
"This guide is queried and ready to display, but throttled currently",
};
case "queried":
return {
label: "Queued",
color: "gray",
description: "This guide is queried but is not ready to display",
};
default:
return {
label: "Not queried",
color: "red",
description: `This guide is not queried (${ERROR_MESSAGE.focusUnselectableGuide.toLowerCase()})`,
};
}
};
export const GuideRowDetails = ({
guide,
}: {
guide: AnnotatedGuide | UncommittedGuide;
}) => {
if (isUncommittedGuide(guide)) {
return (
<Box px="3" py="2">
<Text as="span" size="1" color="gray">
This guide has never been committed and published.
</Text>
</Box>
);
}
const { annotation } = guide;
const selectableStatusSummary = getSelectableStatusSummary(
annotation.selectable.status,
);
return (
<Stack px="3" py="2" gap="2" direction="row" align="flex-start">
<CardContainer title="Eligibility">
<StatusRow
label="Active"
value={annotation.active.status ? "Yes" : "No"}
color={annotation.active.status ? "blue" : "red"}
tooltip="Eligible if the guide is currently active"
/>
<StatusRow
label="Archived"
value={annotation.archived.status ? "Yes" : "No"}
color={annotation.archived.status ? "red" : "blue"}
tooltip="Eligible if the guide has not been dismissed/archived by the user already"
/>
<StatusRow
label="Targeting"
value={annotation.targetable.status ? "Yes" : "No"}
color={annotation.targetable.status ? "blue" : "red"}
tooltip="Eligible if the user meets the guide's targeting conditions"
/>
</CardContainer>
<CardContainer title="Visibility">
<StatusRow
label="Activation"
value={annotation.activatable.status ? "Yes" : "No"}
color={annotation.activatable.status ? "blue" : "red"}
tooltip="Visible when the user's current location matches the guide's activation rules"
/>
<StatusRow
label="Display"
value={selectableStatusSummary.label}
color={selectableStatusSummary.color}
tooltip={
<Text as="span" size="1">
Visible when the guide is queried via `useGuide(s)` in the current
page,
<br />
and ready to display per its position in the display pipeline:
<br />
{selectableStatusSummary.description}
</Text>
}
/>
</CardContainer>
</Stack>
);
};