Skip to content

Commit

Permalink
UI changes
Browse files Browse the repository at this point in the history
  • Loading branch information
WithoutPants committed Sep 22, 2023
1 parent 83e2ba0 commit 6e6e70f
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 5 deletions.
4 changes: 4 additions & 0 deletions graphql/documents/mutations/plugins.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ mutation RunPluginTask(
) {
runPluginTask(plugin_id: $plugin_id, task_name: $task_name, args: $args)
}

mutation SetPluginsEnabled($enabledMap: BoolMap!) {
setPluginsEnabled(enabledMap: $enabledMap)
}
2 changes: 2 additions & 0 deletions graphql/documents/queries/plugins.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ query Plugins {
plugins {
id
name
enabled
description
url
version
Expand All @@ -26,6 +27,7 @@ query PluginTasks {
plugin {
id
name
enabled
}
}
}
56 changes: 52 additions & 4 deletions ui/v2.5/src/components/Settings/SettingsPluginsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import React, { useMemo } from "react";
import { Button } from "react-bootstrap";
import { FormattedMessage, useIntl } from "react-intl";
import * as GQL from "src/core/generated-graphql";
import { mutateReloadPlugins, usePlugins } from "src/core/StashService";
import {
mutateReloadPlugins,
mutateSetPluginsEnabled,
usePlugins,
} from "src/core/StashService";
import { useToast } from "src/hooks/Toast";
import TextUtils from "src/utils/text";
import { CollapseButton } from "../Shared/CollapseButton";
Expand All @@ -16,7 +20,11 @@ export const SettingsPluginsPanel: React.FC = () => {
const Toast = useToast();
const intl = useIntl();

const { data, loading } = usePlugins();
const [changedPluginID, setChangedPluginID] = React.useState<
string | undefined
>();

const { data, loading, refetch } = usePlugins();

async function onReloadPlugins() {
await mutateReloadPlugins().catch((e) => Toast.error(e));
Expand All @@ -40,6 +48,39 @@ export const SettingsPluginsPanel: React.FC = () => {
}
}

function renderEnableButton(pluginID: string, enabled: boolean) {
async function onClick() {
await mutateSetPluginsEnabled({ [pluginID]: !enabled }).catch((e) =>
Toast.error(e)
);

setChangedPluginID(pluginID);
refetch();
}

return (
<Button size="sm" onClick={onClick}>
<FormattedMessage
id={enabled ? "actions.disable" : "actions.enable"}
/>
</Button>
);
}

function onReloadUI() {
window.location.reload();
}

function maybeRenderReloadUI(pluginID: string) {
if (pluginID === changedPluginID) {
return (
<Button size="sm" onClick={() => onReloadUI()}>
Reload UI
</Button>
);
}
}

function renderPlugins() {
const elements = (data?.plugins ?? []).map((plugin) => (
<SettingGroup
Expand All @@ -48,9 +89,16 @@ export const SettingsPluginsPanel: React.FC = () => {
heading: `${plugin.name} ${
plugin.version ? `(${plugin.version})` : undefined
}`,
className: !plugin.enabled ? "disabled" : undefined,
subHeading: plugin.description,
}}
topLevel={renderLink(plugin.url ?? undefined)}
topLevel={
<>
{renderLink(plugin.url ?? undefined)}
{maybeRenderReloadUI(plugin.id)}
{renderEnableButton(plugin.id, plugin.enabled)}
</>
}
>
{renderPluginHooks(plugin.hooks ?? undefined)}
</SettingGroup>
Expand Down Expand Up @@ -98,7 +146,7 @@ export const SettingsPluginsPanel: React.FC = () => {
}

return renderPlugins();
}, [data?.plugins, intl]);
}, [data?.plugins, intl, Toast, changedPluginID, refetch]);

if (loading) return <LoadingIndicator />;

Expand Down
2 changes: 1 addition & 1 deletion ui/v2.5/src/components/Settings/Tasks/PluginTasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const PluginTasks: React.FC = () => {
}

const taskPlugins = plugins.data.plugins.filter(
(p) => p.tasks && p.tasks.length > 0
(p) => p.enabled && p.tasks && p.tasks.length > 0
);

return (
Expand Down
8 changes: 8 additions & 0 deletions ui/v2.5/src/core/StashService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2091,6 +2091,14 @@ export const mutateMigrate = (input: GQL.MigrateInput) =>
},
});

type BoolMap = { [key: string]: boolean };

export const mutateSetPluginsEnabled = (enabledMap: BoolMap) =>
client.mutate<GQL.SetPluginsEnabledMutation>({
mutation: GQL.SetPluginsEnabledDocument,
variables: { enabledMap },
});

/// Tasks

export const mutateMetadataScan = (input: GQL.ScanMetadataInput) =>
Expand Down
2 changes: 2 additions & 0 deletions ui/v2.5/src/locales/en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@
"delete_file_and_funscript": "Delete file (and funscript)",
"delete_generated_supporting_files": "Delete generated supporting files",
"delete_stashid": "Delete StashID",
"disable": "Disable",
"disallow": "Disallow",
"download": "Download",
"download_anonymised": "Download anonymised",
"download_backup": "Download Backup",
"edit": "Edit",
"edit_entity": "Edit {entityType}",
"enable": "Enable",
"encoding_image": "Encoding image",
"export": "Export",
"export_all": "Export all…",
Expand Down

0 comments on commit 6e6e70f

Please sign in to comment.