|
@@ -1,5 +1,6 @@
|
|
|
import { Button, Tooltip } from '@chakra-ui/react';
|
|
|
import React from 'react';
|
|
|
+import { IconType } from 'react-icons';
|
|
|
import { FiExternalLink, FiPause, FiPlay, FiSettings, FiTrash2 } from 'react-icons/fi';
|
|
|
import { MdSystemUpdateAlt } from 'react-icons/md';
|
|
|
import { TiCancel } from 'react-icons/ti';
|
|
@@ -19,6 +20,26 @@ interface IProps {
|
|
|
onCancel: () => void;
|
|
|
}
|
|
|
|
|
|
+interface BtnProps {
|
|
|
+ Icon?: IconType;
|
|
|
+ onClick: () => void;
|
|
|
+ width?: number | null;
|
|
|
+ title?: string;
|
|
|
+ color?: string;
|
|
|
+ loading?: boolean;
|
|
|
+}
|
|
|
+
|
|
|
+const ActionButton: React.FC<BtnProps> = (props) => {
|
|
|
+ const { Icon, onClick, title, loading, width = 150, color = 'gray' } = props;
|
|
|
+
|
|
|
+ return (
|
|
|
+ <Button isLoading={loading} onClick={onClick} width={width || undefined} colorScheme={color} className="mt-3 mr-2">
|
|
|
+ {title}
|
|
|
+ {Icon && <Icon className="ml-1" />}
|
|
|
+ </Button>
|
|
|
+ );
|
|
|
+};
|
|
|
+
|
|
|
const AppActions: React.FC<IProps> = ({ app, status, onInstall, onUninstall, onStart, onStop, onOpen, onUpdate, onCancel, updateAvailable, onUpdateSettings }) => {
|
|
|
const hasSettings = Object.keys(app.form_fields).length > 0;
|
|
|
|
|
@@ -30,110 +51,64 @@ const AppActions: React.FC<IProps> = ({ app, status, onInstall, onUninstall, onS
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+ const StartButton = <ActionButton Icon={FiPlay} onClick={onStart} title="Start" color="green" />;
|
|
|
+ const RemoveButton = <ActionButton Icon={FiTrash2} onClick={onUninstall} title="Remove" />;
|
|
|
+ const SettingsButton = <ActionButton Icon={FiSettings} width={null} onClick={onUpdateSettings} />;
|
|
|
+ const StopButton = <ActionButton Icon={FiPause} onClick={onStop} title="Stop" color="red" />;
|
|
|
+ const OpenButton = <ActionButton Icon={FiExternalLink} onClick={onOpen} title="Open" />;
|
|
|
+ const LoadingButtion = <ActionButton loading onClick={() => null} color="green" />;
|
|
|
+ const CancelButton = <ActionButton Icon={TiCancel} onClick={onCancel} title="Cancel" />;
|
|
|
+ const InstallButton = <ActionButton onClick={onInstall} title="Install" color="green" />;
|
|
|
+ const UpdateButton = (
|
|
|
+ <Tooltip label="Download update">
|
|
|
+ <ActionButton Icon={MdSystemUpdateAlt} onClick={onUpdate} width={null} />
|
|
|
+ </Tooltip>
|
|
|
+ );
|
|
|
+
|
|
|
switch (status) {
|
|
|
case AppStatusEnum.Stopped:
|
|
|
- buttons.push(
|
|
|
- <Button onClick={onStart} width={150} colorScheme="green" className="mt-3 mr-2">
|
|
|
- Start
|
|
|
- <FiPlay className="ml-1" />
|
|
|
- </Button>,
|
|
|
- <Button onClick={onUninstall} width={150} colorScheme="gray" className="mt-3 mr-2">
|
|
|
- Remove
|
|
|
- <FiTrash2 className="ml-1" />
|
|
|
- </Button>,
|
|
|
- );
|
|
|
+ buttons.push(StartButton, RemoveButton);
|
|
|
if (hasSettings) {
|
|
|
- buttons.push(
|
|
|
- <Tooltip label="Update settings">
|
|
|
- <Button onClick={onUpdateSettings} colorScheme="gray" className="mt-3 mr-2">
|
|
|
- <FiSettings className="ml-1" />
|
|
|
- </Button>
|
|
|
- </Tooltip>,
|
|
|
- );
|
|
|
+ buttons.push(SettingsButton);
|
|
|
}
|
|
|
if (updateAvailable) {
|
|
|
- buttons.push(
|
|
|
- <Tooltip label="Download update">
|
|
|
- <Button onClick={onUpdate} colorScheme="gray" className="mt-3 mr-2">
|
|
|
- <MdSystemUpdateAlt className="ml-1" />
|
|
|
- </Button>
|
|
|
- </Tooltip>,
|
|
|
- );
|
|
|
+ buttons.push(UpdateButton);
|
|
|
}
|
|
|
break;
|
|
|
case AppStatusEnum.Running:
|
|
|
- buttons.push(
|
|
|
- <Button onClick={onStop} width={150} colorScheme="red" className="mt-3 mr-2">
|
|
|
- Stop
|
|
|
- <FiPause className="ml-1" />
|
|
|
- </Button>,
|
|
|
- <Button onClick={onOpen} width={150} colorScheme="gray" className="mt-3 mr-2">
|
|
|
- Open
|
|
|
- <FiExternalLink className="ml-1" />
|
|
|
- </Button>,
|
|
|
- );
|
|
|
+ buttons.push(StopButton, OpenButton);
|
|
|
if (hasSettings) {
|
|
|
- buttons.push(
|
|
|
- <Tooltip label="Update settings">
|
|
|
- <Button onClick={onUpdateSettings} colorScheme="gray" className="mt-3 mr-2">
|
|
|
- <FiSettings className="ml-1" />
|
|
|
- </Button>
|
|
|
- </Tooltip>,
|
|
|
- );
|
|
|
+ buttons.push(SettingsButton);
|
|
|
}
|
|
|
if (updateAvailable) {
|
|
|
- buttons.push(
|
|
|
- <Tooltip label="Download update">
|
|
|
- <Button onClick={onUpdate} colorScheme="gray" className="mt-3 mr-2">
|
|
|
- <MdSystemUpdateAlt className="ml-1" />
|
|
|
- </Button>
|
|
|
- </Tooltip>,
|
|
|
- );
|
|
|
+ buttons.push(UpdateButton);
|
|
|
}
|
|
|
break;
|
|
|
case AppStatusEnum.Installing:
|
|
|
case AppStatusEnum.Uninstalling:
|
|
|
case AppStatusEnum.Starting:
|
|
|
case AppStatusEnum.Stopping:
|
|
|
- buttons.push(
|
|
|
- <Button isLoading onClick={() => null} width={160} colorScheme="green" className="mt-3">
|
|
|
- Install
|
|
|
- <FiPlay className="ml-1" />
|
|
|
- </Button>,
|
|
|
- <Button onClick={onCancel} colorScheme="gray" className="mt-3 mr-2 ml-2">
|
|
|
- <TiCancel />
|
|
|
- </Button>,
|
|
|
- );
|
|
|
+ buttons.push(LoadingButtion, CancelButton);
|
|
|
break;
|
|
|
|
|
|
case AppStatusEnum.Updating:
|
|
|
- buttons.push(
|
|
|
- <Button isLoading onClick={() => null} width={160} colorScheme="green" className="mt-3">
|
|
|
- Updating
|
|
|
- <FiPlay className="ml-1" />
|
|
|
- </Button>,
|
|
|
- <Button onClick={onCancel} colorScheme="gray" className="mt-3 mr-2 ml-2">
|
|
|
- <TiCancel />
|
|
|
- </Button>,
|
|
|
- );
|
|
|
+ buttons.push(LoadingButtion, CancelButton);
|
|
|
break;
|
|
|
case AppStatusEnum.Missing:
|
|
|
- buttons.push(
|
|
|
- <Button onClick={onInstall} width={160} colorScheme="green" className="mt-3">
|
|
|
- Install
|
|
|
- </Button>,
|
|
|
- );
|
|
|
+ buttons.push(InstallButton);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
return (
|
|
|
- <div className="flex items-center sm:items-start flex-col md:flex-row">
|
|
|
- {buttons.map((button) => {
|
|
|
- return button;
|
|
|
- })}
|
|
|
- {renderStatus()}
|
|
|
+ <div className="flex flex-1 flex-col justify-start">
|
|
|
+ <div className="flex flex-1 justify-center md:justify-start flex-wrap">
|
|
|
+ {buttons.map((button) => {
|
|
|
+ return button;
|
|
|
+ })}
|
|
|
+ </div>
|
|
|
+ <div className="mt-1 flex justify-center md:justify-start">{renderStatus()}</div>
|
|
|
</div>
|
|
|
);
|
|
|
};
|