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

(feat Preview UI): Added more build status messages #35103

16 changes: 10 additions & 6 deletions packages/gatsby-plugin-gatsby-cloud/src/components/Indicator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, useCallback, useRef } from "react"
import React, { useState, useEffect, useRef } from "react"
import IndicatorProvider from "../context/indicatorProvider"
import { BuildStatus } from "../models/enums"
import { useTrackEvent, getBuildInfo } from "../utils"
Expand Down Expand Up @@ -203,11 +203,15 @@ const Indicator = () => {
siteInfo,
isOnPrettyUrl,
}

if (currentBuild?.buildStatus === BuildStatus.BUILDING) {
setBuildInfo({ ...newBuildInfo, buildStatus: BuildStatus.BUILDING })
} else if (currentBuild?.buildStatus === BuildStatus.ERROR) {
setBuildInfo({ ...newBuildInfo, buildStatus: BuildStatus.ERROR })
if (
[
BuildStatus.BUILDING,
BuildStatus.ERROR,
BuildStatus.QUEUED,
BuildStatus.UPLOADING,
].includes(currentBuild?.buildStatus)
) {
setBuildInfo({ ...newBuildInfo, buildStatus: currentBuild?.buildStatus })
} else if (buildId && buildId === newBuildInfo?.currentBuild?.id) {
setBuildInfo({ ...newBuildInfo, buildStatus: BuildStatus.UPTODATE })
} else if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,20 @@ const InfoIndicatorButton = ({
}

useEffect(() => {
const displaySimpleMessage = (message, show = false) => {
setButtonProps({
...initialButtonProps,
tooltip: {
testId: initialButtonProps.testId,
content: message,
overrideShow: show,
show,
hoverable: !show,
},
active: true,
hoverable: !show,
})
}
const buildStatusActions = {
[BuildStatus.UPTODATE]: () => {
if (shouldShowFeedback) {
Expand All @@ -151,22 +165,12 @@ const InfoIndicatorButton = ({
hoverable: true,
})
} else {
setButtonProps({
...initialButtonProps,
tooltip: {
testId: initialButtonProps.testId,
content: `Preview updated ${formatDistance(
Date.now(),
new Date(createdAt),
{ includeSeconds: true }
)} ago`,
overrideShow: false,
show: false,
hoverable: true,
},
active: true,
hoverable: true,
})
const message = `Preview updated ${formatDistance(
Date.now(),
new Date(createdAt),
{ includeSeconds: true }
)} ago`
displaySimpleMessage(message)
}
},
[BuildStatus.SUCCESS]: () => {
Expand Down Expand Up @@ -215,14 +219,13 @@ const InfoIndicatorButton = ({
onClick: onTooltipToogle,
})
},
[BuildStatus.BUILDING]: () =>
displaySimpleMessage(`Building your preview...`, true),
[BuildStatus.QUEUED]: () =>
displaySimpleMessage(`Kicking off your build...`, true),
[BuildStatus.UPLOADING]: () => displaySimpleMessage(`Deploying...`, true),
}

// this is because the build status enum is used for ui state - so we can't have 1 ui state that covers multiple build statuses.
// If we don't have content sync info (pollForNodeManifest), we have to assume that a currently building build isn't applicable to the current user. So we default to the least noisy state which is UPTODATE.
// @todo refactor and decouple build states from UI states - this state should be something like uiState === `IDLE`
buildStatusActions[BuildStatus.BUILDING] =
buildStatusActions[BuildStatus.UPTODATE]

const contentSyncSuccessAction = nodeManifestRedirectUrl
? () => {
setButtonProps(btnProps => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ export enum BuildStatus {
UPTODATE = `UPTODATE`,
ERROR = `ERROR`,
BUILDING = `BUILDING`,
QUEUED = `QUEUED`,
UPLOADING = `UPLOADING`,
}