Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,24 @@ import {
import { useDataQualityContext } from '../../data_quality_context';
import { formControlLayoutCss, optionCss, optionLabelCss } from './styles';

const getPhaseKey = (
option: EuiComboBoxOptionOption<string | number | string[] | undefined>
): string => (typeof option.value === 'string' ? option.value : '');

const renderOption = (
option: EuiComboBoxOptionOption<string | number | string[] | undefined>
): React.ReactNode => (
<EuiToolTip content={`${option.label}: ${getIlmPhaseDescription(option.label)}`}>
<div css={optionCss} tabIndex={0}>
<span css={optionLabelCss}>{`${option.label}`}</span>
{': '}
<span>{getIlmPhaseDescription(option.label)}</span>
</div>
</EuiToolTip>
);
): React.ReactNode => {
const phaseKey = getPhaseKey(option);
return (
<EuiToolTip content={`${option.label}: ${getIlmPhaseDescription(phaseKey)}`}>
<div css={optionCss} tabIndex={0}>
<span css={optionLabelCss}>{`${option.label}`}</span>
{': '}
<span>{getIlmPhaseDescription(phaseKey)}</span>
</div>
</EuiToolTip>
);
};

const IlmPhaseFilterComponent: React.FC = () => {
const { selectedIlmPhaseOptions, setSelectedIlmPhaseOptions } = useDataQualityContext();
Expand Down Expand Up @@ -64,6 +71,7 @@ const IlmPhaseFilterComponent: React.FC = () => {
selectedOptions={selectedIlmPhaseOptions}
options={ilmPhaseOptionsStatic}
onChange={handleSetSelectedOptions}
aria-label={ILM_PHASE}
/>
</EuiFormControlLayout>
</EuiToolTip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { IndicesCheckContext } from './contexts/indices_check_context';
import { useIndicesCheck } from './hooks/use_indices_check';
import { useResultsRollup } from './hooks/use_results_rollup';
import { ilmPhaseOptionsStatic, EMPTY_STAT } from './constants';
import { ilmPhasesFromSelectedOptions } from './utils/ilm_phases_from_selected_options';
import { DataQualitySummary } from './data_quality_summary';
import { DataQualityDetails } from './data_quality_details';

Expand Down Expand Up @@ -104,7 +105,7 @@ const DataQualityPanelComponent: React.FC<Props> = ({
[toasts]
);
const ilmPhases: string[] = useMemo(
() => selectedIlmPhaseOptions.map(({ label }) => label),
() => ilmPhasesFromSelectedOptions(selectedIlmPhaseOptions),
[selectedIlmPhaseOptions]
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { EuiComboBoxOptionOption } from '@elastic/eui';

import { ilmPhasesFromSelectedOptions } from './ilm_phases_from_selected_options';

describe('ilmPhasesFromSelectedOptions', () => {
it('returns English phase values when labels are localized (ja-JP / i18n regression)', () => {
const selected: EuiComboBoxOptionOption[] = [
{ label: 'ホット', value: 'hot' },
{ label: 'ウォーム', value: 'warm' },
{ label: '管理対象外', value: 'unmanaged' },
];

expect(ilmPhasesFromSelectedOptions(selected)).toEqual(['hot', 'warm', 'unmanaged']);
});

it('returns values when labels match English defaults', () => {
const selected: EuiComboBoxOptionOption[] = [
{ label: 'hot', value: 'hot' },
{ label: 'warm', value: 'warm' },
];

expect(ilmPhasesFromSelectedOptions(selected)).toEqual(['hot', 'warm']);
});

it('drops options without a string value', () => {
const selected: EuiComboBoxOptionOption[] = [
{ label: 'hot', value: 'hot' },
{ label: 'broken' },
];

expect(ilmPhasesFromSelectedOptions(selected)).toEqual(['hot']);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { EuiComboBoxOptionOption } from '@elastic/eui';

/**
* Returns canonical ILM phase values for filtering (matches `getIlmPhase` output).
* Uses option `value`, not localized `label`, so non-English locales keep working.
*/
export const ilmPhasesFromSelectedOptions = (
selectedIlmPhaseOptions: EuiComboBoxOptionOption[]
): string[] =>
selectedIlmPhaseOptions
.map(({ value }) => value)
.filter((v): v is string => typeof v === 'string');
Loading