Skip to content

Commit

Permalink
Display repsonse rate in sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
atrincas committed Dec 3, 2024
1 parent 57243c7 commit ae07ebc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions client/src/containers/sandbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const Sandbox: FC = () => {
<Widget
breakdown={breakdown || undefined}
indicator={widget.indicator}
responseRate={widget.responseRate}
question={widget.question}
visualization={visualization || widget.defaultVisualization}
data={widget.data}
Expand Down
7 changes: 6 additions & 1 deletion client/src/containers/sandbox/user-sandbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FC, useEffect } from "react";
import { useAtom } from "jotai";
import { useSession } from "next-auth/react";

import { getResponseRate } from "@/lib/normalize-widget-data";
import { client } from "@/lib/queryClient";
import { queryKeys } from "@/lib/queryKeys";

Expand Down Expand Up @@ -53,7 +54,10 @@ const Sandbox: FC<SandboxProps> = ({ customWidgetId }) => {
},
{
enabled: !!indicator,
select: (res) => res.body.data,
select: (res) => ({
...res.body.data,
responseRate: getResponseRate(res.body.data.data),
}),
},
);

Expand All @@ -76,6 +80,7 @@ const Sandbox: FC<SandboxProps> = ({ customWidgetId }) => {
{widget && (
<Widget
indicator={widget.indicator}
responseRate={widget.responseRate}
question={widget.question}
visualization={visualization || widget.defaultVisualization}
data={widget.data}
Expand Down
2 changes: 1 addition & 1 deletion client/src/containers/widget/widget-header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Title from "@/components/ui/title";

interface WidgetHeaderProps {
indicator: string;
responseRate: number;
responseRate?: number;
question?: string;
menu?: React.ReactNode;
className?: string;
Expand Down
6 changes: 5 additions & 1 deletion client/src/hooks/use-sandbox-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import {
} from "@shared/dto/widgets/widget-visualizations.constants";
import { parseAsStringEnum, useQueryState } from "nuqs";

import { normalizeWidgetData } from "@/lib/normalize-widget-data";
import {
getResponseRate,
normalizeWidgetData,
} from "@/lib/normalize-widget-data";
import { client } from "@/lib/queryClient";
import { queryKeys } from "@/lib/queryKeys";

Expand Down Expand Up @@ -37,6 +40,7 @@ function useSandboxWidget() {
select: (res) => ({
...res.body.data,
data: normalizeWidgetData(res.body.data.data),
responseRate: getResponseRate(res.body.data.data),
}),
},
);
Expand Down

0 comments on commit ae07ebc

Please sign in to comment.