mirror of
https://github.com/portainer/portainer.git
synced 2025-08-05 05:45:22 +02:00
refactor(gitops): migrate git form to react [EE-4849] (#8268)
This commit is contained in:
parent
afe6cd6df0
commit
273a3f9a10
130 changed files with 3194 additions and 1190 deletions
|
@ -1,8 +1,8 @@
|
|||
import { useEnvironment } from '@/react/portainer/environments/queries/useEnvironment';
|
||||
import { useEnvironment } from '@/react/portainer/environments/queries';
|
||||
|
||||
import { useEnvironmentId } from './useEnvironmentId';
|
||||
|
||||
export function useCurrentEnvironment() {
|
||||
const id = useEnvironmentId();
|
||||
export function useCurrentEnvironment(force = true) {
|
||||
const id = useEnvironmentId(force);
|
||||
return useEnvironment(id);
|
||||
}
|
||||
|
|
|
@ -1,21 +1,22 @@
|
|||
import _ from 'lodash';
|
||||
import { useState, useRef, useCallback } from 'react';
|
||||
import { useState, useRef, useCallback, useEffect } from 'react';
|
||||
|
||||
export function useDebounce(
|
||||
defaultValue: string,
|
||||
onChange: (value: string) => void
|
||||
) {
|
||||
const [searchValue, setSearchValue] = useState(defaultValue);
|
||||
export function useDebounce(value: string, onChange: (value: string) => void) {
|
||||
const [debouncedValue, setDebouncedValue] = useState(value);
|
||||
|
||||
const onChangeDebounces = useRef(_.debounce(onChange, 300));
|
||||
|
||||
const handleChange = useCallback(
|
||||
(value: string) => {
|
||||
setSearchValue(value);
|
||||
setDebouncedValue(value);
|
||||
onChangeDebounces.current(value);
|
||||
},
|
||||
[onChangeDebounces, setSearchValue]
|
||||
[onChangeDebounces, setDebouncedValue]
|
||||
);
|
||||
|
||||
return [searchValue, handleChange] as const;
|
||||
useEffect(() => {
|
||||
setDebouncedValue(value);
|
||||
}, [value]);
|
||||
|
||||
return [debouncedValue, handleChange] as const;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,19 @@
|
|||
import { useCurrentStateAndParams } from '@uirouter/react';
|
||||
|
||||
export function useEnvironmentId() {
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
|
||||
export function useEnvironmentId(force = true): EnvironmentId {
|
||||
const {
|
||||
params: { endpointId: environmentId },
|
||||
} = useCurrentStateAndParams();
|
||||
|
||||
if (!environmentId) {
|
||||
if (!force) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
throw new Error('endpointId url param is required');
|
||||
}
|
||||
|
||||
return environmentId;
|
||||
return parseInt(environmentId, 10);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue