Skip to content

Commit

Permalink
(feat Preview UI): Added more build status messages (#35103)
Browse files Browse the repository at this point in the history
* intiial commit

* canary commit #1

* canary commit #2

* canary commit #3

* tmp

* canary commit #4

* update #4

* update #5

* made sure messages are seen and removed code for idle state

* fixed issue with BUILDING status

* temp

* made sure tooltip stays visible
  • Loading branch information
leithonenglish authored Mar 11, 2022
1 parent 796800f commit 79d5463
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 28 deletions.
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`,
}

0 comments on commit 79d5463

Please sign in to comment.