Skip to content

Commit 50ec785

Browse files
committed
Migrate expanded message components to UI registry
Remove @redpanda-data/ui from the expanded-message chain: expanded-message, message-meta-data, payload-component, and troubleshoot-report-viewer now use registry components and Tailwind. Replace useToast with sonner and useColorModeValue with theme tokens.
1 parent c32443f commit 50ec785

4 files changed

Lines changed: 43 additions & 77 deletions

File tree

frontend/src/components/pages/topics/Tab.Messages/message-display/expanded-message.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* by the Apache License, Version 2.0
1010
*/
1111

12-
import { Box, Flex, useColorModeValue } from '@redpanda-data/ui';
1312
import React, { type FC, type ReactNode, useCallback } from 'react';
1413

1514
import { MessageHeaders } from './message-headers';
@@ -25,14 +24,14 @@ const ExpandedMessageFooter: FC<{ children?: ReactNode; onDownloadRecord?: () =>
2524
children,
2625
onDownloadRecord,
2726
}) => (
28-
<Flex gap={2} my={4} style={{ justifyContent: 'flex-end' }}>
27+
<div className="my-4 flex justify-end gap-2">
2928
{children}
3029
{Boolean(onDownloadRecord) && (
3130
<Button onClick={onDownloadRecord} variant="outline">
3231
Download Record
3332
</Button>
3433
)}
35-
</Flex>
34+
</div>
3635
);
3736

3837
type ExpandedMessageProps = {
@@ -57,7 +56,6 @@ export const ExpandedMessage: FC<ExpandedMessageProps> = React.memo(
5756
onCopyKey,
5857
onCopyValue,
5958
}) => {
60-
const bg = useColorModeValue('gray.50', 'gray.600');
6159
const handleLoadLargeMessage = useCallback(
6260
() =>
6361
onLoadLargeMessage && topicName !== undefined
@@ -80,7 +78,7 @@ export const ExpandedMessage: FC<ExpandedMessageProps> = React.memo(
8078
}, [msg, onCopyValue]);
8179

8280
return (
83-
<Box bg={bg} px={10} py={6}>
81+
<div className="bg-muted/30 px-10 py-6">
8482
<MessageMetaData msg={msg} />
8583
<Tabs defaultValue="value">
8684
<TabsList className="w-full" columns={3} layout="equal">
@@ -123,7 +121,7 @@ export const ExpandedMessage: FC<ExpandedMessageProps> = React.memo(
123121
) : null}
124122
</TabsContent>
125123
</Tabs>
126-
</Box>
124+
</div>
127125
);
128126
}
129127
);

frontend/src/components/pages/topics/Tab.Messages/message-display/message-meta-data.tsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
* by the Apache License, Version 2.0
1010
*/
1111

12-
import { Flex, Text } from '@redpanda-data/ui';
13-
import React from 'react';
12+
import type React from 'react';
1413

1514
import { MessageSchema } from './message-schema';
1615
import type { TopicMessage } from '../../../../../state/rest-interfaces';
1716
import { numberToThousandsString } from '../../../../../utils/tsx-utils';
1817
import { prettyBytes, titleCase } from '../../../../../utils/utils';
18+
import { Text } from '../../../../redpanda-ui/components/typography';
1919

2020
export const MessageMetaData = (props: { msg: TopicMessage }) => {
2121
const msg = props.msg;
@@ -36,17 +36,13 @@ export const MessageMetaData = (props: { msg: TopicMessage }) => {
3636
}
3737

3838
return (
39-
<Flex gap={10} my={6}>
39+
<div className="my-6 flex gap-10">
4040
{Object.entries(data).map(([k, v]) => (
41-
<Flex direction="column" key={k} rowGap=".4em">
42-
<Text fontSize="md" fontWeight="600">
43-
{k}
44-
</Text>
45-
<Text color="" fontSize="sm">
46-
{v}
47-
</Text>
48-
</Flex>
41+
<div className="flex flex-col gap-[0.4em]" key={k}>
42+
<Text className="font-semibold text-base">{k}</Text>
43+
<Text className="text-sm">{v}</Text>
44+
</div>
4945
))}
50-
</Flex>
46+
</div>
5147
);
5248
};

frontend/src/components/pages/topics/Tab.Messages/message-display/payload-component.tsx

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
* by the Apache License, Version 2.0
1010
*/
1111

12-
import { Button, Flex, useToast } from '@redpanda-data/ui';
1312
import type { ReactNode } from 'react';
1413
import { useMemo, useState } from 'react';
14+
import { toast } from 'sonner';
1515

1616
import type { Payload } from '../../../../../state/rest-interfaces';
1717
import { KowlJsonView } from '../../../../misc/kowl-json-view';
18+
import { Button } from '../../../../redpanda-ui/components/button';
1819
import { getControlCharacterName } from '../helpers';
1920

2021
// Regex for checking printable ASCII characters
@@ -64,6 +65,7 @@ type PayloadRenderData =
6465
| { type: 'json'; content: string | object | null | undefined }
6566
| { type: 'error'; content: string };
6667

68+
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: complex payload parsing
6769
function preparePayloadData(payload: Payload): PayloadRenderData {
6870
try {
6971
if (payload === null || payload === undefined || payload.payload === null || payload.payload === undefined) {
@@ -120,41 +122,33 @@ function preparePayloadData(payload: Payload): PayloadRenderData {
120122
}
121123
}
122124

123-
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: complex business logic
124125
export const PayloadComponent = (p: { payload: Payload; loadLargeMessage: () => Promise<void> }) => {
125126
const { payload, loadLargeMessage } = p;
126-
const toast = useToast();
127127
const [isLoadingLargeMessage, setLoadingLargeMessage] = useState(false);
128128
const renderData = useMemo(() => preparePayloadData(payload), [payload]);
129129

130130
if (payload.isPayloadTooLarge) {
131131
return (
132-
<Flex flexDirection="column" gap="4">
133-
<Flex alignItems="center" gap="2">
132+
<div className="flex flex-col gap-4">
133+
<div className="flex items-center gap-2">
134134
Because this message size exceeds the display limit, loading it could cause performance degradation.
135-
</Flex>
135+
</div>
136136
<Button
137+
className="w-40"
137138
data-testid="load-anyway-button"
138139
isLoading={isLoadingLargeMessage}
139-
loadingText="Loading..."
140140
onClick={() => {
141141
setLoadingLargeMessage(true);
142142
loadLargeMessage()
143-
.catch((err) =>
144-
toast({
145-
status: 'error',
146-
description: err instanceof Error ? err.message : String(err),
147-
})
148-
)
143+
.catch((err) => toast.error(err instanceof Error ? err.message : String(err)))
149144
.finally(() => setLoadingLargeMessage(false));
150145
}}
151-
size="small"
146+
size="sm"
152147
variant="outline"
153-
width="10rem"
154148
>
155149
Load anyway
156150
</Button>
157-
</Flex>
151+
</div>
158152
);
159153
}
160154

frontend/src/components/pages/topics/Tab.Messages/message-display/troubleshoot-report-viewer.tsx

Lines changed: 21 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
* by the Apache License, Version 2.0
1010
*/
1111

12-
import { Alert, AlertDescription, AlertIcon, AlertTitle, Box, Grid, GridItem, Heading } from '@redpanda-data/ui';
13-
import { useState } from 'react';
12+
import { AlertTriangle } from 'lucide-react';
13+
import { Fragment, useState } from 'react';
1414

1515
import type { Payload } from '../../../../../state/rest-interfaces';
16+
import { Alert, AlertDescription, AlertTitle } from '../../../../redpanda-ui/components/alert';
17+
import { Heading } from '../../../../redpanda-ui/components/typography';
1618

1719
export const TroubleshootReportViewer = (props: { payload: Payload }) => {
1820
const report = props.payload.troubleshootReport;
@@ -26,18 +28,11 @@ export const TroubleshootReportViewer = (props: { payload: Payload }) => {
2628
}
2729

2830
return (
29-
<Box mb="4" mt="4">
31+
<div className="my-4">
3032
<Heading as="h4">Deserialization Troubleshoot Report</Heading>
31-
<Alert background="red.50" flexDirection="column" my={4} status="error" variant="subtle">
32-
<AlertTitle
33-
alignItems="center"
34-
alignSelf="flex-start"
35-
display="flex"
36-
flexDirection="row"
37-
fontWeight="normal"
38-
pb="4"
39-
>
40-
<AlertIcon /> Errors were encountered when deserializing this message
33+
<Alert className="mt-4" icon={<AlertTriangle />} variant="destructive">
34+
<AlertTitle className="flex items-center font-normal [&]:line-clamp-none">
35+
Errors were encountered when deserializing this message
4136
<button
4237
className="cursor-pointer border-none bg-transparent pl-2 font-medium text-primary underline underline-offset-4"
4338
onClick={() => setShow(!show)}
@@ -46,36 +41,19 @@ export const TroubleshootReportViewer = (props: { payload: Payload }) => {
4641
{show ? 'Hide' : 'Show'}
4742
</button>
4843
</AlertTitle>
49-
<AlertDescription display={show ? undefined : 'none'} whiteSpace="pre-wrap">
50-
<Grid columnGap="4" rowGap="1" templateColumns="auto 1fr">
51-
{report.map((e) => (
52-
<>
53-
<GridItem
54-
fontWeight="bold"
55-
key={`${e.serdeName}-name`}
56-
pl="8"
57-
px="5"
58-
py="2"
59-
textTransform="capitalize"
60-
w="100%"
61-
>
62-
{e.serdeName}
63-
</GridItem>
64-
<GridItem
65-
background="red.100"
66-
fontFamily="monospace"
67-
key={`${e.serdeName}-message`}
68-
px="5"
69-
py="2"
70-
w="100%"
71-
>
72-
{e.message}
73-
</GridItem>
74-
</>
75-
))}
76-
</Grid>
77-
</AlertDescription>
44+
{show ? (
45+
<AlertDescription className="whitespace-pre-wrap">
46+
<div className="grid grid-cols-[auto_1fr] gap-x-4 gap-y-1">
47+
{report.map((e) => (
48+
<Fragment key={e.serdeName}>
49+
<div className="w-full px-5 py-2 pl-8 font-bold capitalize">{e.serdeName}</div>
50+
<div className="w-full bg-red-100 px-5 py-2 font-mono">{e.message}</div>
51+
</Fragment>
52+
))}
53+
</div>
54+
</AlertDescription>
55+
) : null}
7856
</Alert>
79-
</Box>
57+
</div>
8058
);
8159
};

0 commit comments

Comments
 (0)