feat(board): update widget preview to 5x3 and harden error boundaries
This commit is contained in:
1 file changed
+94
-39
@@ -652,19 +652,47 @@ const WidgetLivePreviewAndConfigPane = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<WidgetLivePreviewAndConfigContent
|
<ErrorBoundary
|
||||||
key={item.kind}
|
fallbackRender={({ resetErrorBoundary, error }) => (
|
||||||
item={item}
|
<Card withBorder radius="md" padding="md" h="100%" shadow="xs">
|
||||||
definition={resources.definition}
|
<Center h={320}>
|
||||||
Component={resources.Component}
|
<Stack align="center" gap="xs">
|
||||||
boardId={boardId}
|
<ThemeIcon size={40} radius="xl" color="red" variant="light">
|
||||||
integrationData={integrationData}
|
<IconApi size={24} />
|
||||||
canCreateIntegration={canCreateIntegration}
|
</ThemeIcon>
|
||||||
onClose={onClose}
|
<Text size="sm" fw={600} c="red">
|
||||||
onOpenConnectIntegration={onOpenConnectIntegration}
|
Failed to load widget preview
|
||||||
onAddWidget={onAddWidget}
|
</Text>
|
||||||
isAdding={isAdding}
|
<Text size="xs" c="dimmed" ta="center" maw={300}>
|
||||||
/>
|
{error instanceof Error ? error.message : String(error)}
|
||||||
|
</Text>
|
||||||
|
<Group gap="xs" mt="xs">
|
||||||
|
<Button size="xs" variant="light" onClick={resetErrorBoundary}>
|
||||||
|
Retry
|
||||||
|
</Button>
|
||||||
|
<Button size="xs" variant="subtle" onClick={onClose}>
|
||||||
|
Close
|
||||||
|
</Button>
|
||||||
|
</Group>
|
||||||
|
</Stack>
|
||||||
|
</Center>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<WidgetLivePreviewAndConfigContent
|
||||||
|
key={item.kind}
|
||||||
|
item={item}
|
||||||
|
definition={resources.definition}
|
||||||
|
Component={resources.Component}
|
||||||
|
boardId={boardId}
|
||||||
|
integrationData={integrationData}
|
||||||
|
canCreateIntegration={canCreateIntegration}
|
||||||
|
onClose={onClose}
|
||||||
|
onOpenConnectIntegration={onOpenConnectIntegration}
|
||||||
|
onAddWidget={onAddWidget}
|
||||||
|
isAdding={isAdding}
|
||||||
|
/>
|
||||||
|
</ErrorBoundary>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -759,8 +787,16 @@ const WidgetLivePreviewAndConfigContent = ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const previewIntegrationIds =
|
const validIntegrationIds = useMemo(() => {
|
||||||
form.values.integrationIds.length > 0 ? form.values.integrationIds : mockIntegration ? [mockIntegration.id] : [];
|
const compatibleIds = new Set(compatibleIntegrations.map((i) => i.id));
|
||||||
|
return form.values.integrationIds.filter((id) => compatibleIds.has(id));
|
||||||
|
}, [form.values.integrationIds, compatibleIntegrations]);
|
||||||
|
|
||||||
|
const previewIntegrationIds = useMemo(() => {
|
||||||
|
if (validIntegrationIds.length > 0) return validIntegrationIds;
|
||||||
|
if (supportsMock && mockIntegration) return [mockIntegration.id];
|
||||||
|
return [];
|
||||||
|
}, [validIntegrationIds, supportsMock, mockIntegration]);
|
||||||
|
|
||||||
const { mutateAsync: createMockIntegration, isPending: isCreatingMock } = clientApi.integration.create.useMutation({
|
const { mutateAsync: createMockIntegration, isPending: isCreatingMock } = clientApi.integration.create.useMutation({
|
||||||
async onSuccess(data) {
|
async onSuccess(data) {
|
||||||
@@ -862,7 +898,7 @@ const WidgetLivePreviewAndConfigContent = ({
|
|||||||
size="sm"
|
size="sm"
|
||||||
leftSection={<IconPlus size={16} />}
|
leftSection={<IconPlus size={16} />}
|
||||||
loading={isAdding}
|
loading={isAdding}
|
||||||
onClick={() => onAddWidget(form.values.options, form.values.integrationIds)}
|
onClick={() => onAddWidget(form.values.options, validIntegrationIds)}
|
||||||
>
|
>
|
||||||
{t("common.action.add")}
|
{t("common.action.add")}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -870,13 +906,13 @@ const WidgetLivePreviewAndConfigContent = ({
|
|||||||
</Group>
|
</Group>
|
||||||
</Group>
|
</Group>
|
||||||
|
|
||||||
{/* Live Widget Preview Frame (Simulating a 3x3 board widget tile) */}
|
{/* Live Widget Preview Frame (Simulating a 5x3 board widget tile) */}
|
||||||
<Box mb="md">
|
<Box mb="md">
|
||||||
<Group justify="space-between" align="center" mb={6}>
|
<Group justify="space-between" align="center" mb={6}>
|
||||||
<Text size="xs" fw={600} c="dimmed" tt="uppercase" lts="0.5px">
|
<Text size="xs" fw={600} c="dimmed" tt="uppercase" lts="0.5px">
|
||||||
Preview (3×3)
|
Preview (5×3)
|
||||||
</Text>
|
</Text>
|
||||||
{form.values.integrationIds.length === 0 && Boolean(mockIntegration) && hasIntegrationSupport && (
|
{validIntegrationIds.length === 0 && Boolean(mockIntegration) && supportsMock && (
|
||||||
<Badge variant="subtle" color="teal" size="xs">
|
<Badge variant="subtle" color="teal" size="xs">
|
||||||
Showing Demo / Mock Data
|
Showing Demo / Mock Data
|
||||||
</Badge>
|
</Badge>
|
||||||
@@ -892,8 +928,9 @@ const WidgetLivePreviewAndConfigContent = ({
|
|||||||
bg="light-dark(var(--mantine-color-body), var(--mantine-color-dark-7))"
|
bg="light-dark(var(--mantine-color-body), var(--mantine-color-dark-7))"
|
||||||
style={{
|
style={{
|
||||||
width: "100%",
|
width: "100%",
|
||||||
maxWidth: 360,
|
maxWidth: 500,
|
||||||
height: 360,
|
height: 300,
|
||||||
|
aspectRatio: "5 / 3",
|
||||||
overflow: "hidden",
|
overflow: "hidden",
|
||||||
position: "relative",
|
position: "relative",
|
||||||
containerType: "size",
|
containerType: "size",
|
||||||
@@ -918,8 +955,8 @@ const WidgetLivePreviewAndConfigContent = ({
|
|||||||
<Component
|
<Component
|
||||||
options={form.values.options as never}
|
options={form.values.options as never}
|
||||||
integrationIds={previewIntegrationIds}
|
integrationIds={previewIntegrationIds}
|
||||||
width={previewWidth || 360}
|
width={previewWidth || 500}
|
||||||
height={previewHeight || 360}
|
height={previewHeight || 300}
|
||||||
isEditMode={false}
|
isEditMode={false}
|
||||||
displayMode="compact"
|
displayMode="compact"
|
||||||
boardId={boardId}
|
boardId={boardId}
|
||||||
@@ -1234,22 +1271,40 @@ const ItemSelectModalFrame = ({
|
|||||||
}, [integrationData, canCreateIntegration, autoCreateMock]);
|
}, [integrationData, canCreateIntegration, autoCreateMock]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ItemSelectModalContent
|
<ErrorBoundary
|
||||||
actions={actions}
|
fallbackRender={({ resetErrorBoundary, error }) => (
|
||||||
integrationData={integrationData}
|
<Center p="xl">
|
||||||
customWidgetDefs={customWidgetDefs}
|
<Stack align="center" gap="sm">
|
||||||
ensureIntegrationDataAsync={() => utils.integration.all.ensureData()}
|
<Text size="sm" c="red" fw={600}>
|
||||||
isAdmin={isAdmin}
|
{t("common.error")}
|
||||||
canCreateIntegration={canCreateIntegration}
|
</Text>
|
||||||
initialWidgetKind={innerProps.initialWidgetKind}
|
<Text size="xs" c="dimmed">
|
||||||
initialSearch={
|
{error instanceof Error ? error.message : String(error)}
|
||||||
innerProps.initialWidgetKind
|
</Text>
|
||||||
? t(`widget.${innerProps.initialWidgetKind}.name`)
|
<Button size="xs" variant="light" onClick={resetErrorBoundary}>
|
||||||
: innerProps.initialIntegrationKind
|
{t("common.action.retry")}
|
||||||
? getIntegrationName(innerProps.initialIntegrationKind)
|
</Button>
|
||||||
: undefined
|
</Stack>
|
||||||
}
|
</Center>
|
||||||
/>
|
)}
|
||||||
|
>
|
||||||
|
<ItemSelectModalContent
|
||||||
|
actions={actions}
|
||||||
|
integrationData={integrationData}
|
||||||
|
customWidgetDefs={customWidgetDefs}
|
||||||
|
ensureIntegrationDataAsync={() => utils.integration.all.ensureData()}
|
||||||
|
isAdmin={isAdmin}
|
||||||
|
canCreateIntegration={canCreateIntegration}
|
||||||
|
initialWidgetKind={innerProps.initialWidgetKind}
|
||||||
|
initialSearch={
|
||||||
|
innerProps.initialWidgetKind
|
||||||
|
? t(`widget.${innerProps.initialWidgetKind}.name`)
|
||||||
|
: innerProps.initialIntegrationKind
|
||||||
|
? getIntegrationName(innerProps.initialIntegrationKind)
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</ErrorBoundary>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user