mirror of
https://github.com/portainer/portainer.git
synced 2025-08-05 13:55:21 +02:00
feat(home): add connect and browse buttons [EE-4182] (#8175)
This commit is contained in:
parent
db9d87c918
commit
8936ae9b7a
16 changed files with 296 additions and 179 deletions
|
@ -3,6 +3,7 @@ import { useEffect } from 'react';
|
|||
import { X, Slash } from 'lucide-react';
|
||||
import clsx from 'clsx';
|
||||
import angular from 'angular';
|
||||
import { useStore } from 'zustand';
|
||||
|
||||
import {
|
||||
PlatformType,
|
||||
|
@ -11,9 +12,9 @@ import {
|
|||
} from '@/react/portainer/environments/types';
|
||||
import { getPlatformType } from '@/react/portainer/environments/utils';
|
||||
import { useEnvironment } from '@/react/portainer/environments/queries/useEnvironment';
|
||||
import { useLocalStorage } from '@/react/hooks/useLocalStorage';
|
||||
import { EndpointProviderInterface } from '@/portainer/services/endpointProvider';
|
||||
import { isBE } from '@/react/portainer/feature-flags/feature-flags.service';
|
||||
import { EndpointProviderInterface } from '@/portainer/services/endpointProvider';
|
||||
import { environmentStore } from '@/react/hooks/current-environment-store';
|
||||
|
||||
import { Icon } from '@@/Icon';
|
||||
|
||||
|
@ -98,35 +99,34 @@ function Content({ environment, onClear }: ContentProps) {
|
|||
function useCurrentEnvironment() {
|
||||
const { params } = useCurrentStateAndParams();
|
||||
const router = useRouter();
|
||||
const [environmentId, setEnvironmentId] = useLocalStorage<
|
||||
EnvironmentId | undefined
|
||||
>('environmentId', undefined, sessionStorage);
|
||||
|
||||
const envStore = useStore(environmentStore);
|
||||
const { setEnvironmentId } = envStore;
|
||||
useEffect(() => {
|
||||
const environmentId = parseInt(params.endpointId, 10);
|
||||
if (params.endpointId && !Number.isNaN(environmentId)) {
|
||||
setEnvironmentId(environmentId);
|
||||
}
|
||||
}, [params.endpointId, setEnvironmentId]);
|
||||
}, [setEnvironmentId, params.endpointId, params.environmentId]);
|
||||
|
||||
return { query: useEnvironment(environmentId), clearEnvironment };
|
||||
return { query: useEnvironment(envStore.environmentId), clearEnvironment };
|
||||
|
||||
function clearEnvironment() {
|
||||
const $injector = angular.element(document).injector();
|
||||
$injector.invoke(
|
||||
/* @ngInject */ (EndpointProvider: EndpointProviderInterface) => {
|
||||
EndpointProvider.setCurrentEndpoint(null);
|
||||
if (!params.endpointId) {
|
||||
if (!params.endpointId && !params.environmentId) {
|
||||
document.title = 'Portainer';
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (params.endpointId) {
|
||||
if (params.endpointId || params.environmentId) {
|
||||
router.stateService.go('portainer.home');
|
||||
}
|
||||
|
||||
setEnvironmentId(undefined);
|
||||
envStore.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue