Skip to content

Commit f38f478

Browse files
committed
chore: move interfaces around and rename getItemProps
1 parent 516755b commit f38f478

File tree

13 files changed

+72
-69
lines changed

13 files changed

+72
-69
lines changed

pages/03-core/core-line-chart.page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ export default function () {
131131
},
132132
},
133133
}}
134-
getItemProps={(id) => ({
135-
status: id === "A" ? "warning" : "default",
134+
getItemOptions={({ itemId }) => ({
135+
status: itemId === "A" ? "warning" : "default",
136136
})}
137137
chartHeight={400}
138138
getTooltipContent={() => ({

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ export default function () {
4949
}}
5050
chartHeight={400}
5151
tooltip={{ placement: "outside" }}
52-
getItemProps={(id) => ({
53-
status: id === "A" ? "warning" : "default",
52+
getItemOptions={({ itemId }) => ({
53+
status: itemId === "A" ? "warning" : "default",
5454
})}
5555
getTooltipContent={() => ({
5656
footer() {

pages/06-visual-tests/column-hover.page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ function Chart({ type }: { type: "single" | "stacked" | "grouped" }) {
7676
],
7777
yAxis: [{ title: { text: "Error count" } }],
7878
}}
79-
getItemProps={(id) => ({
80-
status: id === "Severe" ? "warning" : "default",
79+
getItemOptions={({ itemId }) => ({
80+
status: itemId === "Severe" ? "warning" : "default",
8181
})}
8282
callback={(api) => {
8383
setTimeout(() => {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ export default function () {
3131
options={{
3232
series: series,
3333
}}
34-
getItemProps={(id) => ({
35-
status: id === "Failed" ? "warning" : "default",
34+
getItemOptions={({ itemId }) => ({
35+
status: itemId === "Failed" ? "warning" : "default",
3636
})}
3737
chartHeight={400}
3838
getTooltipContent={() => ({

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,20 +1459,20 @@ minimum width, the horizontal scrollbar is automatically added.",
14591459
"description": "Specifies the options for each item in the chart.",
14601460
"i18nTag": undefined,
14611461
"inlineType": {
1462-
"name": "(id: string) => ChartItemOptions",
1462+
"name": "(props: CoreChartProps.GetItemOptionsProps) => CoreChartProps.ChartItemOptions",
14631463
"parameters": [
14641464
{
1465-
"name": "id",
1466-
"type": "string",
1465+
"name": "props",
1466+
"type": "CoreChartProps.GetItemOptionsProps",
14671467
},
14681468
],
1469-
"returnType": "ChartItemOptions",
1469+
"returnType": "CoreChartProps.ChartItemOptions",
14701470
"type": "function",
14711471
},
1472-
"name": "getItemProps",
1472+
"name": "getItemOptions",
14731473
"optional": true,
14741474
"systemTags": undefined,
1475-
"type": "((id: string) => ChartItemOptions)",
1475+
"type": "((props: CoreChartProps.GetItemOptionsProps) => CoreChartProps.ChartItemOptions)",
14761476
"visualRefreshTag": undefined,
14771477
},
14781478
{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,8 @@ describe("CoreChart: legend", () => {
562562
},
563563
],
564564
},
565-
getItemProps: (id) => ({
566-
status: id === "L1" ? "warning" : "default",
565+
getItemOptions: ({ itemId }) => ({
566+
status: itemId === "L1" ? "warning" : "default",
567567
}),
568568
});
569569

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import "highcharts/highcharts-more";
77
import "highcharts/modules/solid-gauge";
88
import { CoreChartProps } from "../../../lib/components/core/interfaces";
99
import {
10-
fillDefaultsForGetItemProps,
10+
fillDefaultsForgetItemOptions,
1111
getChartLegendItems,
1212
getLegendsProps,
1313
getPointColor,
@@ -80,7 +80,7 @@ describe("CoreChart: utils", () => {
8080
callback: (api) => (chartApi = api),
8181
});
8282

83-
const items = getChartLegendItems(chartApi!.chart, fillDefaultsForGetItemProps(undefined));
83+
const items = getChartLegendItems(chartApi!.chart, fillDefaultsForgetItemOptions(undefined));
8484
expect(items[0].isSecondary).toBe(axisOptions.opposite);
8585
},
8686
);
@@ -110,7 +110,7 @@ describe("CoreChart: utils", () => {
110110
callback: (api) => (chartApi = api),
111111
});
112112

113-
const items = getChartLegendItems(chartApi!.chart, fillDefaultsForGetItemProps(undefined));
113+
const items = getChartLegendItems(chartApi!.chart, fillDefaultsForgetItemOptions(undefined));
114114
expect(items).toHaveLength(2);
115115
expect(items[0].isSecondary).toBe(false);
116116
expect(items[1].isSecondary).toBe(true);
@@ -138,7 +138,7 @@ describe("CoreChart: utils", () => {
138138
callback: (api) => (chartApi = api),
139139
});
140140

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

143143
if (type === "gauge" || type === "solidgauge") {
144144
expect(items).toHaveLength(1);
@@ -257,29 +257,29 @@ describe("CoreChart: utils", () => {
257257
});
258258
});
259259

260-
describe("fillDefaultsForGetItemProps", () => {
260+
describe("fillDefaultsForgetItemOptions", () => {
261261
describe.each([
262262
{
263-
scenario: "getItemProps is undefined",
264-
getItemProps: undefined,
263+
scenario: "getItemOptions is undefined",
264+
getItemOptions: undefined,
265265
id: "item1",
266266
expected: { status: "default", markerAriaDescription: undefined },
267267
},
268268
{
269-
scenario: "getItemProps returns empty object",
270-
getItemProps: () => ({}),
269+
scenario: "getItemOptions returns empty object",
270+
getItemOptions: () => ({}),
271271
id: "item1",
272272
expected: { status: "default", markerAriaDescription: undefined },
273273
},
274274
{
275-
scenario: "getItemProps returns status",
276-
getItemProps: () => ({ status: "warning" as const }),
275+
scenario: "getItemOptions returns status",
276+
getItemOptions: () => ({ status: "warning" as const }),
277277
id: "item1",
278278
expected: { status: "warning", markerAriaDescription: undefined },
279279
},
280280
{
281-
scenario: "getItemProps returns status and contains i18n",
282-
getItemProps: () => ({ status: "warning" as const }),
281+
scenario: "getItemOptions returns status and contains i18n",
282+
getItemOptions: () => ({ status: "warning" as const }),
283283
id: "item1",
284284
expected: { status: "warning", markerAriaDescription: "hello hi" },
285285
options: {
@@ -288,18 +288,18 @@ describe("CoreChart: utils", () => {
288288
},
289289
},
290290
{
291-
scenario: "getItemProps returns status and contains i18n - getI18nFromStatus returns undefined",
292-
getItemProps: () => ({ status: "warning" as const }),
291+
scenario: "getItemOptions returns status and contains i18n - getI18nFromStatus returns undefined",
292+
getItemOptions: () => ({ status: "warning" as const }),
293293
id: "item1",
294294
expected: { status: "warning", markerAriaDescription: undefined },
295295
options: {
296296
markerAriaDescriptionTemplate: "hello {status}",
297297
getI18nFromStatus: (): undefined => undefined,
298298
},
299299
},
300-
])("$scenario", ({ getItemProps, id, expected, options }) => {
300+
])("$scenario", ({ getItemOptions, id, expected, options }) => {
301301
it("should return correct default values", () => {
302-
const result = fillDefaultsForGetItemProps(getItemProps, options);
302+
const result = fillDefaultsForgetItemOptions(getItemOptions, options);
303303
expect(result(id)).toEqual(expected);
304304
});
305305
});

src/core/chart-api/chart-extra-context.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { getChartSeries } from "../../internal/utils/chart-series";
88
import { getSeriesData } from "../../internal/utils/series-data";
99
import { ChartLabels } from "../i18n-utils";
1010
import { CoreChartProps, Rect } from "../interfaces";
11-
import { fillDefaultsForGetItemProps, getGroupRect, isSeriesStacked } from "../utils";
11+
import { fillDefaultsForgetItemOptions, getGroupRect, isSeriesStacked } from "../utils";
1212

1313
// Chart API context is used for dependency injection for chart utilities.
1414
// It is initialized on chart render, and includes the chart instance, consumer
@@ -32,7 +32,7 @@ export namespace ChartExtraContext {
3232
tooltipEnabled: boolean;
3333
keyboardNavigationEnabled: boolean;
3434
labels: ChartLabels;
35-
getItemProps: ReturnType<typeof fillDefaultsForGetItemProps>;
35+
getItemOptions: ReturnType<typeof fillDefaultsForgetItemOptions>;
3636
}
3737

3838
export interface Handlers {
@@ -64,7 +64,7 @@ export function createChartContext(): ChartExtraContext {
6464
tooltipEnabled: false,
6565
keyboardNavigationEnabled: false,
6666
labels: {},
67-
getItemProps: fillDefaultsForGetItemProps(undefined),
67+
getItemOptions: fillDefaultsForgetItemOptions(undefined),
6868
},
6969
handlers: {},
7070
state: {},

src/core/chart-api/chart-extra-legend.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class ChartExtraLegend extends AsyncStore<ReactiveLegendState> {
8484

8585
private initLegend = () => {
8686
const prevState = this.get().items.reduce((map, item) => map.set(item.id, item), new Map<string, LegendItem>());
87-
const itemSpecs = getChartLegendItems(this.context.chart(), this.context.settings.getItemProps);
87+
const itemSpecs = getChartLegendItems(this.context.chart(), this.context.settings.getItemOptions);
8888
const legendItems = itemSpecs.map(
8989
({ id, name, color, markerType, visible, status, isSecondary, markerAriaDescription }) => {
9090
const marker = this.renderMarker(markerType, color, visible, status, markerAriaDescription);

src/core/chart-core.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5-
// SPDX-License-Identifier: Apache-2.0
6-
74
import { useRef } from "react";
85
import clsx from "clsx";
96
import type Highcharts from "highcharts";
@@ -30,7 +27,7 @@ import { VerticalAxisTitle } from "./components/core-vertical-axis-title";
3027
import { getFormatter } from "./formatters";
3128
import { useChartI18n } from "./i18n-utils";
3229
import { CoreChartProps } from "./interfaces";
33-
import { fillDefaultsForGetItemProps, i18nStatus } from "./utils";
30+
import { fillDefaultsForgetItemOptions, i18nStatus } from "./utils";
3431
import { getLegendsProps, getPointAccessibleDescription } from "./utils";
3532

3633
import styles from "./styles.css.js";
@@ -68,7 +65,7 @@ export function InternalCoreChart({
6865
onVisibleItemsChange,
6966
visibleItems,
7067
__internalRootRef,
71-
getItemProps,
68+
getItemOptions,
7269
...rest
7370
}: CoreChartProps & InternalBaseComponentProps) {
7471
const highcharts = rest.highcharts as null | typeof Highcharts;
@@ -80,7 +77,7 @@ export function InternalCoreChart({
8077
tooltipEnabled: tooltipOptions?.enabled !== false,
8178
keyboardNavigationEnabled: keyboardNavigation,
8279
labels,
83-
getItemProps: fillDefaultsForGetItemProps(getItemProps, {
80+
getItemOptions: fillDefaultsForgetItemOptions(getItemOptions, {
8481
markerAriaDescriptionTemplate: i18nStrings?.chartMarkerAriaDescriptionTemplate,
8582
getI18nFromStatus: i18nStatus(i18nStrings),
8683
}),

0 commit comments

Comments
 (0)