[Enterprise Search] Add required flag to connector configurable fields (#155043)

## Summary

Adds a required flag to configurable fields. If the configuration field
has `required: true` then the input will be required as well.
This is not applicable to radios and switches, which can't be null.
This commit is contained in:
Navarone Feekery 2023-04-17 21:57:15 +02:00 committed by GitHub
parent efc7ca6a07
commit 8d9777b94f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 59 additions and 9 deletions

View file

@ -22,6 +22,7 @@ export const NATIVE_CONNECTOR_DEFINITIONS: Record<string, NativeConnector | unde
),
options: [],
order: 1,
required: true,
sensitive: false,
value: '',
},
@ -35,6 +36,7 @@ export const NATIVE_CONNECTOR_DEFINITIONS: Record<string, NativeConnector | unde
),
options: [],
order: 2,
required: true,
sensitive: false,
value: '',
},
@ -48,6 +50,7 @@ export const NATIVE_CONNECTOR_DEFINITIONS: Record<string, NativeConnector | unde
),
options: [],
order: 3,
required: true,
sensitive: true,
value: '',
},
@ -61,6 +64,7 @@ export const NATIVE_CONNECTOR_DEFINITIONS: Record<string, NativeConnector | unde
),
options: [],
order: 4,
required: true,
sensitive: false,
value: '',
},
@ -74,6 +78,7 @@ export const NATIVE_CONNECTOR_DEFINITIONS: Record<string, NativeConnector | unde
),
options: [],
order: 5,
required: true,
sensitive: false,
value: '',
},
@ -87,6 +92,7 @@ export const NATIVE_CONNECTOR_DEFINITIONS: Record<string, NativeConnector | unde
),
options: [],
order: 6,
required: true,
sensitive: false,
value: true,
},
@ -116,6 +122,7 @@ export const NATIVE_CONNECTOR_DEFINITIONS: Record<string, NativeConnector | unde
),
options: [],
order: 1,
required: true,
sensitive: false,
value: '',
},
@ -129,6 +136,7 @@ export const NATIVE_CONNECTOR_DEFINITIONS: Record<string, NativeConnector | unde
),
options: [],
order: 2,
required: true,
sensitive: false,
value: '',
},
@ -142,6 +150,7 @@ export const NATIVE_CONNECTOR_DEFINITIONS: Record<string, NativeConnector | unde
),
options: [],
order: 3,
required: false,
sensitive: false,
value: '',
},
@ -155,6 +164,7 @@ export const NATIVE_CONNECTOR_DEFINITIONS: Record<string, NativeConnector | unde
),
options: [],
order: 4,
required: false,
sensitive: true,
value: '',
},
@ -168,6 +178,7 @@ export const NATIVE_CONNECTOR_DEFINITIONS: Record<string, NativeConnector | unde
),
options: [],
order: 5,
required: true,
sensitive: false,
value: '',
},
@ -181,6 +192,7 @@ export const NATIVE_CONNECTOR_DEFINITIONS: Record<string, NativeConnector | unde
),
options: [],
order: 6,
required: true,
sensitive: false,
value: '',
},
@ -194,6 +206,7 @@ export const NATIVE_CONNECTOR_DEFINITIONS: Record<string, NativeConnector | unde
),
options: [],
order: 7,
required: true,
sensitive: false,
value: false,
},
@ -207,6 +220,7 @@ export const NATIVE_CONNECTOR_DEFINITIONS: Record<string, NativeConnector | unde
),
options: [],
order: 8,
required: true,
sensitive: false,
value: '',
},

View file

@ -15,6 +15,7 @@ export interface ConnectorConfigProperties {
label: string;
options: SelectOptions[];
order?: number | null;
required: boolean;
sensitive: boolean;
value: string | number | boolean | null;
}

View file

@ -39,6 +39,7 @@ export const indices: ElasticsearchIndexWithIngestion[] = [
label: 'bar',
options: [],
order: 1,
required: false,
sensitive: false,
value: 'barbar',
},
@ -145,6 +146,7 @@ export const indices: ElasticsearchIndexWithIngestion[] = [
label: 'bar',
options: [],
order: 1,
required: false,
sensitive: false,
value: 'barbar',
},

View file

@ -49,6 +49,7 @@ export const connectorIndex: ConnectorViewIndex = {
label: 'bar',
options: [],
order: 1,
required: false,
sensitive: false,
value: 'barbar',
},
@ -159,6 +160,7 @@ export const crawlerIndex: CrawlerViewIndex = {
label: 'bar',
options: [],
order: 1,
required: false,
sensitive: false,
value: 'barbar',
},

View file

@ -42,13 +42,15 @@ export const ConnectorConfigurationField: React.FC<ConnectorConfigurationFieldPr
const { status } = useValues(ConnectorConfigurationApiLogic);
const { setLocalConfigEntry } = useActions(ConnectorConfigurationLogic);
const { key, display, label, options, sensitive, value } = configEntry;
const { key, display, label, options, required, sensitive, value } = configEntry;
switch (display) {
case 'dropdown':
return options.length > 3 ? (
<EuiSelect
disabled={status === Status.LOADING}
options={options.map((option) => ({ text: option.label, value: option.value }))}
required={required}
value={ensureStringType(value)}
onChange={(event) => {
setLocalConfigEntry({ ...configEntry, value: event.target.value });
@ -56,20 +58,22 @@ export const ConnectorConfigurationField: React.FC<ConnectorConfigurationFieldPr
/>
) : (
<EuiRadioGroup
options={options.map((option) => ({ id: option.value, label: option.label }))}
disabled={status === Status.LOADING}
idSelected={ensureStringType(value)}
name="radio group"
options={options.map((option) => ({ id: option.value, label: option.label }))}
onChange={(id) => {
setLocalConfigEntry({ ...configEntry, value: id });
}}
name="radio group"
/>
);
case 'numeric':
return (
<EuiFieldNumber
value={ensureNumberType(value)}
disabled={status === Status.LOADING}
required={required}
value={ensureNumberType(value)}
onChange={(event) => {
setLocalConfigEntry({ ...configEntry, value: event.target.value });
}}
@ -79,8 +83,9 @@ export const ConnectorConfigurationField: React.FC<ConnectorConfigurationFieldPr
case 'textarea':
const textarea = (
<EuiTextArea
value={ensureStringType(value)}
disabled={status === Status.LOADING}
required={required}
value={ensureStringType(value)}
onChange={(event) => {
setLocalConfigEntry({ ...configEntry, value: event.target.value });
}}
@ -110,17 +115,19 @@ export const ConnectorConfigurationField: React.FC<ConnectorConfigurationFieldPr
default:
return sensitive ? (
<EuiFieldPassword
value={ensureStringType(value)}
disabled={status === Status.LOADING}
required={required}
type="dual"
value={ensureStringType(value)}
onChange={(event) => {
setLocalConfigEntry({ ...configEntry, value: event.target.value });
}}
/>
) : (
<EuiFieldText
value={ensureStringType(value)}
disabled={status === Status.LOADING}
required={required}
value={ensureStringType(value)}
onChange={(event) => {
setLocalConfigEntry({ ...configEntry, value: event.target.value });
}}

View file

@ -56,6 +56,7 @@ describe('ConnectorConfigurationLogic', () => {
label: 'newBar',
options: [],
order: 1,
required: false,
sensitive: false,
value: 'oldBar',
},
@ -70,6 +71,7 @@ describe('ConnectorConfigurationLogic', () => {
label: 'newBar',
options: [],
order: 1,
required: false,
sensitive: false,
value: 'oldBar',
},
@ -81,6 +83,7 @@ describe('ConnectorConfigurationLogic', () => {
label: 'newBar',
options: [],
order: 1,
required: false,
sensitive: false,
value: 'oldBar',
},
@ -94,6 +97,7 @@ describe('ConnectorConfigurationLogic', () => {
label: 'thirdBar',
options: [],
order: 1,
required: false,
sensitive: false,
value: 'fourthBar',
},
@ -106,6 +110,7 @@ describe('ConnectorConfigurationLogic', () => {
label: 'thirdBar',
options: [],
order: 1,
required: false,
sensitive: false,
value: 'fourthBar',
},
@ -117,6 +122,7 @@ describe('ConnectorConfigurationLogic', () => {
label: 'thirdBar',
options: [],
order: 1,
required: false,
sensitive: false,
value: 'fourthBar',
},
@ -131,6 +137,7 @@ describe('ConnectorConfigurationLogic', () => {
label: 'foo',
options: [],
order: 1,
required: false,
sensitive: false,
value: 'foofoo',
},
@ -139,6 +146,7 @@ describe('ConnectorConfigurationLogic', () => {
label: 'thirdBar',
options: [],
order: 2,
required: false,
sensitive: true,
value: 'fourthBar',
},
@ -149,6 +157,7 @@ describe('ConnectorConfigurationLogic', () => {
label: 'foo',
options: [],
order: 1,
required: false,
sensitive: false,
value: 'foofoo',
},
@ -157,6 +166,7 @@ describe('ConnectorConfigurationLogic', () => {
label: 'thirdBar',
options: [],
order: 2,
required: false,
sensitive: true,
value: 'fourthBar',
},
@ -167,6 +177,7 @@ describe('ConnectorConfigurationLogic', () => {
label: 'foo',
options: [],
order: 1,
required: false,
sensitive: false,
value: 'fafa',
});
@ -178,6 +189,7 @@ describe('ConnectorConfigurationLogic', () => {
label: 'foo',
options: [],
order: 1,
required: false,
sensitive: false,
value: 'foofoo',
},
@ -186,6 +198,7 @@ describe('ConnectorConfigurationLogic', () => {
label: 'thirdBar',
options: [],
order: 2,
required: false,
sensitive: true,
value: 'fourthBar',
},
@ -197,6 +210,7 @@ describe('ConnectorConfigurationLogic', () => {
label: 'foo',
options: [],
order: 1,
required: false,
sensitive: false,
value: 'foofoo',
},
@ -206,6 +220,7 @@ describe('ConnectorConfigurationLogic', () => {
label: 'thirdBar',
options: [],
order: 2,
required: false,
sensitive: true,
value: 'fourthBar',
},
@ -216,6 +231,7 @@ describe('ConnectorConfigurationLogic', () => {
label: 'foo',
options: [],
order: 1,
required: false,
sensitive: false,
value: 'fafa',
},
@ -224,6 +240,7 @@ describe('ConnectorConfigurationLogic', () => {
label: 'thirdBar',
options: [],
order: 2,
required: false,
sensitive: true,
value: 'fourthBar',
},
@ -235,6 +252,7 @@ describe('ConnectorConfigurationLogic', () => {
label: 'foo',
options: [],
order: 1,
required: false,
sensitive: false,
value: 'fafa',
},
@ -244,6 +262,7 @@ describe('ConnectorConfigurationLogic', () => {
label: 'thirdBar',
options: [],
order: 2,
required: false,
sensitive: true,
value: 'fourthBar',
},
@ -264,6 +283,7 @@ describe('ConnectorConfigurationLogic', () => {
label: 'bar',
options: [],
order: 1,
required: false,
sensitive: false,
value: 'barbar',
},
@ -296,6 +316,7 @@ describe('ConnectorConfigurationLogic', () => {
label: 'bar',
options: [],
order: 1,
required: false,
sensitive: false,
value: 'barbar',
},
@ -313,6 +334,7 @@ describe('ConnectorConfigurationLogic', () => {
label: 'bar',
options: [],
order: 1,
required: false,
sensitive: false,
value: 'barbar',
},
@ -331,6 +353,7 @@ describe('ConnectorConfigurationLogic', () => {
label: 'bar',
options: [],
order: 1,
required: false,
sensitive: true,
value: 'Barbara',
},

View file

@ -59,6 +59,7 @@ export interface ConfigEntry {
label: string;
options: SelectOptions[];
order?: number;
required: boolean;
sensitive: boolean;
value: string | number | boolean | null;
}
@ -213,10 +214,10 @@ export const ConnectorConfigurationLogic = kea<
{
setLocalConfigEntry: (
configState,
{ key, display, label, options, order, sensitive, value }
{ key, display, label, options, order, required, sensitive, value }
) => ({
...configState,
[key]: { display, label, options, order, sensitive, value },
[key]: { display, label, options, order, required, sensitive, value },
}),
setLocalConfigState: (_, { configState }) => configState,
},