-
Notifications
You must be signed in to change notification settings - Fork 78
feat(FR-1560): auto-dismiss running notification with timeout animation #4411
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: graphite-base/4411
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 |
|---|---|---|
|
|
@@ -3,16 +3,10 @@ import SessionStatusTag from './ComputeSessionNodeItems/SessionStatusTag'; | |
| import { useUpdateEffect } from 'ahooks'; | ||
| import { BAIFlex, BAILink, BAINotificationItem } from 'backend.ai-ui'; | ||
| import dayjs from 'dayjs'; | ||
| import React, { useEffect, useState } from 'react'; | ||
| import React, { useEffect, useEffectEvent } from 'react'; | ||
| import { useTranslation } from 'react-i18next'; | ||
| import { | ||
| fetchQuery, | ||
| graphql, | ||
| useFragment, | ||
| useRelayEnvironment, | ||
| } from 'react-relay'; | ||
| import { graphql, useRefetchableFragment } from 'react-relay'; | ||
| import { BAIComputeSessionNodeNotificationItemFragment$key } from 'src/__generated__/BAIComputeSessionNodeNotificationItemFragment.graphql'; | ||
| import { BAIComputeSessionNodeNotificationItemRefreshQuery } from 'src/__generated__/BAIComputeSessionNodeNotificationItemRefreshQuery.graphql'; | ||
| import { | ||
| NotificationState, | ||
| useSetBAINotification, | ||
|
|
@@ -27,11 +21,15 @@ interface BAINodeNotificationItemProps { | |
| const BAIComputeSessionNodeNotificationItem: React.FC< | ||
| BAINodeNotificationItemProps | ||
| > = ({ sessionFrgmt, showDate, notification }) => { | ||
| const { destroyNotification } = useSetBAINotification(); | ||
| 'use memo'; | ||
| const { destroyNotification, upsertNotification } = useSetBAINotification(); | ||
| const { t } = useTranslation(); | ||
| const node = useFragment( | ||
| const [node, refetch] = useRefetchableFragment( | ||
| graphql` | ||
| fragment BAIComputeSessionNodeNotificationItemFragment on ComputeSessionNode { | ||
| fragment BAIComputeSessionNodeNotificationItemFragment on ComputeSessionNode | ||
| @refetchable( | ||
| queryName: "BAIComputeSessionNodeNotificationItemFragment_RefetchQuery" | ||
| ) { | ||
| row_id | ||
| id | ||
| name | ||
|
|
@@ -43,23 +41,22 @@ const BAIComputeSessionNodeNotificationItem: React.FC< | |
| sessionFrgmt, | ||
| ); | ||
|
|
||
| // TODO: delete this when Status subscription is implemented | ||
| const [delay, setDelay] = useState<number | null>(null); | ||
| UNSAFE_useAutoRefreshInterval(node?.id || '', delay); | ||
| const closeNotificationWithProgress = useEffectEvent(() => { | ||
| if (notification.open) { | ||
| upsertNotification({ | ||
| key: notification.key, | ||
| pauseOnHover: true, | ||
| showProgress: true, | ||
| duration: 10, | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| if ( | ||
| !node?.status || | ||
| node?.status === 'TERMINATED' || | ||
| node?.status === 'CANCELLED' | ||
| ) { | ||
| setDelay(null); | ||
| } else if (node?.status === 'RUNNING') { | ||
| setDelay(15000); | ||
| } else { | ||
| setDelay(3000); | ||
| if (node?.status === 'RUNNING') { | ||
| closeNotificationWithProgress(); | ||
| } | ||
| }, [node?.status]); | ||
|
Comment on lines
55
to
59
|
||
| // --- | ||
|
|
||
| useUpdateEffect(() => { | ||
| if (node?.status === 'TERMINATED' || node?.status === 'CANCELLED') { | ||
|
|
@@ -69,6 +66,22 @@ const BAIComputeSessionNodeNotificationItem: React.FC< | |
| } | ||
| }, [node?.status]); | ||
|
|
||
| const delay = ['TERMINATED', 'CANCELLED', null, undefined].includes( | ||
| node?.status, | ||
| ) | ||
| ? null | ||
| : node?.status === 'RUNNING' | ||
| ? 15000 | ||
| : 3000; | ||
| useInterval(() => { | ||
| refetch( | ||
| {}, | ||
| { | ||
| fetchPolicy: 'store-and-network', | ||
| }, | ||
| ); | ||
| }, delay); | ||
|
|
||
| return ( | ||
| node && ( | ||
| <BAINotificationItem | ||
|
|
@@ -117,27 +130,3 @@ const BAIComputeSessionNodeNotificationItem: React.FC< | |
| }; | ||
|
|
||
| export default BAIComputeSessionNodeNotificationItem; | ||
|
|
||
| const UNSAFE_useAutoRefreshInterval = ( | ||
| sessionId: string, | ||
| delay: number | null, | ||
| ) => { | ||
| // const [delay, setDelay] = useState<number|null>(3000); | ||
| const relayEnv = useRelayEnvironment(); | ||
|
|
||
| useInterval(() => { | ||
| fetchQuery<BAIComputeSessionNodeNotificationItemRefreshQuery>( | ||
| relayEnv, | ||
| graphql` | ||
| query BAIComputeSessionNodeNotificationItemRefreshQuery( | ||
| $id: GlobalIDField! | ||
| ) { | ||
| compute_session_node(id: $id) { | ||
| ...BAINodeNotificationItemFragment | ||
| } | ||
| } | ||
| `, | ||
| { id: sessionId }, | ||
| ).toPromise(); | ||
| }, delay); | ||
| }; | ||
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.
Unknown directive: 'use memo'.