Skip to content

Commit 75df86b

Browse files
committed
feat: clean up code
1 parent 76cc6b3 commit 75df86b

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

src/chart_types/xy_chart/renderer/canvas/xy_chart.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ class XYChartComponent extends React.Component<XYChartProps> {
171171

172172
const chartSeriesTypes =
173173
seriesTypes.size > 1 ? `Mixed chart: ${[...seriesTypes].join(' and ')} chart` : `${[...seriesTypes]} chart`;
174+
const chartIdDescription = `${chartId}--description`;
174175
return (
175176
<figure>
176177
<canvas
@@ -184,11 +185,11 @@ class XYChartComponent extends React.Component<XYChartProps> {
184185
}}
185186
// eslint-disable-next-line jsx-a11y/no-interactive-element-to-noninteractive-role
186187
role="presentation"
187-
{...(description ? { 'aria-describedby': `${chartId}--${chartSeriesTypes.length}` } : {})}
188+
{...(description ? { 'aria-describedby': chartIdDescription } : {})}
188189
>
189190
{(description || useDefaultSummary) && (
190191
<div className="echScreenReaderOnly">
191-
{description && <p id={`${chartId}--${chartSeriesTypes.length}`}>{description}</p>}
192+
{description && <p id={chartIdDescription}>{description}</p>}
192193
{useDefaultSummary && (
193194
<dl>
194195
<dt>Chart type</dt>
@@ -262,11 +263,12 @@ const mapStateToProps = (state: GlobalChartState): ReactiveChartStateProps => {
262263
}
263264

264265
const { geometries, geometriesIndex } = computeSeriesGeometriesSelector(state);
266+
const { debug, description, useDefaultSummary } = getSettingsSpecSelector(state);
265267

266268
return {
267269
initialized: true,
268270
isChartEmpty: isChartEmptySelector(state),
269-
debug: getSettingsSpecSelector(state).debug,
271+
debug,
270272
geometries,
271273
geometriesIndex,
272274
theme: getChartThemeSelector(state),
@@ -283,8 +285,8 @@ const mapStateToProps = (state: GlobalChartState): ReactiveChartStateProps => {
283285
annotationSpecs: getAnnotationSpecsSelector(state),
284286
panelGeoms: computePanelsSelectors(state),
285287
seriesTypes: getSeriesTypes(state),
286-
description: getSettingsSpecSelector(state).description,
287-
useDefaultSummary: getSettingsSpecSelector(state).useDefaultSummary,
288+
description,
289+
useDefaultSummary,
288290
chartId: getChartIdSelector(state),
289291
};
290292
};

src/chart_types/xy_chart/state/chart_state.a11y.test.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,16 @@ describe('custom description for screen readers', () => {
3636
{ x: 2, y: 5 },
3737
],
3838
}),
39+
MockGlobalSpec.settings(),
3940
],
4041
store,
4142
);
42-
MockStore.addSpecs([MockGlobalSpec.settings()], store);
4343
});
4444
it('should test defaults', () => {
4545
const state = store.getState();
46-
const descriptionValue = getSettingsSpecSelector(state).description;
47-
const defaultGeneratedSeriesTypes = getSettingsSpecSelector(state).useDefaultSummary;
48-
expect(descriptionValue).toBeUndefined();
49-
expect(defaultGeneratedSeriesTypes).toBeTrue();
46+
const { description, useDefaultSummary } = getSettingsSpecSelector(state);
47+
expect(description).toBeUndefined();
48+
expect(useDefaultSummary).toBeTrue();
5049
});
5150
it('should allow user to set a custom description for chart', () => {
5251
MockStore.addSpecs(
@@ -58,8 +57,8 @@ describe('custom description for screen readers', () => {
5857
store,
5958
);
6059
const state = store.getState();
61-
const descriptionValue = getSettingsSpecSelector(state).description;
62-
expect(descriptionValue).toBe('This is sample Kibana data');
60+
const { description } = getSettingsSpecSelector(state);
61+
expect(description).toBe('This is sample Kibana data');
6362
});
6463
it('should be able to disable generated descriptions', () => {
6564
MockStore.addSpecs(
@@ -71,7 +70,7 @@ describe('custom description for screen readers', () => {
7170
store,
7271
);
7372
const state = store.getState();
74-
const disableGeneratedSeriesTypes = getSettingsSpecSelector(state).useDefaultSummary;
75-
expect(disableGeneratedSeriesTypes).toBe(false);
73+
const { useDefaultSummary } = getSettingsSpecSelector(state);
74+
expect(useDefaultSummary).toBe(false);
7675
});
7776
});

0 commit comments

Comments
 (0)