diff --git a/src/scripture-forge/src/home/project-table.component.tsx b/src/scripture-forge/src/home/project-table.component.tsx index b7d05d9..ca3ca03 100644 --- a/src/scripture-forge/src/home/project-table.component.tsx +++ b/src/scripture-forge/src/home/project-table.component.tsx @@ -21,6 +21,7 @@ import { SlingshotDraftSetupState, SlingshotProjectConnectionState, } from 'scripture-forge'; +import { isDraftCurrentlyGenerating } from '../utils'; type SortConfig = { key: 'fullName' | 'language' | 'draftSetupState' | 'action'; @@ -138,8 +139,7 @@ export default function ProjectTable({ const draftInfo = await draftInfoPdp.getDraftInfo(undefined); if ( - draftInfo.currentlyGeneratingDraftStatus && - draftInfo.currentlyGeneratingDraftStatus.state !== 'COMPLETED' && + isDraftCurrentlyGenerating(draftInfo.currentlyGeneratingDraftStatus?.state) && !pollTimeout ) pollTimeout = setTimeout(() => { @@ -247,9 +247,9 @@ export default function ProjectTable({ const buildTableDraftSetupStateElement = (projectInfo: ProjectInfo) => { const { connectionState, draftSetupState } = projectInfo.draftInfo; - const isDraftGenerating = - projectInfo.draftInfo.currentlyGeneratingDraftStatus && - projectInfo.draftInfo.currentlyGeneratingDraftStatus.state !== 'COMPLETED'; + const isDraftGenerating = isDraftCurrentlyGenerating( + projectInfo.draftInfo.currentlyGeneratingDraftStatus?.state, + ); let statusText = ''; @@ -339,9 +339,9 @@ export default function ProjectTable({ ); case 'connected': { - const isDraftGenerating = - projectInfo.draftInfo.currentlyGeneratingDraftStatus && - projectInfo.draftInfo.currentlyGeneratingDraftStatus.state !== 'COMPLETED'; + const isDraftGenerating = isDraftCurrentlyGenerating( + projectInfo.draftInfo.currentlyGeneratingDraftStatus?.state, + ); if (draftSetupState === 'hasFinishedDraft') return ( diff --git a/src/scripture-forge/src/projects/slingshot-project-data-provider-engine.model.ts b/src/scripture-forge/src/projects/slingshot-project-data-provider-engine.model.ts index d144531..0e4a2a2 100644 --- a/src/scripture-forge/src/projects/slingshot-project-data-provider-engine.model.ts +++ b/src/scripture-forge/src/projects/slingshot-project-data-provider-engine.model.ts @@ -136,10 +136,13 @@ export default class SlingshotProjectDataProviderEngine `${this.projectInfo.projectId} SF Project endpoint indicated there is a finished draft but received response for last completed ${lastCompletedDraftStatus} and for currently generating ${currentlyGeneratingDraftStatus}! Not sure what to do with this`, ); - if (lastCompletedDraftStatus === StatusCodes.NO_CONTENT) { + if ( + lastCompletedDraftStatus === StatusCodes.NO_CONTENT || + lastCompletedDraftStatus === StatusCodes.NOT_FOUND + ) { if (draftSetupState === 'hasFinishedDraft') throw new Error( - `${this.projectInfo.projectId} SF Project endpoint indicated there is a finished draft but received no content response for last completed ${lastCompletedDraftStatus}! Not sure what to do with this`, + `${this.projectInfo.projectId} SF Project endpoint indicated there is a finished draft but received non-content response for last completed ${lastCompletedDraftStatus}! Not sure what to do with this`, ); } else if (typeof lastCompletedDraftStatus === 'number') throw new Error( @@ -150,20 +153,27 @@ export default class SlingshotProjectDataProviderEngine if ( typeof currentlyGeneratingDraftStatus === 'number' && - currentlyGeneratingDraftStatus !== StatusCodes.NO_CONTENT + currentlyGeneratingDraftStatus !== StatusCodes.NO_CONTENT && + currentlyGeneratingDraftStatus !== StatusCodes.NOT_FOUND ) throw new Error( `Requesting currently generating draft status for SF project id ${this.projectInfo.projectId} returned error code ${lastCompletedDraftStatus}! Not sure what to do with this`, ); - if (lastCompletedDraftStatus !== StatusCodes.NO_CONTENT) { + if ( + lastCompletedDraftStatus !== StatusCodes.NO_CONTENT && + lastCompletedDraftStatus !== StatusCodes.NOT_FOUND + ) { if (draftSetupState === 'draftingNotAvailable') throw new Error( `${this.projectInfo.projectId} SF Project endpoint indicated drafting is not available, but we received draft information from last completed! Not sure what to do with this`, ); draftInfo.lastCompletedDraftStatus = lastCompletedDraftStatus; } - if (currentlyGeneratingDraftStatus !== StatusCodes.NO_CONTENT) { + if ( + currentlyGeneratingDraftStatus !== StatusCodes.NO_CONTENT && + currentlyGeneratingDraftStatus !== StatusCodes.NOT_FOUND + ) { if (draftSetupState === 'draftingNotAvailable') throw new Error( `${this.projectInfo.projectId} SF Project endpoint indicated drafting is not available, but we received draft information from currently generating! Not sure what to do with this`, diff --git a/src/scripture-forge/src/utils.ts b/src/scripture-forge/src/utils.ts new file mode 100644 index 0000000..73577f3 --- /dev/null +++ b/src/scripture-forge/src/utils.ts @@ -0,0 +1,19 @@ +import { SlingshotDraftBuildState } from 'scripture-forge'; + +/** + * Whether a draft state indicates the draft is currently generating as opposed to finished in some + * way (success or otherwise) + * + * @param draftState The state of the draft build + * @returns `true` if currently generating. `false` otherwise including if state is `undefined`. + */ +export function isDraftCurrentlyGenerating( + draftState: SlingshotDraftBuildState | undefined, +): boolean { + return ( + !!draftState && + draftState !== 'COMPLETED' && + draftState !== 'FAULTED' && + draftState !== 'CANCELED' + ); +}