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
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 Down Expand Up @@ -31,6 +31,7 @@
const SiteGenStepErrorState = () => {
const navigate = useNavigate();
const isLargeViewport = useViewportMatch( 'small' );
const [ disableRetry, setDisableRetry ] = useState( false );

const {
setIsHeaderEnabled,
Expand All @@ -55,7 +56,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 63 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 @@ -186,6 +191,7 @@
onClick={ () => {
handleRetry();
} }
disabled={ true === disableRetry }
>
<p className="nfd-onboarding-button--site-gen-next--text">
{ content.buttonText }
Expand All @@ -200,6 +206,7 @@
onClick={ () => {
handleRetry();
} }
disabled={ true === disableRetry }
>
<p className="nfd-onboarding-button--site-gen-next--text">
{ content.buttonText }
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