Skip to content

Commit a260f51

Browse files
authored
Merge pull request #1389 from Dhanus3133/feat/policy-new-tab
feat: Support opening policy in new tab for easier navigation
2 parents 5ff10ee + 8db7d9f commit a260f51

3 files changed

Lines changed: 43 additions & 26 deletions

File tree

apps/app/src/app/(app)/[orgId]/policies/all/components/policies-table-columns.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,32 @@ import { StatusIndicator } from '@/components/status-indicator';
55
import { formatDate } from '@/lib/format';
66
import { Policy } from '@db';
77
import { ColumnDef } from '@tanstack/react-table';
8+
import { ExternalLink } from 'lucide-react';
9+
import Link from 'next/link';
810

9-
export function getPolicyColumns(): ColumnDef<Policy>[] {
11+
export function getPolicyColumns(orgId: string): ColumnDef<Policy>[] {
1012
return [
1113
{
1214
id: 'name',
1315
accessorKey: 'name',
1416
header: ({ column }) => <DataTableColumnHeader column={column} title="Policy Name" />,
1517
cell: ({ row }) => {
18+
const policyName = row.getValue('name') as string;
19+
const policyHref = `/${orgId}/policies/${row.original.id}`;
20+
1621
return (
17-
<div className="flex items-center gap-2">
18-
<span className="max-w-[31.25rem] truncate font-medium">{row.getValue('name')}</span>
19-
</div>
22+
<Link
23+
href={policyHref}
24+
target="_blank"
25+
rel="noopener noreferrer"
26+
onClick={(e) => e.stopPropagation()}
27+
className="group flex items-center gap-2"
28+
>
29+
<span className="max-w-[31.25rem] truncate font-medium group-hover:underline">
30+
{policyName}
31+
</span>
32+
<ExternalLink className="size-4 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100" />
33+
</Link>
2034
);
2135
},
2236
meta: {

apps/app/src/app/(app)/[orgId]/policies/all/components/policies-table.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ interface PoliciesTableProps {
1616

1717
export function PoliciesTable({ promises }: PoliciesTableProps) {
1818
const [{ data, pageCount }] = React.use(promises);
19-
const { orgId } = useParams();
19+
const params = useParams();
20+
const orgId = params.orgId as string;
2021

21-
const columns = React.useMemo(() => getPolicyColumns(), []);
22+
const columns = React.useMemo(() => getPolicyColumns(orgId), [orgId]);
2223

2324
const { table } = useDataTable({
2425
data,

apps/app/src/components/data-table/data-table.tsx

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ export function DataTable<TData>({
3333
if (onRowClick) {
3434
onRowClick(row);
3535
}
36-
if (getRowId) {
36+
if (getRowId && rowClickBasePath) {
3737
const id = getRowId(row);
3838
router.push(`${rowClickBasePath}/${id}`);
3939
}
4040
};
4141

42-
// Apply client-side filtering
4342
const filteredRows = table.getFilteredRowModel().rows;
43+
const isRowClickable = !!(getRowId && rowClickBasePath) || !!onRowClick;
4444

4545
return (
4646
<div className={cn('space-y-4', className)} {...props}>
@@ -78,25 +78,27 @@ export function DataTable<TData>({
7878
<TableRow
7979
key={row.id}
8080
data-state={row.getIsSelected() && 'selected'}
81-
className={cn((getRowId || onRowClick) && 'hover:bg-muted/50 cursor-pointer')}
82-
onClick={() => handleRowClick(row.original)}
81+
className={cn(isRowClickable && 'hover:bg-muted/50 cursor-pointer')}
82+
onClick={isRowClickable ? () => handleRowClick(row.original) : undefined}
8383
>
84-
{row.getVisibleCells().map((cell, index) => (
85-
<TableCell
86-
key={cell.id}
87-
className={cn(
88-
index !== 0 && 'hidden md:table-cell',
89-
index === 0 && 'truncate',
90-
)}
91-
style={{
92-
...getCommonPinningStyles({
93-
column: cell.column,
94-
}),
95-
}}
96-
>
97-
{flexRender(cell.column.columnDef.cell, cell.getContext())}
98-
</TableCell>
99-
))}
84+
{row.getVisibleCells().map((cell, index) => {
85+
return (
86+
<TableCell
87+
key={cell.id}
88+
className={cn(
89+
index !== 0 && 'hidden md:table-cell',
90+
index === 0 && 'truncate',
91+
)}
92+
style={{
93+
...getCommonPinningStyles({
94+
column: cell.column,
95+
}),
96+
}}
97+
>
98+
{flexRender(cell.column.columnDef.cell, cell.getContext())}
99+
</TableCell>
100+
);
101+
})}
100102
</TableRow>
101103
))
102104
) : (

0 commit comments

Comments
 (0)