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
Merge requests
!59
feat(alert): extra time for alerts and allow cancel operation by user click
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
feat(alert): extra time for alerts and allow cancel operation by user click
feat/alert_click
into
main
Overview
1
Commits
1
Pipelines
1
Changes
3
Merged
Leonardo Christino
requested to merge
feat/alert_click
into
main
1 year ago
Overview
1
Commits
1
Pipelines
1
Changes
3
Expand
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
53e431a6
1 commit,
1 year ago
3 files
+
61
−
41
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
libs/shared/lib/data-access/authorization/dashboardAlerts.tsx
+
46
−
20
Options
import
React
,
{
ReactNode
,
useEffect
,
useState
}
from
'
react
'
;
import
React
,
{
ReactNode
,
useEffect
,
useState
,
useImperativeHandle
,
useRef
}
from
'
react
'
;
import
Broker
from
'
@graphpolaris/shared/lib/data-access/socket/broker
'
;
import
{
useImmer
}
from
'
use-immer
'
;
import
CheckCircleOutlineIcon
from
'
@mui/icons-material/CheckCircleOutline
'
;
import
{
useAppDispatch
,
useConfig
}
from
'
../store
'
;
import
ErrorOutlineIcon
from
'
@mui/icons-material/ErrorOutline
'
;
import
{
removeLastError
,
removeLastWarning
}
from
'
../store/configSlice
'
;
import
{
includes
}
from
'
lodash-es
'
;
type
Message
=
{
message
:
ReactNode
;
@@ -12,32 +13,52 @@ type Message = {
};
export
const
DashboardAlerts
=
(
props
:
{
timer
?:
number
})
=>
{
const
[
messages
,
setMessages
]
=
useImmer
<
{
data
:
any
;
routingKey
:
string
;
message
:
Message
;
showing
:
boolean
}[]
>
([]);
const
timer
=
props
.
timer
||
12
00
;
const
[
messages
,
setMessages
]
=
useImmer
<
{
data
:
any
;
routingKey
:
string
;
message
:
Message
;
showing
:
boolean
;
key
:
string
}[]
>
([]);
const
timer
=
props
.
timer
||
40
00
;
const
config
=
useConfig
();
const
dispatch
=
useAppDispatch
();
const
ref
=
useRef
<
any
>
(
null
);
async
function
processMessage
(
message
:
Message
|
undefined
,
data
:
any
,
routingKey
:
string
)
{
// Queue the message to be shown for props.time time, then fade it out matching the animation of animate-closemenu fade out time
if
(
message
)
{
useImperativeHandle
(
ref
,
()
=>
({
onAdd
:
(
message
:
Message
,
data
:
any
,
routingKey
:
string
)
=>
{
let
newMessage
=
{
data
,
routingKey
,
message
:
message
as
Message
,
showing
:
true
,
key
:
`
${
Date
.
now
()}
-
${
Math
.
random
()}
`
};
setMessages
((
draft
)
=>
{
draft
.
unshift
(
newMessage
);
return
draft
;
});
return
newMessage
.
key
;
},
onTimeout
:
(
key
:
string
)
=>
{
setMessages
((
draft
)
=>
{
const
idx
=
draft
.
findIndex
((
m
)
=>
m
.
key
===
key
);
if
(
idx
===
-
1
)
return
draft
;
draft
.
splice
(
idx
,
1
);
return
draft
;
});
},
onShowTimeout
:
(
key
:
string
)
=>
{
setMessages
((
draft
)
=>
{
draft
.
unshift
({
data
,
routingKey
,
message
:
message
as
Message
,
showing
:
true
});
const
idx
=
draft
.
findIndex
((
m
)
=>
m
.
key
===
key
);
if
(
idx
===
-
1
)
return
draft
;
draft
[
idx
].
showing
=
false
;
return
draft
;
});
setTimeout
(()
=>
{
setMessages
((
draft
)
=>
{
draft
[
draft
.
length
-
1
].
showing
=
fals
e
;
// draft.pop();
return
draft
;
});
ref
.
current
.
onTimeout
(
key
);
return
tru
e
;
},
300
);
// matches the animation of animate-closemenu
},
})
)
;
setTimeout
(()
=>
{
setMessages
((
draft
)
=>
{
draft
.
pop
();
return
draft
;
});
return
true
;
},
300
);
// matches the animation of animate-closemenu
async
function
processMessage
(
message
:
Message
|
undefined
,
data
:
any
,
routingKey
:
string
)
{
// Queue the message to be shown for props.time time, then fade it out matching the animation of animate-closemenu fade out time
if
(
message
&&
ref
?.
current
)
{
const
key
=
ref
.
current
.
onAdd
(
message
,
data
,
routingKey
);
setTimeout
(()
=>
{
ref
.
current
.
onShowTimeout
(
key
);
return
true
;
},
timer
);
}
}
@@ -125,13 +146,18 @@ export const DashboardAlerts = (props: { timer?: number }) => {
<
div
key
=
{
i
}
className
=
{
`absolute bottom-5 right-5 w-fit min-w-[20rem] alert z-50 `
+
`absolute bottom-5 right-5 w-fit min-w-[20rem]
cursor-pointer
alert z-50 `
+
(
m
.
showing
?
'
animate-openmenu
'
:
'
animate-closemenu
'
)
+
(
m
.
message
?.
className
||
''
)
}
style
=
{
{
transform
:
`translateY(-
${
i
*
5
}
rem)`
,
}
}
onClick
=
{
(
e
)
=>
{
e
.
preventDefault
();
e
.
stopPropagation
();
ref
.
current
.
onShowTimeout
(
m
.
key
);
}
}
>
<
span
className
=
"flex flex-row content-center gap-3 text-white"
>
{
m
.
message
.
message
}
</
span
>
{
/* {!message && (m.data?.status ? m.data.status : m.routingKey)} */
}
Loading