@terreno/ui 57.3.0 → 57.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AnnouncementBanner.d.ts +12 -0
- package/dist/AnnouncementBanner.js +61 -0
- package/dist/AnnouncementBanner.js.map +1 -0
- package/dist/AnnouncementNavigator.d.ts +11 -0
- package/dist/AnnouncementNavigator.js +189 -0
- package/dist/AnnouncementNavigator.js.map +1 -0
- package/dist/AnnouncementScreen.d.ts +12 -0
- package/dist/AnnouncementScreen.js +28 -0
- package/dist/AnnouncementScreen.js.map +1 -0
- package/dist/AreaChart.d.ts +5 -0
- package/dist/AreaChart.js +69 -0
- package/dist/AreaChart.js.map +1 -0
- package/dist/BarChart.d.ts +5 -0
- package/dist/BarChart.js +89 -0
- package/dist/BarChart.js.map +1 -0
- package/dist/Button.js +17 -3
- package/dist/Button.js.map +1 -1
- package/dist/Common.d.ts +96 -0
- package/dist/Common.js.map +1 -1
- package/dist/DashboardGrid.d.ts +4 -0
- package/dist/DashboardGrid.js +38 -0
- package/dist/DashboardGrid.js.map +1 -0
- package/dist/DataTable.js +83 -11
- package/dist/DataTable.js.map +1 -1
- package/dist/DonutChart.d.ts +5 -0
- package/dist/DonutChart.js +84 -0
- package/dist/DonutChart.js.map +1 -0
- package/dist/Filter.js +12 -2
- package/dist/Filter.js.map +1 -1
- package/dist/GPTChat.d.ts +7 -1
- package/dist/GPTChat.js +28 -15
- package/dist/GPTChat.js.map +1 -1
- package/dist/LineChart.d.ts +5 -0
- package/dist/LineChart.js +68 -0
- package/dist/LineChart.js.map +1 -0
- package/dist/MarkdownEmbed.d.ts +6 -0
- package/dist/MarkdownEmbed.js +17 -0
- package/dist/MarkdownEmbed.js.map +1 -0
- package/dist/MarkdownView.js +38 -3
- package/dist/MarkdownView.js.map +1 -1
- package/dist/Modal.js +12 -10
- package/dist/Modal.js.map +1 -1
- package/dist/ModalSheet.d.ts +5 -1
- package/dist/ModalSheet.js +31 -13
- package/dist/ModalSheet.js.map +1 -1
- package/dist/MultiselectField.js +4 -9
- package/dist/MultiselectField.js.map +1 -1
- package/dist/NotificationBell.d.ts +16 -0
- package/dist/NotificationBell.js +15 -0
- package/dist/NotificationBell.js.map +1 -0
- package/dist/NotificationInbox.d.ts +21 -0
- package/dist/NotificationInbox.js +41 -0
- package/dist/NotificationInbox.js.map +1 -0
- package/dist/NotificationPreferences.d.ts +14 -0
- package/dist/NotificationPreferences.js +32 -0
- package/dist/NotificationPreferences.js.map +1 -0
- package/dist/TextField.js +83 -6
- package/dist/TextField.js.map +1 -1
- package/dist/announcementBuildVersion.d.ts +6 -0
- package/dist/announcementBuildVersion.js +21 -0
- package/dist/announcementBuildVersion.js.map +1 -0
- package/dist/announcementFrequency.d.ts +42 -0
- package/dist/announcementFrequency.js +163 -0
- package/dist/announcementFrequency.js.map +1 -0
- package/dist/announcementPlatform.d.ts +2 -0
- package/dist/announcementPlatform.js +11 -0
- package/dist/announcementPlatform.js.map +1 -0
- package/dist/charts/ChartFrame.d.ts +12 -0
- package/dist/charts/ChartFrame.js +13 -0
- package/dist/charts/ChartFrame.js.map +1 -0
- package/dist/charts/bars.d.ts +18 -0
- package/dist/charts/bars.js +29 -0
- package/dist/charts/bars.js.map +1 -0
- package/dist/charts/layout.d.ts +47 -0
- package/dist/charts/layout.js +56 -0
- package/dist/charts/layout.js.map +1 -0
- package/dist/charts/paths.d.ts +31 -0
- package/dist/charts/paths.js +52 -0
- package/dist/charts/paths.js.map +1 -0
- package/dist/charts/scales.d.ts +6 -0
- package/dist/charts/scales.js +43 -0
- package/dist/charts/scales.js.map +1 -0
- package/dist/charts/theme.d.ts +9 -0
- package/dist/charts/theme.js +15 -0
- package/dist/charts/theme.js.map +1 -0
- package/dist/charts/types/chartTypes.d.ts +17 -0
- package/dist/charts/types/chartTypes.js +2 -0
- package/dist/charts/types/chartTypes.js.map +1 -0
- package/dist/dashboardGridLayout.d.ts +22 -0
- package/dist/dashboardGridLayout.js +33 -0
- package/dist/dashboardGridLayout.js.map +1 -0
- package/dist/dataTableFilters.d.ts +33 -0
- package/dist/dataTableFilters.js +221 -0
- package/dist/dataTableFilters.js.map +1 -0
- package/dist/dataTableListQuery.d.ts +42 -0
- package/dist/dataTableListQuery.js +161 -0
- package/dist/dataTableListQuery.js.map +1 -0
- package/dist/index.d.ts +18 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts +12 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js +8 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
- package/dist/markdownEmbeds.d.ts +6 -0
- package/dist/markdownEmbeds.js +59 -0
- package/dist/markdownEmbeds.js.map +1 -0
- package/dist/testing/resolveTestId.js +2 -1
- package/dist/testing/resolveTestId.js.map +1 -1
- package/dist/testing/types.d.ts +3 -0
- package/dist/textFieldOscillationGuard.d.ts +25 -0
- package/dist/textFieldOscillationGuard.js +41 -0
- package/dist/textFieldOscillationGuard.js.map +1 -0
- package/dist/useAcknowledgeAnnouncement.d.ts +71 -0
- package/dist/useAcknowledgeAnnouncement.js +94 -0
- package/dist/useAcknowledgeAnnouncement.js.map +1 -0
- package/dist/useAnnouncements.d.ts +73 -0
- package/dist/useAnnouncements.js +66 -0
- package/dist/useAnnouncements.js.map +1 -0
- package/package.json +7 -18
- package/src/AnnouncementBanner.test.tsx +267 -0
- package/src/AnnouncementBanner.tsx +128 -0
- package/src/AnnouncementNavigator.test.tsx +759 -0
- package/src/AnnouncementNavigator.tsx +287 -0
- package/src/AnnouncementScreen.test.tsx +97 -0
- package/src/AnnouncementScreen.tsx +70 -0
- package/src/AreaChart.test.tsx +68 -0
- package/src/AreaChart.tsx +194 -0
- package/src/BarChart.test.tsx +96 -0
- package/src/BarChart.tsx +208 -0
- package/src/Button.test.tsx +66 -0
- package/src/Button.tsx +17 -2
- package/src/Common.ts +95 -0
- package/src/ConsentNavigator.test.tsx +55 -0
- package/src/DashboardGrid.test.tsx +75 -0
- package/src/DashboardGrid.tsx +69 -0
- package/src/DataTable.test.tsx +296 -1
- package/src/DataTable.tsx +210 -18
- package/src/DonutChart.test.tsx +121 -0
- package/src/DonutChart.tsx +160 -0
- package/src/EmojiSelector.test.tsx +51 -0
- package/src/Field.test.tsx +18 -0
- package/src/Filter.test.tsx +25 -0
- package/src/Filter.tsx +38 -7
- package/src/GPTChat.test.tsx +107 -0
- package/src/GPTChat.tsx +176 -86
- package/src/LineChart.test.tsx +166 -0
- package/src/LineChart.tsx +190 -0
- package/src/MarkdownEmbed.test.tsx +34 -0
- package/src/MarkdownEmbed.tsx +43 -0
- package/src/MarkdownView.test.tsx +59 -2
- package/src/MarkdownView.tsx +51 -3
- package/src/Modal.test.tsx +107 -14
- package/src/Modal.tsx +20 -8
- package/src/ModalSheet.test.tsx +121 -9
- package/src/ModalSheet.tsx +46 -11
- package/src/MultiselectField.test.tsx +21 -0
- package/src/MultiselectField.tsx +11 -13
- package/src/NotificationBell.test.tsx +91 -0
- package/src/NotificationBell.tsx +77 -0
- package/src/NotificationInbox.test.tsx +130 -0
- package/src/NotificationInbox.tsx +144 -0
- package/src/NotificationPreferences.test.tsx +25 -0
- package/src/NotificationPreferences.tsx +75 -0
- package/src/RootImportRegression.test.tsx +20 -0
- package/src/TextField.test.tsx +421 -0
- package/src/TextField.tsx +121 -4
- package/src/__snapshots__/Field.test.tsx.snap +22 -0
- package/src/__snapshots__/ModalSheet.test.tsx.snap +4 -1
- package/src/__snapshots__/TextArea.test.tsx.snap +5 -5
- package/src/__snapshots__/TextField.test.tsx.snap +5 -5
- package/src/announcementBuildVersion.test.ts +43 -0
- package/src/announcementBuildVersion.ts +21 -0
- package/src/announcementFrequency.test.ts +245 -0
- package/src/announcementFrequency.ts +246 -0
- package/src/announcementPlatform.test.ts +27 -0
- package/src/announcementPlatform.ts +13 -0
- package/src/charts/ChartFrame.tsx +67 -0
- package/src/charts/bars.test.ts +56 -0
- package/src/charts/bars.ts +53 -0
- package/src/charts/layout.test.ts +80 -0
- package/src/charts/layout.ts +99 -0
- package/src/charts/paths.test.ts +79 -0
- package/src/charts/paths.ts +100 -0
- package/src/charts/scales.test.ts +59 -0
- package/src/charts/scales.ts +60 -0
- package/src/charts/theme.test.ts +22 -0
- package/src/charts/theme.ts +24 -0
- package/src/charts/types/chartTypes.ts +19 -0
- package/src/dashboardGridLayout.test.ts +90 -0
- package/src/dashboardGridLayout.ts +60 -0
- package/src/dataTableFilters.test.tsx +552 -0
- package/src/dataTableFilters.tsx +441 -0
- package/src/dataTableListQuery.test.ts +220 -0
- package/src/dataTableListQuery.ts +201 -0
- package/src/index.tsx +21 -1
- package/src/lazyBoundaries/heavyOptionalExports.tsx +28 -0
- package/src/login/__snapshots__/LoginScreen.test.tsx.snap +22 -0
- package/src/markdownEmbeds.test.ts +53 -0
- package/src/markdownEmbeds.ts +62 -0
- package/src/pdfHtmlTemplate.test.ts +119 -0
- package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +22 -0
- package/src/testing/resolveTestId.test.ts +3 -0
- package/src/testing/resolveTestId.ts +1 -0
- package/src/testing/types.ts +3 -0
- package/src/textFieldOscillationGuard.test.ts +63 -0
- package/src/textFieldOscillationGuard.ts +89 -0
- package/src/types/react-native-markdown-display.d.ts +6 -0
- package/src/types/react-native-swiper-flatlist.d.ts +5 -5
- package/src/useAcknowledgeAnnouncement.test.ts +223 -0
- package/src/useAcknowledgeAnnouncement.ts +166 -0
- package/src/useAnnouncements.test.ts +226 -0
- package/src/useAnnouncements.ts +150 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import {describe, expect, it, spyOn} from "bun:test";
|
|
2
|
+
import {act, fireEvent} from "@testing-library/react-native";
|
|
3
|
+
import {Linking} from "react-native";
|
|
4
|
+
|
|
5
|
+
import {LineChart} from "./LineChart";
|
|
6
|
+
import {renderWithTheme} from "./test-utils";
|
|
7
|
+
|
|
8
|
+
const POINTS = [
|
|
9
|
+
{label: "A", value: 0},
|
|
10
|
+
{label: "B", value: 50},
|
|
11
|
+
{label: "C", value: 100},
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
describe("LineChart", () => {
|
|
15
|
+
it("renders one mark testID per point", () => {
|
|
16
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
17
|
+
<LineChart data={POINTS} testID="chart" />
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
expect(getByTestId("chart.point.0-clickable")).toBeTruthy();
|
|
21
|
+
expect(getByTestId("chart.point.1-clickable")).toBeTruthy();
|
|
22
|
+
expect(getByTestId("chart.point.2-clickable")).toBeTruthy();
|
|
23
|
+
expect(queryByTestId("chart.point.3-clickable")).toBeNull();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("forwards the chart summary accessibility label to the frame", () => {
|
|
27
|
+
const {getByTestId} = renderWithTheme(
|
|
28
|
+
<LineChart accessibilityLabel="Weekly signups chart" data={POINTS} testID="chart" />
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
expect(getByTestId("chart").props.accessibilityLabel).toBe("Weekly signups chart");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("shows emptyText when data is empty", () => {
|
|
35
|
+
const {getByText, queryByText} = renderWithTheme(
|
|
36
|
+
<LineChart data={[]} emptyText="Nothing yet" />
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
expect(getByText("Nothing yet")).toBeTruthy();
|
|
40
|
+
expect(queryByText("Line chart")).toBeNull();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("shows the default empty copy", () => {
|
|
44
|
+
const {getByText} = renderWithTheme(<LineChart data={[]} />);
|
|
45
|
+
|
|
46
|
+
expect(getByText("No data")).toBeTruthy();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("shows a spinner when loading and hides marks", async () => {
|
|
50
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
51
|
+
<LineChart data={POINTS} loading testID="chart" />
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
expect(queryByTestId("chart.point.0-clickable")).toBeNull();
|
|
55
|
+
|
|
56
|
+
await act(async () => {
|
|
57
|
+
await new Promise((resolve) => setTimeout(resolve, 350));
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
expect(getByTestId("chart.spinner")).toBeTruthy();
|
|
61
|
+
expect(queryByTestId("chart.point.0-clickable")).toBeNull();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("prefers loading over empty copy", async () => {
|
|
65
|
+
const {queryByText, getByTestId} = renderWithTheme(
|
|
66
|
+
<LineChart data={[]} emptyText="Nothing yet" loading testID="chart" />
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
expect(queryByText("Nothing yet")).toBeNull();
|
|
70
|
+
|
|
71
|
+
await act(async () => {
|
|
72
|
+
await new Promise((resolve) => setTimeout(resolve, 350));
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
expect(getByTestId("chart.spinner")).toBeTruthy();
|
|
76
|
+
expect(queryByText("Nothing yet")).toBeNull();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("shows tooltip copy after pressing a mark", async () => {
|
|
80
|
+
const {getByTestId, getByText, queryByTestId} = renderWithTheme(
|
|
81
|
+
<LineChart data={POINTS} testID="chart" />
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
expect(queryByTestId("chart.tooltip")).toBeNull();
|
|
85
|
+
|
|
86
|
+
await act(async () => {
|
|
87
|
+
fireEvent.press(getByTestId("chart.point.1-clickable"));
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
expect(getByTestId("chart.tooltip")).toBeTruthy();
|
|
91
|
+
expect(getByText("B: 50")).toBeTruthy();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("updates or clears the active tooltip when data changes", async () => {
|
|
95
|
+
const {getByTestId, getByText, queryByTestId, rerender} = renderWithTheme(
|
|
96
|
+
<LineChart data={POINTS} testID="chart" />
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
await act(async () => {
|
|
100
|
+
fireEvent.press(getByTestId("chart.point.1-clickable"));
|
|
101
|
+
});
|
|
102
|
+
rerender(
|
|
103
|
+
<LineChart
|
|
104
|
+
data={[
|
|
105
|
+
{label: "A", value: 0},
|
|
106
|
+
{label: "B", value: 75},
|
|
107
|
+
]}
|
|
108
|
+
testID="chart"
|
|
109
|
+
/>
|
|
110
|
+
);
|
|
111
|
+
expect(getByText("B: 75")).toBeTruthy();
|
|
112
|
+
|
|
113
|
+
rerender(<LineChart data={[{label: "A", value: 0}]} testID="chart" />);
|
|
114
|
+
expect(queryByTestId("chart.tooltip")).toBeNull();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("renders the legend label", () => {
|
|
118
|
+
const {getByText} = renderWithTheme(<LineChart data={POINTS} legendLabel="Sales" />);
|
|
119
|
+
|
|
120
|
+
expect(getByText("Sales")).toBeTruthy();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("resizes the plot to a measured container narrower than the default width", async () => {
|
|
124
|
+
const {getByTestId} = renderWithTheme(<LineChart data={POINTS} testID="chart" />);
|
|
125
|
+
|
|
126
|
+
await act(async () => {
|
|
127
|
+
fireEvent(getByTestId("chart.plot"), "layout", {
|
|
128
|
+
nativeEvent: {layout: {height: 200, width: 120}},
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const markStyle = getByTestId("chart.point.2-clickable").props.style;
|
|
133
|
+
const styles = Array.isArray(markStyle) ? markStyle : [markStyle];
|
|
134
|
+
const positioned = styles.find(
|
|
135
|
+
(entry: {left?: number} | undefined) => typeof entry?.left === "number"
|
|
136
|
+
) as {left: number};
|
|
137
|
+
|
|
138
|
+
expect(positioned.left).toBeLessThan(120);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("keeps x-axis labels absolutely positioned so a long label cannot widen the chart", () => {
|
|
142
|
+
const {getByTestId} = renderWithTheme(
|
|
143
|
+
<LineChart data={[{label: "A very long axis label", value: 10}]} testID="chart" />
|
|
144
|
+
);
|
|
145
|
+
const slotStyle = getByTestId("chart.xtick.0").props.style;
|
|
146
|
+
const styles = Array.isArray(slotStyle) ? slotStyle : [slotStyle];
|
|
147
|
+
|
|
148
|
+
expect(styles).toEqual(
|
|
149
|
+
expect.arrayContaining([expect.objectContaining({position: "absolute"})])
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("does not open URLs from x-axis labels", async () => {
|
|
154
|
+
const openURLSpy = spyOn(Linking, "openURL").mockImplementation(() => Promise.resolve(true));
|
|
155
|
+
const {getByText} = renderWithTheme(
|
|
156
|
+
<LineChart data={[{label: "https://evil.example", value: 10}]} />
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
await act(async () => {
|
|
160
|
+
fireEvent.press(getByText("https://evil.example"));
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
expect(openURLSpy).not.toHaveBeenCalled();
|
|
164
|
+
openURLSpy.mockRestore();
|
|
165
|
+
});
|
|
166
|
+
});
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import type {FC} from "react";
|
|
2
|
+
import {useCallback, useState} from "react";
|
|
3
|
+
import {Circle, Path, Svg, Line as SvgLine} from "react-native-svg";
|
|
4
|
+
|
|
5
|
+
import {Box} from "./Box";
|
|
6
|
+
import type {LayoutChangeEvent, LineChartProps} from "./Common";
|
|
7
|
+
import {ChartFrame} from "./charts/ChartFrame";
|
|
8
|
+
import {
|
|
9
|
+
CHART_X_AXIS_HEIGHT,
|
|
10
|
+
getChartAxisWidth,
|
|
11
|
+
getChartPlot,
|
|
12
|
+
getPlotHeight,
|
|
13
|
+
getXTickStyle,
|
|
14
|
+
getYTickStyle,
|
|
15
|
+
} from "./charts/layout";
|
|
16
|
+
import {getLinePath} from "./charts/paths";
|
|
17
|
+
import {createCartesianScales, getYTickValues} from "./charts/scales";
|
|
18
|
+
import {getChartPaint} from "./charts/theme";
|
|
19
|
+
import type {ChartPoint} from "./charts/types/chartTypes";
|
|
20
|
+
import {Text} from "./Text";
|
|
21
|
+
import {useTheme} from "./Theme";
|
|
22
|
+
import {resolveTestID} from "./testing/resolveTestId";
|
|
23
|
+
|
|
24
|
+
const DEFAULT_HEIGHT = 200;
|
|
25
|
+
const DEFAULT_WIDTH = 300;
|
|
26
|
+
const MARK_HIT_SIZE = 24;
|
|
27
|
+
|
|
28
|
+
const formatChartTooltip = ({
|
|
29
|
+
formatValue,
|
|
30
|
+
point,
|
|
31
|
+
}: {
|
|
32
|
+
formatValue: (value: number) => string;
|
|
33
|
+
point: ChartPoint;
|
|
34
|
+
}): string => {
|
|
35
|
+
return `${point.label}: ${formatValue(point.value)}`;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const LineChart: FC<LineChartProps> = ({
|
|
39
|
+
accessibilityLabel,
|
|
40
|
+
data,
|
|
41
|
+
emptyText = "No data",
|
|
42
|
+
formatValue = String,
|
|
43
|
+
height = DEFAULT_HEIGHT,
|
|
44
|
+
legendLabel,
|
|
45
|
+
loading = false,
|
|
46
|
+
testID,
|
|
47
|
+
}) => {
|
|
48
|
+
const {theme} = useTheme();
|
|
49
|
+
const paint = getChartPaint(theme);
|
|
50
|
+
const [chartWidth, setChartWidth] = useState(DEFAULT_WIDTH);
|
|
51
|
+
const [activePointIndex, setActivePointIndex] = useState<number | undefined>(undefined);
|
|
52
|
+
|
|
53
|
+
const handleLayout = useCallback((event: LayoutChangeEvent): void => {
|
|
54
|
+
const nextWidth = event.nativeEvent.layout.width;
|
|
55
|
+
if (nextWidth > 0) {
|
|
56
|
+
setChartWidth(nextWidth);
|
|
57
|
+
}
|
|
58
|
+
}, []);
|
|
59
|
+
|
|
60
|
+
const handleMarkPress = useCallback((pointIndex: number): void => {
|
|
61
|
+
setActivePointIndex(pointIndex);
|
|
62
|
+
}, []);
|
|
63
|
+
|
|
64
|
+
const axisWidth = getChartAxisWidth(chartWidth);
|
|
65
|
+
const plotHeight = getPlotHeight({hasLegend: Boolean(legendLabel), height});
|
|
66
|
+
const plot = getChartPlot({chartWidth, height: plotHeight});
|
|
67
|
+
const plotWidth = chartWidth - axisWidth;
|
|
68
|
+
const scales = createCartesianScales({plot, points: data});
|
|
69
|
+
const linePath = getLinePath({points: data, scales});
|
|
70
|
+
const yTicks = getYTickValues(data);
|
|
71
|
+
const activePoint = activePointIndex === undefined ? undefined : data[activePointIndex];
|
|
72
|
+
const tooltipText = activePoint
|
|
73
|
+
? formatChartTooltip({formatValue, point: activePoint})
|
|
74
|
+
: undefined;
|
|
75
|
+
const summaryLabel =
|
|
76
|
+
accessibilityLabel ?? (legendLabel ? `${legendLabel} line chart` : "Line chart");
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<ChartFrame
|
|
80
|
+
accessibilityLabel={summaryLabel}
|
|
81
|
+
emptyText={emptyText}
|
|
82
|
+
isEmpty={data.length === 0}
|
|
83
|
+
legendLabel={legendLabel}
|
|
84
|
+
loading={loading}
|
|
85
|
+
testID={testID}
|
|
86
|
+
tooltipText={tooltipText}
|
|
87
|
+
>
|
|
88
|
+
<Box minWidth={0} onLayout={handleLayout} testID={resolveTestID(testID, "plot")} width="100%">
|
|
89
|
+
<Box direction="row" height={plotHeight}>
|
|
90
|
+
<Box height={plotHeight} position="relative" width={axisWidth}>
|
|
91
|
+
{yTicks.map((tick) => (
|
|
92
|
+
<Box
|
|
93
|
+
dangerouslySetInlineStyle={{__style: getYTickStyle({axisWidth, y: scales.y(tick)})}}
|
|
94
|
+
key={`ytick-${tick}`}
|
|
95
|
+
>
|
|
96
|
+
<Text align="right" color="secondaryDark" size="sm" skipLinking truncate>
|
|
97
|
+
{formatValue(tick)}
|
|
98
|
+
</Text>
|
|
99
|
+
</Box>
|
|
100
|
+
))}
|
|
101
|
+
</Box>
|
|
102
|
+
<Box flex="grow" height={plotHeight} minWidth={0} overflow="hidden" position="relative">
|
|
103
|
+
<Svg height={plotHeight} width={plotWidth}>
|
|
104
|
+
{yTicks.map((tick) => {
|
|
105
|
+
const y = scales.y(tick);
|
|
106
|
+
return (
|
|
107
|
+
<SvgLine
|
|
108
|
+
key={`grid-${tick}`}
|
|
109
|
+
stroke={paint.grid}
|
|
110
|
+
strokeWidth={1}
|
|
111
|
+
x1={plot.left}
|
|
112
|
+
x2={plot.left + plot.width}
|
|
113
|
+
y1={y}
|
|
114
|
+
y2={y}
|
|
115
|
+
/>
|
|
116
|
+
);
|
|
117
|
+
})}
|
|
118
|
+
{linePath ? (
|
|
119
|
+
<Path d={linePath} fill="none" stroke={paint.series} strokeWidth={2} />
|
|
120
|
+
) : null}
|
|
121
|
+
{data.map((point) => (
|
|
122
|
+
<Circle
|
|
123
|
+
cx={scales.xCenter(point.label)}
|
|
124
|
+
cy={scales.y(point.value)}
|
|
125
|
+
fill={paint.series}
|
|
126
|
+
key={`dot-${point.label}`}
|
|
127
|
+
r={4}
|
|
128
|
+
/>
|
|
129
|
+
))}
|
|
130
|
+
</Svg>
|
|
131
|
+
{data.map((point, index) => {
|
|
132
|
+
const onPress = (): void => {
|
|
133
|
+
handleMarkPress(index);
|
|
134
|
+
};
|
|
135
|
+
return (
|
|
136
|
+
<Box
|
|
137
|
+
accessibilityHint={`Show value for ${point.label}`}
|
|
138
|
+
accessibilityLabel={`${point.label}: ${formatValue(point.value)}`}
|
|
139
|
+
dangerouslySetInlineStyle={{
|
|
140
|
+
__style: {
|
|
141
|
+
height: MARK_HIT_SIZE,
|
|
142
|
+
left: scales.xCenter(point.label) - MARK_HIT_SIZE / 2,
|
|
143
|
+
position: "absolute",
|
|
144
|
+
top: scales.y(point.value) - MARK_HIT_SIZE / 2,
|
|
145
|
+
width: MARK_HIT_SIZE,
|
|
146
|
+
},
|
|
147
|
+
}}
|
|
148
|
+
key={`mark-${point.label}`}
|
|
149
|
+
onClick={onPress}
|
|
150
|
+
onHoverStart={onPress}
|
|
151
|
+
testID={resolveTestID(testID, `point.${index}`)}
|
|
152
|
+
/>
|
|
153
|
+
);
|
|
154
|
+
})}
|
|
155
|
+
</Box>
|
|
156
|
+
</Box>
|
|
157
|
+
<Box direction="row">
|
|
158
|
+
<Box width={axisWidth} />
|
|
159
|
+
<Box
|
|
160
|
+
flex="grow"
|
|
161
|
+
height={CHART_X_AXIS_HEIGHT}
|
|
162
|
+
minWidth={0}
|
|
163
|
+
overflow="hidden"
|
|
164
|
+
position="relative"
|
|
165
|
+
>
|
|
166
|
+
{data.map((point, index) => (
|
|
167
|
+
<Box
|
|
168
|
+
dangerouslySetInlineStyle={{
|
|
169
|
+
__style: getXTickStyle({
|
|
170
|
+
bandwidth: scales.bandwidth,
|
|
171
|
+
xCenter: scales.xCenter(point.label),
|
|
172
|
+
}),
|
|
173
|
+
}}
|
|
174
|
+
key={`xtick-${point.label}`}
|
|
175
|
+
testID={resolveTestID(testID, `xtick.${index}`)}
|
|
176
|
+
>
|
|
177
|
+
<Text align="center" color="secondaryDark" size="sm" skipLinking truncate>
|
|
178
|
+
{point.label}
|
|
179
|
+
</Text>
|
|
180
|
+
</Box>
|
|
181
|
+
))}
|
|
182
|
+
</Box>
|
|
183
|
+
</Box>
|
|
184
|
+
</Box>
|
|
185
|
+
</ChartFrame>
|
|
186
|
+
);
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
export type {LineChartProps} from "./Common";
|
|
190
|
+
export type {ChartPoint} from "./charts/types/chartTypes";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {describe, expect, it, mock} from "bun:test";
|
|
2
|
+
import {Platform} from "react-native";
|
|
3
|
+
|
|
4
|
+
import {MarkdownEmbed} from "./MarkdownEmbed";
|
|
5
|
+
import {renderWithTheme} from "./test-utils";
|
|
6
|
+
|
|
7
|
+
mock.module("react-native-webview", () => ({
|
|
8
|
+
default: () => null,
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
describe("MarkdownEmbed", () => {
|
|
12
|
+
const originalOS = Platform.OS;
|
|
13
|
+
|
|
14
|
+
it("returns null for non-embeddable URLs", () => {
|
|
15
|
+
const result = renderWithTheme(<MarkdownEmbed url="https://example.com/docs" />);
|
|
16
|
+
expect(result.toJSON()).toBeNull();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("renders the web iframe on web", () => {
|
|
20
|
+
Platform.OS = "web";
|
|
21
|
+
const result = renderWithTheme(
|
|
22
|
+
<MarkdownEmbed url="https://www.youtube.com/watch?v=dQw4w9WgXcQ" />
|
|
23
|
+
);
|
|
24
|
+
expect(result.getByTestId("markdown-embed-web")).toBeTruthy();
|
|
25
|
+
Platform.OS = originalOS;
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("renders the native webview on ios", () => {
|
|
29
|
+
Platform.OS = "ios";
|
|
30
|
+
const result = renderWithTheme(<MarkdownEmbed url="https://www.loom.com/share/abc123def456" />);
|
|
31
|
+
expect(result.getByTestId("markdown-embed-native")).toBeTruthy();
|
|
32
|
+
Platform.OS = originalOS;
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React, {useMemo} from "react";
|
|
2
|
+
import {Platform} from "react-native";
|
|
3
|
+
import WebView from "react-native-webview";
|
|
4
|
+
|
|
5
|
+
import {Box} from "./Box";
|
|
6
|
+
import {toMediaEmbedUrl} from "./markdownEmbeds";
|
|
7
|
+
|
|
8
|
+
interface MarkdownEmbedProps {
|
|
9
|
+
url: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const MarkdownEmbed: React.FC<MarkdownEmbedProps> = ({url}) => {
|
|
13
|
+
const embedUrl = useMemo(() => toMediaEmbedUrl(url), [url]);
|
|
14
|
+
if (!embedUrl) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (Platform.OS === "web") {
|
|
19
|
+
return (
|
|
20
|
+
<Box margin={3} testID="markdown-embed-web" width="100%">
|
|
21
|
+
<iframe
|
|
22
|
+
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
|
23
|
+
allowFullScreen
|
|
24
|
+
src={embedUrl}
|
|
25
|
+
style={{aspectRatio: "16 / 9", border: 0, borderRadius: 8, width: "100%"}}
|
|
26
|
+
title="Embedded media"
|
|
27
|
+
/>
|
|
28
|
+
</Box>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<Box height={220} margin={3} testID="markdown-embed-native" width="100%">
|
|
34
|
+
<WebView
|
|
35
|
+
allowsFullscreenVideo
|
|
36
|
+
javaScriptEnabled
|
|
37
|
+
mediaPlaybackRequiresUserAction={false}
|
|
38
|
+
source={{uri: embedUrl}}
|
|
39
|
+
style={{borderRadius: 8, flex: 1}}
|
|
40
|
+
/>
|
|
41
|
+
</Box>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {describe, expect, it, mock} from "bun:test";
|
|
1
|
+
import {describe, expect, it, mock, spyOn} from "bun:test";
|
|
2
2
|
import assert from "node:assert";
|
|
3
|
-
import {waitFor} from "@testing-library/react-native";
|
|
3
|
+
import {fireEvent, waitFor} from "@testing-library/react-native";
|
|
4
|
+
import {Image, Linking} from "react-native";
|
|
4
5
|
|
|
5
6
|
import {MarkdownView} from "./MarkdownView";
|
|
6
7
|
import {renderWithTheme} from "./test-utils";
|
|
@@ -119,4 +120,60 @@ describe("MarkdownView", () => {
|
|
|
119
120
|
});
|
|
120
121
|
expect(onLoad).toHaveBeenCalled();
|
|
121
122
|
});
|
|
123
|
+
|
|
124
|
+
it("opens ordinary markdown links", async () => {
|
|
125
|
+
const openURL = mock(() => Promise.resolve(true));
|
|
126
|
+
Linking.openURL = openURL;
|
|
127
|
+
const {getByText} = renderWithTheme(
|
|
128
|
+
<MarkdownView>[Docs](https://example.com/docs)</MarkdownView>
|
|
129
|
+
);
|
|
130
|
+
await waitFor(() => {
|
|
131
|
+
expect(getByText("Docs")).toBeTruthy();
|
|
132
|
+
});
|
|
133
|
+
fireEvent.press(getByText("Docs"));
|
|
134
|
+
expect(openURL).toHaveBeenCalledWith("https://example.com/docs");
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("renders YouTube and Loom links as embed components", async () => {
|
|
138
|
+
const {toJSON} = renderWithTheme(
|
|
139
|
+
<MarkdownView>
|
|
140
|
+
{
|
|
141
|
+
"[YouTube](https://www.youtube.com/watch?v=dQw4w9WgXcQ)\n\n"
|
|
142
|
+
}
|
|
143
|
+
</MarkdownView>
|
|
144
|
+
);
|
|
145
|
+
await waitFor(() => {
|
|
146
|
+
const serialized = JSON.stringify(toJSON());
|
|
147
|
+
const hasEmbed =
|
|
148
|
+
serialized.includes("markdown-embed-web") || serialized.includes("markdown-embed-native");
|
|
149
|
+
expect(hasEmbed).toBe(true);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("passes ordinary image keys directly instead of spreading them through props", async () => {
|
|
154
|
+
const consoleError = spyOn(console, "error").mockImplementation(() => {});
|
|
155
|
+
const originalGetSize = Image.getSize;
|
|
156
|
+
Image.getSize = mock((_uri: string, success: (width: number, height: number) => void): void => {
|
|
157
|
+
success(1200, 800);
|
|
158
|
+
});
|
|
159
|
+
try {
|
|
160
|
+
const {toJSON} = renderWithTheme(
|
|
161
|
+
<MarkdownView>
|
|
162
|
+
{""}
|
|
163
|
+
</MarkdownView>
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
await waitFor(() => {
|
|
167
|
+
assert.ok(JSON.stringify(toJSON()).includes("announcement-overview.png"));
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
const keySpreadWarnings = consoleError.mock.calls.filter(([message]) =>
|
|
171
|
+
String(message).includes('A props object containing a "key" prop')
|
|
172
|
+
);
|
|
173
|
+
assert.equal(keySpreadWarnings.length, 0);
|
|
174
|
+
} finally {
|
|
175
|
+
Image.getSize = originalGetSize;
|
|
176
|
+
consoleError.mockRestore();
|
|
177
|
+
}
|
|
178
|
+
});
|
|
122
179
|
});
|
package/src/MarkdownView.tsx
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import React, {lazy, Suspense, useEffect, useMemo} from "react";
|
|
2
|
-
import {Platform} from "react-native";
|
|
1
|
+
import React, {lazy, Suspense, useCallback, useEffect, useMemo} from "react";
|
|
2
|
+
import {Linking, Platform} from "react-native";
|
|
3
3
|
import type Markdown from "react-native-markdown-display";
|
|
4
|
+
import {FitImage, renderRules} from "react-native-markdown-display";
|
|
4
5
|
|
|
6
|
+
import {MarkdownEmbed} from "./MarkdownEmbed";
|
|
7
|
+
import {isEmbeddableMediaUrl, toMediaEmbedUrl} from "./markdownEmbeds";
|
|
5
8
|
import {Spinner} from "./Spinner";
|
|
6
9
|
import {useTerrenoFontsLoaded} from "./TerrenoFontProvider";
|
|
7
10
|
import {useTheme} from "./Theme";
|
|
@@ -148,10 +151,55 @@ const MarkdownViewComponent: React.FC<MarkdownViewProps> = ({children, inverted,
|
|
|
148
151
|
};
|
|
149
152
|
}, [textColor, theme.border.default, theme.surface.neutralLight]);
|
|
150
153
|
|
|
154
|
+
const handleLinkPress = useCallback((url: string): boolean => {
|
|
155
|
+
void Linking.openURL(url);
|
|
156
|
+
return false;
|
|
157
|
+
}, []);
|
|
158
|
+
|
|
159
|
+
const markdownRules = useMemo<React.ComponentProps<typeof Markdown>["rules"]>(() => {
|
|
160
|
+
return {
|
|
161
|
+
image: (node, _children, _parent, styles, allowedImageHandlers, defaultImageHandler) => {
|
|
162
|
+
const src = node.attributes?.src;
|
|
163
|
+
if (typeof src === "string" && isEmbeddableMediaUrl(src) && toMediaEmbedUrl(src)) {
|
|
164
|
+
return <MarkdownEmbed key={node.key} url={src} />;
|
|
165
|
+
}
|
|
166
|
+
if (typeof src !== "string") {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
const isAllowed = allowedImageHandlers.some((handler) =>
|
|
170
|
+
src.toLowerCase().startsWith(handler.toLowerCase())
|
|
171
|
+
);
|
|
172
|
+
if (!isAllowed && defaultImageHandler === null) {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
const alt = node.attributes?.alt;
|
|
176
|
+
return (
|
|
177
|
+
<FitImage
|
|
178
|
+
accessibilityLabel={typeof alt === "string" ? alt : undefined}
|
|
179
|
+
accessible={Boolean(alt)}
|
|
180
|
+
indicator
|
|
181
|
+
key={node.key}
|
|
182
|
+
source={{uri: isAllowed ? src : `${defaultImageHandler}${src}`}}
|
|
183
|
+
style={styles._VIEW_SAFE_image}
|
|
184
|
+
/>
|
|
185
|
+
);
|
|
186
|
+
},
|
|
187
|
+
link: (node, children, parent, styles, onLinkPress) => {
|
|
188
|
+
const href = node.attributes?.href;
|
|
189
|
+
if (typeof href === "string" && isEmbeddableMediaUrl(href) && toMediaEmbedUrl(href)) {
|
|
190
|
+
return <MarkdownEmbed key={node.key} url={href} />;
|
|
191
|
+
}
|
|
192
|
+
return renderRules.link?.(node, children, parent, styles, onLinkPress);
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
}, []);
|
|
196
|
+
|
|
151
197
|
return (
|
|
152
198
|
<Suspense fallback={<Spinner />}>
|
|
153
199
|
<MarkdownLoadNotifier onLoad={onLoad} />
|
|
154
|
-
<LazyMarkdown style={markdownStyle}>
|
|
200
|
+
<LazyMarkdown onLinkPress={handleLinkPress} rules={markdownRules} style={markdownStyle}>
|
|
201
|
+
{children}
|
|
202
|
+
</LazyMarkdown>
|
|
155
203
|
</Suspense>
|
|
156
204
|
);
|
|
157
205
|
};
|