-
Notifications
You must be signed in to change notification settings - Fork 6.5k
feat(web): update providers on every machine with one click #14678
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,112 @@ | ||
| import { PROVIDER_DISPLAY_NAMES } from "@t3tools/contracts"; | ||
| import { useMemo, useRef, useState } from "react"; | ||
|
|
||
| import { useEnvironments } from "~/state/environments"; | ||
| import { serverEnvironment } from "~/state/server"; | ||
| import { useAtomCommand } from "~/state/use-atom-command"; | ||
| import { | ||
| canOneClickUpdateProviderCandidate, | ||
| collectProviderUpdateCandidates, | ||
| getProviderUpdateRunToastView, | ||
| type ProviderUpdateRun, | ||
| } from "./ProviderUpdateLaunchNotification.logic"; | ||
| import { Button } from "./ui/button"; | ||
| import { stackedThreadToast, toastManager } from "./ui/toast"; | ||
| import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip"; | ||
|
|
||
| /** | ||
| * Updates every outdated provider on every connected machine at once, then | ||
| * reports the results in one toast. Each server queues updates that share an | ||
| * installer, so sending them all together is safe. The server still checks | ||
| * permissions: a session that cannot operate a machine gets a failure line for | ||
| * it. Renders nothing when no machine has a one-click update. | ||
| */ | ||
| export function ProviderUpdatesAction() { | ||
| const { environments } = useEnvironments(); | ||
| const updateProvider = useAtomCommand(serverEnvironment.updateProvider, { | ||
| reportFailure: false, | ||
| }); | ||
| const pending = useRef(false); | ||
| const [isPending, setIsPending] = useState(false); | ||
| const machines = useMemo( | ||
| () => | ||
| environments.flatMap((environment) => { | ||
| const providers = environment.serverConfig?.providers ?? []; | ||
| if (environment.connection.phase !== "connected") { | ||
| return []; | ||
| } | ||
| const candidates = collectProviderUpdateCandidates(providers).filter((candidate) => | ||
| canOneClickUpdateProviderCandidate(candidate, providers), | ||
| ); | ||
| return candidates.length > 0 | ||
| ? [{ environmentId: environment.environmentId, label: environment.label, candidates }] | ||
| : []; | ||
| }), | ||
| [environments], | ||
| ); | ||
| // Candidates leave the list as soon as their servers report them queued, so | ||
| // keep the button while the run is in flight. | ||
| if (machines.length === 0 && !isPending) { | ||
| return null; | ||
| } | ||
|
|
||
| const handleUpdate = async () => { | ||
| if (pending.current) return; | ||
| pending.current = true; | ||
| setIsPending(true); | ||
| try { | ||
| const runs = await Promise.all( | ||
| machines.flatMap(({ environmentId, label, candidates }) => | ||
| candidates.map(async (candidate): Promise<ProviderUpdateRun> => ({ | ||
| machineLabel: label, | ||
| driver: candidate.driver, | ||
| instanceId: candidate.instanceId, | ||
| result: await updateProvider({ | ||
| environmentId, | ||
| input: { provider: candidate.driver, instanceId: candidate.instanceId }, | ||
| }), | ||
| })), | ||
| ), | ||
| ); | ||
| const view = getProviderUpdateRunToastView(runs); | ||
| if (view) { | ||
| toastManager.add( | ||
| stackedThreadToast({ | ||
| ...view, | ||
| description: <span className="whitespace-pre-line">{view.description}</span>, | ||
| }), | ||
| ); | ||
| } | ||
| } finally { | ||
| pending.current = false; | ||
| setIsPending(false); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Tooltip> | ||
| <TooltipTrigger | ||
| render={ | ||
| <Button | ||
| size="xs" | ||
| variant="ghost-muted" | ||
| disabled={isPending} | ||
| onClick={() => void handleUpdate()} | ||
| > | ||
| {isPending ? "Updating…" : "Update all"} | ||
| </Button> | ||
| } | ||
| /> | ||
| <TooltipPopup side="top"> | ||
| {machines.map((machine) => ( | ||
| <div key={machine.environmentId}> | ||
| {machine.label}:{" "} | ||
| {machine.candidates | ||
| .map((candidate) => PROVIDER_DISPLAY_NAMES[candidate.driver] ?? candidate.driver) | ||
| .join(", ")} | ||
| </div> | ||
| ))} | ||
| </TooltipPopup> | ||
| </Tooltip> | ||
| ); | ||
| } | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 1457
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 31148
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 38506
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 21568
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 42292
Preserve one-click candidates by
instanceId.ProviderUpdatesActionsends one request for each retained candidate.ProviderMaintenanceRunner.updateProviderresolves and updates only the suppliedinstanceId. Driver-level deduplication can therefore leave another eligible installation outdated.Suggested fix
🤖 Prompt for AI Agents