Skip to content

Commit

Permalink
[Search] Add delete connector endpoint through new _connectors api (e…
Browse files Browse the repository at this point in the history
…lastic#175249)

## Summary

Add Delete connector modal


https://github.com/elastic/kibana/assets/1410658/16838df7-9614-40b2-a768-ad9de0393d49



### Checklist

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
  • Loading branch information
efegurkan authored Jan 30, 2024
1 parent 7f9b8a2 commit cc7d283
Show file tree
Hide file tree
Showing 7 changed files with 530 additions and 147 deletions.
10 changes: 10 additions & 0 deletions x-pack/plugins/enterprise_search/common/types/connectors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export interface DeleteConnectorResponse {
acknowledge: boolean;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { DeleteConnectorResponse } from '../../../../../common/types/connectors';

import { Actions, createApiLogic } from '../../../shared/api_logic/create_api_logic';
import { HttpLogic } from '../../../shared/http';

export interface DeleteConnectorApiLogicArgs {
connectorId: string;
shouldDeleteIndex: boolean;
}

export interface DeleteConnectorApiLogicResponse {
acknowledged: boolean;
}

export const deleteConnector = async ({
connectorId,
shouldDeleteIndex = false,
}: DeleteConnectorApiLogicArgs) => {
return await HttpLogic.values.http.delete(
`/internal/enterprise_search/connectors/${connectorId}`,
{
query: {
shouldDeleteIndex,
},
}
);
};

export const DeleteConnectorApiLogic = createApiLogic(
['delete_connector_api_logic'],
deleteConnector
);

export type DeleteConnectorApiLogicActions = Actions<
DeleteConnectorApiLogicArgs,
DeleteConnectorResponse
>;
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { ConnectorStats } from './connector_stats';
import { ConnectorsLogic } from './connectors_logic';
import { ConnectorsTable } from './connectors_table';
import { CrawlerEmptyState } from './crawler_empty_state';
import { DeleteConnectorModal } from './delete_connector_modal';

export const baseBreadcrumbs = [
i18n.translate('xpack.enterpriseSearch.content.connectors.breadcrumb', {
Expand All @@ -53,7 +54,8 @@ export interface ConnectorsProps {
isCrawler: boolean;
}
export const Connectors: React.FC<ConnectorsProps> = ({ isCrawler }) => {
const { fetchConnectors, onPaginate, setIsFirstRequest } = useActions(ConnectorsLogic);
const { fetchConnectors, onPaginate, setIsFirstRequest, openDeleteModal } =
useActions(ConnectorsLogic);
const { data, isLoading, searchParams, isEmpty, connectors } = useValues(ConnectorsLogic);
const { errorConnectingMessage } = useValues(HttpLogic);
const [searchQuery, setSearchValue] = useState('');
Expand All @@ -69,151 +71,158 @@ export const Connectors: React.FC<ConnectorsProps> = ({ isCrawler }) => {
return !isLoading && isEmpty && !isCrawler ? (
<SelectConnector />
) : (
<EnterpriseSearchContentPageTemplate
pageChrome={baseBreadcrumbs}
pageViewTelemetry={!isCrawler ? 'Connectors' : 'Web Crawlers'}
isLoading={isLoading}
pageHeader={{
pageTitle: !isCrawler
? i18n.translate('xpack.enterpriseSearch.connectors.title', {
defaultMessage: 'Elasticsearch connectors',
})
: i18n.translate('xpack.enterpriseSearch.crawlers.title', {
defaultMessage: 'Elasticsearch web crawlers',
}),
rightSideGroupProps: {
gutterSize: 's',
},
rightSideItems: isLoading
? []
: !isCrawler
? [
<EuiButton
key="newConnector"
color="primary"
iconType="plusInCircle"
fill
onClick={() => {
KibanaLogic.values.navigateToUrl(NEW_INDEX_SELECT_CONNECTOR_PATH);
}}
>
<FormattedMessage
id="xpack.enterpriseSearch.connectors.newConnectorButtonLabel"
defaultMessage="New Connector"
/>
</EuiButton>,
<EuiButton
key="newConnectorNative"
onClick={() => {
KibanaLogic.values.navigateToUrl(NEW_INDEX_SELECT_CONNECTOR_NATIVE_PATH);
}}
>
{i18n.translate('xpack.enterpriseSearch.connectors.newNativeConnectorButtonLabel', {
defaultMessage: 'New Native Connector',
})}
</EuiButton>,
<EuiButton
key="newConnectorClient"
onClick={() => {
KibanaLogic.values.navigateToUrl(NEW_INDEX_SELECT_CONNECTOR_CLIENTS_PATH);
}}
>
{i18n.translate(
'xpack.enterpriseSearch.connectors.newConnectorsClientButtonLabel',
{ defaultMessage: 'New Connector Client' }
)}
</EuiButton>,
]
: [
<EuiButton
disabled={Boolean(errorConnectingMessage)}
key="newCrawler"
color="primary"
iconType="plusInCircle"
fill
onClick={() => {
KibanaLogic.values.navigateToUrl(
generateEncodedPath(NEW_INDEX_METHOD_PATH, {
type: INGESTION_METHOD_IDS.CRAWLER,
})
);
}}
>
{i18n.translate('xpack.enterpriseSearch.connectors.newCrawlerButtonLabel', {
defaultMessage: 'New web crawler',
})}
</EuiButton>,
],
}}
>
{Boolean(errorConnectingMessage) && (
<>
<CannotConnect />
<EuiSpacer />
</>
)}
<ConnectorStats isCrawler={isCrawler} />
<EuiSpacer />

<EuiFlexGroup direction="column">
{isEmpty && isCrawler ? (
<CrawlerEmptyState />
) : (
<>
<EuiFlexItem>
<EuiTitle>
<h2>
{!isCrawler ? (
<FormattedMessage
id="xpack.enterpriseSearch.connectorsTable.h2.availableConnectorsLabel"
defaultMessage="Available connectors"
/>
) : (
<FormattedMessage
id="xpack.enterpriseSearch.connectorsTable.h2.availableCrawlersLabel"
defaultMessage="Available web crawlers"
/>
<>
<DeleteConnectorModal />
<EnterpriseSearchContentPageTemplate
pageChrome={baseBreadcrumbs}
pageViewTelemetry={!isCrawler ? 'Connectors' : 'Web Crawlers'}
isLoading={isLoading}
pageHeader={{
pageTitle: !isCrawler
? i18n.translate('xpack.enterpriseSearch.connectors.title', {
defaultMessage: 'Elasticsearch connectors',
})
: i18n.translate('xpack.enterpriseSearch.crawlers.title', {
defaultMessage: 'Elasticsearch web crawlers',
}),
rightSideGroupProps: {
gutterSize: 's',
},
rightSideItems: isLoading
? []
: !isCrawler
? [
<EuiButton
key="newConnector"
color="primary"
iconType="plusInCircle"
fill
onClick={() => {
KibanaLogic.values.navigateToUrl(NEW_INDEX_SELECT_CONNECTOR_PATH);
}}
>
<FormattedMessage
id="xpack.enterpriseSearch.connectors.newConnectorButtonLabel"
defaultMessage="New Connector"
/>
</EuiButton>,
<EuiButton
key="newConnectorNative"
onClick={() => {
KibanaLogic.values.navigateToUrl(NEW_INDEX_SELECT_CONNECTOR_NATIVE_PATH);
}}
>
{i18n.translate(
'xpack.enterpriseSearch.connectors.newNativeConnectorButtonLabel',
{
defaultMessage: 'New Native Connector',
}
)}
</h2>
</EuiTitle>
</EuiFlexItem>
<EuiFlexItem>
<EuiSearchBar
query={searchQuery}
box={{
incremental: true,
placeholder: !isCrawler
? i18n.translate(
'xpack.enterpriseSearch.connectorsTable.euiSearchBar.filterConnectorsPlaceholder',
{ defaultMessage: 'Filter connectors' }
)
: i18n.translate(
'xpack.enterpriseSearch.connectorsTable.euiSearchBar.filterCrawlersPlaceholder',
{ defaultMessage: 'Filter web crawlers' }
),
}}
aria-label={
!isCrawler
? i18n.translate(
'xpack.enterpriseSearch.connectorsTable.euiSearchBar.filterConnectorsLabel',
{ defaultMessage: 'Filter connectors' }
)
: i18n.translate(
'xpack.enterpriseSearch.connectorsTable.euiSearchBar.filterCrawlersLabel',
{ defaultMessage: 'Filter web crawlers' }
)
}
onChange={(event) => setSearchValue(event.queryText)}
/>
</EuiFlexItem>
<ConnectorsTable
items={connectors || []}
meta={data?.meta}
onChange={handlePageChange(onPaginate)}
/>
</EuiButton>,
<EuiButton
key="newConnectorClient"
onClick={() => {
KibanaLogic.values.navigateToUrl(NEW_INDEX_SELECT_CONNECTOR_CLIENTS_PATH);
}}
>
{i18n.translate(
'xpack.enterpriseSearch.connectors.newConnectorsClientButtonLabel',
{ defaultMessage: 'New Connector Client' }
)}
</EuiButton>,
]
: [
<EuiButton
disabled={Boolean(errorConnectingMessage)}
key="newCrawler"
color="primary"
iconType="plusInCircle"
fill
onClick={() => {
KibanaLogic.values.navigateToUrl(
generateEncodedPath(NEW_INDEX_METHOD_PATH, {
type: INGESTION_METHOD_IDS.CRAWLER,
})
);
}}
>
{i18n.translate('xpack.enterpriseSearch.connectors.newCrawlerButtonLabel', {
defaultMessage: 'New web crawler',
})}
</EuiButton>,
],
}}
>
{Boolean(errorConnectingMessage) && (
<>
<CannotConnect />
<EuiSpacer />
</>
)}
</EuiFlexGroup>
</EnterpriseSearchContentPageTemplate>
<ConnectorStats isCrawler={isCrawler} />
<EuiSpacer />

<EuiFlexGroup direction="column">
{isEmpty && isCrawler ? (
<CrawlerEmptyState />
) : (
<>
<EuiFlexItem>
<EuiTitle>
<h2>
{!isCrawler ? (
<FormattedMessage
id="xpack.enterpriseSearch.connectorsTable.h2.availableConnectorsLabel"
defaultMessage="Available connectors"
/>
) : (
<FormattedMessage
id="xpack.enterpriseSearch.connectorsTable.h2.availableCrawlersLabel"
defaultMessage="Available web crawlers"
/>
)}
</h2>
</EuiTitle>
</EuiFlexItem>
<EuiFlexItem>
<EuiSearchBar
query={searchQuery}
box={{
incremental: true,
placeholder: !isCrawler
? i18n.translate(
'xpack.enterpriseSearch.connectorsTable.euiSearchBar.filterConnectorsPlaceholder',
{ defaultMessage: 'Filter connectors' }
)
: i18n.translate(
'xpack.enterpriseSearch.connectorsTable.euiSearchBar.filterCrawlersPlaceholder',
{ defaultMessage: 'Filter web crawlers' }
),
}}
aria-label={
!isCrawler
? i18n.translate(
'xpack.enterpriseSearch.connectorsTable.euiSearchBar.filterConnectorsLabel',
{ defaultMessage: 'Filter connectors' }
)
: i18n.translate(
'xpack.enterpriseSearch.connectorsTable.euiSearchBar.filterCrawlersLabel',
{ defaultMessage: 'Filter web crawlers' }
)
}
onChange={(event) => setSearchValue(event.queryText)}
/>
</EuiFlexItem>
<ConnectorsTable
items={connectors || []}
meta={data?.meta}
onChange={handlePageChange(onPaginate)}
onDelete={openDeleteModal}
/>
</>
)}
</EuiFlexGroup>
</EnterpriseSearchContentPageTemplate>
</>
);
};
Loading

0 comments on commit cc7d283

Please sign in to comment.