Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

refactor(pam): extract getColumnIndicator into shared data-explorer-types

Bernie Gandin1d62b42cfa0c
diff --git a/frontend/src/pages/pam/PamDataExplorerPage/components/DataExplorerGrid.tsx b/frontend/src/pages/pam/PamDataExplorerPage/components/DataExplorerGrid.tsx
index a6f9b8bfb5..ee024ed5c0 100644
--- a/frontend/src/pages/pam/PamDataExplorerPage/components/DataExplorerGrid.tsx
+++ b/frontend/src/pages/pam/PamDataExplorerPage/components/DataExplorerGrid.tsx
@@ -11,6 +11,7 @@ import { DataGrid, useDataGrid } from "@app/components/v3/generic/DataGrid";
import { Skeleton } from "@app/components/v3/generic/Skeleton";
import type { ColumnInfo, FieldInfo, ForeignKeyInfo, TableDetail } from "../data-explorer-types";
+import { getColumnIndicator } from "../data-explorer-types";
import type { FilterCondition, SortCondition } from "../sql-generation";
import {
buildCountQuery,
@@ -117,23 +118,6 @@ const SELECT_COLUMN: ColumnDef<RowData> = {
enableResizing: false
};
-function getColumnIndicator(
- colName: string,
- primaryKeys: string[],
- fkMap: Map<string, ForeignKeyInfo>
-): { type: "pk" | "fk"; tooltip?: string } | undefined {
- if (primaryKeys.includes(colName)) return { type: "pk" };
- const fk = fkMap.get(colName);
- if (fk) {
- const targetCol = fk.targetColumns[fk.columns.indexOf(colName)] ?? fk.targetColumns[0];
- return {
- type: "fk",
- tooltip: `\u2192 ${fk.targetSchema}.${fk.targetTable}(${targetCol})`
- };
- }
- return undefined;
-}
-
function buildColumnDefs(
cols: ColumnInfo[],
primaryKeys: string[],
diff --git a/frontend/src/pages/pam/PamDataExplorerPage/components/QueryResultsTable.tsx b/frontend/src/pages/pam/PamDataExplorerPage/components/QueryResultsTable.tsx
index 33b6ce35b0..158bce5007 100644
--- a/frontend/src/pages/pam/PamDataExplorerPage/components/QueryResultsTable.tsx
+++ b/frontend/src/pages/pam/PamDataExplorerPage/components/QueryResultsTable.tsx
@@ -5,6 +5,7 @@ import { Spinner } from "@app/components/v2";
import { DataGrid, useDataGrid } from "@app/components/v3/generic/DataGrid";
import type { FieldInfo, ForeignKeyInfo, TableDetail } from "../data-explorer-types";
+import { getColumnIndicator } from "../data-explorer-types";
const MAX_ROWS = 500;
@@ -25,20 +26,6 @@ type Props = {
type RowData = Record<string, unknown>;
-function getColumnIndicator(
- name: string,
- primaryKeys: string[],
- fkMap: Map<string, ForeignKeyInfo>
-): { type: "pk" | "fk"; tooltip?: string } | undefined {
- if (primaryKeys.includes(name)) return { type: "pk" };
- const fk = fkMap.get(name);
- if (fk) {
- const targetCol = fk.targetColumns[fk.columns.indexOf(name)] ?? fk.targetColumns[0];
- return { type: "fk", tooltip: `\u2192 ${fk.targetSchema}.${fk.targetTable}(${targetCol})` };
- }
- return undefined;
-}
-
function buildColumns(fields: FieldInfo[], tableDetail: TableDetail | null): ColumnDef<RowData>[] {
const colTypeMap = new Map<string, string>();
const primaryKeys: string[] = [];
@@ -86,7 +73,10 @@ function ResultsGrid({
const displayRows = useMemo(() => result.rows.slice(0, MAX_ROWS), [result.rows]);
const isTruncated = result.rows.length >= MAX_ROWS;
- const columns = useMemo(() => buildColumns(result.fields, tableDetail), [result.fields, tableDetail]);
+ const columns = useMemo(
+ () => buildColumns(result.fields, tableDetail),
+ [result.fields, tableDetail]
+ );
const getRowId = useCallback((_row: RowData, index: number) => String(index), []);
@@ -143,7 +133,11 @@ export function QueryResultsTable({ result, error, isRunning, tableDetail }: Pro
if (result.rows.length === 0) {
const cmdUpper = result.command.toUpperCase();
const count = result.rowCount ?? 0;
- const verb: Record<string, string> = { INSERT: "inserted", UPDATE: "updated", DELETE: "deleted" };
+ const verb: Record<string, string> = {
+ INSERT: "inserted",
+ UPDATE: "updated",
+ DELETE: "deleted"
+ };
const message = verb[cmdUpper]
? `${count} row${count !== 1 ? "s" : ""} ${verb[cmdUpper]}`
diff --git a/frontend/src/pages/pam/PamDataExplorerPage/data-explorer-types.ts b/frontend/src/pages/pam/PamDataExplorerPage/data-explorer-types.ts
index 435da716ec..5b0a6f4b39 100644
--- a/frontend/src/pages/pam/PamDataExplorerPage/data-explorer-types.ts
+++ b/frontend/src/pages/pam/PamDataExplorerPage/data-explorer-types.ts
@@ -57,3 +57,17 @@ export type TableDetail = {
export type FieldInfo = {
name: string;
};
+
+export function getColumnIndicator(
+ colName: string,
+ primaryKeys: string[],
+ fkMap: Map<string, ForeignKeyInfo>
+): { type: "pk" | "fk"; tooltip?: string } | undefined {
+ if (primaryKeys.includes(colName)) return { type: "pk" };
+ const fk = fkMap.get(colName);
+ if (fk) {
+ const targetCol = fk.targetColumns[fk.columns.indexOf(colName)] ?? fk.targetColumns[0];
+ return { type: "fk", tooltip: `\u2192 ${fk.targetSchema}.${fk.targetTable}(${targetCol})` };
+ }
+ return undefined;
+}