Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cases] Show deprecated icon in connectors with isDeprecated true #132237

Merged
merged 10 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions x-pack/plugins/actions/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface ActionResult {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
config: Record<string, any>;
isPreconfigured: boolean;
isDeprecated?: boolean;
}

// the result returned from an action type executor function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,26 @@ describe('ConnectorsDropdown', () => {
);
expect(tooltips[0]).toBeInTheDocument();
});

test('it shows the deprecated tooltip when the connector is deprecated by configuration', () => {
const connector = connectors[0];
render(
<ConnectorsDropdown
{...props}
connectors={[
{
...connector,
isDeprecated: true,
},
]}
selectedConnector={connector.id}
/>,
{ wrapper: ({ children }) => <TestProviders>{children}</TestProviders> }
);

const tooltips = screen.getAllByText(
'This connector is deprecated. Update it, or create a new one.'
);
expect(tooltips[0]).toBeInTheDocument();
});
});
44 changes: 7 additions & 37 deletions x-pack/plugins/cases/public/components/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,53 +46,23 @@ describe('Utils', () => {
config: { usesTableApi: false },
secrets: {},
isPreconfigured: false,
isDeprecated: false,
};

it('returns false if the connector is not defined', () => {
expect(isDeprecatedConnector()).toBe(false);
});

it('returns false if the connector is not ITSM or SecOps', () => {
expect(isDeprecatedConnector(connector)).toBe(false);
});

it('returns false if the connector is .servicenow and the usesTableApi=false', () => {
expect(isDeprecatedConnector({ ...connector, actionTypeId: '.servicenow' })).toBe(false);
it('returns false if the connector is marked as deprecated', () => {
expect(isDeprecatedConnector({ ...connector, isDeprecated: false })).toBe(false);
});

it('returns false if the connector is .servicenow-sir and the usesTableApi=false', () => {
expect(isDeprecatedConnector({ ...connector, actionTypeId: '.servicenow-sir' })).toBe(false);
it('returns true if the connector is marked as deprecated', () => {
expect(isDeprecatedConnector({ ...connector, isDeprecated: true })).toBe(true);
});

it('returns true if the connector is .servicenow and the usesTableApi=true', () => {
it('returns true if the connector is marked as deprecated (preconfigured connector)', () => {
expect(
isDeprecatedConnector({
...connector,
actionTypeId: '.servicenow',
config: { usesTableApi: true },
})
isDeprecatedConnector({ ...connector, isDeprecated: true, isPreconfigured: true })
).toBe(true);
});

it('returns true if the connector is .servicenow-sir and the usesTableApi=true', () => {
expect(
isDeprecatedConnector({
...connector,
actionTypeId: '.servicenow-sir',
config: { usesTableApi: true },
})
).toBe(true);
});

it('returns false if the connector preconfigured', () => {
expect(isDeprecatedConnector({ ...connector, isPreconfigured: true })).toBe(false);
});

it('returns false if the config is undefined', () => {
expect(
// @ts-expect-error
isDeprecatedConnector({ ...connector, config: undefined })
).toBe(false);
});
});
});
23 changes: 1 addition & 22 deletions x-pack/plugins/cases/public/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,5 @@ export const getConnectorIcon = (

// TODO: Remove when the applications are certified
export const isDeprecatedConnector = (connector?: CaseActionConnector): boolean => {
/**
* It is not possible to know if a preconfigured connector
* is deprecated or not as the config property of a
* preconfigured connector is not returned by the
* actions framework
*/
if (connector == null || connector.config == null || connector.isPreconfigured) {
return false;
}

if (connector.actionTypeId === '.servicenow' || connector.actionTypeId === '.servicenow-sir') {
/**
* Connector's prior to the Elastic ServiceNow application
* use the Table API (https://developer.servicenow.com/dev.do#!/reference/api/rome/rest/c_TableAPI)
* Connectors after the Elastic ServiceNow application use the
* Import Set API (https://developer.servicenow.com/dev.do#!/reference/api/rome/rest/c_ImportSetAPI)
* A ServiceNow connector is considered deprecated if it uses the Table API.
*/
return !!connector.config.usesTableApi;
}

return false;
return connector?.isDeprecated ?? false;
};