Skip to content

Commit

Permalink
Merge pull request #463 from SquirrelCorporation/458-feature-provide-…
Browse files Browse the repository at this point in the history
…a-confirmation-before-reboot

Add confirmation prompt for critical quick actions
  • Loading branch information
SquirrelDeveloper authored Nov 12, 2024
2 parents 58c6566 + fb028f7 commit d2b2e0f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TerminalStateProps } from '@/components/PlaybookExecutionModal';
import PlaybookSelectionModal from '@/components/PlaybookSelection/PlaybookSelectionModal';
import { DownOutlined } from '@ant-design/icons';
import { history } from '@umijs/max';
import { Dropdown, MenuProps, Space } from 'antd';
import { Dropdown, MenuProps, Popconfirm, Space } from 'antd';
import { ItemType } from 'rc-menu/es/interface';
import React, { Dispatch, ReactNode, SetStateAction } from 'react';
import { API, SsmAnsible } from 'ssm-shared-lib';
Expand All @@ -22,6 +22,10 @@ export type QuickActionProps = {
const DeviceQuickActionDropDown: React.FC<QuickActionProps> = (props) => {
const [playbookSelectionModalIsOpened, setPlaybookSelectionModalIsOpened] =
React.useState(false);
const [showConfirmation, setShowConfirmation] = React.useState({
visible: false,
onConfirm: () => {},
});

const onClick: MenuProps['onClick'] = ({ key }) => {
const idx = parseInt(key);
Expand All @@ -30,13 +34,27 @@ const DeviceQuickActionDropDown: React.FC<QuickActionProps> = (props) => {
alert('Internal Error');
return;
}

if (DeviceQuickActionReference[idx].action === Actions.CONNECT) {
history.push({
pathname: `/manage/devices/ssh/${props.target?.uuid}`,
});
return;
}
if (DeviceQuickActionReference[idx].type === Types.PLAYBOOK) {
if (DeviceQuickActionReference[idx].needConfirmation) {
setShowConfirmation({
visible: true,
onConfirm: () => {
props.setTerminal({
isOpen: true,
quickRef: DeviceQuickActionReference[idx].playbookQuickRef,
target: props.target ? [props.target] : undefined,
});
},
});
return;
}
props.setTerminal({
isOpen: true,
quickRef: DeviceQuickActionReference[idx].playbookQuickRef,
Expand Down Expand Up @@ -104,6 +122,19 @@ const DeviceQuickActionDropDown: React.FC<QuickActionProps> = (props) => {
itemSelected={props.target ? [props.target] : undefined}
callback={onSelectPlaybook}
/>
<Popconfirm
title={'Are you sure you want to execute this action?'}
open={showConfirmation.visible}
onConfirm={() => {
showConfirmation.onConfirm();
setShowConfirmation({ visible: false, onConfirm: () => {} });
}}
onCancel={() =>
setShowConfirmation({ visible: false, onConfirm: () => {} })
}
okText="Yes"
cancelText="No"
/>
<Dropdown menu={{ items, onClick }}>
<a onClick={(e) => e.preventDefault()}>
<Space>{props.children ? props.children : <DownOutlined />}</Space>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type QuickActionReferenceType = {
onAdvancedMenu: boolean;
children?: QuickActionReferenceType[];
icon?: React.ReactNode;
needConfirmation?: boolean;
};

export enum Actions {
Expand All @@ -47,6 +48,7 @@ const DeviceQuickActionReference: QuickActionReferenceType[] = [
icon: <ReloadOutlined />,
label: 'Reboot',
onAdvancedMenu: false,
needConfirmation: true,
},
{
type: Types.ACTION,
Expand Down

0 comments on commit d2b2e0f

Please sign in to comment.