Skip to content

Commit 12e420b

Browse files
authored
Fixed redirecting to schema using object help menu (#7427)
1 parent 4c8ce2b commit 12e420b

File tree

6 files changed

+18
-13
lines changed

6 files changed

+18
-13
lines changed

frontend/app/src/entities/nodes/object/ui/object-table/object-table-context.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ export const ObjectTableProvider = ({
3939

4040
React.useEffect(() => {
4141
if (!kindInQsp) return;
42+
if (window.location.pathname === "/schema") {
43+
// nuqs updates faster than React router QSP. If navigating to another route using "kind" QSP, it'll update it here 1st.
44+
return;
45+
}
4246
if (!isGenericSchema(schema) || !schema.used_by?.find((kind) => kind === kindInQsp)) {
4347
setObjectTableQueryParams({ kind: null });
4448
}

frontend/app/src/entities/schema/ui/schema-selector.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ type SchemaSelectorProps = {
2424
className?: string;
2525
};
2626
export const SchemaSelector = ({ className = "" }: SchemaSelectorProps) => {
27-
const [selectedKind, setKind] = useQueryState(
28-
QSP.KIND,
29-
parseAsNativeArrayOf(parseAsString).withDefault([])
30-
);
27+
const [selectedKind, setKind] = useQueryState(QSP.KIND, parseAsNativeArrayOf(parseAsString));
3128
const nodes = useAtomValue(nodeSchemasAtom);
3229
const generics = useAtomValue(genericSchemasAtom);
3330
const profiles = useAtomValue(profileSchemasAtom);

frontend/app/src/entities/schema/ui/schema-viewer.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ import { SchemaHelpMenu } from "./schema-help-menu";
2828
import { ModelDisplay, PropertyRow, TabPanelStyled, TabStyled } from "./styled";
2929

3030
export const SchemaViewerStack = ({ className = "" }: { className: string }) => {
31-
const [selectedKind, setKinds] = useQueryState(
32-
QSP.KIND,
33-
parseAsNativeArrayOf(parseAsString).withDefault([])
34-
);
31+
const [selectedKind, setKinds] = useQueryState(QSP.KIND, parseAsNativeArrayOf(parseAsString));
3532
const nodes = useAtomValue(nodeSchemasAtom);
3633
const generics = useAtomValue(genericSchemasAtom);
3734
const profiles = useAtomValue(profileSchemasAtom);

frontend/app/src/entities/schema/ui/styled.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,7 @@ export const TabPanelStyled = ({ className, ...props }: TabPanelProps) => {
146146
export const NullDisplay = () => <div className="text-gray-500 text-xs">null</div>;
147147

148148
export const ModelDisplay = ({ kinds }: { kinds?: string[] }) => {
149-
const [selectedKinds, setKinds] = useQueryState(
150-
QSP.KIND,
151-
parseAsNativeArrayOf(parseAsString).withDefault([])
152-
);
149+
const [selectedKinds, setKinds] = useQueryState(QSP.KIND, parseAsNativeArrayOf(parseAsString));
153150
if (!kinds) return null;
154151
if (kinds.length === 0) return <span>empty</span>;
155152

frontend/app/src/shared/components/menu/object-help-button.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Icon } from "@iconify-icon/react";
22
import { Pressable } from "react-aria-components";
33

44
import { INFRAHUB_DOC_LOCAL } from "@/config/config";
5+
import { QSP } from "@/config/qsp";
56

67
import { constructPath } from "@/shared/api/rest/fetch";
78
import {
@@ -50,7 +51,7 @@ export const ObjectHelpButton = ({ documentationUrl, kind, ...props }: ObjectHel
5051

5152
<MenuItem
5253
isDisabled={!kind}
53-
href={constructPath("/schema", [{ name: "kind", value: kind }])}
54+
href={constructPath("/schema", [{ name: QSP.KIND, value: kind }])}
5455
>
5556
<Icon icon="mdi:code-json" className="text-lg" />
5657
Schema

frontend/app/tests/e2e/schema.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ import { expect, test } from "@playwright/test";
33
import { saveScreenshotForDocs } from "../utils";
44

55
test.describe("/schema - Schema visualizer", () => {
6+
test("redirect to schema page using object help menu", async ({ page }) => {
7+
await page.goto("/objects/InfraInterface");
8+
await page.getByRole("button", { name: "?" }).click();
9+
await page.getByRole("menuitem", { name: "Schema" }).click();
10+
await expect(page.getByTestId("schema-viewer")).toBeVisible();
11+
await expect(page.getByText("KindInfraInterface")).toBeVisible();
12+
await expect(page).toHaveURL(/\/schema\?kind=InfraInterface/);
13+
});
14+
615
test("display help menu correctly", async ({ page }) => {
716
await page.goto("/schema");
817

0 commit comments

Comments
 (0)