From 8a5ee5b417df26c08446b1a43b8d1e10f7cb361a Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Tue, 29 Jul 2025 17:34:49 -0600 Subject: [PATCH] create additional refs and playground --- .../report-playground-2/ReportPlayground.tsx | 139 +++++++++++------- .../src/components/ui/report/ReportEditor.tsx | 2 +- .../ui/report/ThemeWrapper/useThemesConfig.ts | 2 +- .../web/src/components/ui/toolbar/Toolbar.tsx | 12 +- apps/web/src/styles/tailwind.css | 1 + 5 files changed, 93 insertions(+), 63 deletions(-) diff --git a/apps/web/src/app/test/report-playground-2/ReportPlayground.tsx b/apps/web/src/app/test/report-playground-2/ReportPlayground.tsx index 5b120df29..b2d3693d7 100644 --- a/apps/web/src/app/test/report-playground-2/ReportPlayground.tsx +++ b/apps/web/src/app/test/report-playground-2/ReportPlayground.tsx @@ -7,6 +7,8 @@ import type { ReportElements } from '@buster/server-shared/reports'; import { useQuery } from '@tanstack/react-query'; import { mainApiV2 } from '@/api/buster_rest/instances'; import { useDebounceEffect } from '@/hooks'; +import { useThemesConfig } from '@/components/ui/report/ThemeWrapper/useThemesConfig'; +import { cn } from '@/lib/utils'; const ReportEditor = dynamic( () => import('@/components/ui/report/ReportEditor').then((mod) => mod.ReportEditor), @@ -14,6 +16,66 @@ const ReportEditor = dynamic( ); // Status indicator component with dynamic backgrounds + +export const ReportPlayground: React.FC = () => { + const [markdown, setMarkdown] = useState(''); + const [hasBeenSuccessFullAtLeastOnce, setHasBeenSuccessFullAtLeastOnce] = useState(false); + + const { data, refetch, isLoading, isFetched, error } = useQuery({ + queryKey: ['report-playground', markdown], + queryFn: () => { + return mainApiV2 + .post<{ elements: ReportElements }>('/temp/validate-markdown', { markdown }) + .then((res) => { + setHasBeenSuccessFullAtLeastOnce(true); + return res.data; + }); + }, + enabled: false + }); + + useDebounceEffect( + () => { + if (markdown.length > 0) { + refetch(); + } + }, + [markdown, refetch], + { wait: 150 } + ); + + const usedValue: ReportElements = hasBeenSuccessFullAtLeastOnce ? data?.elements || [] : value; + + return ( +
+
+ setMarkdown(e.target.value)} + /> + + {data && ( +
+
+

Successful Response:

+
+                {JSON.stringify(data.elements, null, 2)}
+              
+
+
+ )} + + +
+
+ +
+
+ ); +}; + interface ValidationStatusProps { isLoading: boolean; error: unknown; @@ -92,62 +154,37 @@ const ValidationStatus: React.FC = ({ ); }; -export const ReportPlayground: React.FC = () => { - const [markdown, setMarkdown] = useState(''); - const [hasBeenSuccessFullAtLeastOnce, setHasBeenSuccessFullAtLeastOnce] = useState(false); +const ThemePicker = React.memo(() => { + const { activeTheme, setActiveTheme, allThemes } = useThemesConfig(); - const { data, refetch, isLoading, isFetched, error } = useQuery({ - queryKey: ['report-playground', markdown], - queryFn: () => { - return mainApiV2 - .post<{ elements: ReportElements }>('/temp/validate-markdown', { markdown }) - .then((res) => { - setHasBeenSuccessFullAtLeastOnce(true); - return res.data; - }); - }, - enabled: false - }); - - useDebounceEffect( - () => { - if (markdown.length > 0) { - refetch(); - } - }, - [markdown, refetch], - { wait: 150 } - ); - - const usedValue: ReportElements = hasBeenSuccessFullAtLeastOnce ? data?.elements || [] : value; + const themesList = Object.values(allThemes); return ( -
-
- setMarkdown(e.target.value)} - /> - - {data && ( -
-
-

Successful Response:

-
-                {JSON.stringify(data.elements, null, 2)}
-              
-
-
- )} -
-
- -
+
+ {themesList.map((theme) => { + const firstThreeColors = Object.values(theme.light).slice(0, 3); + + const isActive = activeTheme.id === theme.id; + return ( +
setActiveTheme(theme)} + title={theme.id} + /> + ); + })}
); -}; +}); + +ThemePicker.displayName = 'ThemePicker'; const value: ReportElements = [ { diff --git a/apps/web/src/components/ui/report/ReportEditor.tsx b/apps/web/src/components/ui/report/ReportEditor.tsx index 34c31b3e9..f661633b3 100644 --- a/apps/web/src/components/ui/report/ReportEditor.tsx +++ b/apps/web/src/components/ui/report/ReportEditor.tsx @@ -59,7 +59,7 @@ export const ReportEditor = React.memo( variant={variant} readonly={readOnly} disabled={disabled} - className={cn('pb-[20vh]', className)}> + className={cn('pb-[15vh]', className)}> diff --git a/apps/web/src/components/ui/report/ThemeWrapper/useThemesConfig.ts b/apps/web/src/components/ui/report/ThemeWrapper/useThemesConfig.ts index f1c4795b6..462ad85ca 100644 --- a/apps/web/src/components/ui/report/ThemeWrapper/useThemesConfig.ts +++ b/apps/web/src/components/ui/report/ThemeWrapper/useThemesConfig.ts @@ -13,5 +13,5 @@ export function useThemesConfig() { const activeTheme = useThemesConfigStore((state) => state.activeTheme); const setActiveTheme = useThemesConfigStore((state) => state.setActiveTheme); - return { activeTheme, setActiveTheme }; + return { activeTheme, setActiveTheme, allThemes: THEMES }; } diff --git a/apps/web/src/components/ui/toolbar/Toolbar.tsx b/apps/web/src/components/ui/toolbar/Toolbar.tsx index bd91ab2f1..baafbfd12 100644 --- a/apps/web/src/components/ui/toolbar/Toolbar.tsx +++ b/apps/web/src/components/ui/toolbar/Toolbar.tsx @@ -275,7 +275,7 @@ function withTooltip(Component: T) { tooltip, tooltipContentProps, tooltipProps, - tooltipTriggerProps, + ref, ...props }: TooltipProps) { const [mounted, setMounted] = React.useState(false); @@ -287,15 +287,7 @@ function withTooltip(Component: T) { const component = )} />; if (tooltip && mounted) { - return ( - - - {component} - - - {tooltip} - - ); + return {component}; } return component; diff --git a/apps/web/src/styles/tailwind.css b/apps/web/src/styles/tailwind.css index 5600536cc..d2d0177b9 100644 --- a/apps/web/src/styles/tailwind.css +++ b/apps/web/src/styles/tailwind.css @@ -2,6 +2,7 @@ @import './tailwindAnimations.css'; @plugin 'tailwind-scrollbar'; @plugin "tailwindcss-animate"; +@plugin 'tailwind-scrollbar-hide'; @custom-variant dark (&:where(.dark, .dark *));