Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit AI Retries #562

Merged
merged 10 commits into from
May 22, 2024
13 changes: 11 additions & 2 deletions src/OnboardingSPA/components/ErrorState/Step/SiteGen/index.js
officiallygod marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// WordPress
import { useViewportMatch } from '@wordpress/compose';
import { useEffect } from '@wordpress/element';
import { useState, useEffect } from '@wordpress/element';
import { useSelect, useDispatch } from '@wordpress/data';
import { Button, Fill } from '@wordpress/components';

Expand All @@ -27,10 +27,12 @@
HEADER_SITEGEN,
pluginDashboardPage,
} from '../../../../../constants';
import { setFlow } from '../../../../utils/api/flow';

const SiteGenStepErrorState = () => {
const navigate = useNavigate();
const isLargeViewport = useViewportMatch( 'small' );
const [ disableRetry, setDisableRetry ] = useState( false );

const {
setIsHeaderEnabled,
Expand All @@ -55,7 +57,11 @@
setIsHeaderNavigationEnabled( true );
setDrawerActiveView( false );
setSidebarActiveView( false );
setDisableRetry(
currentData.sitegen?.siteGenErrorMeta?.retryCount >
currentData.sitegen?.siteGenErrorMeta?.maxRetryCount
);
officiallygod marked this conversation as resolved.
Show resolved Hide resolved
}, [] );

Check warning on line 64 in src/OnboardingSPA/components/ErrorState/Step/SiteGen/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'currentData.sitegen?.siteGenErrorMeta?.maxRetryCount', 'currentData.sitegen?.siteGenErrorMeta?.retryCount', 'setDrawerActiveView', 'setHeaderActiveView', 'setHideFooterNav', 'setIsHeaderEnabled', 'setIsHeaderNavigationEnabled', and 'setSidebarActiveView'. Either include them or remove the dependency array

const { brandConfig, currentData, currentStep, previousStep, allSteps } =
useSelect( ( select ) => {
Expand Down Expand Up @@ -100,8 +106,9 @@
navigate( data.steps[ 1 ].path );
};

const handleRetry = () => {
const handleRetry = async () => {
updateSiteGenErrorStatus( false );
await setFlow( currentData );
};

const handleGoBack = () => {
Expand Down Expand Up @@ -186,6 +193,7 @@
onClick={ () => {
handleRetry();
} }
disabled={ true === disableRetry }
>
<p className="nfd-onboarding-button--site-gen-next--text">
{ content.buttonText }
Expand All @@ -200,6 +208,7 @@
onClick={ () => {
handleRetry();
} }
disabled={ true === disableRetry }
>
<p className="nfd-onboarding-button--site-gen-next--text">
{ content.buttonText }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
initializeThemes();
initializeSettings();
getEditedEntityRecord( 'root', 'site' );
}, [] );

Check warning on line 106 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has a missing dependency: 'getEditedEntityRecord'. Either include it or remove the dependency array

useEffect( () => {
document.body.classList.add( `nfd-brand-${ newfoldBrand }` );
Expand All @@ -111,20 +111,20 @@

useEffect( () => {
trackChapters();
}, [ currentStep ] );

Check warning on line 114 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has a missing dependency: 'trackChapters'. Either include it or remove the dependency array

useEffect( () => {
if ( initialize ) {
initializePlugins( pluginInstallHash );
setInterval( cronTrigger, 45000 );
}
}, [ initialize ] );

Check warning on line 121 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has a missing dependency: 'pluginInstallHash'. Either include it or remove the dependency array

useEffect( () => {
syncStoreToDB();
generateSiteGenData();
handlePreviousStepTracking();
}, [ location.pathname ] );

Check warning on line 127 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'generateSiteGenData', 'handlePreviousStepTracking', and 'syncStoreToDB'. Either include them or remove the dependency array

useEffect( () => {
if (
Expand All @@ -134,7 +134,7 @@
generateSiteGenData();
}
prevSiteGenErrorStatus.current = siteGenErrorStatus;
}, [ siteGenErrorStatus ] );

Check warning on line 137 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has a missing dependency: 'generateSiteGenData'. Either include it or remove the dependency array

async function syncStoreToDB() {
// The First Fork Step doesn't have any Store changes
Expand Down Expand Up @@ -261,6 +261,15 @@
return;
}

// If retries are exhausted don't make requests
if (
currentData.sitegen?.siteGenErrorMeta?.retryCount >=
currentData.sitegen?.siteGenErrorMeta?.maxRetryCount
) {
updateSiteGenErrorStatus( true );
return;
}

setIsGeneratingSiteMeta( true );

if ( ! window.nfdOnboarding?.siteGenTimerInterval ) {
Expand Down
15 changes: 14 additions & 1 deletion src/OnboardingSPA/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,26 @@ export function data( state = {}, action ) {
};

case 'SET_SITEGEN_AI_ERROR_STATUS':
// Only update if the prev value was false and now there is an error else don't
const shouldUpdateRetryCount =
! state.flowData.sitegen.siteGenErrorMeta.status &&
action.siteGenErrorStatus;
return {
...state,
flowData: {
...state.flowData,
sitegen: {
...state.flowData.sitegen,
siteGenErrorStatus: action.siteGenErrorStatus,
siteGenErrorMeta: {
...state.flowData.sitegen.siteGenErrorMeta,
status: action.siteGenErrorStatus,
retryCount:
shouldUpdateRetryCount === true
? state.flowData.sitegen.siteGenErrorMeta
.retryCount + 1
: state.flowData.sitegen.siteGenErrorMeta
.retryCount,
},
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/OnboardingSPA/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ export function getCustomizeSidebarData( state ) {
}

export function getSiteGenErrorStatus( state ) {
return state.data.flowData.sitegen.siteGenErrorStatus;
return state.data.flowData.sitegen.siteGenErrorMeta.status;
}

export function getInteractionDisabled( state ) {
Expand Down
Loading