Skip to content

Commit 3306c80

Browse files
NicolappsConvex, Inc.
authored andcommitted
Fix documentHref to use object arg + use component ID (#40819)
GitOrigin-RevId: 9c5c1b5197b2ee29a1774aefae87e7c2e6f9a11e
1 parent 594f517 commit 3306c80

File tree

4 files changed

+32
-17
lines changed

4 files changed

+32
-17
lines changed

npm-packages/dashboard-common/src/elements/ObjectEditor/useIdDecorations.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
} from "@common/lib/utils";
1818
import { useNents } from "@common/lib/useNents";
1919
import { LiteralNode } from "@common/elements/ObjectEditor/ast/types";
20+
import url from "url";
2021

2122
const MAX_IDS_TO_DECORATE = 100;
2223

@@ -302,10 +303,13 @@ export function registerIdCommands(
302303
componentId: string | null;
303304
},
304305
) => {
305-
const href = documentHref(deploymentsURI, args.tableName, args.id);
306-
const query = `${href.query.component ? `component=${href.query.component}&` : ""}table=${href.query.table}&filters=${href.query.filters}`;
307-
const url = `${deploymentsURI}/data?${query}`;
308-
window.open(`${window.location.origin}${url}`, "_blank");
306+
const href = documentHref({
307+
deploymentsURI,
308+
tableName: args.tableName,
309+
id: args.id,
310+
componentId: args.componentId,
311+
});
312+
window.open(url.format(href), "_blank");
309313
},
310314
);
311315

npm-packages/dashboard-common/src/features/data/components/Table/DataCell/utils/useIdReferenceLink.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import { DeploymentInfoContext } from "@common/lib/deploymentContext";
1010
export function useIdReferenceLink(value: Value, columnName: string) {
1111
const stringValue = typeof value === "string" ? value : stringifyValue(value);
1212

13+
const componentId = useNents().selectedNent?.id ?? null;
1314
const tableMapping = useQuery(udfs.getTableMapping.default, {
14-
componentId: useNents().selectedNent?.id ?? null,
15+
componentId,
1516
});
1617
const referencedTableName = getReferencedTableName(tableMapping, value);
1718
const isReference = referencedTableName !== null;
@@ -24,7 +25,12 @@ export function useIdReferenceLink(value: Value, columnName: string) {
2425

2526
const link =
2627
isReference && referencedTableName
27-
? documentHref(deploymentsURI, referencedTableName, stringValue)
28+
? documentHref({
29+
deploymentsURI,
30+
tableName: referencedTableName,
31+
id: stringValue,
32+
componentId,
33+
})
2834
: undefined;
2935

3036
return link;

npm-packages/dashboard-common/src/lib/utils.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,17 @@ export function getReferencedTableName(
8080
return tableMapping[tableNumber] ?? null;
8181
}
8282

83-
export function documentHref(
84-
deploymentsURI: string,
85-
tableName: string,
86-
id: string,
87-
componentId?: string,
88-
): {
83+
export function documentHref({
84+
deploymentsURI,
85+
tableName,
86+
id,
87+
componentId,
88+
}: {
89+
deploymentsURI: string;
90+
tableName: string;
91+
id: string;
92+
componentId: string | null;
93+
}): {
8994
pathname: string;
9095
query: { [key: string]: string };
9196
} {

npm-packages/dashboard/src/components/health/EventsForInsight.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -548,12 +548,12 @@ function EventOccDocumentId({
548548
<div className="flex w-[16rem]">
549549
{event.occDocumentId && insight.details.occTableName ? (
550550
<Link
551-
href={documentHref(
551+
href={documentHref({
552552
deploymentsURI,
553-
insight.details.occTableName,
554-
event.occDocumentId,
555-
componentId || undefined,
556-
)}
553+
tableName: insight.details.occTableName,
554+
id: event.occDocumentId,
555+
componentId: componentId ?? null,
556+
})}
557557
target="_blank"
558558
className="flex items-center gap-1 text-content-link hover:underline"
559559
>

0 commit comments

Comments
 (0)