mirror of https://github.com/portainer/portainer
fix(sidebar): rework the update notification [EE-4119] (#7575)
parent
d24e5ff71e
commit
c79be58700
|
@ -5,6 +5,7 @@ import { useLocalStorage } from '@/portainer/hooks/useLocalStorage';
|
||||||
interface UIState {
|
interface UIState {
|
||||||
dismissedInfoPanels: Record<string, string>;
|
dismissedInfoPanels: Record<string, string>;
|
||||||
dismissedInfoHash: string;
|
dismissedInfoHash: string;
|
||||||
|
dismissedUpdateVersion: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
type UIStateService = [UIState, (state: UIState) => void];
|
type UIStateService = [UIState, (state: UIState) => void];
|
||||||
|
|
|
@ -26,6 +26,7 @@ function StateManagerFactory(
|
||||||
dismissedInfoPanels: {},
|
dismissedInfoPanels: {},
|
||||||
dismissedInfoHash: '',
|
dismissedInfoHash: '',
|
||||||
timesPasswordChangeSkipped: {},
|
timesPasswordChangeSkipped: {},
|
||||||
|
dismissedUpdateVersion: '',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,19 @@
|
||||||
.update-notification {
|
.root {
|
||||||
font-size: 14px;
|
|
||||||
padding: 12px;
|
padding: 12px;
|
||||||
border-radius: 2px;
|
margin-bottom: 20px;
|
||||||
background-color: #ff851b;
|
text-align: left;
|
||||||
margin-bottom: 5px;
|
}
|
||||||
|
|
||||||
|
.dismissTitle {
|
||||||
|
color: var(--white-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dismissBtn {
|
||||||
|
border: none;
|
||||||
|
background: none;
|
||||||
|
color: var(--text-muted-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.actions {
|
||||||
|
padding-left: 26px;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
import { useQuery } from 'react-query';
|
import { useQuery } from 'react-query';
|
||||||
|
import clsx from 'clsx';
|
||||||
|
|
||||||
import { getVersionStatus } from '@/portainer/services/api/status.service';
|
import { getVersionStatus } from '@/portainer/services/api/status.service';
|
||||||
|
import { useUIState } from '@/portainer/hooks/UIStateProvider';
|
||||||
|
|
||||||
|
import { Icon } from '@@/Icon';
|
||||||
|
|
||||||
import styles from './UpdateNotifications.module.css';
|
import styles from './UpdateNotifications.module.css';
|
||||||
|
|
||||||
export function UpdateNotification() {
|
export function UpdateNotification() {
|
||||||
|
const [uiState, setUIState] = useUIState();
|
||||||
const query = useUpdateNotification();
|
const query = useUpdateNotification();
|
||||||
|
|
||||||
if (!query.data || !query.data.UpdateAvailable) {
|
if (!query.data || !query.data.UpdateAvailable) {
|
||||||
|
@ -13,19 +18,56 @@ export function UpdateNotification() {
|
||||||
|
|
||||||
const { LatestVersion } = query.data;
|
const { LatestVersion } = query.data;
|
||||||
|
|
||||||
|
if (
|
||||||
|
uiState?.dismissedUpdateVersion?.length > 0 &&
|
||||||
|
LatestVersion?.length > 0 &&
|
||||||
|
uiState?.dismissedUpdateVersion === LatestVersion
|
||||||
|
) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.updateNotification}>
|
<div
|
||||||
<a
|
className={clsx(
|
||||||
target="_blank"
|
styles.root,
|
||||||
href={`https://github.com/portainer/portainer/releases/tag/${LatestVersion}`}
|
'rounded border py-2',
|
||||||
style={{ color: '#091e5d' }}
|
'bg-blue-11 th-dark:bg-gray-warm-11',
|
||||||
rel="noreferrer"
|
'border-blue-9 th-dark:border-gray-warm-9'
|
||||||
>
|
)}
|
||||||
<i className="fa-lg fas fa-cloud-download-alt space-right" />A new
|
>
|
||||||
version is available
|
<div className={clsx(styles.dismissTitle, 'vertical-center')}>
|
||||||
</a>
|
<Icon icon="download-cloud" mode="primary" feather size="md" />
|
||||||
|
<span className="space-left">
|
||||||
|
New version available {LatestVersion}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={clsx(styles.actions)}>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={clsx(styles.dismissBtn, 'space-right')}
|
||||||
|
onClick={() => onDismiss(LatestVersion)}
|
||||||
|
>
|
||||||
|
Dismiss
|
||||||
|
</button>
|
||||||
|
<a
|
||||||
|
className="hyperlink space-left"
|
||||||
|
target="_blank"
|
||||||
|
href={`https://github.com/portainer/portainer/releases/tag/${LatestVersion}`}
|
||||||
|
rel="noreferrer"
|
||||||
|
>
|
||||||
|
See what's new
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function onDismiss(version: string) {
|
||||||
|
setUIState({
|
||||||
|
...uiState,
|
||||||
|
dismissedUpdateVersion: version,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function useUpdateNotification() {
|
function useUpdateNotification() {
|
||||||
|
|
Loading…
Reference in New Issue