@terreno/ui 57.8.0 → 57.10.1
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/README.md +2 -0
- package/dist/AreaChart.d.ts +1 -1
- package/dist/AreaChart.d.ts.map +1 -1
- package/dist/AreaChart.js +70 -22
- package/dist/AreaChart.js.map +1 -1
- package/dist/BarChart.d.ts.map +1 -1
- package/dist/BarChart.js +55 -13
- package/dist/BarChart.js.map +1 -1
- package/dist/Button.d.ts.map +1 -1
- package/dist/Button.js +19 -4
- package/dist/Button.js.map +1 -1
- package/dist/ChartCard.d.ts +5 -0
- package/dist/ChartCard.d.ts.map +1 -0
- package/dist/ChartCard.js +18 -0
- package/dist/ChartCard.js.map +1 -0
- package/dist/Common.d.ts +147 -6
- package/dist/Common.d.ts.map +1 -1
- package/dist/Common.js.map +1 -1
- package/dist/DashboardGrid.d.ts +6 -2
- package/dist/DashboardGrid.d.ts.map +1 -1
- package/dist/DashboardGrid.js +43 -10
- package/dist/DashboardGrid.js.map +1 -1
- package/dist/DateTimeField.d.ts.map +1 -1
- package/dist/DateTimeField.js +90 -17
- package/dist/DateTimeField.js.map +1 -1
- package/dist/DonutChart.d.ts.map +1 -1
- package/dist/DonutChart.js +20 -10
- package/dist/DonutChart.js.map +1 -1
- package/dist/DropdownMenuItem.d.ts +16 -0
- package/dist/DropdownMenuItem.d.ts.map +1 -0
- package/dist/DropdownMenuItem.js +11 -0
- package/dist/DropdownMenuItem.js.map +1 -0
- package/dist/FilePickerButton.d.ts +15 -1
- package/dist/FilePickerButton.d.ts.map +1 -1
- package/dist/FilePickerButton.js +90 -13
- package/dist/FilePickerButton.js.map +1 -1
- package/dist/GPTChat.d.ts +57 -1
- package/dist/GPTChat.d.ts.map +1 -1
- package/dist/GPTChat.js +301 -20
- package/dist/GPTChat.js.map +1 -1
- package/dist/HtmlFrame.d.ts +11 -0
- package/dist/HtmlFrame.d.ts.map +1 -0
- package/dist/HtmlFrame.js +29 -0
- package/dist/HtmlFrame.js.map +1 -0
- package/dist/LineChart.d.ts +1 -1
- package/dist/LineChart.d.ts.map +1 -1
- package/dist/LineChart.js +62 -21
- package/dist/LineChart.js.map +1 -1
- package/dist/Scorecard.d.ts +5 -0
- package/dist/Scorecard.d.ts.map +1 -0
- package/dist/Scorecard.js +11 -0
- package/dist/Scorecard.js.map +1 -0
- package/dist/SparklineChart.d.ts +5 -0
- package/dist/SparklineChart.d.ts.map +1 -0
- package/dist/SparklineChart.js +35 -0
- package/dist/SparklineChart.js.map +1 -0
- package/dist/Text.d.ts +1 -1
- package/dist/Text.d.ts.map +1 -1
- package/dist/Text.js +2 -2
- package/dist/Text.js.map +1 -1
- package/dist/TextField.d.ts.map +1 -1
- package/dist/TextField.js +12 -4
- package/dist/TextField.js.map +1 -1
- package/dist/ToastNotifications.d.ts.map +1 -1
- package/dist/ToastNotifications.js +29 -6
- package/dist/ToastNotifications.js.map +1 -1
- package/dist/WebDropdownMenu.d.ts +2 -1
- package/dist/WebDropdownMenu.d.ts.map +1 -1
- package/dist/WebDropdownMenu.js +2 -6
- package/dist/WebDropdownMenu.js.map +1 -1
- package/dist/asks/AskCard.d.ts +34 -0
- package/dist/asks/AskCard.d.ts.map +1 -0
- package/dist/asks/AskCard.js +91 -0
- package/dist/asks/AskCard.js.map +1 -0
- package/dist/asks/AskChoice.d.ts +11 -0
- package/dist/asks/AskChoice.d.ts.map +1 -0
- package/dist/asks/AskChoice.js +146 -0
- package/dist/asks/AskChoice.js.map +1 -0
- package/dist/asks/AskConfirm.d.ts +15 -0
- package/dist/asks/AskConfirm.d.ts.map +1 -0
- package/dist/asks/AskConfirm.js +17 -0
- package/dist/asks/AskConfirm.js.map +1 -0
- package/dist/asks/AskFiles.d.ts +18 -0
- package/dist/asks/AskFiles.d.ts.map +1 -0
- package/dist/asks/AskFiles.js +149 -0
- package/dist/asks/AskFiles.js.map +1 -0
- package/dist/asks/AskForm.d.ts +27 -0
- package/dist/asks/AskForm.d.ts.map +1 -0
- package/dist/asks/AskForm.js +146 -0
- package/dist/asks/AskForm.js.map +1 -0
- package/dist/asks/AskMarkdown.d.ts +25 -0
- package/dist/asks/AskMarkdown.d.ts.map +1 -0
- package/dist/asks/AskMarkdown.js +73 -0
- package/dist/asks/AskMarkdown.js.map +1 -0
- package/dist/asks/SimpleAskCard.d.ts +23 -0
- package/dist/asks/SimpleAskCard.d.ts.map +1 -0
- package/dist/asks/SimpleAskCard.js +32 -0
- package/dist/asks/SimpleAskCard.js.map +1 -0
- package/dist/asks/askControls.d.ts +33 -0
- package/dist/asks/askControls.d.ts.map +1 -0
- package/dist/asks/askControls.js +30 -0
- package/dist/asks/askControls.js.map +1 -0
- package/dist/asks/askFileRefs.d.ts +26 -0
- package/dist/asks/askFileRefs.d.ts.map +1 -0
- package/dist/asks/askFileRefs.js +75 -0
- package/dist/asks/askFileRefs.js.map +1 -0
- package/dist/asks/askFormDraft.d.ts +60 -0
- package/dist/asks/askFormDraft.d.ts.map +1 -0
- package/dist/asks/askFormDraft.js +224 -0
- package/dist/asks/askFormDraft.js.map +1 -0
- package/dist/asks/askSummary.d.ts +10 -0
- package/dist/asks/askSummary.d.ts.map +1 -0
- package/dist/asks/askSummary.js +138 -0
- package/dist/asks/askSummary.js.map +1 -0
- package/dist/asks/askTypes.d.ts +21 -0
- package/dist/asks/askTypes.d.ts.map +1 -0
- package/dist/asks/askTypes.js +2 -0
- package/dist/asks/askTypes.js.map +1 -0
- package/dist/asks/simpleCardButtonVariants.d.ts +5 -0
- package/dist/asks/simpleCardButtonVariants.d.ts.map +1 -0
- package/dist/asks/simpleCardButtonVariants.js +8 -0
- package/dist/asks/simpleCardButtonVariants.js.map +1 -0
- package/dist/blocks/BlocksError.d.ts +8 -0
- package/dist/blocks/BlocksError.d.ts.map +1 -0
- package/dist/blocks/BlocksError.js +14 -0
- package/dist/blocks/BlocksError.js.map +1 -0
- package/dist/blocks/BlocksView.d.ts +10 -0
- package/dist/blocks/BlocksView.d.ts.map +1 -0
- package/dist/blocks/BlocksView.js +90 -0
- package/dist/blocks/BlocksView.js.map +1 -0
- package/dist/blocks/blockRenderers.d.ts +25 -0
- package/dist/blocks/blockRenderers.d.ts.map +1 -0
- package/dist/blocks/blockRenderers.js +136 -0
- package/dist/blocks/blockRenderers.js.map +1 -0
- package/dist/blocks/datasetToPoints.d.ts +22 -0
- package/dist/blocks/datasetToPoints.d.ts.map +1 -0
- package/dist/blocks/datasetToPoints.js +28 -0
- package/dist/blocks/datasetToPoints.js.map +1 -0
- package/dist/blocks/useBlockSelections.d.ts +6 -0
- package/dist/blocks/useBlockSelections.d.ts.map +1 -0
- package/dist/blocks/useBlockSelections.js +10 -0
- package/dist/blocks/useBlockSelections.js.map +1 -0
- package/dist/blocks/useResolvedDatasets.d.ts +18 -0
- package/dist/blocks/useResolvedDatasets.d.ts.map +1 -0
- package/dist/blocks/useResolvedDatasets.js +59 -0
- package/dist/blocks/useResolvedDatasets.js.map +1 -0
- package/dist/blocks/useResolvedImages.d.ts +15 -0
- package/dist/blocks/useResolvedImages.d.ts.map +1 -0
- package/dist/blocks/useResolvedImages.js +66 -0
- package/dist/blocks/useResolvedImages.js.map +1 -0
- package/dist/charts/ChartFacadeContainer.d.ts +10 -0
- package/dist/charts/ChartFacadeContainer.d.ts.map +1 -0
- package/dist/charts/ChartFacadeContainer.js +10 -0
- package/dist/charts/ChartFacadeContainer.js.map +1 -0
- package/dist/charts/ChartFrame.d.ts +4 -0
- package/dist/charts/ChartFrame.d.ts.map +1 -1
- package/dist/charts/ChartFrame.js +4 -2
- package/dist/charts/ChartFrame.js.map +1 -1
- package/dist/charts/layout.d.ts +9 -2
- package/dist/charts/layout.d.ts.map +1 -1
- package/dist/charts/layout.js +28 -6
- package/dist/charts/layout.js.map +1 -1
- package/dist/charts/scales.d.ts +3 -1
- package/dist/charts/scales.d.ts.map +1 -1
- package/dist/charts/scales.js +7 -7
- package/dist/charts/scales.js.map +1 -1
- package/dist/charts/series.d.ts +15 -0
- package/dist/charts/series.d.ts.map +1 -0
- package/dist/charts/series.js +19 -0
- package/dist/charts/series.js.map +1 -0
- package/dist/charts/types/chartTypes.d.ts +7 -0
- package/dist/charts/types/chartTypes.d.ts.map +1 -1
- package/dist/dashboardGridLayout.d.ts +6 -0
- package/dist/dashboardGridLayout.d.ts.map +1 -1
- package/dist/dashboardGridLayout.js +19 -3
- package/dist/dashboardGridLayout.js.map +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts +15 -0
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts.map +1 -1
- package/dist/lazyBoundaries/heavyOptionalExports.js +10 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
- package/dist/resolveDocumentBodyPortalTarget.d.ts +7 -0
- package/dist/resolveDocumentBodyPortalTarget.d.ts.map +1 -0
- package/dist/resolveDocumentBodyPortalTarget.js +12 -0
- package/dist/resolveDocumentBodyPortalTarget.js.map +1 -0
- package/package.json +2 -1
- package/src/AIRequestExplorer.test.tsx +2 -2
- package/src/AreaChart.test.tsx +81 -0
- package/src/AreaChart.tsx +171 -62
- package/src/BarChart.test.tsx +119 -0
- package/src/BarChart.tsx +94 -20
- package/src/Button.test.tsx +72 -0
- package/src/Button.tsx +34 -4
- package/src/ChartCard.test.tsx +79 -0
- package/src/ChartCard.tsx +80 -0
- package/src/Common.ts +136 -2
- package/src/DashboardGrid.test.tsx +98 -1
- package/src/DashboardGrid.tsx +71 -20
- package/src/DateTimeField.test.tsx +185 -2
- package/src/DateTimeField.tsx +106 -16
- package/src/DonutChart.test.tsx +78 -10
- package/src/DonutChart.tsx +87 -14
- package/src/DropdownMenuItem.tsx +48 -0
- package/src/FilePickerButton.test.tsx +116 -9
- package/src/FilePickerButton.tsx +177 -23
- package/src/GPTChat.test.tsx +891 -8
- package/src/GPTChat.tsx +713 -45
- package/src/HtmlFrame.tsx +60 -0
- package/src/LineChart.test.tsx +109 -10
- package/src/LineChart.tsx +154 -58
- package/src/Scorecard.test.tsx +65 -0
- package/src/Scorecard.tsx +45 -0
- package/src/SparklineChart.test.tsx +69 -0
- package/src/SparklineChart.tsx +85 -0
- package/src/Text.test.tsx +22 -0
- package/src/Text.tsx +10 -1
- package/src/TextField.test.tsx +16 -0
- package/src/TextField.tsx +13 -3
- package/src/ToastNotifications.tsx +33 -6
- package/src/ToastNotifications.webModal.test.tsx +285 -0
- package/src/WebDropdownMenu.tsx +3 -7
- package/src/asks/AskCard.test.tsx +1428 -0
- package/src/asks/AskCard.tsx +240 -0
- package/src/asks/AskChoice.tsx +368 -0
- package/src/asks/AskConfirm.tsx +42 -0
- package/src/asks/AskFiles.test.tsx +347 -0
- package/src/asks/AskFiles.tsx +246 -0
- package/src/asks/AskForm.tsx +334 -0
- package/src/asks/AskMarkdown.tsx +176 -0
- package/src/asks/SimpleAskCard.test.tsx +253 -0
- package/src/asks/SimpleAskCard.tsx +82 -0
- package/src/asks/askControls.tsx +98 -0
- package/src/asks/askFileRefs.test.ts +155 -0
- package/src/asks/askFileRefs.ts +98 -0
- package/src/asks/askFormDraft.test.ts +347 -0
- package/src/asks/askFormDraft.ts +309 -0
- package/src/asks/askSummary.test.ts +255 -0
- package/src/asks/askSummary.ts +160 -0
- package/src/asks/askTypes.ts +25 -0
- package/src/asks/asksUseTerrenoComponents.test.ts +55 -0
- package/src/asks/simpleCardButtonVariants.ts +14 -0
- package/src/blocks/BlocksError.tsx +28 -0
- package/src/blocks/BlocksView.test.tsx +607 -0
- package/src/blocks/BlocksView.tsx +125 -0
- package/src/blocks/blockRenderers.tsx +288 -0
- package/src/blocks/datasetToPoints.test.ts +31 -0
- package/src/blocks/datasetToPoints.ts +48 -0
- package/src/blocks/useBlockSelections.ts +13 -0
- package/src/blocks/useResolvedDatasets.ts +78 -0
- package/src/blocks/useResolvedImages.ts +81 -0
- package/src/bunSetup.ts +1 -0
- package/src/charts/ChartFacadeContainer.tsx +35 -0
- package/src/charts/ChartFrame.tsx +39 -1
- package/src/charts/layout.test.ts +22 -1
- package/src/charts/layout.ts +37 -4
- package/src/charts/scales.test.ts +33 -0
- package/src/charts/scales.ts +10 -6
- package/src/charts/series.ts +43 -0
- package/src/charts/types/chartTypes.ts +8 -0
- package/src/dashboardGridLayout.test.ts +59 -1
- package/src/dashboardGridLayout.ts +30 -3
- package/src/index.tsx +13 -0
- package/src/isolated/HtmlFrame.isolated.tsx +54 -0
- package/src/lazyBoundaries/heavyOptionalExports.test.tsx +2 -0
- package/src/lazyBoundaries/heavyOptionalExports.tsx +35 -0
- package/src/resolveDocumentBodyPortalTarget.ts +11 -0
package/src/DateTimeField.tsx
CHANGED
|
@@ -18,6 +18,13 @@ import {useTheme} from "./Theme";
|
|
|
18
18
|
import {TimezonePicker} from "./TimezonePicker";
|
|
19
19
|
import {resolveFieldTestIDsFromProps} from "./testing/resolveTestId";
|
|
20
20
|
|
|
21
|
+
/** The state each segment index edits, per field type. */
|
|
22
|
+
const SEGMENT_NAMES = {
|
|
23
|
+
date: ["month", "day", "year"],
|
|
24
|
+
datetime: ["month", "day", "year", "hour", "minute"],
|
|
25
|
+
time: ["hour", "minute"],
|
|
26
|
+
} as const;
|
|
27
|
+
|
|
21
28
|
interface SeparatorProps {
|
|
22
29
|
type: "date" | "time";
|
|
23
30
|
}
|
|
@@ -418,6 +425,7 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
|
|
|
418
425
|
title,
|
|
419
426
|
value,
|
|
420
427
|
onChange,
|
|
428
|
+
onEntryStatusChange,
|
|
421
429
|
timezone: providedTimezone,
|
|
422
430
|
onTimezoneChange,
|
|
423
431
|
errorText,
|
|
@@ -436,6 +444,18 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
|
|
|
436
444
|
const [year, setYear] = useState("");
|
|
437
445
|
const [hour, setHour] = useState("");
|
|
438
446
|
const [minute, setMinute] = useState("");
|
|
447
|
+
// Whether the minute's "00" came from the user clearing the segment rather than from a value.
|
|
448
|
+
const isMinuteClearedRef = useRef(false);
|
|
449
|
+
// The last value this field emitted, so a controlled parent passing it back is not taken as
|
|
450
|
+
// an external change.
|
|
451
|
+
const lastEmittedRef = useRef<string | undefined>(undefined);
|
|
452
|
+
const emitChange = useCallback(
|
|
453
|
+
(next: string): void => {
|
|
454
|
+
lastEmittedRef.current = next;
|
|
455
|
+
onChange(next);
|
|
456
|
+
},
|
|
457
|
+
[onChange]
|
|
458
|
+
);
|
|
439
459
|
const [fieldErrors, setFieldErrors] = useState<Record<number, string | undefined>>({});
|
|
440
460
|
const [localTimezone, setLocalTimezone] = useState(
|
|
441
461
|
providedTimezone ?? DateTime.local().zoneName ?? "UTC"
|
|
@@ -574,10 +594,13 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
|
|
|
574
594
|
const hourVal = override?.hour ?? hour;
|
|
575
595
|
let date: DateTime;
|
|
576
596
|
if (type === "datetime") {
|
|
577
|
-
if (!monthVal || !dayVal || !yearVal || !
|
|
597
|
+
if (!monthVal || !dayVal || !yearVal || !hourVal || !minuteVal) {
|
|
578
598
|
return undefined;
|
|
579
599
|
}
|
|
580
600
|
let hourNum = parseInt(hourVal, 10);
|
|
601
|
+
if (Number.isNaN(hourNum)) {
|
|
602
|
+
return undefined;
|
|
603
|
+
}
|
|
581
604
|
if (ampPmVal === "pm" && hourNum !== 12) {
|
|
582
605
|
hourNum += 12;
|
|
583
606
|
} else if (ampPmVal === "am" && hourNum === 12) {
|
|
@@ -616,10 +639,13 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
|
|
|
616
639
|
}
|
|
617
640
|
);
|
|
618
641
|
} else {
|
|
619
|
-
if (!
|
|
642
|
+
if (!hourVal || !minuteVal) {
|
|
643
|
+
return undefined;
|
|
644
|
+
}
|
|
645
|
+
let hourNum = parseInt(hourVal, 10);
|
|
646
|
+
if (Number.isNaN(hourNum)) {
|
|
620
647
|
return undefined;
|
|
621
648
|
}
|
|
622
|
-
let hourNum = parseInt(hour, 10);
|
|
623
649
|
if (ampPmVal === "pm" && hourNum !== 12) {
|
|
624
650
|
hourNum += 12;
|
|
625
651
|
} else if (ampPmVal === "am" && hourNum === 12) {
|
|
@@ -647,6 +673,37 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
|
|
|
647
673
|
[amPm, month, day, year, hour, minute, timezone, type]
|
|
648
674
|
);
|
|
649
675
|
|
|
676
|
+
/**
|
|
677
|
+
* Tells `onEntryStatusChange` what the segments hold after a typed change: nothing, an entry
|
|
678
|
+
* that is unfinished or has a segment error, or a complete value. Clearing the minute segment
|
|
679
|
+
* resets it to "00", so a "00" minute counts as empty only when the user cleared it; the "00"
|
|
680
|
+
* of an on-the-hour value is still part of the entry.
|
|
681
|
+
*/
|
|
682
|
+
const reportEntryStatus = useCallback(
|
|
683
|
+
(
|
|
684
|
+
override: {day?: string; hour?: string; minute?: string; month?: string; year?: string},
|
|
685
|
+
errors: Record<number, string | undefined>
|
|
686
|
+
): void => {
|
|
687
|
+
if (!onEntryStatusChange) {
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
const next = {day, hour, minute, month, year, ...override};
|
|
691
|
+
const dateParts = type === "time" ? [] : [next.month, next.day, next.year];
|
|
692
|
+
const timeParts = type === "date" ? [] : [next.hour];
|
|
693
|
+
const hasMinute =
|
|
694
|
+
type !== "date" &&
|
|
695
|
+
next.minute !== "" &&
|
|
696
|
+
!(next.minute === "00" && isMinuteClearedRef.current);
|
|
697
|
+
if (![...dateParts, ...timeParts].some(Boolean) && !hasMinute) {
|
|
698
|
+
onEntryStatusChange("empty");
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
const hasError = Object.values(errors).some((error) => error !== undefined);
|
|
702
|
+
onEntryStatusChange(!hasError && getISOFromFields(override) ? "valid" : "invalid");
|
|
703
|
+
},
|
|
704
|
+
[onEntryStatusChange, day, hour, minute, month, year, type, getISOFromFields]
|
|
705
|
+
);
|
|
706
|
+
|
|
650
707
|
/**
|
|
651
708
|
* Handles text changes in any {@link DateTimeSegment} input.
|
|
652
709
|
* Strips non-numeric characters, validates the value, updates local state,
|
|
@@ -665,14 +722,21 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
|
|
|
665
722
|
// This lets users freely edit or clear the minute field without breaking the time format.
|
|
666
723
|
const finalValue = numericValue === "" ? "00" : numericValue.slice(-2);
|
|
667
724
|
const minuteNum = parseInt(finalValue, 10);
|
|
725
|
+
isMinuteClearedRef.current = numericValue === "";
|
|
668
726
|
|
|
669
727
|
// Update the minute state so the UI reflects the latest input,
|
|
670
728
|
// even if it's temporarily invalid
|
|
671
729
|
// This allows the user to freely edit or clear the field.
|
|
672
730
|
setMinute(finalValue);
|
|
673
731
|
|
|
732
|
+
const isValidMinute = !Number.isNaN(minuteNum) && minuteNum >= 0 && minuteNum <= 59;
|
|
733
|
+
reportEntryStatus(
|
|
734
|
+
{minute: finalValue},
|
|
735
|
+
{...fieldErrors, [index]: isValidMinute ? undefined : "Minute must be between 0 and 59"}
|
|
736
|
+
);
|
|
737
|
+
|
|
674
738
|
// Only update ref and result if it's a valid minute value
|
|
675
|
-
if (
|
|
739
|
+
if (isValidMinute) {
|
|
676
740
|
pendingValueRef.current = {minute: finalValue};
|
|
677
741
|
setFieldErrors((prev) => ({...prev, [index]: undefined}));
|
|
678
742
|
|
|
@@ -681,7 +745,7 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
|
|
|
681
745
|
if (result) {
|
|
682
746
|
const currentValueUTC = value ? DateTime.fromISO(value).toUTC().toISO() : undefined;
|
|
683
747
|
if (result !== currentValueUTC) {
|
|
684
|
-
|
|
748
|
+
emitChange(result);
|
|
685
749
|
}
|
|
686
750
|
}
|
|
687
751
|
} else {
|
|
@@ -700,6 +764,10 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
|
|
|
700
764
|
|
|
701
765
|
const error = validateField(index, finalValue);
|
|
702
766
|
setFieldErrors((prev) => ({...prev, [index]: error}));
|
|
767
|
+
const segmentName = SEGMENT_NAMES[type][index];
|
|
768
|
+
if (segmentName) {
|
|
769
|
+
reportEntryStatus({[segmentName]: finalValue}, {...fieldErrors, [index]: error});
|
|
770
|
+
}
|
|
703
771
|
|
|
704
772
|
if (type === "date" || type === "datetime") {
|
|
705
773
|
if (index === 0) {
|
|
@@ -744,7 +812,7 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
|
|
|
744
812
|
if (result) {
|
|
745
813
|
const currentValueUTC = value ? DateTime.fromISO(value).toUTC().toISO() : undefined;
|
|
746
814
|
if (result !== currentValueUTC) {
|
|
747
|
-
|
|
815
|
+
emitChange(result);
|
|
748
816
|
}
|
|
749
817
|
}
|
|
750
818
|
}
|
|
@@ -756,7 +824,19 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
|
|
|
756
824
|
inputRefs.current[index + 1]?.focus();
|
|
757
825
|
}
|
|
758
826
|
},
|
|
759
|
-
[
|
|
827
|
+
[
|
|
828
|
+
type,
|
|
829
|
+
getFieldConfigs,
|
|
830
|
+
getISOFromFields,
|
|
831
|
+
emitChange,
|
|
832
|
+
value,
|
|
833
|
+
validateField,
|
|
834
|
+
month,
|
|
835
|
+
day,
|
|
836
|
+
year,
|
|
837
|
+
fieldErrors,
|
|
838
|
+
reportEntryStatus,
|
|
839
|
+
]
|
|
760
840
|
);
|
|
761
841
|
|
|
762
842
|
/**
|
|
@@ -768,7 +848,8 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
|
|
|
768
848
|
(inputDate: string) => {
|
|
769
849
|
// Handle clear case - empty string should clear the field
|
|
770
850
|
if (!inputDate || inputDate === "") {
|
|
771
|
-
|
|
851
|
+
emitChange("");
|
|
852
|
+
onEntryStatusChange?.("empty");
|
|
772
853
|
setShowDate(false);
|
|
773
854
|
return;
|
|
774
855
|
}
|
|
@@ -794,6 +875,7 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
|
|
|
794
875
|
hourNum = hourNum === 0 ? 12 : hourNum;
|
|
795
876
|
setHour(hourNum.toString().padStart(2, "0"));
|
|
796
877
|
setMinute(parsedDate.minute.toString().padStart(2, "0"));
|
|
878
|
+
isMinuteClearedRef.current = false;
|
|
797
879
|
}
|
|
798
880
|
|
|
799
881
|
// Normalize emitted value to ISO (UTC for date-only)
|
|
@@ -804,10 +886,11 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
|
|
|
804
886
|
.set({millisecond: 0, second: 0})
|
|
805
887
|
.toISO()
|
|
806
888
|
: parsedDate.set({millisecond: 0, second: 0}).toUTC().toISO();
|
|
807
|
-
|
|
889
|
+
emitChange(normalized ?? "");
|
|
890
|
+
onEntryStatusChange?.("valid");
|
|
808
891
|
setShowDate(false);
|
|
809
892
|
},
|
|
810
|
-
[
|
|
893
|
+
[emitChange, onEntryStatusChange, type]
|
|
811
894
|
);
|
|
812
895
|
|
|
813
896
|
/**
|
|
@@ -820,13 +903,14 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
|
|
|
820
903
|
// Compare in UTC to avoid timezone issues
|
|
821
904
|
const currentValueUTC = value ? DateTime.fromISO(value).toUTC().toISO() : undefined;
|
|
822
905
|
if (iso && iso !== currentValueUTC) {
|
|
823
|
-
|
|
906
|
+
emitChange(iso);
|
|
824
907
|
}
|
|
908
|
+
reportEntryStatus({...pendingValueRef.current}, fieldErrors);
|
|
825
909
|
|
|
826
910
|
// Clear the pending value after processing
|
|
827
911
|
pendingValueRef.current = undefined;
|
|
828
912
|
},
|
|
829
|
-
[getISOFromFields,
|
|
913
|
+
[getISOFromFields, emitChange, value, reportEntryStatus, fieldErrors]
|
|
830
914
|
);
|
|
831
915
|
|
|
832
916
|
// Handle external value changes
|
|
@@ -865,6 +949,12 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
|
|
|
865
949
|
hourNum = hourNum === 0 ? 12 : hourNum;
|
|
866
950
|
setHour(hourNum.toString().padStart(2, "0"));
|
|
867
951
|
setMinute(parsedDate.minute.toString().padStart(2, "0"));
|
|
952
|
+
const lastEmitted = lastEmittedRef.current
|
|
953
|
+
? DateTime.fromISO(lastEmittedRef.current)
|
|
954
|
+
: undefined;
|
|
955
|
+
if (!lastEmitted?.isValid || lastEmitted.toMillis() !== parsedDate.toMillis()) {
|
|
956
|
+
isMinuteClearedRef.current = false;
|
|
957
|
+
}
|
|
868
958
|
}
|
|
869
959
|
}, [value, type, timezone]);
|
|
870
960
|
|
|
@@ -936,10 +1026,10 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
|
|
|
936
1026
|
const iso = getISOFromFields({amPm: newAmPm});
|
|
937
1027
|
const currentValueUTC = value ? DateTime.fromISO(value).toUTC().toISO() : undefined;
|
|
938
1028
|
if (iso && iso !== currentValueUTC) {
|
|
939
|
-
|
|
1029
|
+
emitChange(iso);
|
|
940
1030
|
}
|
|
941
1031
|
},
|
|
942
|
-
[getISOFromFields, value,
|
|
1032
|
+
[getISOFromFields, value, emitChange]
|
|
943
1033
|
);
|
|
944
1034
|
|
|
945
1035
|
/** Handles timezone changes from the TimezonePicker, recomputes and emits the ISO value. */
|
|
@@ -953,10 +1043,10 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
|
|
|
953
1043
|
const iso = getISOFromFields({timezone: tz});
|
|
954
1044
|
const currentValueUTC = value ? DateTime.fromISO(value).toUTC().toISO() : undefined;
|
|
955
1045
|
if (iso && iso !== currentValueUTC) {
|
|
956
|
-
|
|
1046
|
+
emitChange(iso);
|
|
957
1047
|
}
|
|
958
1048
|
},
|
|
959
|
-
[getISOFromFields, value,
|
|
1049
|
+
[getISOFromFields, value, emitChange, onTimezoneChange]
|
|
960
1050
|
);
|
|
961
1051
|
|
|
962
1052
|
const openActionSheet = useCallback((): void => {
|
package/src/DonutChart.test.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {describe, expect, it
|
|
1
|
+
import {describe, expect, it} from "bun:test";
|
|
2
2
|
import {act, fireEvent} from "@testing-library/react-native";
|
|
3
|
-
import {
|
|
3
|
+
import {assert} from "chai";
|
|
4
4
|
|
|
5
5
|
import {DonutChart} from "./DonutChart";
|
|
6
6
|
import {renderWithTheme} from "./test-utils";
|
|
@@ -11,6 +11,78 @@ const POINTS = [
|
|
|
11
11
|
];
|
|
12
12
|
|
|
13
13
|
describe("DonutChart", () => {
|
|
14
|
+
it("renders center copy and default percent shares in the legend", () => {
|
|
15
|
+
const {getAllByText, getByTestId, getByText} = renderWithTheme(
|
|
16
|
+
<DonutChart centerTitle="Cost" centerValue="$1.15K" data={POINTS} testID="chart" />
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
assert.exists(getByText("$1.15K"));
|
|
20
|
+
assert.exists(getByText("Cost"));
|
|
21
|
+
assert.exists(getByTestId("chart.center"));
|
|
22
|
+
assert.exists(getByTestId("chart.center.value"));
|
|
23
|
+
assert.exists(getByTestId("chart.center.title"));
|
|
24
|
+
assert.equal(getByTestId("chart.share.0").props.children, "50%");
|
|
25
|
+
assert.lengthOf(getAllByText("50%"), 2);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("supports custom share formatting and a single 100% slice", () => {
|
|
29
|
+
const {getByTestId, getByText} = renderWithTheme(
|
|
30
|
+
<DonutChart
|
|
31
|
+
centerTitle="Conversions"
|
|
32
|
+
centerValue="7.00"
|
|
33
|
+
data={[{label: "Mobile phones", value: 7}]}
|
|
34
|
+
formatShare={(value, total): string => `${value} of ${total}`}
|
|
35
|
+
testID="chart"
|
|
36
|
+
/>
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
assert.isNotEmpty(getByTestId("chart.slice.0").props.d);
|
|
40
|
+
assert.exists(getByText("7 of 7"));
|
|
41
|
+
assert.exists(getByText("7.00"));
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("formats one full slice as 100% and zero totals as 0%", () => {
|
|
45
|
+
const full = renderWithTheme(
|
|
46
|
+
<DonutChart data={[{label: "Mobile phones", value: 7}]} testID="full-chart" />
|
|
47
|
+
);
|
|
48
|
+
assert.equal(full.getByTestId("full-chart.share.0").props.children, "100%");
|
|
49
|
+
|
|
50
|
+
const emptyTotal = renderWithTheme(
|
|
51
|
+
<DonutChart
|
|
52
|
+
data={[
|
|
53
|
+
{label: "A", value: 0},
|
|
54
|
+
{label: "B", value: -1},
|
|
55
|
+
]}
|
|
56
|
+
testID="zero-chart"
|
|
57
|
+
/>
|
|
58
|
+
);
|
|
59
|
+
assert.equal(emptyTotal.getByTestId("zero-chart.share.0").props.children, "0%");
|
|
60
|
+
assert.equal(emptyTotal.getByTestId("zero-chart.share.1").props.children, "0%");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("renders chart-card header shortcuts and omits them without title", async (): Promise<void> => {
|
|
64
|
+
let pressCount = 0;
|
|
65
|
+
const titled = renderWithTheme(
|
|
66
|
+
<DonutChart
|
|
67
|
+
data={POINTS}
|
|
68
|
+
onPeriodPress={(): void => {
|
|
69
|
+
pressCount += 1;
|
|
70
|
+
}}
|
|
71
|
+
periodLabel="Last 30 days"
|
|
72
|
+
testID="chart"
|
|
73
|
+
title="Cost by Device"
|
|
74
|
+
/>
|
|
75
|
+
);
|
|
76
|
+
assert.exists(titled.getByText("Cost by Device"));
|
|
77
|
+
assert.exists(titled.getByText("Last 30 days"));
|
|
78
|
+
fireEvent.press(titled.getByTestId("chart.card.period-clickable"));
|
|
79
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
80
|
+
assert.equal(pressCount, 1);
|
|
81
|
+
|
|
82
|
+
const plain = renderWithTheme(<DonutChart data={POINTS} testID="plain-chart" />);
|
|
83
|
+
assert.notExists(plain.queryByTestId("plain-chart.card"));
|
|
84
|
+
});
|
|
85
|
+
|
|
14
86
|
it("renders one mark testID per slice", () => {
|
|
15
87
|
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
16
88
|
<DonutChart data={POINTS} testID="chart" />
|
|
@@ -105,17 +177,13 @@ describe("DonutChart", () => {
|
|
|
105
177
|
expect(queryByTestId("chart.tooltip")).toBeNull();
|
|
106
178
|
});
|
|
107
179
|
|
|
108
|
-
it("does not open URLs from slice legend labels",
|
|
109
|
-
const openURLSpy = spyOn(Linking, "openURL").mockImplementation(() => Promise.resolve(true));
|
|
180
|
+
it("does not open URLs from slice legend labels", () => {
|
|
110
181
|
const {getByText} = renderWithTheme(
|
|
111
182
|
<DonutChart data={[{label: "https://evil.example", value: 10}]} />
|
|
112
183
|
);
|
|
113
184
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
expect(openURLSpy).not.toHaveBeenCalled();
|
|
119
|
-
openURLSpy.mockRestore();
|
|
185
|
+
// The suite shares one Linking mock, so a spy on openURL also records calls
|
|
186
|
+
// from other files. A label is inert when it has no press handler.
|
|
187
|
+
expect(getByText("https://evil.example").props.onPress).toBeUndefined();
|
|
120
188
|
});
|
|
121
189
|
});
|
package/src/DonutChart.tsx
CHANGED
|
@@ -4,11 +4,13 @@ import {Path, Svg} from "react-native-svg";
|
|
|
4
4
|
|
|
5
5
|
import {Box} from "./Box";
|
|
6
6
|
import type {DonutChartProps, LayoutChangeEvent} from "./Common";
|
|
7
|
+
import {ChartFacadeContainer} from "./charts/ChartFacadeContainer";
|
|
7
8
|
import {ChartFrame} from "./charts/ChartFrame";
|
|
8
9
|
import {getDonutSize} from "./charts/layout";
|
|
9
10
|
import {getDonutSliceAngles, getDonutSliceHitCenter, getDonutSlicePath} from "./charts/paths";
|
|
10
11
|
import {getChartPaint} from "./charts/theme";
|
|
11
12
|
import type {ChartPoint} from "./charts/types/chartTypes";
|
|
13
|
+
import {Heading} from "./Heading";
|
|
12
14
|
import {Text} from "./Text";
|
|
13
15
|
import {useTheme} from "./Theme";
|
|
14
16
|
import {resolveTestID} from "./testing/resolveTestId";
|
|
@@ -16,6 +18,13 @@ import {resolveTestID} from "./testing/resolveTestId";
|
|
|
16
18
|
const DEFAULT_SIZE = 220;
|
|
17
19
|
const MARK_HIT_SIZE = 24;
|
|
18
20
|
|
|
21
|
+
const formatDefaultShare = (value: number, total: number): string => {
|
|
22
|
+
if (total <= 0) {
|
|
23
|
+
return "0%";
|
|
24
|
+
}
|
|
25
|
+
return `${Math.round((Math.max(value, 0) / total) * 100)}%`;
|
|
26
|
+
};
|
|
27
|
+
|
|
19
28
|
const formatChartTooltip = ({
|
|
20
29
|
formatValue,
|
|
21
30
|
point,
|
|
@@ -38,12 +47,18 @@ const getSliceAngles = (
|
|
|
38
47
|
|
|
39
48
|
export const DonutChart: FC<DonutChartProps> = ({
|
|
40
49
|
accessibilityLabel,
|
|
50
|
+
centerTitle,
|
|
51
|
+
centerValue,
|
|
41
52
|
data,
|
|
42
53
|
emptyText = "No data",
|
|
54
|
+
formatShare = formatDefaultShare,
|
|
43
55
|
formatValue = String,
|
|
44
56
|
height = DEFAULT_SIZE,
|
|
45
57
|
loading = false,
|
|
58
|
+
onPeriodPress,
|
|
59
|
+
periodLabel,
|
|
46
60
|
testID,
|
|
61
|
+
title,
|
|
47
62
|
}) => {
|
|
48
63
|
const {theme} = useTheme();
|
|
49
64
|
const paint = getChartPaint(theme);
|
|
@@ -66,13 +81,14 @@ export const DonutChart: FC<DonutChartProps> = ({
|
|
|
66
81
|
const outerRadius = Math.max(size / 2 - 8, 1);
|
|
67
82
|
const innerRadius = outerRadius * 0.55;
|
|
68
83
|
const slices = getSliceAngles(data);
|
|
84
|
+
const total = data.reduce((sum, point) => sum + Math.max(point.value, 0), 0);
|
|
69
85
|
const activePoint = activePointIndex === undefined ? undefined : data[activePointIndex];
|
|
70
86
|
const tooltipText = activePoint
|
|
71
87
|
? formatChartTooltip({formatValue, point: activePoint})
|
|
72
88
|
: undefined;
|
|
73
89
|
const summaryLabel = accessibilityLabel ?? "Donut chart";
|
|
74
90
|
|
|
75
|
-
|
|
91
|
+
const chart = (
|
|
76
92
|
<ChartFrame
|
|
77
93
|
accessibilityLabel={summaryLabel}
|
|
78
94
|
emptyText={emptyText}
|
|
@@ -100,10 +116,39 @@ export const DonutChart: FC<DonutChartProps> = ({
|
|
|
100
116
|
})}
|
|
101
117
|
fill={slice.point.color ?? paint.slices[index % paint.slices.length]}
|
|
102
118
|
key={`slice-${slice.point.label}`}
|
|
119
|
+
testID={resolveTestID(testID, `slice.${index}`)}
|
|
103
120
|
transform={`translate(${center}, ${center})`}
|
|
104
121
|
/>
|
|
105
122
|
))}
|
|
106
123
|
</Svg>
|
|
124
|
+
{centerValue || centerTitle ? (
|
|
125
|
+
<Box
|
|
126
|
+
alignItems="center"
|
|
127
|
+
dangerouslySetInlineStyle={{__style: {left: 0, top: 0}}}
|
|
128
|
+
height={size}
|
|
129
|
+
justifyContent="center"
|
|
130
|
+
position="absolute"
|
|
131
|
+
testID={resolveTestID(testID, "center")}
|
|
132
|
+
width={size}
|
|
133
|
+
>
|
|
134
|
+
{centerValue ? (
|
|
135
|
+
<Heading align="center" size="sm" testID={resolveTestID(testID, "center.value")}>
|
|
136
|
+
{centerValue}
|
|
137
|
+
</Heading>
|
|
138
|
+
) : null}
|
|
139
|
+
{centerTitle ? (
|
|
140
|
+
<Text
|
|
141
|
+
align="center"
|
|
142
|
+
color="secondaryDark"
|
|
143
|
+
size="sm"
|
|
144
|
+
skipLinking
|
|
145
|
+
testID={resolveTestID(testID, "center.title")}
|
|
146
|
+
>
|
|
147
|
+
{centerTitle}
|
|
148
|
+
</Text>
|
|
149
|
+
) : null}
|
|
150
|
+
</Box>
|
|
151
|
+
) : null}
|
|
107
152
|
{slices.map((slice, index) => {
|
|
108
153
|
const onPress = (): void => {
|
|
109
154
|
handleMarkPress(index);
|
|
@@ -134,19 +179,36 @@ export const DonutChart: FC<DonutChartProps> = ({
|
|
|
134
179
|
</Box>
|
|
135
180
|
<Box direction="column" gap={1} padding={2}>
|
|
136
181
|
{data.map((point, index) => (
|
|
137
|
-
<Box
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
182
|
+
<Box
|
|
183
|
+
direction="row"
|
|
184
|
+
gap={2}
|
|
185
|
+
justifyContent="between"
|
|
186
|
+
key={`legend-${point.label}`}
|
|
187
|
+
minWidth={0}
|
|
188
|
+
width="100%"
|
|
189
|
+
>
|
|
190
|
+
<Box alignItems="center" direction="row" gap={2} minWidth={0}>
|
|
191
|
+
<Box
|
|
192
|
+
dangerouslySetInlineStyle={{
|
|
193
|
+
__style: {
|
|
194
|
+
backgroundColor: point.color ?? paint.slices[index % paint.slices.length],
|
|
195
|
+
height: 12,
|
|
196
|
+
width: 12,
|
|
197
|
+
},
|
|
198
|
+
}}
|
|
199
|
+
testID={resolveTestID(testID, `swatch.${index}`)}
|
|
200
|
+
/>
|
|
201
|
+
<Text size="sm" skipLinking truncate>
|
|
202
|
+
{point.label}
|
|
203
|
+
</Text>
|
|
204
|
+
</Box>
|
|
205
|
+
<Text
|
|
206
|
+
color="secondaryDark"
|
|
207
|
+
size="sm"
|
|
208
|
+
skipLinking
|
|
209
|
+
testID={resolveTestID(testID, `share.${index}`)}
|
|
210
|
+
>
|
|
211
|
+
{formatShare(point.value, total)}
|
|
150
212
|
</Text>
|
|
151
213
|
</Box>
|
|
152
214
|
))}
|
|
@@ -154,6 +216,17 @@ export const DonutChart: FC<DonutChartProps> = ({
|
|
|
154
216
|
</Box>
|
|
155
217
|
</ChartFrame>
|
|
156
218
|
);
|
|
219
|
+
|
|
220
|
+
return (
|
|
221
|
+
<ChartFacadeContainer
|
|
222
|
+
onPeriodPress={onPeriodPress}
|
|
223
|
+
periodLabel={periodLabel}
|
|
224
|
+
testID={testID}
|
|
225
|
+
title={title}
|
|
226
|
+
>
|
|
227
|
+
{chart}
|
|
228
|
+
</ChartFacadeContainer>
|
|
229
|
+
);
|
|
157
230
|
};
|
|
158
231
|
|
|
159
232
|
export type {DonutChartProps} from "./Common";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type React from "react";
|
|
2
|
+
import {Pressable} from "react-native";
|
|
3
|
+
|
|
4
|
+
import {Box} from "./Box";
|
|
5
|
+
import type {IconName, IconProps, TextColor} from "./Common";
|
|
6
|
+
import {Icon} from "./Icon";
|
|
7
|
+
import {Text} from "./Text";
|
|
8
|
+
|
|
9
|
+
export interface DropdownMenuItemProps {
|
|
10
|
+
accessibilityLabel?: string;
|
|
11
|
+
/** Text and icon color. Defaults to the dark secondary text color. */
|
|
12
|
+
color?: TextColor;
|
|
13
|
+
iconName: IconName;
|
|
14
|
+
/** Icon style. Defaults to the outlined `regular` glyph. */
|
|
15
|
+
iconType?: IconProps["type"];
|
|
16
|
+
label: string;
|
|
17
|
+
onClick: () => void;
|
|
18
|
+
testID?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** A single icon + label row for an action menu rendered inside a `DropdownPanel`. */
|
|
22
|
+
export const DropdownMenuItem = ({
|
|
23
|
+
accessibilityLabel,
|
|
24
|
+
color = "secondaryDark",
|
|
25
|
+
iconName,
|
|
26
|
+
iconType = "regular",
|
|
27
|
+
label,
|
|
28
|
+
onClick,
|
|
29
|
+
testID,
|
|
30
|
+
}: DropdownMenuItemProps): React.ReactElement => {
|
|
31
|
+
// A plain Pressable keeps onClick synchronous with the press, which web file pickers need.
|
|
32
|
+
return (
|
|
33
|
+
<Pressable
|
|
34
|
+
accessibilityHint={`Press to ${label.toLowerCase()}`}
|
|
35
|
+
accessibilityLabel={accessibilityLabel ?? label}
|
|
36
|
+
accessibilityRole="menuitem"
|
|
37
|
+
onPress={onClick}
|
|
38
|
+
testID={testID}
|
|
39
|
+
>
|
|
40
|
+
<Box alignItems="center" direction="row" gap={2} paddingX={2} paddingY={2} rounding="md">
|
|
41
|
+
<Icon color={color} iconName={iconName} size="sm" type={iconType} />
|
|
42
|
+
<Text color={color} size="sm">
|
|
43
|
+
{label}
|
|
44
|
+
</Text>
|
|
45
|
+
</Box>
|
|
46
|
+
</Pressable>
|
|
47
|
+
);
|
|
48
|
+
};
|