Skip to content

Commit a53c15a

Browse files
committed
Add highlighted classes for tables and columns based on a URL param
1 parent ce2c26d commit a53c15a

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/Visualizer/components/TableNode.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useState, FC, useEffect } from "react";
22
import { Handle, Position, NodeProps } from "reactflow";
33
import { KeyIcon } from "../components";
44
import { markdown } from "../helpers";
5+
import { isTableHighlighted, isColumnHighlighted } from "../helpers/tableHighlights";
56

67
import "@reactflow/node-resizer/dist/style.css";
78

@@ -24,8 +25,23 @@ export const TableNode: FC<NodeProps> = ({ data }) => {
2425
}, false);
2526
}, []);
2627

28+
const columnClass = ({ selectedColumn, columnName }: { selectedColumn: string, columnName: string }) => {
29+
const classes = ["column-name"]
30+
31+
if (selectedColumn === columnName) {
32+
classes.push("column-name--selected")
33+
}
34+
35+
if (isColumnHighlighted({ schema: data.schema, tableName: data.name, columnName })) {
36+
classes.push("column-name--highlighted")
37+
}
38+
39+
return classes.join(" ")
40+
}
41+
2742
return (
28-
<div className="table">
43+
<div
44+
className={`table ${isTableHighlighted({ schema: data.schema, tableName: data.name }) ? 'table--highlighted' : ''}`}>
2945
<div
3046
style={{ backgroundColor: data.schemaColor }}
3147
className="table__name"
@@ -46,7 +62,7 @@ export const TableNode: FC<NodeProps> = ({ data }) => {
4662
{data.columns.map((column: any, index: any) => (
4763
<div
4864
key={index}
49-
className={selectedColumn === column.name ? "column-name column-name--selected" : "column-name"}
65+
className={columnClass({ selectedColumn, columnName: column.name })}
5066
onMouseEnter={() => {
5167
if(descriptionOnHoverActive) {
5268
setSelectedColumn(column.name)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const currentUrl = new URL(window.location.href)
2+
const urlParams = currentUrl.searchParams
3+
const highlights = (urlParams.get("highlights") || "").split(";").reduce((acc: { [key: string]: string[] }, section: string) => {
4+
const [tableName, fields] = section.split(":");
5+
6+
if (tableName && fields) {
7+
acc[tableName] = fields.split(",");
8+
}
9+
10+
return acc;
11+
}, {} as { [key: string]: string[] });
12+
13+
export const isTableHighlighted = ({ schema, tableName }: { schema: string | undefined, tableName: string }) => {
14+
const fullTableName = schema ? `${schema}.${tableName}` : tableName
15+
16+
return highlights.hasOwnProperty(fullTableName);
17+
}
18+
19+
export const isColumnHighlighted = ({ schema, tableName, columnName }: { schema: string | undefined, tableName: string, columnName: string }) => {
20+
const fullTableName = schema ? `${schema}.${tableName}` : tableName
21+
22+
return highlights[fullTableName]?.includes(columnName);
23+
}

0 commit comments

Comments
 (0)