feat: clean up server power action buttons (#5836)

This commit is contained in:
Calum H.
2026-04-17 18:11:52 +01:00
committed by GitHub
parent 5244060588
commit dd51c08a18
4 changed files with 229 additions and 80 deletions

View File

@@ -20,15 +20,24 @@ export function useServerPowerAction(options?: { disabled?: Ref<boolean> }) {
const isStopping = computed(() => powerState.value === 'stopping')
const isStarting = computed(() => powerState.value === 'starting')
const isTransitioning = computed(() => isStarting.value || isStopping.value)
const showStopButton = computed(() => isRunning.value || isStarting.value)
const showStopSplit = computed(() => isRunning.value || isStarting.value || isStopping.value)
const showRestartButton = computed(() => isRunning.value || isStarting.value)
const isBlockedByPropsOrBusy = computed(
() => Boolean(options?.disabled?.value) || busyReasons.value.length > 0,
)
const busyTooltip = computed(() => {
if (isStarting.value) return 'Your server is starting'
return busyReasons.value.length > 0 ? formatMessage(busyReasons.value[0].reason) : undefined
})
const canTakeAction = computed(
() => !isTransitioning.value && !options?.disabled?.value && busyReasons.value.length === 0,
const canTakeAction = computed(() => !isTransitioning.value && !isBlockedByPropsOrBusy.value)
const canKill = computed(
() =>
!isBlockedByPropsOrBusy.value && (isStopping.value || isRunning.value || isStarting.value),
)
const primaryActionText = computed(() => {
@@ -57,7 +66,11 @@ export function useServerPowerAction(options?: { disabled?: Ref<boolean> }) {
}
function initiateAction(action: PowerAction) {
if (!canTakeAction.value) return
if (action === 'Kill') {
if (!canKill.value) return
} else {
if (!canTakeAction.value) return
}
void sendPowerAction(action)
}
@@ -70,9 +83,11 @@ export function useServerPowerAction(options?: { disabled?: Ref<boolean> }) {
isRunning,
isStopping,
isTransitioning,
showStopButton,
showStopSplit,
showRestartButton,
busyTooltip,
canTakeAction,
canKill,
primaryActionText,
sendPowerAction,
initiateAction,