Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions web-common/src/features/dashboards/pivot/PivotDimensionCell.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<script lang="ts">
import ExternalLink from "@rilldata/web-common/components/icons/ExternalLink.svelte";

export let value: string | null | undefined;
export let href: string;
</script>

<div class="dimension-cell">
<span class="truncate min-w-0">{value ?? "null"}</span>
<a
class="external-link"
target="_blank"
rel="noopener noreferrer"
{href}
title={href}
onclick={(e) => e.stopPropagation()}
>
<ExternalLink className="fill-primary-600" />
</a>
</div>

<style lang="postcss">
.dimension-cell {
@apply flex items-center gap-x-1 min-w-0;
}

.external-link {
@apply inline-flex items-center shrink-0 opacity-0 transition-opacity;
}

.dimension-cell:hover .external-link {
@apply opacity-100;
}
</style>
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import PercentageChange from "@rilldata/web-common/components/data-types/PercentageChange.svelte";
import DeltaChange from "@rilldata/web-common/features/dashboards/dimension-table/DeltaChange.svelte";
import DeltaChangePercentage from "@rilldata/web-common/features/dashboards/dimension-table/DeltaChangePercentage.svelte";
import {
URI_DIMENSION_SUFFIX,
makeHref,
} from "@rilldata/web-common/features/dashboards/leaderboard/leaderboard-utils";
import {
getNextLimitLabel,
LOADING_CELL,
Expand All @@ -15,6 +19,7 @@ import type { ColumnDef } from "tanstack-table-8-svelte-5";
import { timeFormat } from "d3-time-format";
import type { ComponentType, SvelteComponent } from "svelte";
import PivotDeltaCell from "./PivotDeltaCell.svelte";
import PivotDimensionCell from "./PivotDimensionCell.svelte";
import PivotExpandableCell from "./PivotExpandableCell.svelte";
import PivotMeasureCell from "./PivotMeasureCell.svelte";
import PivotShowMoreCell from "./PivotShowMoreCell.svelte";
Expand Down Expand Up @@ -317,17 +322,32 @@ function getFlatColumnDef(
): ColumnDef<PivotDataRow>[] {
const rowDefinitions: ColumnDef<PivotDataRow>[] = rowDimensions.map(
(d, i) => {
const dimSpec = config.allDimensions.find(
(dim) => dim.name === d.name || dim.column === d.name,
);
const uriField =
dimSpec?.uri && dimSpec.name
? dimSpec.name + URI_DIMENSION_SUFFIX
: undefined;

return {
id: d.name,
accessorFn: (row) => row[d.name],
header: d.label || d.name,
cell: ({ getValue }) => {
cell: ({ row, getValue }) => {
const value = formatDimensionValue(
getValue() as string,
i,
config.time,
rowDimensionNames,
);
if (uriField) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets move this check a level above, that way we only branch based on uri field during column definition construction vs on every cell.

const uri = row.original[uriField] as string | null | undefined;
const href = makeHref(uri ?? null, (value as string) ?? "");
if (href) {
return cellComponent(PivotDimensionCell, { value, href });
}
}
if (value === null) return "null";
return value;
},
Expand Down
19 changes: 18 additions & 1 deletion web-common/src/features/dashboards/pivot/pivot-data-store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ConnectError } from "@connectrpc/connect";
import { getURIRequestMeasure } from "@rilldata/web-common/features/dashboards/dashboard-utils";
import { getDimensionFilterWithSearch } from "@rilldata/web-common/features/dashboards/dimension-table/dimension-table-utils";
import {
calculateEffectiveRowLimit,
Expand All @@ -12,6 +13,7 @@ import { createAndExpression } from "@rilldata/web-common/features/dashboards/st
import type { TimeRangeString } from "@rilldata/web-common/lib/time/types";
import type {
V1Expression,
V1MetricsViewAggregationMeasure,
V1MetricsViewAggregationResponse,
V1MetricsViewAggregationSort,
} from "@rilldata/web-common/runtime-client";
Expand Down Expand Up @@ -113,7 +115,22 @@ export function createTableCellQuery(
};
} else return { name: dimension };
});
const measureBody = measureNames.map((m) => ({ name: m }));
const measureBody: V1MetricsViewAggregationMeasure[] = measureNames.map(
(m) => ({ name: m }),
);

// Request computed URI measures for flat-mode row dimensions that define a
// uri template, so dimension cells can render as links (matching leaderboard).
if (isFlat) {
for (const dimensionName of rowDimensionNames) {
const dimSpec = config.allDimensions.find(
(d) => d.name === dimensionName || d.column === dimensionName,
);
if (dimSpec?.uri && dimSpec.name) {
measureBody.push(getURIRequestMeasure(dimSpec.name));
}
}
}

const { filters: filterForInitialTable, timeFilters } =
getFilterForPivotTable(
Expand Down
Loading