-
Notifications
You must be signed in to change notification settings - Fork 202
Add UI SQS message send/list/delete features #1140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tuliocll
wants to merge
3
commits into
softwaremill:master
Choose a base branch
from
tuliocll:new/create-and-view-messages
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,14 +1,15 @@ | ||
| import React from "react"; | ||
| import NavBar from "../NavBar/NavBar"; | ||
| import QueuesTable from "../Queues/QueuesTable"; | ||
| import { SnackbarProvider } from "notistack"; | ||
|
|
||
| const Main: React.FC = () => { | ||
| return ( | ||
| <> | ||
| <NavBar/> | ||
| <QueuesTable/> | ||
| </> | ||
| ); | ||
| return ( | ||
| <SnackbarProvider maxSnack={3}> | ||
| <NavBar /> | ||
| <QueuesTable /> | ||
| </SnackbarProvider> | ||
| ); | ||
| }; | ||
|
|
||
| export default Main; | ||
| export default Main; |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import React, { useState } from "react"; | ||
| import { | ||
| Dialog, | ||
| DialogActions, | ||
| DialogContent, | ||
| DialogTitle, | ||
| TextField, | ||
| Button, | ||
| } from "@material-ui/core"; | ||
| import { useSnackbar } from "notistack"; | ||
|
|
||
| import QueueService from "../services/QueueService"; | ||
|
|
||
| interface NewMessageModalProps { | ||
| open: boolean; | ||
| onClose: () => void; | ||
| queueName: string; | ||
| } | ||
|
|
||
| const NewMessageModal: React.FC<NewMessageModalProps> = ({ | ||
| open, | ||
| onClose, | ||
| queueName, | ||
| }) => { | ||
| const [messageBody, setMessageBody] = useState(""); | ||
| const [loading, setLoading] = useState(false); | ||
| const { enqueueSnackbar } = useSnackbar(); | ||
|
|
||
| const handleSendMessage = async () => { | ||
| if (!messageBody.trim()) { | ||
| enqueueSnackbar("Message body cannot be empty", { | ||
| variant: "error", | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| setLoading(true); | ||
| try { | ||
| await QueueService.sendMessage(queueName, messageBody); | ||
| enqueueSnackbar("Message sent successfully!", { | ||
| variant: "success", | ||
| }); | ||
| setMessageBody(""); | ||
| onClose(); | ||
| } catch (error) { | ||
| enqueueSnackbar("Failed to send message", { | ||
tuliocll marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| variant: "error", | ||
| }); | ||
| console.error("Error sending message:", error); | ||
| } finally { | ||
| setLoading(false); | ||
| } | ||
| }; | ||
|
|
||
| const handleClose = () => { | ||
| setMessageBody(""); | ||
| onClose(); | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
tuliocll marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <Dialog open={open} onClose={handleClose} maxWidth="md" fullWidth> | ||
| <DialogTitle>New Message - {queueName}</DialogTitle> | ||
| <DialogContent> | ||
| <TextField | ||
| autoFocus | ||
| margin="dense" | ||
| label="Message Body" | ||
| type="text" | ||
| fullWidth | ||
| multiline | ||
| rows={6} | ||
| variant="outlined" | ||
| value={messageBody} | ||
| onChange={(e) => setMessageBody(e.target.value)} | ||
| placeholder="Enter your message body here..." | ||
| /> | ||
| </DialogContent> | ||
| <DialogActions> | ||
| <Button onClick={handleClose} color="secondary"> | ||
| Cancel | ||
| </Button> | ||
| <Button | ||
| onClick={handleSendMessage} | ||
| color="primary" | ||
| variant="contained" | ||
| disabled={loading} | ||
| > | ||
| {loading ? "Sending..." : "Send"} | ||
| </Button> | ||
| </DialogActions> | ||
| </Dialog> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export default NewMessageModal; | ||
This file contains hidden or 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,25 +1,43 @@ | ||
| interface QueueMessagesData { | ||
| queueName: string; | ||
| currentMessagesNumber: number; | ||
| delayedMessagesNumber: number; | ||
| notVisibleMessagesNumber: number; | ||
| isOpened: boolean | ||
| queueName: string; | ||
| currentMessagesNumber: number; | ||
| delayedMessagesNumber: number; | ||
| notVisibleMessagesNumber: number; | ||
| isOpened: boolean; | ||
| messages?: QueueMessage[]; | ||
| messagesLoading?: boolean; | ||
| messagesError?: string | null; | ||
| } | ||
|
|
||
| interface QueueStatistic { | ||
| name: string; | ||
| statistics: Statistics; | ||
| name: string; | ||
| statistics: Statistics; | ||
| } | ||
|
|
||
| interface Statistics { | ||
| approximateNumberOfVisibleMessages: number; | ||
| approximateNumberOfMessagesDelayed: number; | ||
| approximateNumberOfInvisibleMessages: number; | ||
| approximateNumberOfVisibleMessages: number; | ||
| approximateNumberOfMessagesDelayed: number; | ||
| approximateNumberOfInvisibleMessages: number; | ||
| } | ||
|
|
||
| interface QueueRedrivePolicyAttribute { | ||
| deadLetterTargetArn: string, | ||
| maxReceiveCount: number | ||
| deadLetterTargetArn: string; | ||
| maxReceiveCount: number; | ||
| } | ||
|
|
||
| export type {QueueMessagesData, QueueStatistic, QueueRedrivePolicyAttribute} | ||
| interface QueueMessage { | ||
| messageId: string; | ||
| body: string; | ||
| sentTimestamp: string; | ||
| receiptHandle?: string; | ||
| attributes?: { [key: string]: string }; | ||
| messageAttributes?: { [key: string]: any }; | ||
tuliocll marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| isExpanded?: boolean; | ||
| } | ||
|
|
||
| export type { | ||
| QueueMessagesData, | ||
| QueueStatistic, | ||
| QueueRedrivePolicyAttribute, | ||
| QueueMessage, | ||
| }; | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| import React from "react"; | ||
| import { render, screen } from "@testing-library/react"; | ||
| import QueueMessagesList from "./QueueMessagesList"; | ||
| import { QueueMessage } from "./QueueMessageData"; | ||
|
|
||
| const mockUpdateMessageExpandedState = jest.fn(); | ||
|
|
||
| describe("<QueueMessagesList /> - New Features", () => { | ||
| describe("HTML Entity Decoding (New Feature)", () => { | ||
| test("decodes HTML entities in message body preview", () => { | ||
| const messageWithEntities: QueueMessage[] = [ | ||
| { | ||
| messageId: "msg-html-entities", | ||
| body: ""organizationId":"test"", | ||
| sentTimestamp: "1609459200000", | ||
| }, | ||
| ]; | ||
|
|
||
| render( | ||
| <QueueMessagesList | ||
| queueName="test-queue" | ||
| messages={messageWithEntities} | ||
| loading={false} | ||
| error={null} | ||
| updateMessageExpandedState={mockUpdateMessageExpandedState} | ||
| /> | ||
| ); | ||
|
|
||
| // Should display decoded version in preview | ||
| expect(screen.getByText('"organizationId":"test"')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test("decodes HTML entities in full message body when expanded", () => { | ||
| const messageWithEntities: QueueMessage[] = [ | ||
| { | ||
| messageId: "msg-html-entities", | ||
| body: ""data":"value"&<test>", | ||
| sentTimestamp: "1609459200000", | ||
| }, | ||
| ]; | ||
|
|
||
| render( | ||
| <QueueMessagesList | ||
| queueName="test-queue" | ||
| messages={messageWithEntities} | ||
| loading={false} | ||
| error={null} | ||
| updateMessageExpandedState={mockUpdateMessageExpandedState} | ||
| /> | ||
| ); | ||
|
|
||
| // Should display decoded version in preview (truncated) | ||
| expect(screen.getByText('"data":"value"&<test>')).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("Props-based State Management (New Feature)", () => { | ||
| test("uses messages from props when provided", () => { | ||
| const propsMessages: QueueMessage[] = [ | ||
| { | ||
| messageId: "props-msg-1", | ||
| body: "Message from props", | ||
| sentTimestamp: "1609459200000", | ||
| }, | ||
| ]; | ||
|
|
||
| render( | ||
| <QueueMessagesList | ||
| queueName="test-queue" | ||
| messages={propsMessages} | ||
| loading={false} | ||
| error={null} | ||
| updateMessageExpandedState={mockUpdateMessageExpandedState} | ||
| /> | ||
| ); | ||
|
|
||
| expect(screen.getByText("Messages (1)")).toBeInTheDocument(); | ||
| expect(screen.getByText("Message from props")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test("shows loading state from props", () => { | ||
| render( | ||
| <QueueMessagesList | ||
| queueName="test-queue" | ||
| messages={[]} | ||
| loading={true} | ||
| error={null} | ||
| updateMessageExpandedState={mockUpdateMessageExpandedState} | ||
| /> | ||
| ); | ||
|
|
||
| expect(screen.getByText("Loading...")).toBeInTheDocument(); | ||
| expect(screen.getByRole("progressbar")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test("shows error state from props", () => { | ||
| const errorMessage = "Failed to fetch messages from parent"; | ||
| render( | ||
| <QueueMessagesList | ||
| queueName="test-queue" | ||
| messages={[]} | ||
| loading={false} | ||
| error={errorMessage} | ||
| updateMessageExpandedState={mockUpdateMessageExpandedState} | ||
| /> | ||
| ); | ||
|
|
||
| expect(screen.getByText(errorMessage)).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.