-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add external windonw button to record details modal
- Loading branch information
1 parent
cb56b58
commit ab80738
Showing
5 changed files
with
93 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,80 @@ | ||
import { Input, Group, Stack, TextInput } from "@mantine/core"; | ||
import { Input, Group, Stack, TextInput, Container, Title } from "@mantine/core"; | ||
|
||
import dayjs from "dayjs"; | ||
import { CodeEditor, ResizableModal } from "../../../components"; | ||
import { pretty } from "../../../helpers/json"; | ||
import { KafkaRecord } from "../../../models"; | ||
|
||
type RecordDetailsModalProps = { | ||
clusterId: string; | ||
topic: string; | ||
record: KafkaRecord; | ||
opened: boolean; | ||
onClose: () => void; | ||
}; | ||
|
||
export const RecordDetailsModal = (props: RecordDetailsModalProps) => { | ||
const { record, topic, opened, onClose } = props; | ||
const RecordDetailsForm = (props: RecordDetailsModalProps & { heightOffset: number }) => { | ||
const { record, topic, heightOffset } = props; | ||
const timestamp = record?.timestamp ? dayjs(record.timestamp).toISOString() : "N/A"; | ||
return ( | ||
<ResizableModal onClose={onClose} opened={opened} title={"Record details"}> | ||
<> | ||
<Stack spacing={3}> | ||
<Group grow position="apart"> | ||
<TextInput label="Topic name" value={topic} /> | ||
<TextInput label="Timestamp(UTC)" value={timestamp} /> | ||
<TextInput readOnly label="Topic name" value={topic} /> | ||
<TextInput readOnly label="Timestamp(UTC)" value={timestamp} /> | ||
</Group> | ||
<Group grow position="apart"> | ||
<TextInput label="Partition" value={record.partition} /> | ||
<TextInput label="Offset" value={record.offset} /> | ||
<TextInput readOnly label="Partition" value={record.partition} /> | ||
<TextInput readOnly label="Offset" value={record.offset} /> | ||
</Group> | ||
<TextInput label="Key" value={record.key} /> | ||
<TextInput readOnly label="Key" value={record.key} /> | ||
</Stack> | ||
<Input.Wrapper mt={3} style={{ height: "calc(100% - 210px)" }} label="Value"> | ||
<Input.Wrapper mt={3} style={{ height: `calc(100% - ${heightOffset}px)` }} label="Value"> | ||
<CodeEditor path={topic} language="json" height={"100%"} value={pretty(record.payload)} readOnly /> | ||
</Input.Wrapper> | ||
</> | ||
); | ||
}; | ||
export const RecordDetailsModal = (props: RecordDetailsModalProps) => { | ||
const { clusterId, record, topic, opened, onClose } = props; | ||
const id = recordId({ | ||
...record, | ||
topic, | ||
clusterId: "123", | ||
}); | ||
return ( | ||
<ResizableModal | ||
onClose={onClose} | ||
opened={opened} | ||
title={"Record details"} | ||
newWindowSettings={{ | ||
url: `/modal/cluster/${clusterId}/topic/${topic}/record/${id}`, | ||
windowTitle: `Record ${topic} ${record.key}`, | ||
beforeOpen: () => storeProps(id, props), | ||
}}> | ||
<RecordDetailsForm {...props} heightOffset={200} /> | ||
</ResizableModal> | ||
); | ||
}; | ||
|
||
export const RecordDetailsWindow = ({ id }: { id: string } & JSX.IntrinsicAttributes) => { | ||
const props = JSON.parse(localStorage.getItem(id) ?? "{}") as RecordDetailsModalProps; | ||
return ( | ||
<Container pt={10} px={20} style={{ height: "100%", maxWidth: "unset" }}> | ||
<Title mb={10} order={3}> | ||
Record details | ||
</Title> | ||
<RecordDetailsForm {...props} heightOffset={270} /> | ||
</Container> | ||
); | ||
}; | ||
|
||
const recordId = (props: { clusterId: string; topic: string; offset: number; partition: number }) => { | ||
const { clusterId, topic, offset, partition } = props; | ||
return `${clusterId}-${topic}-${partition}-${offset}`; | ||
}; | ||
|
||
const storeProps = (id: string, props: RecordDetailsModalProps): string => { | ||
localStorage.setItem(id, JSON.stringify(props)); | ||
return id; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters