Skip to content

Commit

Permalink
Allow disabling extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
maksis committed Nov 11, 2024
1 parent 5d0a5a2 commit 49e1bc4
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
36 changes: 36 additions & 0 deletions src/actions/ui/extension/ExtensionManageActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ import { MENU_DIVIDER } from 'constants/ActionConstants';
type Filter = UI.ActionFilter<API.Extension>;
const isManaged: Filter = ({ itemData: extension }) => extension.managed;
const isRunning: Filter = ({ itemData: extension }) => extension.running;
const isDisabled: Filter = ({ itemData: extension }) => extension.disabled;
const hasSettings: Filter = ({ itemData: extension }) => extension.has_settings;

const canStart: Filter = (data) => isManaged(data) && !isRunning(data);
const canStop: Filter = (data) => isManaged(data) && isRunning(data);

const canDisable: Filter = (data) => isManaged(data) && !isDisabled(data);
const canEnable: Filter = (data) => isManaged(data) && isDisabled(data);

const handleConfigure: UI.ActionHandler<API.Extension> = ({
itemData: extension,
navigate,
Expand All @@ -35,6 +39,18 @@ const handleStop: UI.ActionHandler<API.Extension> = ({ itemData: extension }) =>
);
};

const handleDisable: UI.ActionHandler<API.Extension> = ({ itemData: extension }) => {
return SocketService.patch(`${ExtensionConstants.EXTENSIONS_URL}/${extension.name}`, {
disabled: true,
});
};

const handleEnable: UI.ActionHandler<API.Extension> = ({ itemData: extension }) => {
return SocketService.patch(`${ExtensionConstants.EXTENSIONS_URL}/${extension.name}`, {
disabled: false,
});
};

const handleRemove: UI.ActionHandler<API.Extension> = ({ itemData }) => {
return SocketService.delete(ExtensionConstants.EXTENSIONS_URL + '/' + itemData.name);
};
Expand Down Expand Up @@ -66,6 +82,24 @@ export const ExtensionConfigureAction = {
handler: handleConfigure,
};

export const ExtensionDisableAction = {
id: 'disable',
displayName: 'Disable',
icon: IconConstants.DISABLE,
filter: canDisable,
access: API.AccessEnum.SETTINGS_EDIT,
handler: handleDisable,
};

export const ExtensionEnableAction = {
id: 'enable',
displayName: 'Enable',
icon: IconConstants.ENABLE,
filter: canEnable,
access: API.AccessEnum.SETTINGS_EDIT,
handler: handleEnable,
};

export const ExtensionRemoveAction = {
id: 'remove',
displayName: 'Uninstall',
Expand All @@ -86,6 +120,8 @@ const ExtensionManageActions: UI.ActionListType<API.Extension> = {
start: ExtensionStartAction,
stop: ExtensionStopAction,
configure: ExtensionConfigureAction,
disable: ExtensionDisableAction,
enable: ExtensionEnableAction,
divider: MENU_DIVIDER,
remove: ExtensionRemoveAction,
};
Expand Down
5 changes: 4 additions & 1 deletion src/constants/IconConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ export default {
OFFLINE: 'plug',
FILTER: 'filter',
SEND: 'send',
CONFIGURE: 'gray configure',
CONFIGURE: 'grey configure',
CLOSE: 'grey remove',
CANCEL: 'remove',
DATE: 'calendar',
MENU: 'content',
NOTIFICATION: 'yellow bell',

DISABLE: 'grey remove',
ENABLE: 'green checkmark',

RELOAD: 'blue refresh',
REFRESH_PLAIN: 'refresh',
REFRESH_COLORED: 'green refresh',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const ExtensionActionButtons: React.FC<ExtensionActionButtonsProps> = ({
{installedPackage && (
<ActionMenu
actions={ExtensionManageActionsMenu}
ids={['configure', 'divider', 'remove']}
ids={['configure', 'enable', 'disable', 'divider', 'remove']}
remoteMenuId={MenuConstants.EXTENSION}
remoteMenuNestingThreshold={10}
itemData={installedPackage}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ const getCornerIcon = (
return 'blue external square';
}

if (installedPackage.running) {
return 'green play';
}

if (installedPackage.disabled) {
return 'grey check circle';
}

return 'green check circle';
};

Expand All @@ -38,6 +46,7 @@ const ExtensionIcon: React.FC<ExtensionIconProps> = ({
<div className="ui image">
<Icon
icon={IconConstants.EXTENSION}
color={installedPackage?.disabled ? 'grey' : undefined}
size={size}
cornerIcon={getCornerIcon(installedPackage, hasUpdate)}
/>
Expand Down
1 change: 1 addition & 0 deletions src/types/api/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface Extension {
version: string;
homepage: string;
author: string;
disabled: boolean;
running: boolean;
private: boolean;
logs: FilesystemItemType[];
Expand Down

0 comments on commit 49e1bc4

Please sign in to comment.