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(gatsby-plugin-gatsby-cloud): request customer feedback #34471

Merged
merged 49 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
00280b5
intitial commit
leithonenglish Jan 4, 2022
c1acc13
added arrow for tooltip
leithonenglish Jan 4, 2022
e1dd6f7
more style updates
leithonenglish Jan 4, 2022
37e408c
refactorings
leithonenglish Jan 6, 2022
4810085
fix for link
Jan 6, 2022
d03262e
initial commit
Jan 6, 2022
bf27c39
completed basic typescript transformation
Jan 6, 2022
c805e77
re-added deleted file
Jan 6, 2022
9ea6609
update eslint ignore
Jan 6, 2022
029e3ce
updated gitignore
Jan 6, 2022
c86dad3
updated gitignore
Jan 6, 2022
7f6d783
fixed text for test
Jan 7, 2022
10b5565
more cleanup
leithonenglish Jan 10, 2022
2d58754
fixes for tooltip
leithonenglish Jan 10, 2022
908b9e6
initial commit
leithonenglish Jan 11, 2022
c9de3bb
ui updates
leithonenglish Jan 11, 2022
d081835
added domain to cookie
leithonenglish Jan 11, 2022
ed4c94a
fixed conflicts
leithonenglish Jan 11, 2022
0d9d0b4
fixed missing imports
leithonenglish Jan 11, 2022
08b2de1
fixed ui issue + re-added functionality
leithonenglish Jan 11, 2022
1a79ea1
refactorings + added functionality to track interactions locally
leithonenglish Jan 12, 2022
5f13663
add providers for cookies and feedback
leithonenglish Jan 12, 2022
e498290
some more cleanup
leithonenglish Jan 13, 2022
d7b4cc9
some more cleanup
leithonenglish Jan 13, 2022
e069cd2
fixed conflicts
leithonenglish Jan 13, 2022
c93f5f1
fixed issue with button not closing
leithonenglish Jan 13, 2022
6dbc153
fixed issue with button not closing
leithonenglish Jan 13, 2022
db7c1c2
fixed issue with button not closing
leithonenglish Jan 13, 2022
ce8be3d
added patch until rewrite
leithonenglish Jan 13, 2022
6ea0db3
more fixes
leithonenglish Jan 13, 2022
630b29a
re-commited the yarn.lock file
leithonenglish Jan 13, 2022
3b6c13f
fix enum error
leithonenglish Jan 14, 2022
da2bf47
Merge branch 'master' into feedback-ui-preview-2
leithonenglish Jan 14, 2022
ae462d0
minor updates
leithonenglish Jan 14, 2022
247e854
removed unused code
leithonenglish Jan 14, 2022
8544260
make sure that indicator button show error tooltip
leithonenglish Jan 14, 2022
a671cf6
fixing test
leithonenglish Jan 17, 2022
b11c5e8
reset tests
leithonenglish Jan 19, 2022
9b321c9
Merge branch 'master' into feedback-ui-preview-2
leithonenglish Jan 19, 2022
6d10b18
commented out failing tests
leithonenglish Jan 19, 2022
5b9a76b
more cleanup
leithonenglish Jan 19, 2022
05be888
updated gitignore
leithonenglish Jan 19, 2022
f7d261e
cleanup gitignore
leithonenglish Jan 19, 2022
1798a90
skipped tests instead of commenting them out
leithonenglish Jan 19, 2022
de32900
put back eslintignore
leithonenglish Jan 19, 2022
84b896f
fixed conflict
leithonenglish Jan 20, 2022
ab10386
removed unnecessary code
leithonenglish Jan 20, 2022
f0af96c
removed unnecessary code
leithonenglish Jan 20, 2022
42dde2e
add more detail note around why tests were skipped
leithonenglish Jan 20, 2022
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
4 changes: 2 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ packages/gatsby-admin/public
packages/gatsby/gatsby-admin-public
packages/gatsby-codemods/transforms
packages/gatsby-source-graphql/batching
packages/gatsby-plugin-gatsby-cloud/components
packages/gatsby-plugin-gatsby-cloud/utils
packages/gatsby-plugin-gatsby-cloud/**/*.js
leithonenglish marked this conversation as resolved.
Show resolved Hide resolved
!packages/gatsby-plugin-gatsby-cloud/src/**/*.js
packages/gatsby-plugin-preact/fast-refresh

packages/gatsby-source-wordpress/test-site/**
Expand Down
7 changes: 5 additions & 2 deletions packages/gatsby-plugin-gatsby-cloud/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
yarn.lock
/*.js
/**/*.js
leithonenglish marked this conversation as resolved.
Show resolved Hide resolved
/**/*.map
!/src/**/*.js
!index.js

/components/
/models/
assets/
utils/
# utils/
2 changes: 2 additions & 0 deletions packages/gatsby-plugin-gatsby-cloud/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions packages/gatsby-plugin-gatsby-cloud/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"@babel/runtime": "^7.15.4",
"date-fns": "^2.28.0",
"fs-extra": "^10.0.0",
"js-cookie": "^3.0.1",
"gatsby-core-utils": "^3.6.0-next.0",
"gatsby-telemetry": "^3.6.0-next.0",
"kebab-hash": "^0.1.2",
Expand Down Expand Up @@ -51,11 +52,11 @@
},
"sideEffects": false,
"scripts": {
"build": "babel src --out-dir . --ignore \"**/__tests__\" && npm run clean && npm run copy-type-declarations",
"build": "babel src --out-dir . --ignore \"**/__tests__\" --extensions \".tsx,.ts,.js\" --source-maps && npm run clean && npm run copy-type-declarations",
leithonenglish marked this conversation as resolved.
Show resolved Hide resolved
"clean": "del-cli ./components/index.d.ts",
"copy-type-declarations": "cpy src/components/index.d.ts components/",
"copy-type-declarations": "cpy src/components/index.d.ts components",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir . --ignore \"**/__tests__\""
"watch": "babel -w src --out-dir . --ignore \"**/__tests__\" --extensions \".tsx,.ts,.js\" --source-maps"
},
"engines": {
"node": ">=14.15.0"
Expand Down
84 changes: 44 additions & 40 deletions packages/gatsby-plugin-gatsby-cloud/src/components/Indicator.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
import React, { useState, useEffect, useCallback, useRef } from "react"
import getBuildInfo from "../utils/getBuildInfo"
import trackEvent from "../utils/trackEvent"
import IndicatorProvider from "../context/indicatorProvider"
import { BuildStatus } from "../models/enums"
import { useTrackEvent, getBuildInfo } from "../utils"
import {
LinkIndicatorButton,
InfoIndicatorButton,
GatsbyIndicatorButton,
} from "./buttons"
import Style from "./Style"

const POLLING_INTERVAL = process.env.GATSBY_PREVIEW_POLL_INTERVAL || 3000

export function PreviewIndicator({ children }) {
return (
<>
<Style />
<div
data-testid="preview-status-indicator"
data-gatsby-preview-indicator="root"
aria-live="assertive"
>
{React.Children.map(children, (child, i) =>
React.cloneElement(child, { ...child.props, buttonIndex: i })
)}
</div>
</>
)
}

let buildId

export default function Indicator() {
const POLLING_INTERVAL = process.env.GATSBY_PREVIEW_POLL_INTERVAL
? parseInt(process.env.GATSBY_PREVIEW_POLL_INTERVAL)
: 3000

const PreviewIndicator = ({ children }) => (
<>
<Style />
<div
data-testid="preview-status-indicator"
data-gatsby-preview-indicator="root"
aria-live="assertive"
>
{children}
</div>
</>
)

let buildId = ``

const Indicator = () => {
const [buildInfo, setBuildInfo] = useState()

const timeoutRef = useRef()
const timeoutRef = useRef(null)
const shouldPoll = useRef(false)
const trackedInitialLoad = useRef(false)
const { track } = useTrackEvent()

const { siteInfo, currentBuild } = buildInfo || {
siteInfo: {},
Expand Down Expand Up @@ -71,18 +70,18 @@ export default function Indicator() {
isOnPrettyUrl,
}

if (currentBuild?.buildStatus === `BUILDING`) {
setBuildInfo({ ...newBuildInfo, buildStatus: `BUILDING` })
} else if (currentBuild?.buildStatus === `ERROR`) {
setBuildInfo({ ...newBuildInfo, buildStatus: `ERROR` })
if (currentBuild?.buildStatus === BuildStatus.BUILDING) {
leithonenglish marked this conversation as resolved.
Show resolved Hide resolved
setBuildInfo({ ...newBuildInfo, buildStatus: BuildStatus.BUILDING })
} else if (currentBuild?.buildStatus === BuildStatus.ERROR) {
setBuildInfo({ ...newBuildInfo, buildStatus: BuildStatus.ERROR })
} else if (buildId && buildId === newBuildInfo?.currentBuild?.id) {
setBuildInfo({ ...newBuildInfo, buildStatus: `UPTODATE` })
setBuildInfo({ ...newBuildInfo, buildStatus: BuildStatus.UPTODATE })
} else if (
buildId &&
buildId !== newBuildInfo?.latestBuild?.id &&
currentBuild?.buildStatus === `SUCCESS`
currentBuild?.buildStatus === BuildStatus.SUCCESS
) {
setBuildInfo({ ...newBuildInfo, buildStatus: `SUCCESS` })
setBuildInfo({ ...newBuildInfo, buildStatus: BuildStatus.SUCCESS })
}

if (shouldPoll.current) {
Expand All @@ -92,7 +91,7 @@ export default function Indicator() {

useEffect(() => {
if (buildInfo?.siteInfo && !trackedInitialLoad.current) {
trackEvent({
track({
eventType: `PREVIEW_INDICATOR_LOADED`,
buildId,
orgId,
Expand All @@ -107,7 +106,7 @@ export default function Indicator() {
shouldPoll.current = true
pollData()

return function cleanup() {
return () => {
leithonenglish marked this conversation as resolved.
Show resolved Hide resolved
shouldPoll.current = false

if (timeoutRef.current) {
Expand All @@ -129,10 +128,15 @@ export default function Indicator() {
}

return (
<PreviewIndicator>
<GatsbyIndicatorButton {...buttonProps} />
<InfoIndicatorButton {...buttonProps} />
<LinkIndicatorButton {...buttonProps} />
</PreviewIndicator>
<IndicatorProvider>
<PreviewIndicator>
<GatsbyIndicatorButton {...buttonProps} buttonIndex={1} />
<InfoIndicatorButton {...buttonProps} buttonIndex={2} />
<LinkIndicatorButton {...buttonProps} buttonIndex={3} />
</PreviewIndicator>
</IndicatorProvider>
)
}

export { PreviewIndicator }
export default Indicator
77 changes: 70 additions & 7 deletions packages/gatsby-plugin-gatsby-cloud/src/components/Style.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const Style = () => (
--gatsby: var(--purple-60);
--purple-40: #b17acc;
--purple-20: #f1defa;
--purple-10: #f6edfa;
--dimmedWhite: rgba(255, 255, 255, 0.8);
--white: #ffffff;
--black: #000000;
Expand Down Expand Up @@ -53,6 +54,7 @@ const Style = () => (
}

[data-gatsby-preview-indicator="button"] {
position: relative;
width: 32px;
height: 32px;
padding: 4px;
Expand All @@ -72,31 +74,57 @@ const Style = () => (
transition: all 0.3s ease-in-out;
}

[data-gatsby-preview-indicator-highlighted-button="true"] {
background: var(--purple-10);
}

[data-gatsby-preview-indicator-active-button="false"] {
opacity: 0.3;
transition: all 0.3s ease-in-out;
}

[data-gatsby-preview-indicator="spinner"] {
position: absolute;
top: 10px;
left: 10px;
animation: spin 1s linear infinite;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
height: 28px;
}

[data-gatsby-preview-indicator="spinner"] svg {
animation: spin 1s linear infinite;
}
[data-gatsby-preview-indicator="tooltip"] {
position: fixed;
margin-left: 48px;
position: absolute;
padding-left: 35px;
top: 50%;
transform: translateY(-50%);
}

[data-gatsby-preview-indicator="tooltip-inner"] {
position: relative;
line-height: 12px;
background: black;
opacity: 1;
color: white;
display: inline;
display: flex;
align-items: center;
padding: 10px 13px;
border-radius: 4px;
user-select: none;
white-space: nowrap;
cursor: default;
}
[data-gatsby-preview-indicator="tooltip-inner"]:before {
content: "";
position: absolute;
top: 50%;
left: -6px;
width: 0;
height: 0;
transform: translateY(-50%);
border-style: solid;
border-width: 10px 10px 10px 0;
border-color: transparent black transparent transparent;
}

[data-gatsby-preview-indicator-visible="false"] {
Expand All @@ -111,6 +139,13 @@ const Style = () => (
transition: all 0.2s ease-in-out;
}

[data-gatsby-preview-indicator-removed="false"] {
display: inline;
}
[data-gatsby-preview-indicator-removed="true"] {
display: none;
}

[data-gatsby-preview-indicator="tooltip-link"] {
background: none;
border: none;
Expand All @@ -126,6 +161,34 @@ const Style = () => (
font-size: 0.8rem;
display: inline;
cursor: pointer;
text-decoration: none;
}

[data-gatsby-preview-indicator="tooltip-link-text"]:hover {
text-decoration: underline;
}

[data-gatsby-preview-indicator="tooltip-close-btn"] {
display: flex;
justify-content: center;
align-items: center;
background: none;
border: none;
padding: 0;
margin-left: 0.8rem;
cursor: pointer;
}

[data-gatsby-preview-indicator="tooltip-close-btn"] svg {
color: white;
opacity: 0.6;
transition-property: color, opacity;
transition-duration: 0.3s;
transition-easing-function: ease-in-out;
}

[data-gatsby-preview-indicator="tooltip-close-btn"]:hover svg {
opacity: 1;
}

[data-gatsby-preview-indicator="tooltip-svg"] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,32 @@
import React from "react"
import IndicatorButton from "./IndicatorButton"
import {
BuildErrorTooltipContent,
BuildSuccessTooltipContent,
} from "../tooltips"
import { gatsbyIcon } from "../icons"
import { BuildStatus } from "../../models/enums"

const getButtonProps = ({
buildStatus,
orgId,
siteId,
buildId,
isOnPrettyUrl,
sitePrefix,
erroredBuildId,
}) => {
switch (buildStatus) {
case `BUILDING`:
case `ERROR`:
case `SUCCESS`:
case `UPTODATE`:
default: {
return {
active: true,
}
}
const getButtonProps = ({ buildStatus, buttonIndex }) => {
const baseProps = {
testId: `gatsby`,
buttonIndex,
iconSvg: gatsbyIcon,
}
}

export default function GatsbyIndicatorButton(props) {
return (
<IndicatorButton
testId="gatsby"
iconSvg={gatsbyIcon}
{...getButtonProps(props)}
buttonIndex={props.buttonIndex}
/>
)
const propsByBuildStatus = {
leithonenglish marked this conversation as resolved.
Show resolved Hide resolved
[BuildStatus.SUCCESS]: null,
[BuildStatus.ERROR]: null,
[BuildStatus.BUILDING]: null,
[BuildStatus.UPTODATE]: {
active: true,
leithonenglish marked this conversation as resolved.
Show resolved Hide resolved
},
}
const props = buildStatus ? propsByBuildStatus[buildStatus] : null
leithonenglish marked this conversation as resolved.
Show resolved Hide resolved
if (props) {
return { ...baseProps, ...props }
}
return baseProps
}

const GatsbyIndicatorButton = props => (
<IndicatorButton {...getButtonProps(props)} />
)

export default GatsbyIndicatorButton
Loading