-
Notifications
You must be signed in to change notification settings - Fork 901
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): New App Icon with refresher (#8382)
* feat(core): New App Icon with refresher * Use observable * feat(core): Update refresh tooltip text
- Loading branch information
1 parent
7ae702e
commit 162e6c0
Showing
6 changed files
with
127 additions
and
3 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
app/scripts/modules/core/src/application/ApplicationFreshIcon.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
|
||
import { Overridable } from '../overrideRegistry/Overridable'; | ||
|
||
import { Icon } from '../presentation'; | ||
|
||
@Overridable('applicationIcon') | ||
export class ApplicationFreshIcon extends React.Component<{}> { | ||
public render() { | ||
return <Icon name="spMenuAppInSync" size="small" appearance="light" />; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
app/scripts/modules/core/src/application/nav/AppRefresher.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
|
||
import { useObservable } from '../../presentation/hooks'; | ||
import { Application } from '../application.model'; | ||
import { IFetchStatus } from '../service/applicationDataSource'; | ||
|
||
import { AppRefresherIcon } from './AppRefresherIcon'; | ||
|
||
export interface IAppRefresherProps { | ||
app: Application; | ||
} | ||
|
||
export const AppRefresher = ({ app }: IAppRefresherProps) => { | ||
const [isRefreshing, setIsRefreshing] = React.useState(false); | ||
const [lastRefresh, setLastRefresh] = React.useState(0); | ||
|
||
const updateStatus = (fetchStatus: IFetchStatus): void => { | ||
if (fetchStatus.status === 'FETCHING') { | ||
setIsRefreshing(true); | ||
} else if (fetchStatus.status === 'FETCHED') { | ||
setIsRefreshing(false); | ||
setLastRefresh(fetchStatus.lastRefresh); | ||
} else { | ||
setIsRefreshing(false); | ||
} | ||
}; | ||
|
||
useObservable(app.status$, updateStatus); | ||
|
||
const handleRefresh = (): void => { | ||
app.refresh(true); | ||
}; | ||
|
||
return ( | ||
<AppRefresherIcon appName={app.name} lastRefresh={lastRefresh} refreshing={isRefreshing} refresh={handleRefresh} /> | ||
); | ||
}; |
63 changes: 63 additions & 0 deletions
63
app/scripts/modules/core/src/application/nav/AppRefresherIcon.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React from 'react'; | ||
import { $window } from 'ngimport'; | ||
|
||
import { ApplicationFreshIcon } from '../ApplicationFreshIcon'; | ||
import { SchedulerFactory } from 'core/scheduler'; | ||
import { Icon, Tooltip } from 'core/presentation'; | ||
import { relativeTime, timestamp } from 'core/utils/timeFormatters'; | ||
|
||
export interface IAppRefreshIconProps { | ||
appName: string; | ||
lastRefresh: number; | ||
refresh: () => void; | ||
refreshing: boolean; | ||
} | ||
|
||
export const AppRefresherIcon = ({ appName, lastRefresh, refresh, refreshing }: IAppRefreshIconProps) => { | ||
const activeRefresher = SchedulerFactory.createScheduler(2000); | ||
const [timeSinceRefresh, setTimeSinceRefresh] = React.useState(relativeTime(lastRefresh)); | ||
const [iconPulsing, setIconPulsing] = React.useState(false); | ||
|
||
React.useEffect(() => { | ||
activeRefresher.subscribe(() => { | ||
setTimeSinceRefresh(relativeTime(lastRefresh)); | ||
}); | ||
|
||
return () => activeRefresher.unsubscribe(); | ||
}, [lastRefresh]); | ||
|
||
const oldAge = 2 * 60 * 1000; // 2 minutes; | ||
const age = new Date().getTime() - lastRefresh; | ||
const isStale = age > oldAge; | ||
|
||
const refreshApp = () => { | ||
setIconPulsing(true); | ||
setTimeout(() => { | ||
setIconPulsing(false); | ||
}, 3000); | ||
refresh(); | ||
}; | ||
|
||
const RefresherTooltip = ( | ||
<span> | ||
<p> | ||
<strong>{appName}</strong> | ||
</p> | ||
<p>{`app data is ${refreshing ? 'refreshing' : 'up to date (click to refresh)'}`}</p> | ||
<p> | ||
Last refresh: {timestamp(lastRefresh)} <br /> {timeSinceRefresh} | ||
</p> | ||
<p>Note: Due to caching, data may be delayed up to 2 minutes</p> | ||
</span> | ||
); | ||
const isRefreshing = iconPulsing || refreshing; | ||
|
||
return ( | ||
<Tooltip template={RefresherTooltip} placement={$window.innerWidth < 1100 ? 'bottom' : 'right'}> | ||
<div className={`application-header-icon${isRefreshing ? ' header-icon-pulsing' : ''}`} onClick={refreshApp}> | ||
{!isStale && !isRefreshing && <ApplicationFreshIcon />} | ||
{(isStale || isRefreshing) && <Icon name="spMenuAppUnsynced" size="small" appearance="light" />} | ||
</div> | ||
</Tooltip> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters