-
Notifications
You must be signed in to change notification settings - Fork 5.5k
feat(connections): show disk capacity per server #10806
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
Open
adamblumoff
wants to merge
4
commits into
pingdotgg:main
Choose a base branch
from
adamblumoff:feat/server-disk-capacity
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
dbdf507
feat(connections): show disk capacity per server
adamblumoff 5cf9707
refactor(connections): show disk capacity in server rings
adamblumoff f154106
fix(connections): isolate disk reads and cover T3 Connect
adamblumoff 3e48edf
fix(server): share pending disk capacity samples
adamblumoff 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
168 changes: 168 additions & 0 deletions
168
apps/mobile/src/features/connection/ConnectionHostStorage.tsx
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,168 @@ | ||
| import { useAtomRefresh, useAtomValue } from "@effect/atom-react"; | ||
| import { useIsFocused } from "@react-navigation/native"; | ||
| import { getHostStoragePresentation } from "@t3tools/client-runtime/host-storage"; | ||
| import type { EnvironmentId } from "@t3tools/contracts"; | ||
| import { useState } from "react"; | ||
| import { Modal, Pressable, View } from "react-native"; | ||
| import Svg, { Circle } from "react-native-svg"; | ||
| import { withUniwind } from "uniwind"; | ||
|
|
||
| import { SymbolView } from "../../components/AppSymbol"; | ||
| import { AppText as Text } from "../../components/AppText"; | ||
| import { serverEnvironment } from "../../state/server"; | ||
|
|
||
| const ThemedSvg = withUniwind(Svg); | ||
|
|
||
| function HostStorageView(props: { | ||
| readonly environmentLabel: string; | ||
| readonly presentation: ReturnType<typeof getHostStoragePresentation>; | ||
| readonly onRefresh?: () => void; | ||
| }) { | ||
| const { presentation } = props; | ||
| const loading = presentation.status === "loading"; | ||
| const [open, setOpen] = useState(false); | ||
| const usedPercent = | ||
| presentation.status === "available" ? 100 - presentation.availablePercent : null; | ||
|
|
||
| return ( | ||
| <> | ||
| <Pressable | ||
| accessibilityRole="button" | ||
| accessibilityLabel={`${props.environmentLabel} disk space${presentation.status === "available" ? `: ${presentation.label}` : ""}`} | ||
| accessibilityHint="Show disk capacity" | ||
| onPress={() => setOpen(true)} | ||
| className="h-11 w-11 items-center justify-center rounded-full active:bg-subtle" | ||
| > | ||
| <ThemedSvg | ||
| width={20} | ||
| height={20} | ||
| viewBox="0 0 24 24" | ||
| colorClassName="accent-foreground-muted" | ||
| > | ||
| <Circle | ||
| cx={12} | ||
| cy={12} | ||
| r={9} | ||
| fill="none" | ||
| stroke="currentColor" | ||
| strokeOpacity={0.2} | ||
| strokeWidth={3} | ||
| /> | ||
| {usedPercent !== null ? ( | ||
| <Circle | ||
| cx={12} | ||
| cy={12} | ||
| r={9} | ||
| fill="none" | ||
| stroke="currentColor" | ||
| strokeWidth={3} | ||
| strokeDasharray={[(2 * Math.PI * 9 * usedPercent) / 100, 2 * Math.PI * 9]} | ||
| rotation={-90} | ||
| origin="12, 12" | ||
| /> | ||
| ) : null} | ||
| </ThemedSvg> | ||
| </Pressable> | ||
| <Modal visible={open} transparent animationType="fade" onRequestClose={() => setOpen(false)}> | ||
| <Pressable | ||
| accessible={false} | ||
| focusable={false} | ||
| className="flex-1 items-center justify-center bg-backdrop px-8" | ||
| onPress={() => setOpen(false)} | ||
| > | ||
| <Pressable | ||
| accessible={false} | ||
| focusable={false} | ||
| accessibilityViewIsModal | ||
| className="w-full max-w-sm gap-3 rounded-2xl bg-card p-4" | ||
| onPress={(event) => event.stopPropagation()} | ||
| > | ||
| <View className="flex-row items-center gap-2"> | ||
| <View className="min-w-0 flex-1 gap-0.5"> | ||
| <Text className="text-xs text-foreground-muted">Disk containing T3 data</Text> | ||
| <Text className="text-xs text-foreground" selectable> | ||
| {presentation.status === "available" | ||
| ? presentation.label | ||
| : loading | ||
| ? "Checking storage…" | ||
| : "Storage unavailable"} | ||
| </Text> | ||
| </View> | ||
| {props.onRefresh ? ( | ||
| <Pressable | ||
| accessibilityRole="button" | ||
| accessibilityLabel={`Refresh disk storage for ${props.environmentLabel}`} | ||
| accessibilityState={{ disabled: loading, busy: loading }} | ||
| disabled={loading} | ||
| onPress={props.onRefresh} | ||
| className="h-11 w-11 items-center justify-center rounded-xl active:bg-subtle disabled:opacity-40" | ||
| > | ||
| <SymbolView | ||
| name="arrow.clockwise" | ||
| size={14} | ||
| tintColorClassName="accent-icon-subtle" | ||
| type="monochrome" | ||
| /> | ||
| </Pressable> | ||
| ) : null} | ||
| </View> | ||
| {presentation.status === "available" ? ( | ||
| <Text className="text-2xs text-foreground-muted"> | ||
| {Math.round(100 - presentation.availablePercent)}% used or reserved{"\n"} | ||
| Checked at {new Date(presentation.sampledAt).toLocaleTimeString()} | ||
| </Text> | ||
| ) : null} | ||
| <Text className="text-xs text-foreground-muted"> | ||
| Other drives may have different space available. | ||
| </Text> | ||
| <Pressable | ||
| accessibilityRole="button" | ||
| onPress={() => setOpen(false)} | ||
| className="min-h-11 items-center justify-center rounded-xl bg-subtle" | ||
| > | ||
| <Text className="text-sm text-foreground">Done</Text> | ||
| </Pressable> | ||
| </Pressable> | ||
| </Pressable> | ||
| </Modal> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| function ConnectedHostStorage(props: { | ||
| readonly environmentId: EnvironmentId; | ||
| readonly environmentLabel: string; | ||
| }) { | ||
| const query = serverEnvironment.hostStorage({ environmentId: props.environmentId, input: {} }); | ||
| const result = useAtomValue(query); | ||
| const refresh = useAtomRefresh(query); | ||
|
|
||
| return ( | ||
| <HostStorageView | ||
| environmentLabel={props.environmentLabel} | ||
| presentation={getHostStoragePresentation(result)} | ||
| onRefresh={refresh} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| export function ConnectionHostStorage(props: { | ||
| readonly environmentId: EnvironmentId; | ||
| readonly environmentLabel: string; | ||
| readonly connected: boolean; | ||
| }) { | ||
| const isFocused = useIsFocused(); | ||
| if (!isFocused) return null; | ||
|
|
||
| return props.connected ? ( | ||
| <ConnectedHostStorage | ||
| environmentId={props.environmentId} | ||
| environmentLabel={props.environmentLabel} | ||
| /> | ||
| ) : ( | ||
| <HostStorageView | ||
| environmentLabel={props.environmentLabel} | ||
| presentation={{ status: "unavailable" }} | ||
| /> | ||
| ); | ||
| } |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.