mirror of
https://github.com/portainer/portainer.git
synced 2025-07-23 07:19:41 +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
27
app/react/components/form-components/useCachedTest.ts
Normal file
27
app/react/components/form-components/useCachedTest.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
import { useRef } from 'react';
|
||||
import { TestContext, TestFunction } from 'yup';
|
||||
|
||||
function cacheTest<T, TContext>(
|
||||
asyncValidate: TestFunction<T, TContext>
|
||||
): TestFunction<T, TContext> {
|
||||
let valid = true;
|
||||
let value: T | undefined;
|
||||
|
||||
return async (newValue: T, context: TestContext<TContext>) => {
|
||||
if (newValue !== value) {
|
||||
value = newValue;
|
||||
|
||||
const response = await asyncValidate.call(context, newValue, context);
|
||||
valid = !!response;
|
||||
}
|
||||
return valid;
|
||||
};
|
||||
}
|
||||
|
||||
export function useCachedValidation<T, TContext>(
|
||||
test: TestFunction<T, TContext>
|
||||
) {
|
||||
const ref = useRef(cacheTest(test));
|
||||
|
||||
return ref.current;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue