/* Copyright 2024 New Vector Ltd. Copyright 2018-2023 The Matrix.org Foundation C.I.C. Copyright 2022 Michael Telatynski <7t3chguy@gmail.com> SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only Please see LICENSE files in the repository root for full details. */ import React, { useState } from "react"; import { _t, _td, TranslationKey } from "../../../languageHandler"; import MatrixClientContext from "../../../contexts/MatrixClientContext"; import BaseDialog from "./BaseDialog"; import { TimelineEventEditor } from "./devtools/Event"; import ServersInRoom from "./devtools/ServersInRoom"; import SettingExplorer from "./devtools/SettingExplorer"; import { RoomStateExplorer } from "./devtools/RoomState"; import BaseTool, { DevtoolsContext, IDevtoolsProps } from "./devtools/BaseTool"; import WidgetExplorer from "./devtools/WidgetExplorer"; import { AccountDataExplorer, RoomAccountDataExplorer } from "./devtools/AccountData"; import SettingsFlag from "../elements/SettingsFlag"; import { SettingLevel } from "../../../settings/SettingLevel"; import ServerInfo from "./devtools/ServerInfo"; import CopyableText from "../elements/CopyableText"; import RoomNotifications from "./devtools/RoomNotifications"; enum Category { Room, Other, } const categoryLabels: Record = { [Category.Room]: _td("devtools|category_room"), [Category.Other]: _td("devtools|category_other"), }; export type Tool = React.FC | ((props: IDevtoolsProps) => JSX.Element); const Tools: Record = { [Category.Room]: [ [_td("devtools|send_custom_timeline_event"), TimelineEventEditor], [_td("devtools|explore_room_state"), RoomStateExplorer], [_td("devtools|explore_room_account_data"), RoomAccountDataExplorer], [_td("devtools|view_servers_in_room"), ServersInRoom], [_td("devtools|notifications_debug"), RoomNotifications], [_td("devtools|active_widgets"), WidgetExplorer], ], [Category.Other]: [ [_td("devtools|explore_account_data"), AccountDataExplorer], [_td("devtools|settings_explorer"), SettingExplorer], [_td("devtools|server_info"), ServerInfo], ], }; interface IProps { roomId: string; threadRootId?: string | null; onFinished(finished?: boolean): void; } type ToolInfo = [label: TranslationKey, tool: Tool]; const DevtoolsDialog: React.FC = ({ roomId, threadRootId, onFinished }) => { const [tool, setTool] = useState(null); let body: JSX.Element; let onBack: () => void; if (tool) { onBack = () => { setTool(null); }; const Tool = tool[1]; body = setTool([label, tool])} />; } else { const onBack = (): void => { onFinished(false); }; body = ( {Object.entries(Tools).map(([category, tools]) => (

{_t(categoryLabels[category as unknown as Category])}

{tools.map(([label, tool]) => { const onClick = (): void => { setTool([label, tool]); }; return ( ); })}
))}

{_t("common|options")}

); } const label = tool ? _t(tool[0]) : _t("devtools|toolbox"); return ( {(cli) => ( <>
{label}
roomId} border={false}> {_t("devtools|room_id", { roomId })} {!threadRootId ? null : ( threadRootId} border={false} > {_t("devtools|thread_root_id", { threadRootId })} )}
{cli.getRoom(roomId) && ( {body} )} )} ); }; export default DevtoolsDialog;