Skip to content

Commit 58ab771

Browse files
committed
chore: refactor getStatus to getItemProps
1 parent e4b6038 commit 58ab771

File tree

6 files changed

+53
-66
lines changed

6 files changed

+53
-66
lines changed

pages/06-visual-tests/cartesian-tooltip.page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const dataA = baseline.map(({ x, y }) => ({ x, y }));
3131
const dataB = baseline.map(({ x, y }, index) => ({ x, y: y + index * 10000 }));
3232

3333
const series: Highcharts.SeriesOptionsType[] = [
34-
{ id: 'A', name: "A", type: "spline", data: dataA },
34+
{ id: "A", name: "A", type: "spline", data: dataA },
3535
{ name: "B", type: "spline", data: dataB },
3636
];
3737

src/__tests__/__snapshots__/documenter.test.ts.snap

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,48 +1456,47 @@ minimum width, the horizontal scrollbar is automatically added.",
14561456
"analyticsTag": undefined,
14571457
"defaultValue": undefined,
14581458
"deprecatedTag": undefined,
1459-
"description": "Called whenever a legend item is hovered to provide content for legend tooltip's header, body, and (optional) footer.
1460-
If not provided, no tooltip will be displayed.",
1459+
"description": "Specifies the options for each item in the chart.",
14611460
"i18nTag": undefined,
14621461
"inlineType": {
1463-
"name": "GetLegendTooltipContent",
1462+
"name": "(id: string) => ChartItemOptions",
14641463
"parameters": [
14651464
{
1466-
"name": "props",
1467-
"type": "GetLegendTooltipContentProps",
1465+
"name": "id",
1466+
"type": "string",
14681467
},
14691468
],
1470-
"returnType": "LegendTooltipContent",
1469+
"returnType": "ChartItemOptions",
14711470
"type": "function",
14721471
},
1473-
"name": "getLegendTooltipContent",
1472+
"name": "getItemProps",
14741473
"optional": true,
14751474
"systemTags": undefined,
1476-
"type": "GetLegendTooltipContent",
1475+
"type": "((id: string) => ChartItemOptions)",
14771476
"visualRefreshTag": undefined,
14781477
},
14791478
{
14801479
"analyticsTag": undefined,
14811480
"defaultValue": undefined,
14821481
"deprecatedTag": undefined,
1483-
"description": "This property is used to provide a custom status for the series markers.
1484-
The callback function is called for each series and should return a status value.",
1482+
"description": "Called whenever a legend item is hovered to provide content for legend tooltip's header, body, and (optional) footer.
1483+
If not provided, no tooltip will be displayed.",
14851484
"i18nTag": undefined,
14861485
"inlineType": {
1487-
"name": "(series: Highcharts.Series) => "warning"",
1486+
"name": "GetLegendTooltipContent",
14881487
"parameters": [
14891488
{
1490-
"name": "series",
1491-
"type": "Highcharts.Series",
1489+
"name": "props",
1490+
"type": "GetLegendTooltipContentProps",
14921491
},
14931492
],
1494-
"returnType": ""warning"",
1493+
"returnType": "LegendTooltipContent",
14951494
"type": "function",
14961495
},
1497-
"name": "getSeriesStatus",
1496+
"name": "getLegendTooltipContent",
14981497
"optional": true,
14991498
"systemTags": undefined,
1500-
"type": "((series: Highcharts.Series) => "warning" | undefined)",
1499+
"type": "GetLegendTooltipContent",
15011500
"visualRefreshTag": undefined,
15021501
},
15031502
{
@@ -1567,19 +1566,20 @@ Supported Highcharts versions: 12.",
15671566
"description": "An object that contains all of the localized strings required by the component.",
15681567
"i18nTag": true,
15691568
"inlineType": {
1570-
"name": "CartesianI18nStrings & PieI18nStrings & CoreI18nStrings",
1569+
"name": "CartesianI18nStrings & PieI18nStrings & CoreI18nStrings & Partial<{ seriesStatusWarningAriaLabel: string; }>",
15711570
"type": "union",
15721571
"valueDescriptions": undefined,
15731572
"values": [
15741573
"CartesianI18nStrings",
15751574
"PieI18nStrings",
15761575
"CoreI18nStrings",
1576+
"Partial<{ seriesStatusWarningAriaLabel: string; }>",
15771577
],
15781578
},
15791579
"name": "i18nStrings",
15801580
"optional": true,
15811581
"systemTags": undefined,
1582-
"type": "CartesianI18nStrings & PieI18nStrings & CoreI18nStrings",
1582+
"type": "CartesianI18nStrings & PieI18nStrings & CoreI18nStrings & Partial<{ seriesStatusWarningAriaLabel: string; }>",
15831583
"visualRefreshTag": undefined,
15841584
},
15851585
{

src/core/__tests__/chart-core-utils.test.tsx

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import "highcharts/highcharts-more";
77
import "highcharts/modules/solid-gauge";
88
import { CoreChartProps } from "../../../lib/components/core/interfaces";
99
import {
10+
fillDefaultsForGetItemProps,
1011
getChartLegendItems,
1112
getLegendsProps,
1213
getPointColor,
@@ -79,7 +80,7 @@ describe("CoreChart: utils", () => {
7980
callback: (api) => (chartApi = api),
8081
});
8182

82-
const items = getChartLegendItems(chartApi!.chart);
83+
const items = getChartLegendItems(chartApi!.chart, fillDefaultsForGetItemProps(undefined));
8384
expect(items[0].isSecondary).toBe(axisOptions.opposite);
8485
},
8586
);
@@ -109,7 +110,7 @@ describe("CoreChart: utils", () => {
109110
callback: (api) => (chartApi = api),
110111
});
111112

112-
const items = getChartLegendItems(chartApi!.chart);
113+
const items = getChartLegendItems(chartApi!.chart, fillDefaultsForGetItemProps(undefined));
113114
expect(items).toHaveLength(2);
114115
expect(items[0].isSecondary).toBe(false);
115116
expect(items[1].isSecondary).toBe(true);
@@ -137,7 +138,7 @@ describe("CoreChart: utils", () => {
137138
callback: (api) => (chartApi = api),
138139
});
139140

140-
const items = getChartLegendItems(chartApi!.chart);
141+
const items = getChartLegendItems(chartApi!.chart, fillDefaultsForGetItemProps(undefined));
141142

142143
if (type === "gauge" || type === "solidgauge") {
143144
expect(items).toHaveLength(1);
@@ -255,4 +256,32 @@ describe("CoreChart: utils", () => {
255256
});
256257
});
257258
});
259+
260+
describe("fillDefaultsForGetItemProps", () => {
261+
describe.each([
262+
{
263+
scenario: "getItemProps is undefined",
264+
getItemProps: undefined,
265+
id: "item1",
266+
expected: { status: "default" },
267+
},
268+
{
269+
scenario: "getItemProps returns empty object",
270+
getItemProps: () => ({}),
271+
id: "item1",
272+
expected: { status: "default" },
273+
},
274+
{
275+
scenario: "getItemProps returns status",
276+
getItemProps: () => ({ status: "active" as const }),
277+
id: "item1",
278+
expected: { status: "active" },
279+
},
280+
])("$scenario", ({ getItemProps, id, expected }) => {
281+
it("should return correct default values", () => {
282+
const result = fillDefaultsForGetItemProps(getItemProps);
283+
expect(result(id)).toEqual(expected);
284+
});
285+
});
286+
});
258287
});

src/core/__tests__/utils.test.ts

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/core/chart-core.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { VerticalAxisTitle } from "./components/core-vertical-axis-title";
3030
import { getFormatter } from "./formatters";
3131
import { useChartI18n } from "./i18n-utils";
3232
import { CoreChartProps } from "./interfaces";
33-
import { fillDefaultsForGetItemProps, getPointAccessibleDescription, hasVisibleLegendItems } from "./utils";
33+
import { fillDefaultsForGetItemProps } from "./utils";
3434
import { getLegendsProps, getPointAccessibleDescription } from "./utils";
3535

3636
import styles from "./styles.css.js";

src/internal/components/series-details/index.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { getDataAttributes } from "../../base-component/get-data-attributes";
1212

1313
import styles from "./styles.css.js";
1414
import testClasses from "./test-classes/styles.css.js";
15-
import { ChartSeriesMarkerStatus } from "../series-marker/interfaces";
1615

1716
interface ChartDetailPair {
1817
key: ReactNode;
@@ -25,8 +24,6 @@ interface ListItemProps {
2524
subItems?: ReadonlyArray<ChartDetailPair>;
2625
marker?: React.ReactNode;
2726
description?: ReactNode;
28-
status: ChartSeriesMarkerStatus;
29-
statusAriaDescription: string;
3027
}
3128

3229
export interface ChartSeriesDetailItem extends ChartDetailPair {
@@ -175,13 +172,12 @@ function ExpandableSeries({
175172
);
176173
}
177174

178-
function NonExpandableSeries({ itemKey, value, subItems, marker, description, status }: ListItemProps) {
175+
function NonExpandableSeries({ itemKey, value, subItems, marker, description }: ListItemProps) {
179176
return (
180177
<>
181178
<div className={clsx(styles["key-value-pair"], styles.announced)}>
182179
<div className={clsx(testClasses.key, styles.key)}>
183180
{marker}
184-
<span style={{ display: "none" }}>warning status</span>
185181
<span>{itemKey}</span>
186182
</div>
187183
<span className={clsx(testClasses.value, styles.value)}>{value}</span>

0 commit comments

Comments
 (0)