-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🪟 🎉 Show notification if Airbyte got updated (#22480)
* WIP * Pass through data-testid * Also check on window.focus * Add more documentation * Update airbyte-webapp/src/hooks/services/useBuildUpdateCheck.ts Co-authored-by: Joey Marshment-Howell <josephkmh@users.noreply.github.com> * Address review * Address review --------- Co-authored-by: Joey Marshment-Howell <josephkmh@users.noreply.github.com>
- Loading branch information
Showing
12 changed files
with
113 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { Plugin } from "vite"; | ||
|
||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
import { v4 as uuidV4 } from "uuid"; | ||
|
||
const buildHash = uuidV4(); | ||
|
||
/** | ||
* A Vite plugin that will generate on every build a new random UUID and write that to the `/buildInfo.json` | ||
* file as well as make it available as `process.env.BUILD_HASH` in code. | ||
*/ | ||
export function buildInfo(): Plugin { | ||
return { | ||
name: "airbyte/build-info", | ||
buildStart() { | ||
fs.writeFileSync(path.resolve(__dirname, "../../public/buildInfo.json"), JSON.stringify({ build: buildHash })); | ||
}, | ||
config: () => ({ | ||
define: { | ||
"process.env.BUILD_HASH": JSON.stringify(buildHash), | ||
}, | ||
}), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { docMiddleware } from "./doc-middleware"; | ||
export { buildInfo } from "./build-info"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { useEffect } from "react"; | ||
import { useIntl } from "react-intl"; | ||
import { fromEvent, interval, merge, throttleTime } from "rxjs"; | ||
|
||
import { useAppMonitoringService } from "./AppMonitoringService"; | ||
import { useNotificationService } from "./Notification"; | ||
|
||
interface BuildInfo { | ||
build: string; | ||
} | ||
|
||
const INTERVAL = 60_000; | ||
const MINIMUM_WAIT_BEFORE_REFETCH = 10_000; | ||
|
||
/** | ||
* This hook sets up a check to /buildInfo.json, which is generated by the build system on every build | ||
* with a new hash. If it ever detects a new hash in it, we know that the Airbyte instance got updated | ||
* and show a notification to the user to reload the page. | ||
*/ | ||
export const useBuildUpdateCheck = () => { | ||
const { formatMessage } = useIntl(); | ||
const { registerNotification } = useNotificationService(); | ||
const { trackError } = useAppMonitoringService(); | ||
|
||
useEffect(() => { | ||
// Trigger the check every ${INTERVAL} milliseconds or whenever the window regains focus again | ||
const subscription = merge(interval(INTERVAL), fromEvent(window, "focus")) | ||
// Throttle it to maximum once every 10 seconds | ||
.pipe(throttleTime(MINIMUM_WAIT_BEFORE_REFETCH)) | ||
.subscribe(async () => { | ||
try { | ||
// Fetch the buildInfo.json file without using any browser cache | ||
const buildInfo: BuildInfo = await fetch("/buildInfo.json", { cache: "no-store" }).then((resp) => | ||
resp.json() | ||
); | ||
|
||
if (buildInfo.build !== process.env.BUILD_HASH) { | ||
registerNotification({ | ||
id: "webapp-updated", | ||
text: formatMessage({ id: "notifications.airbyteUpdated" }), | ||
nonClosable: true, | ||
actionBtnText: formatMessage({ id: "notifications.airbyteUpdated.reload" }), | ||
onAction: () => window.location.reload(), | ||
}); | ||
} | ||
} catch (e) { | ||
// We ignore all errors from the build update check, since it's an optional check to | ||
// inform the user. We don't want to treat failed requests here as errors. | ||
trackError(e); | ||
} | ||
}); | ||
|
||
return () => { | ||
subscription.unsubscribe(); | ||
}; | ||
}, [formatMessage, registerNotification, trackError]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters