-
Notifications
You must be signed in to change notification settings - Fork 24
Refactor monitor UI components #522
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,8 @@ interface MonitorFormWizardProps { | |
| missingParamsMessage?: string | null; | ||
| backLabel?: string; | ||
| isTypeEditable?: boolean; | ||
| existingMonitorNames?: string[]; | ||
| editingMonitorName?: string; | ||
| } | ||
|
|
||
| export function MonitorFormWizard({ | ||
|
|
@@ -56,6 +58,8 @@ export function MonitorFormWizard({ | |
| missingParamsMessage, | ||
| backLabel = "Back to Monitors", | ||
| isTypeEditable = true, | ||
| existingMonitorNames = [], | ||
| editingMonitorName, | ||
| }: MonitorFormWizardProps) { | ||
| const [page, setPage] = useState<1 | 2>(1); | ||
| const [formData, setFormData] = | ||
|
|
@@ -100,12 +104,26 @@ export function MonitorFormWizard({ | |
| if (field === "displayName" || field === "name") { | ||
| const slugError = validateField("name", next.name, next); | ||
| setFieldError("name", slugError); | ||
|
|
||
| // Duplicate name check: exclude current monitor when editing | ||
| const namesToCheck = existingMonitorNames.filter( | ||
| (n) => n !== editingMonitorName, | ||
| ); | ||
| const isDuplicate = | ||
| next.name.trim().length >= 3 && | ||
| namesToCheck.includes(next.name.trim()); | ||
| if (isDuplicate) { | ||
| setFieldError( | ||
| "displayName", | ||
| "A monitor with this name already exists.", | ||
| ); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The duplicate-check here compares This means:
Should compare normalized Same issue applies to the submit-time check at lines ~212-223. |
||
| } | ||
|
|
||
| return next; | ||
| }); | ||
| }, | ||
| [setFieldError, validateField], | ||
| [setFieldError, validateField, existingMonitorNames, editingMonitorName], | ||
| ); | ||
|
|
||
| const handleToggleEvaluator = useCallback( | ||
|
|
@@ -191,8 +209,29 @@ export function MonitorFormWizard({ | |
| return; | ||
| } | ||
|
|
||
| // Duplicate name check on submit (exclude current monitor when editing) | ||
| const namesToCheck = existingMonitorNames.filter( | ||
| (n) => n !== editingMonitorName, | ||
| ); | ||
| if ( | ||
| formData.name.trim().length >= 3 && | ||
| namesToCheck.includes(formData.name.trim()) | ||
| ) { | ||
| setFieldError("displayName", "A monitor with this name already exists."); | ||
| setPage(1); | ||
| return; | ||
| } | ||
|
|
||
| onSubmit(formData); | ||
| }, [formData, missingParamsMessage, onSubmit, guardSubmit]); | ||
| }, [ | ||
| formData, | ||
| missingParamsMessage, | ||
| onSubmit, | ||
| guardSubmit, | ||
| existingMonitorNames, | ||
| editingMonitorName, | ||
| setFieldError, | ||
| ]); | ||
|
|
||
| const canAdvance = | ||
| formData.displayName.trim().length >= 3 && formData.name.trim().length >= 3; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ | |
|
|
||
| import { useCallback, type MouseEvent } from "react"; | ||
| import { CircularProgress, IconButton, Tooltip } from "@wso2/oxygen-ui"; | ||
| import { Calendar, Pause, Play } from "@wso2/oxygen-ui-icons-react"; | ||
| import { Pause, Play } from "@wso2/oxygen-ui-icons-react"; | ||
| import { | ||
| useStartMonitor, | ||
| useStopMonitor, | ||
|
|
@@ -98,13 +98,7 @@ export function MonitorStartStopButton({ | |
|
|
||
| if (isPastMonitor) { | ||
| return ( | ||
| <Tooltip title="Past monitors cannot be started"> | ||
| <span> | ||
| <IconButton disabled> | ||
| <Calendar size={16} /> | ||
| </IconButton> | ||
| </span> | ||
| </Tooltip> | ||
| null | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Since const tooltipTitle = isActive ? "Stop Monitor" : "Start Monitor";Also, the |
||
| ); | ||
| } | ||
| if (isStarting || isStopping) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.