-
-
Notifications
You must be signed in to change notification settings - Fork 38
A failed Create call now switches to the page with an error #177
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
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 |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| } | ||
|
|
||
| .monitor-configure-page-button { | ||
| position: relative; | ||
| padding: 12px; | ||
| background-color: var(--accent-800); | ||
| border-radius: 8px; | ||
|
|
@@ -31,6 +32,17 @@ | |
| &:hover { | ||
| background-color: var(--accent-700); | ||
| } | ||
|
|
||
| &.error-circle::after { | ||
| content: ""; | ||
| position: absolute; | ||
| top: 40%; | ||
| right: 10px; | ||
| width: 10px; | ||
| height: 10px; | ||
| background-color: red; | ||
| border-radius: 50%; | ||
| } | ||
|
Comment on lines
+36
to
+45
Owner
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. Not now but moving this to an explanation mark or some sort of icon in the future |
||
| } | ||
|
|
||
| .monitor-configure-left-container { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,34 +24,71 @@ const useMonitorForm = ( | |
| values: Partial<MonitorProps> = defaultInputs, | ||
| isEdit: boolean = false, | ||
| closeModal: () => void, | ||
| setMonitor: (monitor: Partial<MonitorProps>) => void | ||
| setMonitor: (monitor: Partial<MonitorProps>) => void, | ||
| setPageId: (id: string) => void, | ||
| ) => { | ||
| const [inputs, setInput] = useState<Partial<MonitorProps>>({ | ||
| ...defaultInputs, | ||
| ...values, | ||
| }); | ||
| const [errors, setErrors] = useState({}); | ||
| const [errorPages, setErrorPages] = useState<Set<string>>(new Set()) | ||
|
|
||
| const handleInput = (name: string, value: any) => { | ||
| setInput((prev) => ({ ...prev, [name]: value })); | ||
| }; | ||
|
|
||
| const getPagesWithErrors = (errorsObj: Record<string,string>) => { | ||
|
|
||
| const associatedPage: Record<string, string> = { | ||
| 'name': "basic", | ||
| 'type': "basic", | ||
| 'url': "basic", | ||
| 'port': "basic", | ||
| 'icon': "basic", | ||
| 'method': "basic", | ||
| 'json_query': "basic", | ||
| 'interval': "interval", | ||
| 'retry': "interval", | ||
| 'retryInterval': "interval", | ||
| 'requestTimeout': "interval", | ||
| 'notificationType': "notification", | ||
| 'headers': "advanced", | ||
| 'body': "advanced", | ||
| 'valid_status_codes': "advanced", | ||
| } | ||
|
Comment on lines
+43
to
+59
Owner
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. Figuring out a way to create a consistent list between all input types so this doesn't need to be updated every time a new monitor type is created. |
||
| const pagesWithError = new Set<string>(); | ||
|
|
||
| Object.keys(errorsObj).forEach(error => { | ||
| const page = associatedPage[error] | ||
| if(error && page) pagesWithError.add(page) | ||
| }) | ||
|
|
||
| return pagesWithError | ||
| } | ||
|
|
||
|
|
||
| const handleActionButtons = (action: string) => () => { | ||
| switch (action) { | ||
| case 'Create': { | ||
| const type = inputs.type ?? defaultInputs.type; | ||
| const validator = monitorValidators[type]; | ||
| if (!validator) return console.log("Validator doesn't exist"); | ||
|
|
||
| const errorsObj = validator(inputs); | ||
| const errorsObj = validator(inputs) as Record<string, string> | false; | ||
|
|
||
| if (errorsObj !== false) { | ||
| const pagesWithErrors = getPagesWithErrors(errorsObj) | ||
| setErrorPages(pagesWithErrors); | ||
| setPageId(Array.from(pagesWithErrors)[0]) | ||
|
|
||
| if (errorsObj) { | ||
| setErrors(errorsObj); | ||
| setErrors(errorsObj); | ||
| break; | ||
| } | ||
|
|
||
| setErrorPages(new Set<string>()) | ||
| setErrors({}); | ||
|
|
||
| handleMonitor(inputs, isEdit, closeModal, setMonitor); | ||
| break; | ||
| } | ||
|
|
@@ -66,7 +103,7 @@ const useMonitorForm = ( | |
| } | ||
| }; | ||
|
|
||
| return { inputs, errors, handleActionButtons, handleInput }; | ||
| return { inputs, errors, handleActionButtons, handleInput, errorPages, setErrorPages }; | ||
| }; | ||
|
|
||
| export default useMonitorForm; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this to
classnamesto make it a bit easier to read