Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
Frontend V2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GraphPolaris
Frontend V2
Commits
290b0200
Commit
290b0200
authored
2 months ago
by
Leonardo
Browse files
Options
Downloads
Patches
Plain Diff
chore: better error handling for errors on cron insight form
parent
a9e55864
No related branches found
Branches containing commit
Tags
v1.67.1
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lib/insight-sharing/FormInsight.tsx
+16
-14
16 additions, 14 deletions
src/lib/insight-sharing/FormInsight.tsx
with
16 additions
and
14 deletions
src/lib/insight-sharing/FormInsight.tsx
+
16
−
14
View file @
290b0200
...
...
@@ -13,8 +13,8 @@ type Props = {
handleSave
:
(
insight
:
InsightModel
,
generateEmail
:
boolean
)
=>
void
;
};
const
FrequencyOptions
=
[
'
Hourly
'
,
'
Daily
'
,
'
Specific Day of the Week
'
]
as const
;
const
FrequencyWeekDays
=
[
'
SUN
'
,
'
MON
'
,
'
TUE
'
,
'
WED
'
,
'
THU
'
,
'
FRI
'
,
'
SAT
'
]
as const
;
const
FrequencyOptions
=
[
'
Hourly
'
,
'
Daily
'
,
'
Specific Day of the Week
'
];
const
FrequencyWeekDays
=
[
'
SUN
'
,
'
MON
'
,
'
TUE
'
,
'
WED
'
,
'
THU
'
,
'
FRI
'
,
'
SAT
'
];
export
function
FormInsight
(
props
:
Props
)
{
const
dispatch
=
useAppDispatch
();
...
...
@@ -105,12 +105,9 @@ export function FormInsight(props: Props) {
props
.
handleSave
(
updatedInsight
,
generateEmail
);
};
const
generateCronExpression
=
(
frequency
:
(
typeof
FrequencyOptions
)[
number
],
minute
:
number
,
hour
:
number
,
dayOfWeek
?:
(
typeof
FrequencyWeekDays
)[
number
],
)
=>
{
const
generateCronExpression
=
(
frequency
:
string
,
minute
:
number
,
hour
:
number
,
dayOfWeek
?:
string
)
=>
{
setFrequency
({
frequency
,
minute
,
hour
,
dayOfWeek
});
let
cron
=
''
;
if
(
frequency
===
'
Hourly
'
)
{
...
...
@@ -123,7 +120,12 @@ export function FormInsight(props: Props) {
throw
new
Error
(
'
Invalid frequency
'
);
}
setFrequency
({
frequency
,
minute
,
hour
,
dayOfWeek
});
if
(
!
cron
||
cron
.
toLowerCase
().
includes
(
'
nan
'
))
{
console
.
error
(
'
Invalid cron expression
'
,
cron
,
frequency
,
minute
,
hour
,
dayOfWeek
);
// dispatch(addError('Invalid cron expression'));
return
;
}
setLocalInsight
({
...
localInsight
,
frequency
:
cron
});
};
...
...
@@ -133,7 +135,7 @@ export function FormInsight(props: Props) {
return
(
<
div
>
<
h2
className
=
"text-lg text-secondary-600 font-bold
"
>
<
h2
className
=
"text-lg text-secondary-600 font-bold"
>
{
capitalizeFirstLetter
(
props
.
insight
.
type
)
}
ID:
{
props
.
insight
.
id
}
</
h2
>
<
div
className
=
"p-2 flex flex-col gap-2"
>
...
...
@@ -288,8 +290,8 @@ export function FormInsight(props: Props) {
label
=
{
'
Frequency to trigger the
'
+
props
.
insight
.
type
}
type
=
"dropdown"
value
=
{
frequency
.
frequency
}
onChange
=
{
value
=>
generateCronExpression
(
String
(
value
)
as
any
,
frequency
.
minute
,
frequency
.
hour
,
frequency
.
dayOfWeek
)
}
options
=
{
FrequencyOptions
as
any
}
onChange
=
{
value
=>
generateCronExpression
(
value
as
string
,
frequency
.
minute
,
frequency
.
hour
,
frequency
.
dayOfWeek
)
}
options
=
{
FrequencyOptions
}
inline
=
{
false
}
size
=
"md"
info
=
{
'
Select the frequency to trigger the
'
+
props
.
insight
.
type
}
...
...
@@ -323,8 +325,8 @@ export function FormInsight(props: Props) {
label
=
"Day of Week"
type
=
"dropdown"
value
=
{
frequency
.
dayOfWeek
}
onChange
=
{
value
=>
generateCronExpression
(
frequency
.
frequency
,
frequency
.
minute
,
frequency
.
hour
,
String
(
value
)
as
any
)
}
options
=
{
FrequencyWeekDays
as
any
}
onChange
=
{
value
=>
generateCronExpression
(
frequency
.
frequency
,
frequency
.
minute
,
frequency
.
hour
,
value
as
string
)
}
options
=
{
FrequencyWeekDays
}
inline
=
{
false
}
size
=
"md"
info
=
{
'
Select the day of the week to trigger the
'
+
props
.
insight
.
type
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment