Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unhalt tree button for moderators #3411

Merged
merged 1 commit into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions website/public/locales/en/message.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
"report_action": "Report",
"report_placeholder": "Why should this message be reviewed?",
"report_title": "Report",
"restart_tree": "Restart tree",
"send_report": "Send",
"stop_tree": "Stop tree",
"submit_labels": "Submit",
"tree_restarted": "Tree restarted {{id}}",
"tree_stopped": "Tree stopped {{id}}",
"view_user": "View user",
"your_recent_messages": "Your Recent Messages",
Expand Down
15 changes: 11 additions & 4 deletions website/src/components/Messages/MessageTableEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,12 @@ const MessageActions = ({
const { t } = useTranslation(["message", "common"]);
const { id } = message;

const { trigger: stopTree } = useSWRMutation<any, any, any, never>(`/api/admin/stop_tree/${id}`, put, {
onSuccess: () => {
const { trigger: setTreeHalted } = useSWRMutation(`/api/admin/set_tree_halted/${id}`, put, {
onSuccess: (data) => {
const displayId = id.slice(0, CHAR_COUNT) + "..." + id.slice(-CHAR_COUNT);
toast({
title: t("common:success"),
description: t("tree_stopped", { id: displayId }),
description: data.halted ? t("tree_stopped", { id: displayId }) : t("tree_restarted", { id: displayId }),
status: "success",
duration: 5000,
isClosable: true,
Expand All @@ -238,7 +238,11 @@ const MessageActions = ({
};

const handleStop = () => {
stopTree();
setTreeHalted(true);
};

const handleRestart = () => {
setTreeHalted(false);
};

const handleCopy = (text: string) => {
Expand Down Expand Up @@ -324,6 +328,9 @@ const MessageActions = ({
<MenuItem onClick={handleStop} icon={<Slash />}>
{t("stop_tree")}
</MenuItem>
<MenuItem onClick={handleRestart} icon={<RefreshCw />}>
{t("restart_tree")}
</MenuItem>
</>
)}
</MenuList>
Expand Down
6 changes: 3 additions & 3 deletions website/src/lib/oasst_api_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ export class OasstApiClient {
}

/**
* Stop message tree
* Set whether a tree is halted
*/
async stop_tree(message_id: string): Promise<void> {
return this.put<void>(`/api/v1/messages/${message_id}/tree/state?halt=true`);
async set_tree_halted(message_id: string, halt: boolean): Promise<void> {
return this.put<void>(`/api/v1/messages/${message_id}/tree/state?halt=${halt}`);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { createApiClient } from "src/lib/oasst_client_factory";

const handler = withAnyRole(["admin", "moderator"], async (req, res, token) => {
const { id } = req.query;
const halt = req.body as boolean;
try {
const client = await createApiClient(token);
await client.stop_tree(id as string);
res.status(200).json({ message: `Tree ${id} stopped`, id });
await client.set_tree_halted(id as string, req.body as boolean);
res.status(200).json({ message: `Tree ${id} restarted`, id, halted: halt });
} catch (e) {
res.status(500).json(e);
}
Expand Down