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

Add prompt for connector configuration being in editable mode #202463

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ interface ConnectorConfigurationProps {
isLoading: boolean;
saveConfig: (configuration: Record<string, string | number | boolean | null>) => void;
saveAndSync?: (configuration: Record<string, string | number | boolean | null>) => void;
onEditStateChange?: (isEdit: boolean) => void;
stackManagementLink?: string;
subscriptionLink?: string;
children?: React.ReactNode;
Expand Down Expand Up @@ -94,6 +95,7 @@ export const ConnectorConfigurationComponent: FC<
isLoading,
saveConfig,
saveAndSync,
onEditStateChange,
subscriptionLink,
stackManagementLink,
}) => {
Expand All @@ -110,6 +112,15 @@ export const ConnectorConfigurationComponent: FC<
);
const [isEditing, setIsEditing] = useState(false);

useEffect(
function propogateEditState() {
if (onEditStateChange) {
onEditStateChange(isEditing);
}
},
[isEditing, onEditStateChange]
);

useEffect(() => {
if (!isDeepEqual(configuration, configurationRef.current)) {
configurationRef.current = configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { useEffect } from 'react';
import React, { useEffect, useState } from 'react';

import { useActions, useValues } from 'kea';

Expand All @@ -21,6 +21,7 @@ import {
} from '@elastic/eui';

import { i18n } from '@kbn/i18n';
import { useKibana } from '@kbn/kibana-react-plugin/public';

import { ConnectorConfigurationComponent, ConnectorStatus } from '@kbn/search-connectors';

Expand All @@ -40,6 +41,8 @@ export const ConfigurationStep: React.FC<ConfigurationStepProps> = ({ title, set
const { connector } = useValues(ConnectorViewLogic);
const { updateConnectorConfiguration } = useActions(ConnectorViewLogic);
const { setFormDirty } = useActions(NewConnectorLogic);
const { overlays } = useKibana().services;
const [isFormEditing, setIsFormEditing] = useState<boolean>(false);
const { status } = useValues(ConnectorConfigurationApiLogic);
const isSyncing = false;

Expand Down Expand Up @@ -77,6 +80,7 @@ export const ConfigurationStep: React.FC<ConfigurationStepProps> = ({ title, set
connectorId: connector.id,
});
}}
onEditStateChange={setIsFormEditing}
/>
<EuiSpacer size="m" />
{isSyncing && (
Expand Down Expand Up @@ -111,7 +115,38 @@ export const ConfigurationStep: React.FC<ConfigurationStepProps> = ({ title, set
<EuiSpacer size="m" />
<EuiButton
data-test-subj="enterpriseSearchStartStepGenerateConfigurationButton"
onClick={() => {
onClick={async () => {
if (isFormEditing) {
const confirmResponse = await overlays?.openConfirm(
i18n.translate('xpack.enterpriseSearch.configureConnector.unsavedPrompt.body', {
defaultMessage:
'You are still editing connector configuration, are you sure you want to continue without saving? You can complete the setup later in the connector configuration page, but this guided flow offers more help.',
}),
{
title: i18n.translate(
'xpack.enterpriseSearch.configureConnector.unsavedPrompt.title',
{
defaultMessage: 'Connector configuration is not saved',
}
),
cancelButtonText: i18n.translate(
'xpack.enterpriseSearch.configureConnector.unsavedPrompt.cancel',
{
defaultMessage: 'Continue setup',
}
),
confirmButtonText: i18n.translate(
'xpack.enterpriseSearch.configureConnector.unsavedPrompt.confirm',
{
defaultMessage: 'Leave the page',
}
),
}
);
if (!confirmResponse) {
return;
}
}
setFormDirty(false);
setCurrentStep('finish');
}}
Expand Down
Loading