forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OpenAI Preconfigured Connector Dashboard Link (elastic#169148)
(cherry picked from commit 75e9d46)
- Loading branch information
1 parent
89f1a28
commit dfa732e
Showing
7 changed files
with
161 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
x-pack/plugins/stack_connectors/public/connector_types/openai/dashboard_link.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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 React, { useCallback } from 'react'; | ||
import { EuiLink } from '@elastic/eui'; | ||
import { useKibana } from '@kbn/triggers-actions-ui-plugin/public'; | ||
import * as i18n from './translations'; | ||
import { useGetDashboard } from './use_get_dashboard'; | ||
|
||
interface Props { | ||
connectorId: string; | ||
connectorName: string; | ||
selectedProvider?: string; | ||
} | ||
// tested from ./connector.test.tsx | ||
export const DashboardLink: React.FC<Props> = ({ | ||
connectorId, | ||
connectorName, | ||
selectedProvider = '', | ||
}) => { | ||
const { dashboardUrl } = useGetDashboard({ connectorId }); | ||
const { | ||
services: { | ||
application: { navigateToUrl }, | ||
}, | ||
} = useKibana(); | ||
const onClick = useCallback( | ||
(e) => { | ||
e.preventDefault(); | ||
if (dashboardUrl) { | ||
navigateToUrl(dashboardUrl); | ||
} | ||
}, | ||
[dashboardUrl, navigateToUrl] | ||
); | ||
return dashboardUrl != null ? ( | ||
<EuiLink data-test-subj="link-gen-ai-token-dashboard" onClick={onClick}> | ||
{i18n.USAGE_DASHBOARD_LINK(selectedProvider, connectorName)} | ||
</EuiLink> | ||
) : null; | ||
}; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export { DashboardLink as default }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...ublic/application/sections/action_connector_form/edit_connector_flyout/read_only.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { I18nProvider } from '@kbn/i18n-react'; | ||
import { render } from '@testing-library/react'; | ||
import { ReadOnlyConnectorMessage } from './read_only'; | ||
import { ActionTypeModel } from '../../../..'; | ||
|
||
const ExtraComponent = jest.fn(() => ( | ||
<div>Extra Component</div> | ||
)) as unknown as ActionTypeModel['actionReadOnlyExtraComponent']; | ||
describe('ReadOnlyConnectorMessage', () => { | ||
it('should render a readonly message with a link to the provided href', () => { | ||
const { getByTestId, getByText, queryByText } = render( | ||
<ReadOnlyConnectorMessage | ||
connectorId="123" | ||
connectorName="Test Connector" | ||
href="https://example.com/" | ||
/>, | ||
{ wrapper: I18nProvider } | ||
); | ||
|
||
expect(getByText('This connector is readonly.')).toBeInTheDocument(); | ||
expect(getByTestId('read-only-link')).toHaveProperty('href', 'https://example.com/'); | ||
expect(queryByText('Extra Component')).toBeNull(); | ||
}); | ||
|
||
it('should render an extra component if provided', () => { | ||
const { getByText } = render( | ||
<ReadOnlyConnectorMessage | ||
connectorId="123" | ||
connectorName="Test Connector" | ||
extraComponent={ExtraComponent} | ||
href="https://example.com" | ||
/>, | ||
{ wrapper: I18nProvider } | ||
); | ||
|
||
expect(getByText('Extra Component')).toBeInTheDocument(); | ||
}); | ||
}); |
42 changes: 42 additions & 0 deletions
42
..._ui/public/application/sections/action_connector_form/edit_connector_flyout/read_only.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { EuiLink, EuiSpacer, EuiText } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import { ActionTypeModel } from '../../../..'; | ||
|
||
export const ReadOnlyConnectorMessage: React.FC<{ | ||
connectorId: string; | ||
connectorName: string; | ||
extraComponent?: ActionTypeModel['actionReadOnlyExtraComponent']; | ||
href: string; | ||
}> = ({ connectorId, connectorName, extraComponent, href }) => { | ||
const ExtraComponent = extraComponent; | ||
return ( | ||
<> | ||
<EuiText> | ||
{i18n.translate('xpack.triggersActionsUI.sections.editConnectorForm.descriptionText', { | ||
defaultMessage: 'This connector is readonly.', | ||
})} | ||
</EuiText> | ||
<EuiLink data-test-subj="read-only-link" href={href} target="_blank"> | ||
<FormattedMessage | ||
id="xpack.triggersActionsUI.sections.editConnectorForm.preconfiguredHelpLabel" | ||
defaultMessage="Learn more about preconfigured connectors." | ||
/> | ||
</EuiLink> | ||
{ExtraComponent && ( | ||
<> | ||
<EuiSpacer size="m" /> | ||
<ExtraComponent connectorId={connectorId} connectorName={connectorName} /> | ||
</> | ||
)} | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters