Skip to content

Commit 3ffb6eb

Browse files
Partial implementation of ColumnStatisticsTable
1 parent af7b090 commit 3ffb6eb

23 files changed

Lines changed: 1080 additions & 164 deletions

packages/client/src/editor/TooltipMenu.tsx

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ export default function TooltipMenu({
326326
() => (state ? getSelectedMetricNode(state, schema) : null),
327327
[state, schema]
328328
);
329+
329330
const isOnlyMetricNode = useMemo(
330331
() => (state ? selectionIsOnlyMetricNode(state, schema) : false),
331332
[state, schema]
@@ -624,6 +625,25 @@ export default function TooltipMenu({
624625
[view, schema]
625626
);
626627

628+
const updateAllDependencies = useCallback(
629+
(updateFn: (dependencies: MetricDependency[]) => MetricDependency[]) => {
630+
if (!view) return;
631+
const currentState = view.state;
632+
const currentSelectedMetric = getSelectedMetricNode(currentState, schema);
633+
if (!currentSelectedMetric) return;
634+
const { node, pos } = currentSelectedMetric;
635+
const metrics = node.attrs.metrics || [];
636+
const newDependencies = updateFn(metrics);
637+
const tr = currentState.tr.setNodeMarkup(pos, undefined, {
638+
...node.attrs,
639+
metrics: newDependencies,
640+
});
641+
view.dispatch(tr);
642+
return;
643+
},
644+
[view, schema]
645+
);
646+
627647
const activeLinkMark = useMemo(() => {
628648
if (!state || !state.selection || state.selection.empty) return null;
629649
const links = getActiveLinks(state) || [];
@@ -1227,6 +1247,7 @@ export default function TooltipMenu({
12271247
node={selectedMetric.node}
12281248
onUpdate={updateMetricNode}
12291249
onUpdateDependencyParameters={updateDependencyParameters}
1250+
onUpdateAllDependencies={updateAllDependencies}
12301251
/>
12311252
</>
12321253
)}
@@ -1239,7 +1260,7 @@ export default function TooltipMenu({
12391260

12401261
// Render in portal to avoid overflow clipping
12411262
return typeof document !== "undefined" &&
1242-
(markCommands.length > 0 || commands.length > 0) &&
1263+
(markCommands.length > 0 || commands.length > 0 || isOnlyMetricNode) &&
12431264
!isOnlyReportTitle
12441265
? createPortal(tooltipContent, document.body)
12451266
: null;
@@ -1494,6 +1515,7 @@ export type TooltipDropdownOption = {
14941515
value: string;
14951516
label: ReactNode;
14961517
icon?: ReactNode;
1518+
disabled?: boolean;
14971519
/**
14981520
* When true, prevents the dropdown from closing on select.
14991521
*/
@@ -1547,9 +1569,11 @@ export function TooltipDropdown({
15471569
<DropdownMenu.Portal>
15481570
<DropdownMenu.Content
15491571
{...contentProps}
1550-
className="bg-white text-gray-900 border border-black/20 rounded shadow-lg px-1 py-1 z-50"
1572+
className="bg-white text-gray-900 border border-black/20 rounded shadow-lg px-1 py-1 z-50 max-h-72 overflow-auto"
15511573
sideOffset={6}
1552-
side="top"
1574+
side="bottom"
1575+
collisionPadding={8}
1576+
avoidCollisions
15531577
data-tooltip-dropdown="true"
15541578
>
15551579
{title && (
@@ -1563,13 +1587,20 @@ export function TooltipDropdown({
15631587
{options.map((opt) => (
15641588
<DropdownMenu.Item
15651589
key={opt.value}
1590+
disabled={opt.disabled}
15661591
className={
15671592
opt.className ??
1568-
`px-2 py-1 text-sm flex items-center gap-2 rounded hover:bg-gray-100 focus:bg-gray-100 outline-none cursor-pointer ${
1569-
opt.value === value ? "text-blue-600" : ""
1570-
}`
1593+
`px-2 py-1 text-sm flex items-center gap-2 rounded ${
1594+
opt.disabled
1595+
? "text-gray-400 cursor-not-allowed"
1596+
: "hover:bg-gray-100 focus:bg-gray-100 cursor-pointer"
1597+
} outline-none ${opt.value === value ? "text-blue-600" : ""}`
15711598
}
15721599
onSelect={(e: Event) => {
1600+
if (opt.disabled) {
1601+
e.preventDefault();
1602+
return;
1603+
}
15731604
if (opt.preventCloseOnSelect) {
15741605
e.preventDefault();
15751606
}
@@ -1726,6 +1757,12 @@ export type ReportWidgetTooltipControlsProps = {
17261757
onUpdateDependencyParameters: (
17271758
updateFn: (dependency: MetricDependency) => MetricDependencyParameters
17281759
) => void;
1760+
/**
1761+
* Update all dependencies related to the node. Callback is called with the current dependencies and should return the new dependencies.
1762+
*/
1763+
onUpdateAllDependencies: (
1764+
updateFn: (dependencies: MetricDependency[]) => MetricDependency[]
1765+
) => void;
17291766
};
17301767

17311768
export type ReportWidgetTooltipControls = FC<ReportWidgetTooltipControlsProps>;

packages/client/src/index.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7649,6 +7649,10 @@ select{
76497649
min-width:32rem
76507650
}
76517651

7652+
.min-w-\[90px\]{
7653+
min-width:90px
7654+
}
7655+
76527656
.\!max-w-128{
76537657
max-width:32rem !important
76547658
}

packages/client/src/reports/components/ReportCardBodyEditor.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ function ReportCardBodyEditorInner({
108108
variables: {
109109
slug: getSlug(),
110110
},
111+
fetchPolicy: "cache-and-network",
111112
});
112113

113114
const langContext = useContext(FormLanguageContext);

0 commit comments

Comments
 (0)