Skip to content

Commit

Permalink
removed flyouts entirely in between usage
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmorris committed Oct 30, 2020
1 parent 2aeeb6e commit 4097102
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ describe('connector_add_flyout', () => {
}}
>
<ConnectorAddFlyout
addFlyoutVisible={true}
setAddFlyoutVisibility={() => {}}
onClose={() => {}}
actionTypes={[
{
id: actionType.id,
Expand Down Expand Up @@ -100,8 +99,7 @@ describe('connector_add_flyout', () => {
}}
>
<ConnectorAddFlyout
addFlyoutVisible={true}
setAddFlyoutVisibility={() => {}}
onClose={() => {}}
actionTypes={[
{
id: actionType.id,
Expand Down Expand Up @@ -160,8 +158,7 @@ describe('connector_add_flyout', () => {
}}
>
<ConnectorAddFlyout
addFlyoutVisible={true}
setAddFlyoutVisibility={() => {}}
onClose={() => {}}
actionTypes={[
{
id: actionType.id,
Expand Down Expand Up @@ -208,8 +205,7 @@ describe('connector_add_flyout', () => {
}}
>
<ConnectorAddFlyout
addFlyoutVisible={true}
setAddFlyoutVisibility={() => {}}
onClose={() => {}}
actionTypes={[
{
id: actionType.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ import { useActionsConnectorsContext } from '../../context/actions_connectors_co
import { VIEW_LICENSE_OPTIONS_LINK } from '../../../common/constants';

export interface ConnectorAddFlyoutProps {
addFlyoutVisible: boolean;
setAddFlyoutVisibility: React.Dispatch<React.SetStateAction<boolean>>;
onClose: () => void;
actionTypes?: ActionType[];
onTestConnector?: (connector: ActionConnector) => void;
}

export const ConnectorAddFlyout = ({
addFlyoutVisible,
setAddFlyoutVisibility,
onClose,
actionTypes,
onTestConnector,
}: ConnectorAddFlyoutProps) => {
Expand Down Expand Up @@ -74,17 +72,13 @@ export const ConnectorAddFlyout = ({
const [isSaving, setIsSaving] = useState<boolean>(false);

const closeFlyout = useCallback(() => {
setAddFlyoutVisibility(false);
setActionType(undefined);
setConnector(initialConnector);
}, [setAddFlyoutVisibility, initialConnector]);
onClose();
}, [onClose, initialConnector]);

const canSave = hasSaveActionsCapability(capabilities);

if (!addFlyoutVisible) {
return null;
}

function onActionTypeChange(newActionType: ActionType) {
setActionType(newActionType);
setActionProperty('actionTypeId', newActionType.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ describe('connector_edit_flyout', () => {
docLinks: deps.docLinks,
}}
>
<ConnectorEditFlyout
initialConnector={connector}
editFlyoutVisible={true}
setEditFlyoutVisibility={(state) => {}}
/>
<ConnectorEditFlyout initialConnector={connector} onClose={() => {}} />
</ActionsConnectorsContextProvider>
</AppContextProvider>
);
Expand Down Expand Up @@ -141,11 +137,7 @@ describe('connector_edit_flyout', () => {
docLinks: deps.docLinks,
}}
>
<ConnectorEditFlyout
initialConnector={connector}
editFlyoutVisible={true}
setEditFlyoutVisibility={(state) => {}}
/>
<ConnectorEditFlyout initialConnector={connector} onClose={() => {}} />
</ActionsConnectorsContextProvider>
</AppContextProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ import './connector_edit_flyout.scss';

export interface ConnectorEditProps {
initialConnector: ActionConnector;
editFlyoutVisible: boolean;
setEditFlyoutVisibility: React.Dispatch<React.SetStateAction<boolean>>;
onClose: () => void;
tab?: EditConectorTabs;
}

Expand All @@ -51,8 +50,7 @@ export enum EditConectorTabs {

export const ConnectorEditFlyout = ({
initialConnector,
editFlyoutVisible,
setEditFlyoutVisibility,
onClose,
tab = EditConectorTabs.Configuration,
}: ConnectorEditProps) => {
const {
Expand Down Expand Up @@ -86,16 +84,12 @@ export const ConnectorEditFlyout = ({
const [isExecutingAction, setIsExecutinAction] = useState<boolean>(false);

const closeFlyout = useCallback(() => {
setEditFlyoutVisibility(false);
setConnector('connector', { ...initialConnector, secrets: {} });
setHasChanges(false);
setTestExecutionResult(none);
onClose();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [setEditFlyoutVisibility]);

if (!editFlyoutVisible) {
return null;
}
}, [onClose]);

const actionTypeModel = actionTypeRegistry.get(connector.actionTypeId);
const errorsInConnectorConfig = (!connector.isPreconfigured
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
EuiEmptyPrompt,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { omit } from 'lodash';
import { FormattedMessage } from '@kbn/i18n/react';
import { useAppDependencies } from '../../../app_context';
import { loadAllActions, loadActionTypes, deleteActions } from '../../../lib/action_connector_api';
Expand Down Expand Up @@ -56,7 +57,6 @@ export const ActionsConnectorsList: React.FunctionComponent = () => {
const [selectedItems, setSelectedItems] = useState<ActionConnectorTableItem[]>([]);
const [isLoadingActionTypes, setIsLoadingActionTypes] = useState<boolean>(false);
const [isLoadingActions, setIsLoadingActions] = useState<boolean>(false);
const [editFlyoutVisible, setEditFlyoutVisibility] = useState<boolean>(false);
const [addFlyoutVisible, setAddFlyoutVisibility] = useState<boolean>(false);
const [editConnectorProps, setEditConnectorProps] = useState<{
initialConnector?: ActionConnector;
Expand Down Expand Up @@ -134,7 +134,6 @@ export const ActionsConnectorsList: React.FunctionComponent = () => {

async function editItem(actionConnector: ActionConnector, tab: EditConectorTabs) {
setEditConnectorProps({ initialConnector: actionConnector, tab });
setEditFlyoutVisibility(true);
}

const actionsTableColumns = [
Expand Down Expand Up @@ -367,20 +366,24 @@ export const ActionsConnectorsList: React.FunctionComponent = () => {
docLinks,
}}
>
<ConnectorAddFlyout
addFlyoutVisible={addFlyoutVisible}
setAddFlyoutVisibility={setAddFlyoutVisibility}
onTestConnector={(connector) => editItem(connector, EditConectorTabs.Test)}
/>
{addFlyoutVisible ? (
<ConnectorAddFlyout
onClose={() => {
setAddFlyoutVisibility(false);
}}
onTestConnector={(connector) => editItem(connector, EditConectorTabs.Test)}
/>
) : null}
{editConnectorProps.initialConnector ? (
<ConnectorEditFlyout
key={`${editConnectorProps.initialConnector.id}${
editConnectorProps.tab ? `:${editConnectorProps.tab}` : ``
}`}
initialConnector={editConnectorProps.initialConnector}
tab={editConnectorProps.tab}
editFlyoutVisible={editFlyoutVisible}
setEditFlyoutVisibility={setEditFlyoutVisibility}
onClose={() => {
setEditConnectorProps(omit(editConnectorProps, 'initialConnector'));
}}
/>
) : null}
</ActionsConnectorsContextProvider>
Expand Down

0 comments on commit 4097102

Please sign in to comment.