mirror of
https://github.com/portainer/portainer.git
synced 2025-08-09 07:45:22 +02:00
Some checks are pending
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:s390x platform:linux version:]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
118 lines
3.5 KiB
TypeScript
118 lines
3.5 KiB
TypeScript
import { useStore } from 'zustand';
|
|
import { useCurrentStateAndParams, useRouter } from '@uirouter/react';
|
|
import { useEffect, useState } from 'react';
|
|
|
|
import { environmentStore } from '@/react/hooks/current-environment-store';
|
|
import { Environment } from '@/react/portainer/environments/types';
|
|
import { snapshotEndpoints } from '@/react/portainer/environments/environment.service';
|
|
import { isEdgeEnvironment } from '@/react/portainer/environments/utils';
|
|
import * as notifications from '@/portainer/services/notifications';
|
|
|
|
import { confirm } from '@@/modals/confirm';
|
|
import { PageHeader } from '@@/PageHeader';
|
|
import { ModalType } from '@@/modals';
|
|
import { buildConfirmButton } from '@@/modals/utils';
|
|
|
|
import { EnvironmentList } from './EnvironmentList';
|
|
import { EdgeLoadingSpinner } from './EdgeLoadingSpinner';
|
|
import { MotdPanel } from './MotdPanel';
|
|
import { LicenseNodePanel } from './LicenseNodePanel';
|
|
import { BackupFailedPanel } from './BackupFailedPanel';
|
|
|
|
export function HomeView() {
|
|
const { clear: clearStore } = useStore(environmentStore);
|
|
|
|
const { params } = useCurrentStateAndParams();
|
|
const [connectingToEdgeEndpoint, setConnectingToEdgeEndpoint] = useState(
|
|
!!params.redirect
|
|
);
|
|
|
|
const router = useRouter();
|
|
|
|
useEffect(() => {
|
|
async function redirect() {
|
|
const options = {
|
|
title: `Failed connecting to ${params.environmentName}`,
|
|
message: `There was an issue connecting to edge agent via tunnel. Click 'Retry' below to retry now, or wait 10 seconds to automatically retry.`,
|
|
confirmButton: buildConfirmButton('Retry', 'primary', 10),
|
|
modalType: ModalType.Destructive,
|
|
};
|
|
|
|
if (await confirm(options)) {
|
|
setConnectingToEdgeEndpoint(true);
|
|
router.stateService.go(params.route, {
|
|
endpointId: params.environmentId,
|
|
});
|
|
} else {
|
|
clearStore();
|
|
router.stateService.go(
|
|
'portainer.home',
|
|
{},
|
|
{ reload: true, inherit: false }
|
|
);
|
|
}
|
|
}
|
|
|
|
if (params.redirect) {
|
|
redirect();
|
|
}
|
|
}, [params, setConnectingToEdgeEndpoint, router, clearStore]);
|
|
|
|
return (
|
|
<>
|
|
<PageHeader
|
|
reload
|
|
title="Home"
|
|
breadcrumbs={[{ label: 'Environments' }]}
|
|
/>
|
|
|
|
{process.env.PORTAINER_EDITION !== 'CE' && <LicenseNodePanel />}
|
|
|
|
<MotdPanel />
|
|
|
|
{process.env.PORTAINER_EDITION !== 'CE' && <BackupFailedPanel />}
|
|
|
|
{connectingToEdgeEndpoint ? (
|
|
<EdgeLoadingSpinner />
|
|
) : (
|
|
<EnvironmentList
|
|
onClickBrowse={handleBrowseClick}
|
|
onRefresh={confirmTriggerSnapshot}
|
|
/>
|
|
)}
|
|
</>
|
|
);
|
|
|
|
async function confirmTriggerSnapshot() {
|
|
const result = await confirmEndpointSnapshot();
|
|
if (!result) {
|
|
return;
|
|
}
|
|
try {
|
|
await snapshotEndpoints();
|
|
notifications.success('Success', 'Environments updated');
|
|
router.stateService.reload();
|
|
} catch (err) {
|
|
notifications.error(
|
|
'Failure',
|
|
err as Error,
|
|
'An error occurred during environment snapshot'
|
|
);
|
|
}
|
|
}
|
|
|
|
function handleBrowseClick(environment: Environment) {
|
|
if (isEdgeEnvironment(environment.Type)) {
|
|
setConnectingToEdgeEndpoint(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
async function confirmEndpointSnapshot() {
|
|
return confirm({
|
|
title: 'Are you sure?',
|
|
modalType: ModalType.Warn,
|
|
message:
|
|
'Triggering a manual refresh will poll each environment to retrieve its information, this may take a few moments.',
|
|
});
|
|
}
|