diff --git a/x-pack/plugins/enterprise_search/common/connectors/native_connectors.ts b/x-pack/plugins/enterprise_search/common/connectors/native_connectors.ts index 10c336540d9fa..aab72dce47f76 100644 --- a/x-pack/plugins/enterprise_search/common/connectors/native_connectors.ts +++ b/x-pack/plugins/enterprise_search/common/connectors/native_connectors.ts @@ -13,6 +13,7 @@ export const NATIVE_CONNECTOR_DEFINITIONS: Record; + export interface ConnectorConfigProperties { + depends_on: Dependency[]; display: string; label: string; - options: SelectOptions[]; + options: SelectOption[]; order?: number | null; required: boolean; sensitive: boolean; diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/__mocks__/search_indices.mock.ts b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/__mocks__/search_indices.mock.ts index 6de267dca4b2f..0ae7543eadd45 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/__mocks__/search_indices.mock.ts +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/__mocks__/search_indices.mock.ts @@ -34,6 +34,7 @@ export const indices: ElasticsearchIndexWithIngestion[] = [ api_key_id: null, configuration: { foo: { + depends_on: [], display: 'textbox', key: 'foo', label: 'bar', @@ -141,6 +142,7 @@ export const indices: ElasticsearchIndexWithIngestion[] = [ api_key_id: null, configuration: { foo: { + depends_on: [], display: 'textbox', key: 'foo', label: 'bar', diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/__mocks__/view_index.mock.ts b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/__mocks__/view_index.mock.ts index 3a799497993ba..517bad3746bc6 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/__mocks__/view_index.mock.ts +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/__mocks__/view_index.mock.ts @@ -44,6 +44,7 @@ export const connectorIndex: ConnectorViewIndex = { api_key_id: null, configuration: { foo: { + depends_on: [], display: 'textbox', key: 'foo', label: 'bar', @@ -155,6 +156,7 @@ export const crawlerIndex: CrawlerViewIndex = { api_key_id: null, configuration: { foo: { + depends_on: [], display: 'textbox', key: 'foo', label: 'bar', diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/connector/connector_configuration_form.tsx b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/connector/connector_configuration_form.tsx index 2ba55dc45c9a3..991e58a672016 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/connector/connector_configuration_form.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/connector/connector_configuration_form.tsx @@ -16,16 +16,22 @@ import { EuiFlexItem, EuiButton, EuiButtonEmpty, + EuiPanel, } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { Status } from '../../../../../../common/types/api'; +import { DependencyLookup } from '../../../../../../common/types/connectors'; import { ConnectorConfigurationApiLogic } from '../../../api/connector/update_connector_configuration_api_logic'; import { ConnectorConfigurationField } from './connector_configuration_field'; -import { ConnectorConfigurationLogic } from './connector_configuration_logic'; +import { + ConfigEntry, + ConnectorConfigurationLogic, + dependenciesSatisfied, +} from './connector_configuration_logic'; export const ConnectorConfigurationForm = () => { const { status } = useValues(ConnectorConfigurationApiLogic); @@ -33,6 +39,14 @@ export const ConnectorConfigurationForm = () => { const { localConfigView } = useValues(ConnectorConfigurationLogic); const { saveConfig, setIsEditing } = useActions(ConnectorConfigurationLogic); + const dependencyLookup: DependencyLookup = localConfigView.reduce( + (prev: Record, configEntry: ConfigEntry) => ({ + ...prev, + [configEntry.key]: configEntry.value, + }), + {} + ); + return ( { @@ -42,9 +56,20 @@ export const ConnectorConfigurationForm = () => { component="form" > {localConfigView.map((configEntry) => { - const { key, label } = configEntry; + const { depends_on: dependencies, key, label } = configEntry; + const hasDependencies = dependencies.length > 0; - return ( + return hasDependencies ? ( + dependenciesSatisfied(dependencies, dependencyLookup) ? ( + + + + + + ) : ( + <> + ) + ) : ( diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/connector/connector_configuration_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/connector/connector_configuration_logic.test.ts index 13cbf2bc0a983..ebb173a3c42ca 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/connector/connector_configuration_logic.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/connector/connector_configuration_logic.test.ts @@ -52,6 +52,7 @@ describe('ConnectorConfigurationLogic', () => { ConnectorConfigurationApiLogic.actions.apiSuccess({ configuration: { foo: { + depends_on: [], display: 'textbox', label: 'newBar', options: [], @@ -67,6 +68,7 @@ describe('ConnectorConfigurationLogic', () => { ...DEFAULT_VALUES, configState: { foo: { + depends_on: [], display: 'textbox', label: 'newBar', options: [], @@ -78,6 +80,7 @@ describe('ConnectorConfigurationLogic', () => { }, configView: [ { + depends_on: [], display: 'textbox', key: 'foo', label: 'newBar', @@ -93,6 +96,7 @@ describe('ConnectorConfigurationLogic', () => { it('should set config on setConfigState', () => { ConnectorConfigurationLogic.actions.setConfigState({ foo: { + depends_on: [], display: 'textbox', label: 'thirdBar', options: [], @@ -106,6 +110,7 @@ describe('ConnectorConfigurationLogic', () => { ...DEFAULT_VALUES, configState: { foo: { + depends_on: [], display: 'textbox', label: 'thirdBar', options: [], @@ -117,6 +122,7 @@ describe('ConnectorConfigurationLogic', () => { }, configView: [ { + depends_on: [], display: 'textbox', key: 'foo', label: 'thirdBar', @@ -133,6 +139,7 @@ describe('ConnectorConfigurationLogic', () => { it('should set local config entry and sort keys', () => { ConnectorConfigurationLogic.actions.setConfigState({ bar: { + depends_on: [], display: 'textbox', label: 'foo', options: [], @@ -142,6 +149,7 @@ describe('ConnectorConfigurationLogic', () => { value: 'foofoo', }, password: { + depends_on: [], display: 'textbox', label: 'thirdBar', options: [], @@ -153,6 +161,7 @@ describe('ConnectorConfigurationLogic', () => { }); ConnectorConfigurationLogic.actions.setLocalConfigState({ bar: { + depends_on: [], display: 'textbox', label: 'foo', options: [], @@ -162,6 +171,7 @@ describe('ConnectorConfigurationLogic', () => { value: 'foofoo', }, password: { + depends_on: [], display: 'textbox', label: 'thirdBar', options: [], @@ -172,6 +182,7 @@ describe('ConnectorConfigurationLogic', () => { }, }); ConnectorConfigurationLogic.actions.setLocalConfigEntry({ + depends_on: [], display: 'textbox', key: 'bar', label: 'foo', @@ -185,6 +196,7 @@ describe('ConnectorConfigurationLogic', () => { ...DEFAULT_VALUES, configState: { bar: { + depends_on: [], display: 'textbox', label: 'foo', options: [], @@ -194,6 +206,7 @@ describe('ConnectorConfigurationLogic', () => { value: 'foofoo', }, password: { + depends_on: [], display: 'textbox', label: 'thirdBar', options: [], @@ -205,6 +218,7 @@ describe('ConnectorConfigurationLogic', () => { }, configView: [ { + depends_on: [], display: 'textbox', key: 'bar', label: 'foo', @@ -215,6 +229,7 @@ describe('ConnectorConfigurationLogic', () => { value: 'foofoo', }, { + depends_on: [], display: 'textbox', key: 'password', label: 'thirdBar', @@ -227,6 +242,7 @@ describe('ConnectorConfigurationLogic', () => { ], localConfigState: { bar: { + depends_on: [], display: 'textbox', label: 'foo', options: [], @@ -236,6 +252,7 @@ describe('ConnectorConfigurationLogic', () => { value: 'fafa', }, password: { + depends_on: [], display: 'textbox', label: 'thirdBar', options: [], @@ -247,6 +264,7 @@ describe('ConnectorConfigurationLogic', () => { }, localConfigView: [ { + depends_on: [], display: 'textbox', key: 'bar', label: 'foo', @@ -257,6 +275,7 @@ describe('ConnectorConfigurationLogic', () => { value: 'fafa', }, { + depends_on: [], display: 'textbox', key: 'password', label: 'thirdBar', @@ -278,6 +297,7 @@ describe('ConnectorConfigurationLogic', () => { configState: connectorIndex.connector.configuration, configView: [ { + depends_on: [], display: 'textbox', key: 'foo', label: 'bar', @@ -311,6 +331,7 @@ describe('ConnectorConfigurationLogic', () => { configState: connectorIndex.connector.configuration, configView: [ { + depends_on: [], display: 'textbox', key: 'foo', label: 'bar', @@ -329,6 +350,7 @@ describe('ConnectorConfigurationLogic', () => { localConfigState: connectorIndex.connector.configuration, localConfigView: [ { + depends_on: [], display: 'textbox', key: 'foo', label: 'bar', @@ -349,6 +371,7 @@ describe('ConnectorConfigurationLogic', () => { ConnectorConfigurationLogic.actions.fetchIndexApiSuccess(connectorIndex); ConnectorConfigurationLogic.actions.setLocalConfigState({ foo: { + depends_on: [], display: 'textbox', label: 'bar', options: [], diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/connector/connector_configuration_logic.ts b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/connector/connector_configuration_logic.ts index d0416ca843c67..fee9496b3c069 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/connector/connector_configuration_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/connector/connector_configuration_logic.ts @@ -7,7 +7,13 @@ import { kea, MakeLogicType } from 'kea'; -import { ConnectorConfiguration, ConnectorStatus } from '../../../../../../common/types/connectors'; +import { + ConnectorConfiguration, + ConnectorStatus, + Dependency, + DependencyLookup, + SelectOption, +} from '../../../../../../common/types/connectors'; import { isNotNullish } from '../../../../../../common/utils/is_not_nullish'; import { @@ -48,16 +54,12 @@ interface ConnectorConfigurationValues { shouldStartInEditMode: boolean; } -interface SelectOptions { - label: string; - value: string; -} - export interface ConfigEntry { + depends_on: Dependency[]; display: string; key: string; label: string; - options: SelectOptions[]; + options: SelectOption[]; order?: number; required: boolean; sensitive: boolean; @@ -107,6 +109,19 @@ export function ensureBooleanType(value: string | number | boolean | null): bool return Boolean(value); } +export function dependenciesSatisfied( + dependencies: Dependency[], + dependencyLookup: DependencyLookup +): boolean { + for (const dependency of dependencies) { + if (dependency.value !== dependencyLookup[dependency.field]) { + return false; + } + } + + return true; +} + export const ConnectorConfigurationLogic = kea< MakeLogicType >({ @@ -214,10 +229,11 @@ export const ConnectorConfigurationLogic = kea< { setLocalConfigEntry: ( configState, - { key, display, label, options, order, required, sensitive, value } + // eslint-disable-next-line @typescript-eslint/naming-convention + { key, depends_on, display, label, options, order, required, sensitive, value } ) => ({ ...configState, - [key]: { display, label, options, order, required, sensitive, value }, + [key]: { depends_on, display, label, options, order, required, sensitive, value }, }), setLocalConfigState: (_, { configState }) => configState, },