fix: resolver avisos de build e tipagem
This commit is contained in:
parent
741f1d7f9c
commit
fa9efdb5af
7 changed files with 154 additions and 59 deletions
|
|
@ -150,6 +150,14 @@ type PackedLayoutItem = LayoutStateItem & {
|
|||
y: number
|
||||
}
|
||||
|
||||
type CanvasRenderableItem = {
|
||||
key: string
|
||||
layout: PackedLayoutItem
|
||||
minW?: number
|
||||
minH?: number
|
||||
element: React.ReactNode
|
||||
}
|
||||
|
||||
type DashboardDetailResult = {
|
||||
dashboard: DashboardRecord
|
||||
widgets: DashboardWidgetRecord[]
|
||||
|
|
@ -542,8 +550,6 @@ export function DashboardBuilder({ dashboardId, editable = true, mode = "edit" }
|
|||
return {
|
||||
key: item.i,
|
||||
layout: item,
|
||||
minW: item.minW,
|
||||
minH: item.minH,
|
||||
element: (
|
||||
<BuilderWidgetCard
|
||||
key={widget.widgetKey}
|
||||
|
|
@ -561,9 +567,11 @@ export function DashboardBuilder({ dashboardId, editable = true, mode = "edit" }
|
|||
onReadyChange={(ready) => handleWidgetReady(widget.widgetKey, ready)}
|
||||
/>
|
||||
),
|
||||
}
|
||||
...(item.minW !== undefined ? { minW: item.minW } : {}),
|
||||
...(item.minH !== undefined ? { minH: item.minH } : {}),
|
||||
} satisfies CanvasRenderableItem
|
||||
})
|
||||
.filter((item): item is { key: string; layout: PackedLayoutItem; minW?: number; minH?: number; element: React.ReactNode } => Boolean(item))
|
||||
.filter(Boolean) as CanvasRenderableItem[]
|
||||
|
||||
const allWidgetsReady = canvasItems.length > 0 && canvasItems.every((item) => readyWidgets.has(item.key))
|
||||
|
||||
|
|
@ -1177,34 +1185,37 @@ function WidgetConfigDialog({
|
|||
widget: DashboardWidgetRecord | null
|
||||
onSubmit: (values: WidgetConfigFormValues) => Promise<void>
|
||||
}) {
|
||||
const normalizedConfig = getWidgetConfigForWidget(widget)
|
||||
const form = useForm<WidgetConfigFormValues>({
|
||||
resolver: zodResolver(widgetConfigSchema),
|
||||
defaultValues: {
|
||||
title: widget?.title ?? widget?.config?.title ?? "",
|
||||
type: widget?.type ?? "kpi",
|
||||
metricKey: widget?.config?.dataSource?.metricKey ?? "",
|
||||
stacked: Boolean((widget?.config as { encoding?: { stacked?: boolean } })?.encoding?.stacked ?? false),
|
||||
legend: Boolean((widget?.config as { options?: { legend?: boolean } })?.options?.legend ?? true),
|
||||
rangeOverride: typeof (widget?.config as { dataSource?: { params?: Record<string, unknown> } })?.dataSource?.params?.range === "string"
|
||||
? ((widget?.config as { dataSource?: { params?: Record<string, unknown> } })?.dataSource?.params?.range as string)
|
||||
: "",
|
||||
showTooltip: Boolean((widget?.config as { options?: { tooltip?: boolean } })?.options?.tooltip ?? true),
|
||||
title: normalizedConfig?.title ?? widget?.title ?? "",
|
||||
type: normalizedConfig?.type ?? widget?.type ?? "kpi",
|
||||
metricKey: normalizedConfig?.dataSource?.metricKey ?? "",
|
||||
stacked: Boolean(normalizedConfig?.encoding && "stacked" in normalizedConfig.encoding ? normalizedConfig.encoding.stacked : false),
|
||||
legend: Boolean(normalizedConfig?.options && "legend" in normalizedConfig.options ? normalizedConfig.options.legend : true),
|
||||
rangeOverride:
|
||||
typeof normalizedConfig?.dataSource?.params?.range === "string"
|
||||
? (normalizedConfig.dataSource?.params?.range as string)
|
||||
: "",
|
||||
showTooltip: Boolean(normalizedConfig?.options && "tooltip" in normalizedConfig.options ? normalizedConfig.options.tooltip : true),
|
||||
},
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (!widget) return
|
||||
const config = getWidgetConfigForWidget(widget)
|
||||
form.reset({
|
||||
title: widget.title ?? (widget.config as { title?: string })?.title ?? "",
|
||||
type: widget.type,
|
||||
metricKey: (widget.config as { dataSource?: { metricKey?: string } })?.dataSource?.metricKey ?? "",
|
||||
stacked: Boolean((widget.config as { encoding?: { stacked?: boolean } })?.encoding?.stacked ?? false),
|
||||
legend: Boolean((widget.config as { options?: { legend?: boolean } })?.options?.legend ?? true),
|
||||
title: config?.title ?? widget.title ?? "",
|
||||
type: config?.type ?? widget.type,
|
||||
metricKey: config?.dataSource?.metricKey ?? "",
|
||||
stacked: Boolean(config?.encoding && "stacked" in config.encoding ? config.encoding.stacked : false),
|
||||
legend: Boolean(config?.options && "legend" in config.options ? config.options.legend : true),
|
||||
rangeOverride:
|
||||
typeof (widget.config as { dataSource?: { params?: Record<string, unknown> } })?.dataSource?.params?.range === "string"
|
||||
? ((widget.config as { dataSource?: { params?: Record<string, unknown> } })?.dataSource?.params?.range as string)
|
||||
typeof config?.dataSource?.params?.range === "string"
|
||||
? (config.dataSource?.params?.range as string)
|
||||
: "",
|
||||
showTooltip: Boolean((widget.config as { options?: { tooltip?: boolean } })?.options?.tooltip ?? true),
|
||||
showTooltip: Boolean(config?.options && "tooltip" in config.options ? config.options.tooltip : true),
|
||||
})
|
||||
}, [widget, form])
|
||||
|
||||
|
|
@ -1249,19 +1260,19 @@ function WidgetConfigDialog({
|
|||
<SwitchField
|
||||
label="Legend"
|
||||
description="Mostra a legenda na visualização."
|
||||
checked={form.watch("legend")}
|
||||
checked={Boolean(form.watch("legend"))}
|
||||
onCheckedChange={(checked) => form.setValue("legend", checked)}
|
||||
/>
|
||||
<SwitchField
|
||||
label="Stacked"
|
||||
description="Acumula as séries no eixo Y."
|
||||
checked={form.watch("stacked")}
|
||||
checked={Boolean(form.watch("stacked"))}
|
||||
onCheckedChange={(checked) => form.setValue("stacked", checked)}
|
||||
/>
|
||||
<SwitchField
|
||||
label="Tooltip"
|
||||
description="Mantém o tooltip interativo."
|
||||
checked={form.watch("showTooltip")}
|
||||
checked={Boolean(form.watch("showTooltip"))}
|
||||
onCheckedChange={(checked) => form.setValue("showTooltip", checked)}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue