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