Skip to content

Commit f21731f

Browse files
authored
Support the warning state for crawler validation steps (#110864)
1 parent d2fffdc commit f21731f

File tree

8 files changed

+48
-12
lines changed

8 files changed

+48
-12
lines changed

x-pack/plugins/enterprise_search/public/applications/app_search/components/crawler/components/add_domain/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@ export const getDomainWithProtocol = async (domain: string) => {
6262

6363
export const domainValidationStateToPanelColor = (
6464
state: CrawlerDomainValidationStepState
65-
): 'success' | 'danger' | 'subdued' => {
65+
): 'success' | 'warning' | 'danger' | 'subdued' => {
6666
switch (state) {
6767
case 'valid':
6868
return 'success';
69+
case 'warning':
70+
return 'warning';
6971
case 'invalid':
7072
return 'danger';
7173
default:

x-pack/plugins/enterprise_search/public/applications/app_search/components/crawler/components/add_domain/validation_state_icon.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ describe('ValidationStateIcon', () => {
2020
expect(wrapper.find(EuiIcon).prop('color')).toEqual('success');
2121
});
2222

23+
it('shows a warning icon when warning', () => {
24+
const wrapper = shallow(<ValidationStateIcon state="warning" />);
25+
26+
expect(wrapper.find(EuiIcon).prop('color')).toEqual('warning');
27+
});
28+
2329
it('shows a danger icon when invalid', () => {
2430
const wrapper = shallow(<ValidationStateIcon state="invalid" />);
2531

x-pack/plugins/enterprise_search/public/applications/app_search/components/crawler/components/add_domain/validation_state_icon.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ import { CrawlerDomainValidationStepState } from '../../types';
1414
export const ValidationStateIcon: React.FC<{ state: CrawlerDomainValidationStepState }> = ({
1515
state,
1616
}) => {
17-
if (state === 'valid') return <EuiIcon color="success" type="checkInCircleFilled" />;
18-
if (state === 'invalid') return <EuiIcon color="danger" type="crossInACircleFilled" />;
19-
return <EuiLoadingSpinner />;
17+
switch (state) {
18+
case 'valid':
19+
return <EuiIcon color="success" type="check" />;
20+
case 'warning':
21+
return <EuiIcon color="warning" type="alert" />;
22+
case 'invalid':
23+
return <EuiIcon color="danger" type="cross" />;
24+
default:
25+
return <EuiLoadingSpinner />;
26+
}
2027
};

x-pack/plugins/enterprise_search/public/applications/app_search/components/crawler/components/add_domain/validation_step_panel.test.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,42 @@ describe('ValidationStepPanel', () => {
1919
const wrapper = shallow(
2020
<ValidationStepPanel step={{ state: 'valid' }} label={'Initial validation'} />
2121
);
22+
2223
it('passed the correct color to the EuiPanel', () => {
2324
expect(wrapper.find(EuiPanel).prop('color')).toEqual('success');
2425
});
26+
2527
it('contains a validation state icon', () => {
2628
expect(wrapper.find(ValidationStateIcon)).toHaveLength(1);
2729
});
30+
2831
it('renders a label', () => {
2932
expect(wrapper.find('h3').text()).toEqual('Initial validation');
3033
});
3134
});
3235
describe('invalid messages and actions', () => {
3336
const errorMessage = 'Error message';
3437
const action = <div data-test-subj="action" />;
38+
3539
it('displays the passed error message and action is invalid', () => {
3640
const wrapper = shallow(
3741
<ValidationStepPanel
3842
step={{ state: 'invalid', message: errorMessage }}
39-
label={'initialValidation'}
43+
label="initialValidation"
44+
action={action}
45+
/>
46+
);
47+
expect(wrapper.find('[data-test-subj="errorMessage"]').dive().text()).toContain(
48+
'Error message'
49+
);
50+
expect(wrapper.find('[data-test-subj="action"]')).toHaveLength(1);
51+
});
52+
53+
it('displays the passed error message and action when state is warning', () => {
54+
const wrapper = shallow(
55+
<ValidationStepPanel
56+
step={{ state: 'warning', message: errorMessage }}
57+
label="initialValidation"
4058
action={action}
4159
/>
4260
);
@@ -45,11 +63,12 @@ describe('ValidationStepPanel', () => {
4563
);
4664
expect(wrapper.find('[data-test-subj="action"]')).toHaveLength(1);
4765
});
48-
it('does not display the passed error message or action when state is not invalid', () => {
66+
67+
it('does not display the passed error message or action when state is loading', () => {
4968
const wrapper = shallow(
5069
<ValidationStepPanel
5170
step={{ state: 'loading', message: errorMessage }}
52-
label={'initialValidation'}
71+
label="initialValidation"
5372
action={action}
5473
/>
5574
);

x-pack/plugins/enterprise_search/public/applications/app_search/components/crawler/components/add_domain/validation_step_panel.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,21 @@ export const ValidationStepPanel: React.FC<ValidationStepPanelProps> = ({
2525
label,
2626
action,
2727
}) => {
28+
const showErrorMessage = step.state === 'invalid' || step.state === 'warning';
29+
2830
return (
2931
<EuiPanel hasShadow={false} color={domainValidationStateToPanelColor(step.state)}>
3032
<EuiFlexGroup gutterSize="s" alignItems="center">
3133
<EuiFlexItem grow={false}>
32-
<ValidationStateIcon state={step?.state} />
34+
<ValidationStateIcon state={step.state} />
3335
</EuiFlexItem>
3436
<EuiFlexItem>
3537
<EuiTitle size="xs">
3638
<h3>{label}</h3>
3739
</EuiTitle>
3840
</EuiFlexItem>
3941
</EuiFlexGroup>
40-
{step.state === 'invalid' && (
42+
{showErrorMessage && (
4143
<>
4244
<EuiText size="s" data-test-subj="errorMessage">
4345
<p>{step.message}</p>

x-pack/plugins/enterprise_search/public/applications/app_search/components/crawler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export interface CrawlerDomainValidationResultFromServer {
135135
}>;
136136
}
137137

138-
export type CrawlerDomainValidationStepState = '' | 'loading' | 'valid' | 'invalid';
138+
export type CrawlerDomainValidationStepState = '' | 'loading' | 'valid' | 'warning' | 'invalid';
139139

140140
export interface CrawlerDomainValidationStep {
141141
state: CrawlerDomainValidationStepState;

x-pack/plugins/enterprise_search/public/applications/app_search/components/crawler/utils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ describe('crawlDomainValidationToResult', () => {
203203

204204
expect(crawlDomainValidationToResult(data)).toEqual({
205205
blockingFailure: false,
206-
state: 'invalid',
206+
state: 'warning',
207207
message: 'A warning, not failure',
208208
} as CrawlerDomainValidationStep);
209209
});

x-pack/plugins/enterprise_search/public/applications/app_search/components/crawler/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export function crawlDomainValidationToResult(
9999

100100
if (warningResult) {
101101
return {
102-
state: 'invalid',
102+
state: 'warning',
103103
blockingFailure: !data.valid,
104104
message: warningResult.comment,
105105
};

0 commit comments

Comments
 (0)