Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/scripture-forge/src/home/project-table.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
SlingshotDraftSetupState,
SlingshotProjectConnectionState,
} from 'scripture-forge';
import { isDraftCurrentlyGenerating } from '../utils';

type SortConfig = {
key: 'fullName' | 'language' | 'draftSetupState' | 'action';
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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 = '';

Expand Down Expand Up @@ -339,9 +339,9 @@ export default function ProjectTable({
</div>
);
case 'connected': {
const isDraftGenerating =
projectInfo.draftInfo.currentlyGeneratingDraftStatus &&
projectInfo.draftInfo.currentlyGeneratingDraftStatus.state !== 'COMPLETED';
const isDraftGenerating = isDraftCurrentlyGenerating(
projectInfo.draftInfo.currentlyGeneratingDraftStatus?.state,
);

if (draftSetupState === 'hasFinishedDraft')
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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`,
Expand Down
19 changes: 19 additions & 0 deletions src/scripture-forge/src/utils.ts
Original file line number Diff line number Diff line change
@@ -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'
);
}
Loading