Disabling connectors for invalid connector types (#86910)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
ymao1 2021-01-05 12:44:48 -05:00 committed by GitHub
parent 3fba4763fb
commit eabd7088bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 5 deletions

View file

@ -116,6 +116,14 @@ describe('actions_connectors_list component with items', () => {
isPreconfigured: true,
config: {},
},
{
id: '4',
actionTypeId: 'nonexistent',
description: 'My invalid connector type',
referencedByCount: 1,
isPreconfigured: false,
config: {},
},
]
);
loadActionTypes.mockResolvedValueOnce([
@ -162,7 +170,7 @@ describe('actions_connectors_list component with items', () => {
it('renders table of connectors', async () => {
await setup();
expect(wrapper.find('EuiInMemoryTable')).toHaveLength(1);
expect(wrapper.find('EuiTableRow')).toHaveLength(3);
expect(wrapper.find('EuiTableRow')).toHaveLength(4);
});
it('renders table with preconfigured connectors', async () => {
@ -170,6 +178,17 @@ describe('actions_connectors_list component with items', () => {
expect(wrapper.find('[data-test-subj="preConfiguredTitleMessage"]')).toHaveLength(2);
});
it('renders unknown connector type as disabled', async () => {
await setup();
expect(wrapper.find('button[data-test-subj="edit4"]').getDOMNode()).toBeDisabled();
expect(
wrapper.find('button[data-test-subj="deleteConnector"]').last().getDOMNode()
).not.toBeDisabled();
expect(
wrapper.find('button[data-test-subj="runConnector"]').last().getDOMNode()
).toBeDisabled();
});
it('supports pagination', async () => {
await setup(
times(15, (index) => ({

View file

@ -164,7 +164,7 @@ export const ActionsConnectorsList: React.FunctionComponent = () => {
data-test-subj={`edit${item.id}`}
onClick={() => editItem(item, EditConectorTabs.Configuration)}
key={item.id}
disabled={actionTypesIndex ? !actionTypesIndex[item.actionTypeId].enabled : true}
disabled={actionTypesIndex ? !actionTypesIndex[item.actionTypeId]?.enabled : true}
>
{value}
</EuiLink>
@ -207,7 +207,7 @@ export const ActionsConnectorsList: React.FunctionComponent = () => {
onDelete={() => setConnectorsToDelete([item.id])}
/>
<RunOperation
canExecute={canExecute}
canExecute={canExecute && actionTypesIndex && actionTypesIndex[item.actionTypeId]}
item={item}
onRun={() => editItem(item, EditConectorTabs.Test)}
/>
@ -226,7 +226,7 @@ export const ActionsConnectorsList: React.FunctionComponent = () => {
columns={actionsTableColumns}
rowProps={(item: ActionConnectorTableItem) => ({
className:
!actionTypesIndex || !actionTypesIndex[item.actionTypeId].enabled
!actionTypesIndex || !actionTypesIndex[item.actionTypeId]?.enabled
? 'actConnectorsList__tableRowDisabled'
: '',
'data-test-subj': 'connectors-row',
@ -234,7 +234,7 @@ export const ActionsConnectorsList: React.FunctionComponent = () => {
cellProps={(item: ActionConnectorTableItem) => ({
'data-test-subj': 'cell',
className:
!actionTypesIndex || !actionTypesIndex[item.actionTypeId].enabled
!actionTypesIndex || !actionTypesIndex[item.actionTypeId]?.enabled
? 'actConnectorsList__tableCellDisabled'
: '',
})}