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

feat: tabs bidirectional sync with the url query #437

Merged
merged 4 commits into from
Dec 12, 2024
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: 1 addition & 1 deletion frontend/src/app-components/widget/ChatWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const ChatWidget = () => {
const pathname = usePathname();
const { apiUrl } = useConfig();
const { isAuthenticated } = useAuth();
const isVisualEditor = pathname === `/${RouterType.VISUAL_EDITOR}`;
const isVisualEditor = pathname.startsWith(`/${RouterType.VISUAL_EDITOR}`);
const allowedDomainsSetting = useSetting(SETTING_TYPE, "allowed_domains");
const themeColorSetting = useSetting(SETTING_TYPE, "theme_color");
const [key, setKey] = useState(generateId());
Expand Down
18 changes: 16 additions & 2 deletions frontend/src/components/settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
Tab,
Tabs,
} from "@mui/material";
import { useRouter } from "next/router";
import { useCallback, useEffect, useMemo, useState } from "react";
import { Controller, useForm } from "react-hook-form";

Expand All @@ -25,7 +26,7 @@ import { useUpdate } from "@/hooks/crud/useUpdate";
import { useToast } from "@/hooks/useToast";
import { useTranslate } from "@/hooks/useTranslate";
import { PageHeader } from "@/layout/content/PageHeader";
import { EntityType } from "@/services/types";
import { EntityType, RouterType } from "@/services/types";
import { ISetting } from "@/types/setting.types";
import { SXStyleOptions } from "@/utils/SXStyleOptions";

Expand Down Expand Up @@ -66,10 +67,16 @@ function groupBy(array: ISetting[]) {
}, {} as Record<string, ISetting[]>);
}

const DEFAULT_SETTINGS_GROUP = "chatbot_settings" as const;

export const Settings = () => {
const { t } = useTranslate();
const router = useRouter();
const group = router.query.group?.toString();
const { toast } = useToast();
const [selectedTab, setSelectedTab] = useState("chatbot_settings");
const [selectedTab, setSelectedTab] = useState(
group || DEFAULT_SETTINGS_GROUP,
);
const { control, watch } = useForm();
const { data: settings } = useFind(
{ entity: EntityType.SETTING },
Expand All @@ -94,6 +101,7 @@ export const Settings = () => {
};
const handleChange = (_event: React.SyntheticEvent, newValue: string) => {
setSelectedTab(newValue);
router.push(`/${RouterType.SETTINGS}/groups/${newValue}`);
};
const isDisabled = (setting: ISetting) => {
return (
Expand Down Expand Up @@ -135,6 +143,12 @@ export const Settings = () => {
};
}, [watch, debouncedUpdate]);

useEffect(() => {
setSelectedTab(group || DEFAULT_SETTINGS_GROUP);

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [group]);

return (
<Grid container gap={3} flexDirection="column">
<PageHeader icon={faCogs} title={t("title.settings")} />
Expand Down
17 changes: 15 additions & 2 deletions frontend/src/components/visual-editor/v2/Diagrams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
DiagramModel,
DiagramModelGenerics,
} from "@projectstorm/react-diagrams";
import { useRouter } from "next/router";
import {
SyntheticEvent,
useCallback,
Expand All @@ -52,7 +53,7 @@ import useDebouncedUpdate from "@/hooks/useDebouncedUpdate";
import { getDisplayDialogs, useDialog } from "@/hooks/useDialog";
import { useSearch } from "@/hooks/useSearch";
import { useTranslate } from "@/hooks/useTranslate";
import { EntityType, Format, QueryType } from "@/services/types";
import { EntityType, Format, QueryType, RouterType } from "@/services/types";
import { IBlock } from "@/types/block.types";
import { ICategory } from "@/types/category.types";
import { BlockPorts } from "@/types/visual-editor.types";
Expand All @@ -65,6 +66,8 @@ import { AdvancedLinkModel } from "./AdvancedLink/AdvancedLinkModel";

const Diagrams = () => {
const { t } = useTranslate();
const router = useRouter();
const flowId = router.query.id?.toString();
const [model, setModel] = useState<
DiagramModel<DiagramModelGenerics> | undefined
>();
Expand Down Expand Up @@ -95,7 +98,9 @@ const Diagrams = () => {
},
{
onSuccess([{ id, zoom, offset }]) {
if (id) {
if (flowId) {
setSelectedCategoryId?.(flowId);
} else if (id) {
setSelectedCategoryId?.(id);
if (engine?.getModel()) {
setViewerOffset(offset || [0, 0]);
Expand Down Expand Up @@ -161,6 +166,8 @@ const Diagrams = () => {
if (id) {
setSelectedCategoryId?.(id);
setSelectedBlockId(undefined); // Reset selected block when switching categories, resetting edit & remove buttons

router.push(`/${RouterType.VISUAL_EDITOR}/flows/${id}`);
}
}
};
Expand All @@ -181,6 +188,12 @@ const Diagrams = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
setSelectedCategoryId(flowId || "");

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [flowId]);

useEffect(() => {
const { canvas, model, engine } = buildDiagram({
zoom: currentCategory?.zoom || 100,
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/pages/settings/groups/[group]/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/

import SettingsPage from "../..";

export default SettingsPage;
11 changes: 11 additions & 0 deletions frontend/src/pages/settings/groups/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/

import SettingsPage from "..";

export default SettingsPage;
File renamed without changes.
11 changes: 11 additions & 0 deletions frontend/src/pages/visual-editor/flows/[id]/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/

import VisualEditorPage from "../..";

export default VisualEditorPage;
11 changes: 11 additions & 0 deletions frontend/src/pages/visual-editor/flows/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/

import VisualEditorPage from "..";

export default VisualEditorPage;
1 change: 1 addition & 0 deletions frontend/src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export enum RouterType {
RESET = "reset",
VISUAL_EDITOR = "visual-editor",
INBOX = "inbox",
SETTINGS = "settings",
}

export const FULL_WIDTH_PATHNAMES: TRouterValues[] = [
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/utils/laylout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/

import { FULL_WIDTH_PATHNAMES, TRouterValues } from "@/services/types";
import { FULL_WIDTH_PATHNAMES } from "@/services/types";

type TLayout = "default" | "full_width";

export const getLayout = (pathname: string): TLayout =>
FULL_WIDTH_PATHNAMES.includes(pathname as TRouterValues)
FULL_WIDTH_PATHNAMES.some((path) => pathname.startsWith(path))
? "full_width"
: "default";
Loading