9024 workflow test serverless function follow up (#9066)
- Fix Tablist style - Fix dropdown style (wrong grey background) - Update dropdown variable when no outputSchema is available https://github.com/user-attachments/assets/56698fe8-8dd3-404a-b2b2-f1eca6f5fa28
This commit is contained in:
@ -8,9 +8,15 @@ import {
|
||||
UpdateOneServerlessFunctionMutationVariables,
|
||||
UpdateServerlessFunctionInput,
|
||||
} from '~/generated-metadata/graphql';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { FIND_ONE_SERVERLESS_FUNCTION } from '@/settings/serverless-functions/graphql/queries/findOneServerlessFunction';
|
||||
import { sleep } from '~/utils/sleep';
|
||||
|
||||
export const useUpdateOneServerlessFunction = () => {
|
||||
export const useUpdateOneServerlessFunction = (
|
||||
serverlessFunctionId: string,
|
||||
) => {
|
||||
const apolloMetadataClient = useApolloMetadataClient();
|
||||
const [isReady, setIsReady] = useState(false);
|
||||
const [mutate] = useMutation<
|
||||
UpdateOneServerlessFunctionMutation,
|
||||
UpdateOneServerlessFunctionMutationVariables
|
||||
@ -19,18 +25,48 @@ export const useUpdateOneServerlessFunction = () => {
|
||||
});
|
||||
|
||||
const updateOneServerlessFunction = async (
|
||||
input: UpdateServerlessFunctionInput,
|
||||
input: Omit<UpdateServerlessFunctionInput, 'id'>,
|
||||
) => {
|
||||
return await mutate({
|
||||
const result = await mutate({
|
||||
variables: {
|
||||
input,
|
||||
input: { ...input, id: serverlessFunctionId },
|
||||
},
|
||||
awaitRefetchQueries: true,
|
||||
refetchQueries: [
|
||||
getOperationName(FIND_ONE_SERVERLESS_FUNCTION_SOURCE_CODE) ?? '',
|
||||
],
|
||||
});
|
||||
setIsReady(false);
|
||||
return result;
|
||||
};
|
||||
|
||||
return { updateOneServerlessFunction };
|
||||
useEffect(() => {
|
||||
let isMounted = true;
|
||||
|
||||
const pollFunctionStatus = async () => {
|
||||
while (isMounted && !isReady) {
|
||||
const { data } = await apolloMetadataClient.query({
|
||||
query: FIND_ONE_SERVERLESS_FUNCTION,
|
||||
variables: { input: { id: serverlessFunctionId } },
|
||||
fetchPolicy: 'network-only', // Always fetch fresh data
|
||||
});
|
||||
|
||||
const serverlessFunction = data?.findOneServerlessFunction;
|
||||
|
||||
if (serverlessFunction?.syncStatus === 'READY') {
|
||||
setIsReady(true);
|
||||
break;
|
||||
}
|
||||
await sleep(500);
|
||||
}
|
||||
};
|
||||
|
||||
pollFunctionStatus();
|
||||
|
||||
return () => {
|
||||
isMounted = false; // Cleanup when the component unmounts
|
||||
};
|
||||
}, [serverlessFunctionId, apolloMetadataClient, isReady]);
|
||||
|
||||
return { updateOneServerlessFunction, isReady };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user