Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

refactor(react): optimize code and ux (#20128)

ecmadaoad2626f70f29
diff --git a/frontend/src/components/v2/Model/PagedProjectTable.vue b/frontend/src/components/v2/Model/PagedProjectTable.vue
deleted file mode 100644
index 4c4aef2b5a..0000000000
--- a/frontend/src/components/v2/Model/PagedProjectTable.vue
+++ /dev/null
@@ -1,96 +0,0 @@
-<template>
- <PagedTable
- ref="projectPagedTable"
- :session-key="sessionKey"
- :fetch-list="fetchProjects"
- :order-keys="['title']"
- >
- <template #table="{ list, loading, sorters, onSortersUpdate }">
- <ProjectV1Table
- v-bind="$attrs"
- :loading="loading"
- :project-list="list"
- :selected-project-names="selectedProjectNames"
- :show-selection="showSelection"
- :show-labels="showLabels"
- :show-actions="showActions"
- :keyword="filter.query"
- :sorters="sorters"
- @update:selected-project-names="updateSelectedProjectNames"
- @update:sorters="onSortersUpdate"
- />
- </template>
- </PagedTable>
-</template>
-
-<script lang="tsx" setup>
-import { ref, watch } from "vue";
-import type { ComponentExposed } from "vue-component-type-helpers";
-import PagedTable from "@/components/v2/Model/PagedTable.vue";
-import { type ProjectFilter, useProjectV1Store } from "@/store";
-import type { Project } from "@/types/proto-es/v1/project_service_pb";
-import ProjectV1Table from "./ProjectV1Table.vue";
-
-const props = withDefaults(
- defineProps<{
- filter: ProjectFilter;
- sessionKey: string;
- selectedProjectNames?: string[];
- showSelection?: boolean;
- showLabels?: boolean;
- showActions?: boolean;
- }>(),
- {
- selectedProjectNames: () => [],
- showSelection: false,
- showLabels: true,
- showActions: false,
- }
-);
-
-const emit = defineEmits<{
- (event: "update:selected-project-names", projectNames: string[]): void;
-}>();
-
-const projectStore = useProjectV1Store();
-
-const projectPagedTable = ref<ComponentExposed<typeof PagedTable<Project>>>();
-
-const updateSelectedProjectNames = (projectNames: string[]) => {
- emit("update:selected-project-names", projectNames);
-};
-
-const refresh = () => {
- projectPagedTable.value?.refresh();
-};
-
-defineExpose({ refresh });
-
-const fetchProjects = async ({
- pageToken,
- pageSize,
- orderBy,
-}: {
- pageToken: string;
- pageSize: number;
- orderBy?: string;
-}) => {
- const { nextPageToken, projects } = await projectStore.fetchProjectList({
- pageToken,
- pageSize,
- filter: props.filter,
- orderBy,
- cache: true,
- });
- return {
- nextPageToken: nextPageToken ?? "",
- list: projects,
- };
-};
-
-watch(
- () => props.filter,
- () => projectPagedTable.value?.refresh(),
- { deep: true }
-);
-</script>
diff --git a/frontend/src/components/v2/Model/ProjectV1Table.vue b/frontend/src/components/v2/Model/ProjectV1Table.vue
deleted file mode 100644
index c1bad4f9c2..0000000000
--- a/frontend/src/components/v2/Model/ProjectV1Table.vue
+++ /dev/null
@@ -1,238 +0,0 @@
-<template>
- <div ref="tableRef">
- <NDataTable
- key="project-table"
- size="small"
- v-bind="$attrs"
- :columns="columnList"
- :data="projectList"
- :striped="true"
- :bordered="bordered"
- :loading="loading"
- :scroll-x="scrollX"
- :row-key="(data: Project) => data.name"
- :checked-row-keys="shouldShowSelection ? selectedProjectNames : undefined"
- :row-props="rowProps"
- :paginate-single-page="false"
- @update:checked-row-keys="updateSelectedProjects"
- @update:sorter="$emit('update:sorters', $event)"
- />
- </div>
-</template>
-
-<script lang="tsx" setup>
-import { useElementSize } from "@vueuse/core";
-import { CheckIcon } from "lucide-vue-next";
-import {
- type DataTableColumn,
- type DataTableSortState,
- NDataTable,
-} from "naive-ui";
-import { computed, ref } from "vue";
-import { useI18n } from "vue-i18n";
-import { useRouter } from "vue-router";
-import ProjectActionDropdown from "@/components/Project/ProjectActionDropdown.vue";
-import { LabelsCell, ProjectNameCell } from "@/components/v2/Model/cells";
-import { PROJECT_V1_ROUTE_DETAIL } from "@/router/dashboard/projectV1";
-import { PROJECT_V1_ROUTE_DASHBOARD } from "@/router/dashboard/workspaceRoutes";
-import { getProjectName } from "@/store/modules/v1/common";
-import type { Project } from "@/types/proto-es/v1/project_service_pb";
-import {
- extractProjectResourceName,
- hasWorkspacePermissionV2,
- TailwindBreakpoints,
-} from "@/utils";
-import HighlightLabelText from "./HighlightLabelText.vue";
-import { mapSorterStatus } from "./utils";
-
-type ProjectDataTableColumn = DataTableColumn<Project> & {
- hide?: boolean;
-};
-
-const props = withDefaults(
- defineProps<{
- projectList: Project[];
- currentProject?: Project;
- bordered?: boolean;
- loading?: boolean;
- keyword?: string;
- // If true, the default behavior of the row click event will be prevented.
- preventDefault?: boolean;
- // Selected project names for batch operations
- selectedProjectNames?: string[];
- // Whether to show selection checkboxes
- showSelection?: boolean;
- // Whether to show labels column (hidden in dropdowns for cleaner UI)
- showLabels?: boolean;
- // Whether to show actions dropdown
- showActions?: boolean;
- sorters?: DataTableSortState[];
- }>(),
- {
- bordered: true,
- currentProject: undefined,
- keyword: undefined,
- selectedProjectNames: () => [],
- showSelection: false,
- showLabels: true,
- showActions: false,
- }
-);
-
-const emit = defineEmits<{
- (event: "row-click", project: Project): void;
- (event: "update:selected-project-names", projectNames: string[]): void;
- (event: "update:sorters", sorters: DataTableSortState[]): void;
-}>();
-
-const { t } = useI18n();
-const router = useRouter();
-const tableRef = ref<HTMLDivElement>();
-const { width: tableWidth } = useElementSize(tableRef);
-const showExtendedColumns = computed(
- () => tableWidth.value > TailwindBreakpoints.md
-);
-
-const hasDeletePermission = computed(() =>
- hasWorkspacePermissionV2("bb.projects.delete")
-);
-
-const shouldShowSelection = computed(
- () => props.showSelection && hasDeletePermission.value
-);
-
-const updateSelectedProjects = (checkedRowKeys: (string | number)[]) => {
- emit("update:selected-project-names", checkedRowKeys as string[]);
-};
-
-const columnList = computed((): ProjectDataTableColumn[] => {
- const columns: ProjectDataTableColumn[] = (
- [
- {
- key: "selection",
- type: shouldShowSelection.value ? "selection" : undefined,
- width: !shouldShowSelection.value ? 32 : 48,
- hide: !shouldShowSelection.value && !props.currentProject,
- disabled: shouldShowSelection.value
- ? (project: Project) => {
- // Disable selection for default project
- return extractProjectResourceName(project.name) === "default";
- }
- : undefined,
- cellProps: shouldShowSelection.value
- ? () => {
- return {
- onClick: (e: MouseEvent) => {
- e.stopPropagation();
- },
- };
- }
- : undefined,
- render: shouldShowSelection.value
- ? undefined
- : (project) => {
- return (
- props.currentProject?.name === project.name && (
- <CheckIcon class="w-4 text-accent" />
- )
- );
- },
- },
- {
- key: "id",
- title: t("common.id"),
- minWidth: 128,
- resizable: true,
- ellipsis: {
- tooltip: true,
- },
- render: (project) => {
- return (
- <HighlightLabelText
- text={extractProjectResourceName(project.name)}
- keyword={props.keyword ?? ""}
- />
- );
- },
- },
- {
- key: "title",
- resizable: true,
- minWidth: 200,
- title: t("project.table.name"),
- render: (project) => (
- <ProjectNameCell project={project} keyword={props.keyword} />
- ),
- },
- {
- key: "labels",
- title: t("common.labels"),
- resizable: true,
- minWidth: 240,
- hide: !props.showLabels || !showExtendedColumns.value,
- render: (project) => (
- <LabelsCell labels={project.labels} showCount={3} placeholder="-" />
- ),
- },
- {
- key: "actions",
- title: "",
- width: 50,
- hide: !props.showActions,
- render: (project) => (
- <div
- class="flex justify-end"
- onClick={(e: MouseEvent) => {
- e.stopPropagation();
- }}
- >
- <ProjectActionDropdown project={project} />
- </div>
- ),
- },
- ] as ProjectDataTableColumn[]
- ).filter((column) => !column.hide);
- return mapSorterStatus(columns, props.sorters);
-});
-
-const scrollX = computed(() => {
- return columnList.value.reduce((sum, col) => {
- return (
- sum +
- ((col as { width?: number; minWidth?: number }).width ??
- (col as { minWidth?: number }).minWidth ??
- 100)
- );
- }, 0);
-});
-
-const rowProps = (project: Project) => {
- return {
- style: "cursor: pointer;",
- onClick: (e: MouseEvent) => {
- if (!props.preventDefault) {
- const currentRouteName = router.currentRoute.value.name?.toString();
- let routeName = PROJECT_V1_ROUTE_DETAIL;
-
- if (currentRouteName?.startsWith(PROJECT_V1_ROUTE_DASHBOARD)) {
- routeName = PROJECT_V1_ROUTE_DETAIL;
- }
-
- const route = router.resolve({
- name: routeName,
- params: {
- projectId: getProjectName(project.name),
- },
- });
- if (e.ctrlKey || e.metaKey) {
- window.open(route.fullPath, "_blank");
- } else {
- router.push(route);
- }
- }
-
- emit("row-click", project);
- },
- };
-};
-</script>
diff --git a/frontend/src/components/v2/Model/index.ts b/frontend/src/components/v2/Model/index.ts
index 53ff723f6c..b7637d98c2 100644
--- a/frontend/src/components/v2/Model/index.ts
+++ b/frontend/src/components/v2/Model/index.ts
@@ -3,10 +3,8 @@ import DatabaseView from "./DatabaseView.vue";
import EnvironmentV1Name from "./EnvironmentV1Name.vue";
import HighlightLabelText from "./HighlightLabelText.vue";
import RichEngineName from "./Instance/RichEngineName.vue";
-import PagedProjectTable from "./PagedProjectTable.vue";
import ProductionEnvironmentV1Icon from "./ProductionEnvironmentV1Icon.vue";
import ProjectV1Name from "./ProjectV1Name.vue";
-import ProjectV1Table from "./ProjectV1Table.vue";
import RichDatabaseName from "./RichDatabaseName.vue";
export * from "./Instance";
@@ -18,8 +16,6 @@ export {
EnvironmentV1Name,
ProductionEnvironmentV1Icon,
ProjectV1Name,
- ProjectV1Table,
- PagedProjectTable,
DatabaseView,
RichEngineName,
HighlightLabelText,
diff --git a/frontend/src/react/components/HighlightLabelText.tsx b/frontend/src/react/components/HighlightLabelText.tsx
index aca8a708b1..ca5826d2c7 100644
--- a/frontend/src/react/components/HighlightLabelText.tsx
+++ b/frontend/src/react/components/HighlightLabelText.tsx
@@ -2,7 +2,7 @@ import { getHighlightHTMLByRegExp } from "@/utils/util";
interface HighlightLabelTextProps {
text: string;
- keyword?: string;
+ keyword?: string | readonly string[];
className?: string;
}
@@ -11,8 +11,13 @@ export function HighlightLabelText({
keyword,
className,
}: HighlightLabelTextProps) {
- const trimmed = keyword?.trim() ?? "";
- if (!trimmed) {
+ const pattern: string | string[] =
+ typeof keyword === "string"
+ ? keyword.trim()
+ : (keyword ?? []).map((k) => k.trim()).filter(Boolean);
+ const isEmpty =
+ typeof pattern === "string" ? pattern === "" : pattern.length === 0;
+ if (isEmpty) {
return <span className={className}>{text}</span>;
}
return (
@@ -21,7 +26,7 @@ export function HighlightLabelText({
// getHighlightHTMLByRegExp escapes the input and sanitizes with
// DOMPurify, so the returned string is safe to inject.
dangerouslySetInnerHTML={{
- __html: getHighlightHTMLByRegExp(text, trimmed),
+ __html: getHighlightHTMLByRegExp(text, pattern),
}}
/>
);
diff --git a/frontend/src/react/components/IssueTable.tsx b/frontend/src/react/components/IssueTable.tsx
index 5916354c24..970ff1407e 100644
--- a/frontend/src/react/components/IssueTable.tsx
+++ b/frontend/src/react/components/IssueTable.tsx
@@ -9,6 +9,7 @@ import {
type SearchParams,
type ValueOption,
} from "@/react/components/AdvancedSearch";
+import { HighlightLabelText } from "@/react/components/HighlightLabelText";
import { HumanizeTs } from "@/react/components/HumanizeTs";
import { TimeRangePicker } from "@/react/components/TimeRangePicker";
import { Button } from "@/react/components/ui/button";
@@ -54,7 +55,6 @@ import {
extractIssueUID,
extractProjectResourceName,
getDefaultPagination,
- getHighlightHTMLByRegExp,
getIssueRoute,
getValueFromSearchParams,
getValuesFromSearchParams,
@@ -616,28 +616,6 @@ export function IssueListItem({
[highlightText]
);
- const highlightedTitle = useMemo(
- () =>
- getHighlightHTMLByRegExp(
- issue.title,
- highlightWords,
- false,
- "bg-yellow-100"
- ),
- [issue.title, highlightWords]
- );
-
- const highlightedDescription = useMemo(
- () =>
- getHighlightHTMLByRegExp(
- issue.description,
- highlightWords,
- false,
- "bg-yellow-100"
- ),
- [issue.description, highlightWords]
- );
-
const expanded =
highlightText &&
issue.description &&
@@ -672,8 +650,12 @@ export function IssueListItem({
href={issueUrl}
className="font-medium text-main text-base truncate hover:underline"
onClick={(e) => e.stopPropagation()}
- dangerouslySetInnerHTML={{ __html: highlightedTitle }}
- />
+ >
+ <HighlightLabelText
+ text={issue.title}
+ keyword={highlightWords}
+ />
+ </a>
) : (
<a
href={issueUrl}
@@ -742,10 +724,12 @@ export function IssueListItem({
)}
</div>
{expanded && (
- <div
- className="mt-2 max-h-80 overflow-auto whitespace-pre-wrap break-all text-sm text-control-light"
- dangerouslySetInnerHTML={{ __html: highlightedDescription }}
- />
+ <div className="mt-2 max-h-80 overflow-auto whitespace-pre-wrap break-all text-sm text-control-light">
+ <HighlightLabelText
+ text={issue.description}
+ keyword={highlightWords}
+ />
+ </div>
)}
</div>
diff --git a/frontend/src/react/components/ProjectTable.tsx b/frontend/src/react/components/ProjectTable.tsx
new file mode 100644
index 0000000000..1e2764753b
--- /dev/null
+++ b/frontend/src/react/components/ProjectTable.tsx
@@ -0,0 +1,351 @@
+import { Check, ChevronDown } from "lucide-react";
+import type { MouseEvent as ReactMouseEvent, ReactNode } from "react";
+import { useTranslation } from "react-i18next";
+import { HighlightLabelText } from "@/react/components/HighlightLabelText";
+import { Badge } from "@/react/components/ui/badge";
+import { Tooltip } from "@/react/components/ui/tooltip";
+import { getProjectName } from "@/react/lib/resourceName";
+import { cn } from "@/react/lib/utils";
+import { State } from "@/types/proto-es/v1/common_pb";
+import type { Project } from "@/types/proto-es/v1/project_service_pb";
+
+const DEFAULT_LABELS_PLACEHOLDER = "-";
+const DEFAULT_LABELS_PREVIEW = 3;
+
+export type ProjectTableSortKey = "title";
+export type ProjectTableSortDirection = "asc" | "desc";
+
+type RenderActions = (project: Project) => ReactNode;
+
+export interface ProjectTableProps {
+ /** Rows to render. */
+ readonly projectList: readonly Project[];
+ /**
+ * When set, the row whose `name` matches gets a leading check icon
+ * (mirrors Vue's `:current-project` mode used in the project switcher).
+ */
+ readonly currentProject?: Project;
+ /** Highlight keyword for the id and title cells. */
+ readonly keyword?: string;
+ /**
+ * Show the loading spinner row instead of `emptyContent` when there
+ * are no projects. Mirrors NDataTable's `:loading` prop.
+ */
+ readonly loading?: boolean;
+ /**
+ * Custom empty-state node. Defaults to a "No data" placeholder.
+ */
+ readonly emptyContent?: ReactNode;
+ /** Mirrors Vue's `:show-selection`. Adds a leading checkbox column. */
+ readonly showSelection?: boolean;
+ /** Mirrors Vue's `:show-labels`. Defaults to true. */
+ readonly showLabels?: boolean;
+ /**
+ * Mirrors Vue's `:show-actions`. When set, the trailing column renders
+ * `renderActions(project)` (typically the project action dropdown).
+ */
+ readonly showActions?: boolean;
+ readonly renderActions?: RenderActions;
+ /** Currently-checked rows (selection mode). */
+ readonly selectedProjectNames?: readonly string[];
+ /** Selection-change callback. */
+ readonly onSelectedChange?: (names: string[]) => void;
+ /** Sortable title column — when active, the header shows the indicator. */
+ readonly sortKey?: string | null;
+ readonly sortOrder?: ProjectTableSortDirection;
+ readonly onSortChange?: (key: ProjectTableSortKey) => void;
+ /**
+ * Click handler. Receives the original event so callers can detect
+ * `ctrl`/`meta` modifiers for "open in new tab".
+ */
+ readonly onRowClick?: (
+ project: Project,
+ event: ReactMouseEvent<HTMLTableRowElement>
+ ) => void;
+ readonly className?: string;
+}
+
+/**
+ * React port of `frontend/src/components/v2/Model/ProjectV1Table.vue`.
+ *
+ * Renders the standard project listing — id / title / labels columns,
+ * with optional leading current-project check, leading selection
+ * checkboxes, and trailing action-dropdown slot. Matches the prop
+ * shape of the Vue component so call sites read the same way.
+ *
+ * Two surfaces consume this today:
+ * - `ProjectsPage` (settings) — `showSelection` + `showActions` +
+ * server-side sort by title.
+ * - `ProjectSwitchPanel` (header popover) — `showLabels=false` +
+ * `currentProject` set to the active project.
+ *
+ * Uses plain HTML table elements (not the shadcn `Table` primitives)
+ * to preserve the visual styling that ProjectsPage shipped with —
+ * specifically: `bg-control-bg` header row, `px-4 py-2` cell padding,
+ * and a rotating `ChevronDown` sort indicator. Switching to the
+ * shadcn primitives would change all of those at once.
+ */
+export function ProjectTable({
+ projectList,
+ currentProject,
+ keyword = "",
+ loading = false,
+ emptyContent,
+ showSelection = false,
+ showLabels = true,
+ showActions = false,
+ renderActions,
+ selectedProjectNames = [],
+ onSelectedChange,
+ sortKey,
+ sortOrder,
+ onSortChange,
+ onRowClick,
+ className,
+}: ProjectTableProps) {
+ const { t } = useTranslation();
+ const showLeadingCheck = !!currentProject && !showSelection;
+ const selectableProjects = projectList.filter(
+ (p) => getProjectName(p.name) !== "default"
+ );
+ const allSelectableNames = selectableProjects.map((p) => p.name);
+ const allSelected =
+ showSelection &&
+ allSelectableNames.length > 0 &&
+ allSelectableNames.every((name) => selectedProjectNames.includes(name));
+
+ const totalColumns =
+ (showSelection || showLeadingCheck ? 1 : 0) +
+ 1 + // id
+ 1 + // title
+ (showLabels ? 1 : 0) +
+ (showActions ? 1 : 0);
+
+ const handleSelectAll = () => {
+ if (!onSelectedChange) return;
+ onSelectedChange(allSelected ? [] : allSelectableNames);
+ };
+
+ const handleToggleRow = (name: string) => {
+ if (!onSelectedChange) return;
+ const next = selectedProjectNames.includes(name)
+ ? selectedProjectNames.filter((n) => n !== name)
+ : [...selectedProjectNames, name];
+ onSelectedChange(next as string[]);
+ };
+
+ return (
+ <table className={cn("w-full text-sm", className)}>
+ <thead>
+ <tr className="bg-control-bg border-b border-control-border">
+ {showSelection ? (
+ <th className="w-12 px-4 py-2">
+ <input
+ type="checkbox"
+ aria-label={t("common.select-all")}
+ checked={allSelected}
+ onChange={handleSelectAll}
+ className="rounded-xs border-control-border"
+ />
+ </th>
+ ) : showLeadingCheck ? (
+ <th className="w-8 px-2 py-2" />
+ ) : null}
+ <th className="px-4 py-2 text-left font-medium min-w-[128px]">
+ {t("common.id")}
+ </th>
+ <th
+ className={cn(
+ "px-4 py-2 text-left font-medium min-w-[200px]",
+ onSortChange && "cursor-pointer select-none"
+ )}
+ onClick={() => onSortChange?.("title")}
+ >
+ <div className="flex items-center gap-x-1">
+ {t("project.table.name")}
+ {onSortChange ? (
+ <SortIndicator
+ active={sortKey === "title"}
+ direction={sortOrder}
+ />
+ ) : null}
+ </div>
+ </th>
+ {showLabels ? (
+ <th className="px-4 py-2 text-left font-medium min-w-[240px] hidden md:table-cell">
+ {t("common.labels")}
+ </th>
+ ) : null}
+ {showActions ? <th className="w-[50px]" /> : null}
+ </tr>
+ </thead>
+ <tbody>
+ {loading && projectList.length === 0 ? (
+ <tr>
+ <td
+ colSpan={totalColumns}
+ className="px-4 py-8 text-center text-control-placeholder"
+ >
+ <div className="flex items-center justify-center gap-x-2">
+ <div className="animate-spin size-4 border-2 border-accent border-t-transparent rounded-full" />
+ {t("common.loading")}
+ </div>
+ </td>
+ </tr>
+ ) : projectList.length === 0 ? (
+ <tr>
+ <td
+ colSpan={totalColumns}
+ className="px-4 py-8 text-center text-control-placeholder"
+ >
+ {emptyContent ?? t("common.no-data")}
+ </td>
+ </tr>
+ ) : (
+ projectList.map((project, i) => {
+ const resourceId = getProjectName(project.name);
+ const isDefault = resourceId === "default";
+ const isCurrent = currentProject?.name === project.name;
+ const isSelected = selectedProjectNames.includes(project.name);
+ return (
+ <tr
+ key={project.name}
+ className={cn(
+ "border-b last:border-b-0",
+ onRowClick && "cursor-pointer hover:bg-control-bg",
+ i % 2 === 1 && "bg-control-bg/50"
+ )}
+ onClick={(event) => onRowClick?.(project, event)}
+ >
+ {showSelection ? (
+ <td
+ className="w-12 px-4 py-2"
+ onClick={(e) => e.stopPropagation()}
+ >
+ <input
+ type="checkbox"
+ aria-label={t("common.select")}
+ checked={isSelected}
+ disabled={isDefault}
+ onChange={() => handleToggleRow(project.name)}
+ className="rounded-xs border-control-border disabled:opacity-50"
+ />
+ </td>
+ ) : showLeadingCheck ? (
+ <td className="w-8 px-2 py-2">
+ {isCurrent ? (
+ <Check className="size-4 text-accent" />
+ ) : null}
+ </td>
+ ) : null}
+ <td className="px-4 py-2">
+ <HighlightLabelText text={resourceId} keyword={keyword} />
+ </td>
+ <td className="px-4 py-2">
+ <div className="flex items-center gap-x-2">
+ <HighlightLabelText
+ text={project.title || resourceId}
+ keyword={keyword}
+ />
+ {project.state === State.DELETED ? (
+ <Badge variant="warning" className="text-xs">
+ {t("common.archived")}
+ </Badge>
+ ) : null}
+ </div>
+ </td>
+ {showLabels ? (
+ <td className="px-4 py-2 hidden md:table-cell">
+ <LabelsCell labels={project.labels ?? {}} />
+ </td>
+ ) : null}
+ {showActions ? (
+ <td
+ className="w-[50px] px-4 py-2"
+ onClick={(e) => e.stopPropagation()}
+ >
+ <div className="flex justify-end">
+ {renderActions?.(project)}
+ </div>
+ </td>
+ ) : null}
+ </tr>
+ );
+ })
+ )}
+ </tbody>
+ </table>
+ );
+}
+
+/**
+ * ProjectsPage's original sort indicator: a single ChevronDown that
+ * rotates 180° when the column is sorted ascending. Inactive state
+ * shows the chevron in `text-control-border` so it reads as "you
+ * could click this". Matches the pre-extraction look.
+ */
+function SortIndicator({
+ active,
+ direction,
+}: {
+ active: boolean;
+ direction?: ProjectTableSortDirection;
+}) {
+ if (!active) {
+ return <ChevronDown className="size-3 text-control-border" />;
+ }
+ return (
+ <ChevronDown
+ className={cn(
+ "size-3 text-accent transition-transform",
+ direction === "asc" && "rotate-180"
+ )}
+ />
+ );
+}
+
+/**
+ * Mirrors Vue's `LabelsCell` — show up to N labels inline, "..." for
+ * the rest, and a tooltip on hover that lists all of them.
+ */
+function LabelsCell({ labels }: { labels: { [key: string]: string } }) {
+ const entries = Object.entries(labels);
+ if (entries.length === 0) {
+ return (
+ <span className="text-control-placeholder">
+ {DEFAULT_LABELS_PLACEHOLDER}
+ </span>
+ );
+ }
+ const visible = entries.slice(0, DEFAULT_LABELS_PREVIEW);
+ const hasMore = entries.length > DEFAULT_LABELS_PREVIEW;
+ const trigger = (
+ <span className="inline-flex items-center gap-x-1">
+ {visible.map(([key, value]) => (
+ <span
+ key={key}
+ className="rounded-xs bg-control-bg py-0.5 px-2 text-sm"
+ >
+ {key}:{value}
+ </span>
+ ))}
+ {hasMore ? <span>…</span> : null}
+ </span>
+ );
+ if (!hasMore) return trigger;
+ return (
+ <Tooltip
+ content={
+ <div className="text-sm flex flex-col gap-y-1">
+ {entries.map(([key, value]) => (
+ <div key={key}>
+ {key}:{value}
+ </div>
+ ))}
+ </div>
+ }
+ >
+ {trigger}
+ </Tooltip>
+ );
+}
diff --git a/frontend/src/react/components/header/ProjectSwitchPanel.test.tsx b/frontend/src/react/components/header/ProjectSwitchPanel.test.tsx
index 532036b41c..56f774a4ce 100644
--- a/frontend/src/react/components/header/ProjectSwitchPanel.test.tsx
+++ b/frontend/src/react/components/header/ProjectSwitchPanel.test.tsx
@@ -180,12 +180,13 @@ describe("ProjectSwitchPanel", () => {
render();
- const row = Array.from(container.querySelectorAll("button")).find(
- (button) => button.textContent?.includes("Recent Project")
+ // Rows are now `<tr>` (table layout, mirroring Vue's ProjectV1Table).
+ const row = Array.from(container.querySelectorAll("tr")).find((tr) =>
+ tr.textContent?.includes("Recent Project")
);
expect(row).not.toBeUndefined();
act(() => {
- row?.click();
+ row?.dispatchEvent(new MouseEvent("click", { bubbles: true }));
});
expect(mocks.resolve).toHaveBeenCalledWith({
@@ -275,11 +276,13 @@ describe("ProjectSwitchPanel", () => {
render();
- const currentProjectRow = Array.from(
- container.querySelectorAll("button")
- ).find((button) => button.textContent?.includes("Recent Project"));
+ const currentProjectRow = Array.from(container.querySelectorAll("tr")).find(
+ (tr) => tr.textContent?.includes("Recent Project")
+ );
act(() => {
- currentProjectRow?.click();
+ currentProjectRow?.dispatchEvent(
+ new MouseEvent("click", { bubbles: true })
+ );
});
expect(mocks.close).toHaveBeenCalledTimes(1);
@@ -296,8 +299,8 @@ describe("ProjectSwitchPanel", () => {
render();
- const row = Array.from(container.querySelectorAll("button")).find(
- (button) => button.textContent?.includes("Recent Project")
+ const row = Array.from(container.querySelectorAll("tr")).find((tr) =>
+ tr.textContent?.includes("Recent Project")
);
act(() => {
row?.dispatchEvent(
diff --git a/frontend/src/react/components/header/ProjectSwitchPanel.tsx b/frontend/src/react/components/header/ProjectSwitchPanel.tsx
index 53c0069a4e..a12ad90f13 100644
--- a/frontend/src/react/components/header/ProjectSwitchPanel.tsx
+++ b/frontend/src/react/components/header/ProjectSwitchPanel.tsx
@@ -1,4 +1,4 @@
-import { Check, ChevronLeft, Plus } from "lucide-react";
+import { ChevronLeft, Plus } from "lucide-react";
import {
type MouseEvent as ReactMouseEvent,
useCallback,
@@ -7,6 +7,7 @@ import {
useState,
} from "react";
import { useTranslation } from "react-i18next";
+import { ProjectTable } from "@/react/components/ProjectTable";
import { Button } from "@/react/components/ui/button";
import { Input } from "@/react/components/ui/input";
import {
@@ -98,62 +99,6 @@ function ProjectSwitchFooter({
);
}
-function ProjectRow({
- project,
- currentProjectName,
- keyword,
- onSelect,
-}: {
- project: Project;
- currentProjectName?: string;
- keyword: string;
- onSelect: (
- project: Project,
- event: ReactMouseEvent<HTMLButtonElement>
- ) => void;
-}) {
- const resourceId = getProjectName(project.name);
- const labels = Object.entries(project.labels ?? {}).slice(0, 3);
- const isCurrent = project.name === currentProjectName;
-
- return (
- <button
- type="button"
- className="flex w-full items-start gap-x-2.5 rounded-sm px-2 py-1.5 text-left hover:bg-control-bg"
- onClick={(event) => onSelect(project, event)}
- >
- <span className="mt-0.5 h-4 w-4 shrink-0">
- {isCurrent ? <Check className="h-4 w-4 text-accent" /> : null}
- </span>
- <span className="min-w-0 flex-1">
- <span className="block truncate font-medium text-control">
- {project.title || resourceId}
- </span>
- <span className="block truncate text-xs text-control-light">
- {resourceId}
- </span>
- {labels.length > 0 ? (
- <span className="mt-1 flex flex-wrap gap-1">
- {labels.map(([key, value]) => (
- <span
- key={`${key}:${value}`}
- className="rounded-full bg-control-bg px-2 py-0.5 text-[11px] text-control-light"
- >
- {key}:{value}
- </span>
- ))}
- </span>
- ) : null}
- {keyword.trim().length > 0 &&
- !project.title.toLowerCase().includes(keyword.toLowerCase()) &&
- !resourceId.toLowerCase().includes(keyword.toLowerCase()) ? (
- <span className="sr-only">{keyword}</span>
- ) : null}
- </span>
- </button>
- );
-}
-
export function ProjectSwitchPanel({
onClose,
onRequestCreate,
@@ -164,7 +109,16 @@ export function ProjectSwitchPanel({
const route = useCurrentRoute();
const { projects: recentProjectList } = useRecentProjects();
const [searchText, setSearchText] = useState("");
- const [selectedTab, setSelectedTab] = useState<ProjectSwitchTab>("all");
+ const [selectedTab, setSelectedTab] = useState<ProjectSwitchTab>(() =>
+ recentProjectList.length > 0 ? "recent" : "all"
+ );
+ // The recent list loads async (localStorage read in useEffect), so the
+ // initializer above may see an empty list. Switch to "recent" once loaded.
+ useEffect(() => {
+ if (recentProjectList.length > 0) {
+ setSelectedTab((prev) => (prev === "all" ? "recent" : prev));
+ }
+ }, [recentProjectList.length]);
const projectId = route.params.projectId as string | undefined;
const currentProjectName = projectId
? `${projectNamePrefix}${projectId}`
@@ -172,21 +126,19 @@ export function ProjectSwitchPanel({
const currentProject = useProject(currentProjectName);
const allowToCreateProject = useWorkspacePermission("bb.projects.create");
- useEffect(() => {
- if (recentProjectList.length > 0) {
- setSelectedTab((previous) => (previous === "all" ? "recent" : previous));
- }
- }, [recentProjectList.length]);
-
const filteredRecentProjectList = useMemo(() => {
return recentProjectList.filter((project) =>
projectMatchesKeyword(project, searchText)
);
}, [recentProjectList, searchText]);
+ // Mirrors Vue's `actualSelectedTab` — force the All view when a search
+ // keyword is active but yields no recent matches, regardless of which
+ // tab the user explicitly clicked. Keeping the trigger highlight in
+ // sync is the consumer's responsibility (we pass `actualSelectedTab`
+ // to `<Tabs value=…>` so both indicator and panel agree).
const actualSelectedTab = useMemo<ProjectSwitchTab>(() => {
if (
- selectedTab === "recent" &&
searchText.trim().length > 0 &&
filteredRecentProjectList.length === 0
) {
@@ -207,7 +159,7 @@ export function ProjectSwitchPanel({
} = useProjectList(searchText);
const handleProjectSelect = useCallback(
- (project: Project, event: ReactMouseEvent<HTMLButtonElement>) => {
+ (project: Project, event: ReactMouseEvent<HTMLElement>) => {
const route = navigate.resolve({
name: PROJECT_V1_ROUTE_DETAIL,
params: {
@@ -256,7 +208,7 @@ export function ProjectSwitchPanel({
<Button
variant="ghost"
size="sm"
- className="mb-2 h-7 w-fit px-0 text-control-light hover:bg-transparent hover:text-control"
+ className="mb-2 mx-3 h-7 w-fit px-0 text-control-light hover:bg-transparent hover:text-control"
onClick={handleGotoWorkspace}
>
<ChevronLeft className="h-4 w-4 opacity-80" />
@@ -268,7 +220,7 @@ export function ProjectSwitchPanel({
value={actualSelectedTab}
onValueChange={(value) => setSelectedTab(value as ProjectSwitchTab)}
>
- <div className="mb-2 flex items-center justify-between gap-x-3">
+ <div className="mb-2 mx-3 flex items-center justify-between gap-x-3">
<TabsList className="gap-x-5">
<TabsTrigger className="pb-1.5" value="recent">
{t("common.recent")}
@@ -301,51 +253,30 @@ export function ProjectSwitchPanel({
</div>
<TabsPanel value="recent" className="mt-0">
- <div className="flex max-h-[26rem] flex-col overflow-auto">
- {filteredRecentProjectList.length === 0 ? (
- <div className="px-3 py-8 text-center text-sm text-control-light">
- {searchText.trim().length > 0
- ? t("common.no-data")
- : t("common.no-data")}
- </div>
- ) : (
- filteredRecentProjectList.map((project) => (
- <ProjectRow
- key={project.name}
- project={project}
- currentProjectName={currentProjectName}
- keyword={searchText}
- onSelect={handleProjectSelect}
- />
- ))
- )}
+ <div className="max-h-[26rem] overflow-auto">
+ <ProjectTable
+ projectList={filteredRecentProjectList}
+ currentProject={currentProject}
+ keyword={searchText}
+ showLabels={false}
+ onRowClick={handleProjectSelect}
+ />
</div>
</TabsPanel>
<TabsPanel value="all" className="mt-0">
- <div className="flex max-h-[26rem] flex-col overflow-auto">
- {isLoading && allProjects.length === 0 ? (
- <div className="px-3 py-8 text-center text-sm text-control-light">
- {t("common.loading")}
- </div>
- ) : allProjects.length === 0 ? (
- <div className="px-3 py-8 text-center text-sm text-control-light">
- {t("common.no-data")}
- </div>
- ) : (
- allProjects.map((project) => (
- <ProjectRow
- key={project.name}
- project={project}
- currentProjectName={currentProjectName}
- keyword={searchText}
- onSelect={handleProjectSelect}
- />
- ))
- )}
+ <div className="max-h-[26rem] overflow-auto">
+ <ProjectTable
+ projectList={allProjects}
+ currentProject={currentProject}
+ keyword={searchText}
+ loading={isLoading}
+ showLabels={false}
+ onRowClick={handleProjectSelect}
+ />
</div>
- <div className="mt-2 border-t border-control-border pt-2">
+ <div className="mt-2 mx-3">
<ProjectSwitchFooter
pageSize={pageSize}
pageSizeOptions={pageSizeOptions}
diff --git a/frontend/src/react/components/header/ProjectSwitchPopover.tsx b/frontend/src/react/components/header/ProjectSwitchPopover.tsx
index 67cc6c2b31..42513019a6 100644
--- a/frontend/src/react/components/header/ProjectSwitchPopover.tsx
+++ b/frontend/src/react/components/header/ProjectSwitchPopover.tsx
@@ -57,7 +57,7 @@ export function ProjectSwitchPopover() {
<PopoverContent
align="start"
sideOffset={6}
- className="w-[24rem] max-w-[calc(100vw-2rem)] p-3"
+ className="w-[24rem] max-w-[calc(100vw-2rem)] p-0! py-3!"
>
<ProjectSwitchPanel
onClose={() => setOpen(false)}
diff --git a/frontend/src/react/components/sql-editor/TabItem/Label.tsx b/frontend/src/react/components/sql-editor/TabItem/Label.tsx
index 6005b1150e..dfb6b54831 100644
--- a/frontend/src/react/components/sql-editor/TabItem/Label.tsx
+++ b/frontend/src/react/components/sql-editor/TabItem/Label.tsx
@@ -114,7 +114,6 @@ export function Label({ tab }: Props) {
/>
{/* Invisible "expand" dbl-click layer — EllipsisText strips onDblClick */}
{!editing && !readonly && (
- // biome-ignore lint/a11y/useKeyWithClickEvents: dbl-click is the trigger
<div
className="absolute inset-0 cursor-text"
onDoubleClick={beginEdit}
diff --git a/frontend/src/react/pages/project/ProjectDataExportPage.tsx b/frontend/src/react/pages/project/ProjectDataExportPage.tsx
index fcc99e50e8..c1ee296854 100644
--- a/frontend/src/react/pages/project/ProjectDataExportPage.tsx
+++ b/frontend/src/react/pages/project/ProjectDataExportPage.tsx
@@ -8,6 +8,7 @@ import {
type SearchScope,
type ValueOption,
} from "@/react/components/AdvancedSearch";
+import { HighlightLabelText } from "@/react/components/HighlightLabelText";
import { Button } from "@/react/components/ui/button";
import { Tooltip } from "@/react/components/ui/tooltip";
import { PagedTableFooter, usePagedData } from "@/react/hooks/usePagedData";
@@ -39,7 +40,6 @@ import {
extractProjectResourceName,
formatAbsoluteDateTime,
getDefaultPagination,
- getHighlightHTMLByRegExp,
getIssueRoute,
hasProjectPermissionV2,
hasWorkspacePermissionV2,
@@ -501,28 +501,6 @@ function IssueListItem({
[highlightText]
);
- const highlightedTitle = useMemo(
- () =>
- getHighlightHTMLByRegExp(
- issue.title,
- highlightWords,
- false,
- "bg-yellow-100"
- ),
- [issue.title, highlightWords]
- );
-
- const highlightedDescription = useMemo(
- () =>
- getHighlightHTMLByRegExp(
- issue.description,
- highlightWords,
- false,
- "bg-yellow-100"
- ),
- [issue.description, highlightWords]
- );
-
const expanded =
highlightText &&
issue.description &&
@@ -548,8 +526,12 @@ function IssueListItem({
href={issueUrl}
className="font-medium text-main text-base truncate hover:underline"
onClick={(e) => e.stopPropagation()}
- dangerouslySetInnerHTML={{ __html: highlightedTitle }}
- />
+ >
+ <HighlightLabelText
+ text={issue.title}
+ keyword={highlightWords}
+ />
+ </a>
) : (
<a
href={issueUrl}
@@ -599,12 +581,12 @@ function IssueListItem({
</div>
{/* Expanded description for search highlights */}
{expanded && (
- <div
- className="mt-2 max-h-80 overflow-auto whitespace-pre-wrap break-all text-sm text-control-light"
- dangerouslySetInnerHTML={{
- __html: highlightedDescription,
- }}
- />
+ <div className="mt-2 max-h-80 overflow-auto whitespace-pre-wrap break-all text-sm text-control-light">
+ <HighlightLabelText
+ text={issue.description}
+ keyword={highlightWords}
+ />
+ </div>
)}
</div>
diff --git a/frontend/src/react/pages/settings/GroupsPage.tsx b/frontend/src/react/pages/settings/GroupsPage.tsx
index e5ccef946d..05006d5bae 100644
--- a/frontend/src/react/pages/settings/GroupsPage.tsx
+++ b/frontend/src/react/pages/settings/GroupsPage.tsx
@@ -12,6 +12,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { ComponentPermissionGuard } from "@/react/components/ComponentPermissionGuard";
import { FeatureBadge } from "@/react/components/FeatureBadge";
+import { HighlightLabelText } from "@/react/components/HighlightLabelText";
import { UserSelect } from "@/react/components/UserSelect";
import { Alert, AlertDescription } from "@/react/components/ui/alert";
import { Badge } from "@/react/components/ui/badge";
@@ -99,25 +100,6 @@ function deduplicateMembers(members: GroupMember[]): GroupMember[] {
return Array.from(map.values());
}
-// ============================================================
-// HighlightText
-// ============================================================
-
-function HighlightText({ text, keyword }: { text: string; keyword: string }) {
- if (!keyword.trim()) return <>{text}</>;
- const idx = text.toLowerCase().indexOf(keyword.toLowerCase());
- if (idx < 0) return <>{text}</>;
- return (
- <>
- {text.slice(0, idx)}
- <span className="bg-yellow-100">
- {text.slice(idx, idx + keyword.length)}
- </span>
- {text.slice(idx + keyword.length)}
- </>
- );
-}
-
// ============================================================
// GroupTable
// ============================================================
@@ -368,7 +350,7 @@ function GroupRow({
<div className="flex flex-col">
<div className="flex items-center gap-x-1.5">
<span>
- <HighlightText text={group.title} keyword={searchText} />
+ <HighlightLabelText text={group.title} keyword={searchText} />
</span>
<span className="text-control-light text-xs">
(
@@ -382,7 +364,7 @@ function GroupRow({
)}
</div>
<span className="textinfolabel text-xs">
- <HighlightText text={group.name} keyword={searchText} />
+ <HighlightLabelText text={group.name} keyword={searchText} />
</span>
</div>
</div>
diff --git a/frontend/src/react/pages/settings/ProjectsPage.tsx b/frontend/src/react/pages/settings/ProjectsPage.tsx
index 772b5cdec2..efd1bc0788 100644
--- a/frontend/src/react/pages/settings/ProjectsPage.tsx
+++ b/frontend/src/react/pages/settings/ProjectsPage.tsx
@@ -1,11 +1,4 @@
-import {
- Archive,
- Check,
- ChevronDown,
- EllipsisVertical,
- Plus,
- Trash2,
-} from "lucide-react";
+import { Archive, Check, EllipsisVertical, Plus, Trash2 } from "lucide-react";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import {
@@ -16,13 +9,13 @@ import {
} from "@/react/components/AdvancedSearch";
import { ProjectCreateDialog } from "@/react/components/header/ProjectCreateDialog";
import { PermissionGuard } from "@/react/components/PermissionGuard";
+import { ProjectTable } from "@/react/components/ProjectTable";
import {
AlertDialog,
AlertDialogContent,
AlertDialogDescription,
AlertDialogTitle,
} from "@/react/components/ui/alert-dialog";
-import { Badge } from "@/react/components/ui/badge";
import { Button } from "@/react/components/ui/button";
import {
DropdownMenu,
@@ -427,30 +420,6 @@ function ProjectActionDropdown({
);
}
-// ============================================================
-// HighlightText
-// ============================================================
-
-function HighlightText({ text, keyword }: { text: string; keyword: string }) {
- if (!keyword) return <>{text}</>;
-
- const lowerText = text.toLowerCase();
- const lowerKeyword = keyword.toLowerCase();
- const index = lowerText.indexOf(lowerKeyword);
-
- if (index === -1) return <>{text}</>;
-
- return (
- <>
- {text.substring(0, index)}
- <span className="bg-yellow-100">
- {text.substring(index, index + keyword.length)}
- </span>
- {text.substring(index + keyword.length)}
- </>
- );
-}
-
// ============================================================
// ProjectsPage (main)
// ============================================================
@@ -695,27 +664,6 @@ export function ProjectsPage() {
.filter((p): p is Project => p !== undefined);
}, [selectedNames, projectStore]);
- const toggleSelection = useCallback((name: string) => {
- setSelectedNames((prev) => {
- const next = new Set(prev);
- if (next.has(name)) next.delete(name);
- else next.add(name);
- return next;
- });
- }, []);
-
- const toggleSelectAll = useCallback(() => {
- setSelectedNames((prev) => {
- const selectableProjects = projects.filter(
- (p) => extractProjectResourceName(p.name) !== "default"
- );
- if (prev.size === selectableProjects.length) {
- return new Set();
- }
- return new Set(selectableProjects.map((p) => p.name));
- });
- }, [projects]);
-
const handleBatchOperation = useCallback(() => {
setSelectedNames(new Set());
fetchProjects(true);
@@ -749,30 +697,6 @@ export function ProjectsPage() {
fetchProjects(true);
}, [fetchProjects]);
- const renderSortIndicator = (columnKey: string) => {
- if (sortKey !== columnKey) {
- return <ChevronDown className="size-3 text-control-border" />;
- }
- return (
- <ChevronDown
- className={cn(
- "h-3 w-3 text-accent transition-transform",
- sortOrder === "asc" && "rotate-180"
- )}
- />
- );
- };
-
- const selectableProjects = useMemo(
- () =>
- projects.filter((p) => extractProjectResourceName(p.name) !== "default"),
- [projects]
- );
-
- const allSelected =
- selectableProjects.length > 0 &&
- selectedNames.size === selectableProjects.length;
-
const pageSizeOptions = getPageSizeOptions();
return (
@@ -805,130 +729,28 @@ export function ProjectsPage() {
)}
{/* Table */}
- <div className="border rounded-sm">
- <div className="overflow-x-auto">
- <table className="w-full text-sm min-w-[700px]">
- <thead>
- <tr className="bg-control-bg border-b border-control-border">
- {canDelete && (
- <th className="w-12 px-4 py-2">
- <input
- type="checkbox"
- checked={allSelected}
- onChange={toggleSelectAll}
- className="rounded-xs border-control-border"
- />
- </th>
- )}
- <th className="px-4 py-2 text-left font-medium min-w-[128px]">
- {t("common.id")}
- </th>
- <th
- className="px-4 py-2 text-left font-medium min-w-[200px] cursor-pointer select-none"
- onClick={() => toggleSort("title")}
- >
- <div className="flex items-center gap-x-1">
- {t("project.table.name")}
- {renderSortIndicator("title")}
- </div>
- </th>
- <th className="px-4 py-2 text-left font-medium min-w-[240px] hidden md:table-cell">
- {t("common.labels")}
- </th>
- <th className="w-[50px]" />
- </tr>
- </thead>
- <tbody>
- {loading && projects.length === 0 ? (
- <tr>
- <td
- colSpan={canDelete ? 5 : 4}
- className="px-4 py-8 text-center text-control-placeholder"
- >
- <div className="flex items-center justify-center gap-x-2">
- <div className="animate-spin size-4 border-2 border-accent border-t-transparent rounded-full" />
- {t("common.loading")}
- </div>
- </td>
- </tr>
- ) : projects.length === 0 ? (
- <tr>
- <td
- colSpan={canDelete ? 5 : 4}
- className="px-4 py-8 text-center text-control-placeholder"
- >
- {t("common.no-data")}
- </td>
- </tr>
- ) : (
- projects.map((project, i) => {
- const resourceName = extractProjectResourceName(project.name);
- const isDefault = resourceName === "default";
- const isSelected = selectedNames.has(project.name);
-
- return (
- <tr
- key={project.name}
- className={cn(
- "border-b last:border-b-0 cursor-pointer hover:bg-control-bg",
- i % 2 === 1 && "bg-control-bg/50"
- )}
- onClick={(e) => handleRowClick(project, e)}
- >
- {canDelete && (
- <td
- className="w-12 px-4 py-2"
- onClick={(e) => e.stopPropagation()}
- >
- <input
- type="checkbox"
- checked={isSelected}
- disabled={isDefault}
- onChange={() => toggleSelection(project.name)}
- className="rounded-xs border-control-border disabled:opacity-50"
- />
- </td>
- )}
- <td className="px-4 py-2">
- <HighlightText
- text={resourceName}
- keyword={searchText}
- />
- </td>
- <td className="px-4 py-2">
- <div className="flex items-center gap-x-2">
- <HighlightText
- text={project.title}
- keyword={searchText}
- />
- {project.state === State.DELETED && (
- <Badge variant="warning" className="text-xs">
- {t("common.archived")}
- </Badge>
- )}
- </div>
- </td>
- <td className="px-4 py-2 hidden md:table-cell">
- <LabelsDisplay labels={project.labels} />
- </td>
- <td className="px-4 py-2">
- <div
- className="flex justify-end"
- onClick={(e) => e.stopPropagation()}
- >
- <ProjectActionDropdown
- project={project}
- onAction={handleProjectAction}
- />
- </div>
- </td>
- </tr>
- );
- })
- )}
- </tbody>
- </table>
- </div>
+ <div className="border rounded-sm overflow-x-auto">
+ <ProjectTable
+ className="min-w-[700px]"
+ projectList={projects}
+ keyword={searchText}
+ loading={loading}
+ showSelection={canDelete}
+ showLabels
+ showActions
+ renderActions={(project) => (
+ <ProjectActionDropdown
+ project={project}
+ onAction={handleProjectAction}
+ />
+ )}
+ selectedProjectNames={Array.from(selectedNames)}
+ onSelectedChange={(names) => setSelectedNames(new Set(names))}
+ sortKey={sortKey}
+ sortOrder={sortOrder}
+ onSortChange={(key) => toggleSort(key)}
+ onRowClick={(project, e) => handleRowClick(project, e)}
+ />
</div>
{/* Pagination footer */}
@@ -952,30 +774,3 @@ export function ProjectsPage() {
</div>
);
}
-
-// ============================================================
-// LabelsDisplay
-// ============================================================
-
-function LabelsDisplay({ labels }: { labels: { [key: string]: string } }) {
- const entries = Object.entries(labels);
- if (entries.length === 0)
- return <span className="text-control-placeholder">-</span>;
-
- const displayEntries = entries.slice(0, 3);
- const hasMore = entries.length > 3;
-
- return (
- <div className="flex items-center gap-x-1">
- {displayEntries.map(([key, value]) => (
- <span
- key={key}
- className="rounded-xs bg-control-bg py-0.5 px-2 text-sm"
- >
- {key}:{value}
- </span>
- ))}
- {hasMore && <span>...</span>}
- </div>
- );
-}
diff --git a/frontend/src/react/pages/settings/SQLReviewPage.tsx b/frontend/src/react/pages/settings/SQLReviewPage.tsx
index 0e9833ad6b..7c212e61c9 100644
--- a/frontend/src/react/pages/settings/SQLReviewPage.tsx
+++ b/frontend/src/react/pages/settings/SQLReviewPage.tsx
@@ -1,6 +1,7 @@
import { Check, Pencil, Plus, Trash2, X } from "lucide-react";
import { useCallback, useEffect, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
+import { HighlightLabelText } from "@/react/components/HighlightLabelText";
import { LearnMoreLink } from "@/react/components/LearnMoreLink";
import { ResourceLink } from "@/react/components/sql-review/ResourceLink";
import { Badge } from "@/react/components/ui/badge";
@@ -70,27 +71,6 @@ function PolicyTable({
[sqlReviewStore, t]
);
- const highlight = useCallback(
- (text: string) => {
- if (!searchText) return text;
- const regex = new RegExp(
- `(${searchText.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})`,
- "gi"
- );
- const parts = text.split(regex);
- return parts.map((part, i) =>
- regex.test(part) ? (
- <mark key={i} className="bg-yellow-100">
- {part}
- </mark>
- ) : (
- part
- )
- );
- },
- [searchText]
- );
-
const [confirmingDelete, setConfirmingDelete] = useState<string | null>(null);
return (
@@ -120,7 +100,9 @@ function PolicyTable({
<TableBody>
{policies.map((policy) => (
<TableRow key={policy.id}>
- <TableCell>{highlight(policy.name)}</TableCell>
+ <TableCell>
+ <HighlightLabelText text={policy.name} keyword={searchText} />
+ </TableCell>
<TableCell>
<div className="flex flex-wrap gap-2">
{policy.resources.length === 0 && <span>-</span>}