mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
refactor: normalize status to variants + icons
This commit is contained in:
parent
5b5cac5478
commit
da02692d93
7 changed files with 31 additions and 27 deletions
|
@ -5,13 +5,10 @@
|
|||
|
||||
import errors from '@/api/errors'
|
||||
import { useInfos } from '@/composables/useInfos'
|
||||
import {
|
||||
STATUS_VARIANT,
|
||||
type APIRequest,
|
||||
type APIRequestAction,
|
||||
} from '@/composables/useRequests'
|
||||
import type { APIRequest, APIRequestAction } from '@/composables/useRequests'
|
||||
import { toEntries } from '@/helpers/commons'
|
||||
import type { Obj } from '@/types/commons'
|
||||
import { STATUS_VARIANT, isOkStatus } from '@/helpers/yunohostArguments'
|
||||
import type { StateStatus, Obj } from '@/types/commons'
|
||||
import type { APIErrorData } from './api'
|
||||
|
||||
/**
|
||||
|
@ -46,8 +43,7 @@ export function openWebSocket(request: APIRequestAction): Promise<Event> {
|
|||
return new Promise((resolve) => {
|
||||
const ws = new WebSocket(`wss://${host.value}/yunohost/api/messages`)
|
||||
ws.onmessage = ({ data }) => {
|
||||
const messages: Record<'info' | 'success' | 'warning' | 'error', string> =
|
||||
JSON.parse(data)
|
||||
const messages: Record<StateStatus, string> = JSON.parse(data)
|
||||
toEntries(messages).forEach(([status, text]) => {
|
||||
text = text.replaceAll('\n', '<br>')
|
||||
const progressBar = text.match(/^\[#*\+*\.*\] > /)?.[0]
|
||||
|
@ -63,9 +59,7 @@ export function openWebSocket(request: APIRequestAction): Promise<Event> {
|
|||
text,
|
||||
variant: STATUS_VARIANT[status],
|
||||
})
|
||||
if (['error', 'warning'].includes(status)) {
|
||||
request.action[`${status as 'error' | 'warning'}s`]++
|
||||
}
|
||||
if (!isOkStatus(status)) request.action[`${status}s`]++
|
||||
})
|
||||
}
|
||||
// ws.onclose = (e) => {}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
import { computed, toRefs } from 'vue'
|
||||
|
||||
import type { APIRequest } from '@/composables/useRequests'
|
||||
import { STATUS_VARIANT } from '@/composables/useRequests'
|
||||
import { STATUS_VARIANT } from '@/helpers/yunohostArguments'
|
||||
|
||||
const props = defineProps<{
|
||||
request: APIRequest
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
import type { ColorVariant } from 'bootstrap-vue-next'
|
||||
import { computed } from 'vue'
|
||||
|
||||
import { DEFAULT_STATUS_ICON } from '@/helpers/yunohostArguments'
|
||||
import { DEFAULT_VARIANT_ICON } from '@/helpers/yunohostArguments'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
|
@ -18,7 +18,7 @@ const props = withDefaults(
|
|||
)
|
||||
|
||||
const icon = computed(() => {
|
||||
return props.icon || DEFAULT_STATUS_ICON[props.variant]
|
||||
return props.icon || DEFAULT_VARIANT_ICON[props.variant]
|
||||
})
|
||||
</script>
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
import type { Breakpoint, ColorVariant } from 'bootstrap-vue-next'
|
||||
import { computed } from 'vue'
|
||||
|
||||
import { DEFAULT_STATUS_ICON } from '@/helpers/yunohostArguments'
|
||||
import { DEFAULT_VARIANT_ICON } from '@/helpers/yunohostArguments'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
|
@ -25,7 +25,7 @@ const props = withDefaults(
|
|||
|
||||
const icon = computed(() => {
|
||||
if (props.noIcon) return
|
||||
return props.icon || DEFAULT_STATUS_ICON[props.variant]
|
||||
return props.icon || DEFAULT_VARIANT_ICON[props.variant]
|
||||
})
|
||||
const class_ = computed(() => {
|
||||
const baseClass = 'yuno-list-group-item-'
|
||||
|
|
|
@ -47,14 +47,6 @@ export type ReconnectingArgs = {
|
|||
delay?: number
|
||||
}
|
||||
|
||||
export const STATUS_VARIANT = {
|
||||
pending: 'primary',
|
||||
success: 'success',
|
||||
warning: 'warning',
|
||||
error: 'danger',
|
||||
info: 'info',
|
||||
} as const
|
||||
|
||||
export const useRequests = createGlobalState(() => {
|
||||
const router = useRouter()
|
||||
|
||||
|
|
|
@ -1,17 +1,30 @@
|
|||
import { toValue, type MaybeRef } from 'vue'
|
||||
|
||||
import { useSettings } from '@/composables/useSettings'
|
||||
import {
|
||||
getFileContent,
|
||||
isEmptyValue,
|
||||
isObjectLiteral,
|
||||
toEntries,
|
||||
} from '@/helpers/commons'
|
||||
import type { ArrInnerType, Obj, Translation } from '@/types/commons'
|
||||
import type {
|
||||
ArrInnerType,
|
||||
Obj,
|
||||
StateStatus,
|
||||
Translation,
|
||||
} from '@/types/commons'
|
||||
import type { AdressModelValue, FileModelValue } from '@/types/form'
|
||||
import { isAdressModelValue, isFileModelValue } from '@/types/form'
|
||||
import { useSettings } from '@/composables/useSettings'
|
||||
|
||||
export const DEFAULT_STATUS_ICON = {
|
||||
export const STATUS_VARIANT = {
|
||||
pending: 'primary',
|
||||
success: 'success',
|
||||
warning: 'warning',
|
||||
error: 'danger',
|
||||
info: 'info',
|
||||
} as const
|
||||
|
||||
export const DEFAULT_VARIANT_ICON = {
|
||||
primary: null,
|
||||
secondary: null,
|
||||
success: 'check',
|
||||
|
@ -21,6 +34,10 @@ export const DEFAULT_STATUS_ICON = {
|
|||
light: null,
|
||||
dark: null,
|
||||
best: null,
|
||||
} as const
|
||||
|
||||
export function isOkStatus(status: StateStatus): status is 'info' | 'success' {
|
||||
return ['info', 'success'].includes(status)
|
||||
}
|
||||
|
||||
// FORMAT FROM CORE
|
||||
|
|
|
@ -27,6 +27,7 @@ export type CustomRoute = {
|
|||
export type RouteFromTo = Record<'to' | 'from', RouteLocationNormalized>
|
||||
export type Translation = string | Record<string, string>
|
||||
export type StateVariant = 'success' | 'info' | 'warning' | 'danger'
|
||||
export type StateStatus = 'success' | 'info' | 'warning' | 'error'
|
||||
|
||||
// HELPERS
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue