mirror of
https://github.com/vatesfr/xen-orchestra.git
synced 2026-09-10 22:14:48 -05:00
feat(web-core): replace no-use-before-define ESLint rule with its TS-compliant version (#7916)
This commit is contained in:
committed by
GitHub
parent
f78a140fbb
commit
e15f2a1428
@@ -104,6 +104,8 @@ module.exports = {
|
||||
'no-redeclare': 'off', // automatically checked by the TypeScript compiler
|
||||
'no-dupe-class-members': 'off', // automatically checked by the TypeScript compiler
|
||||
'no-undef': 'off', // automatically checked by the TypeScript compiler
|
||||
'no-use-before-define': 'off', // replaced with the rule below
|
||||
'@typescript-eslint/no-use-before-define': ['error', { functions: false }],
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'vue/multi-word-component-names': 'off',
|
||||
// Vue 3 - Strongly Recommended
|
||||
|
||||
@@ -32,7 +32,7 @@ const url = computed(() => {
|
||||
let vncClient: VncClient | undefined
|
||||
let nConnectionAttempts = 0
|
||||
|
||||
const handleDisconnectionEvent = () => {
|
||||
function handleDisconnectionEvent() {
|
||||
clearVncClient()
|
||||
|
||||
if (props.isConsoleAvailable) {
|
||||
@@ -51,9 +51,12 @@ const handleDisconnectionEvent = () => {
|
||||
createVncConnection()
|
||||
}
|
||||
}
|
||||
const handleConnectionEvent = () => (nConnectionAttempts = 0)
|
||||
|
||||
const clearVncClient = () => {
|
||||
function handleConnectionEvent() {
|
||||
nConnectionAttempts = 0
|
||||
}
|
||||
|
||||
function clearVncClient() {
|
||||
if (vncClient === undefined) {
|
||||
return
|
||||
}
|
||||
@@ -66,7 +69,7 @@ const clearVncClient = () => {
|
||||
vncClient = undefined
|
||||
}
|
||||
|
||||
const createVncConnection = async () => {
|
||||
async function createVncConnection() {
|
||||
if (nConnectionAttempts !== 0) {
|
||||
await promiseTimeout(FIBONACCI_MS_ARRAY[nConnectionAttempts - 1])
|
||||
|
||||
|
||||
@@ -109,6 +109,8 @@ enum TAB {
|
||||
SETTINGS,
|
||||
}
|
||||
|
||||
const selectedTab = ref<TAB>(TAB.NONE)
|
||||
|
||||
const tab = (tab: TAB, params: Param[]) =>
|
||||
reactive({
|
||||
onClick: () => (selectedTab.value = tab),
|
||||
@@ -131,8 +133,6 @@ const eventParams = computed(() => [
|
||||
const settingParams = computed(() => props.params.filter(isSettingParam))
|
||||
const slotParams = computed(() => props.params.filter(isSlotParam))
|
||||
|
||||
const selectedTab = ref<TAB>(TAB.NONE)
|
||||
|
||||
onBeforeMount(() => {
|
||||
if (propParams.value.length !== 0) {
|
||||
selectedTab.value = TAB.PROPS
|
||||
|
||||
@@ -60,6 +60,8 @@ const { hasError: vmStoreHasError, isReady: isVmStoreReady, records: vms } = use
|
||||
|
||||
const { getByOpaqueRef: getVmMetrics, isReady: isVmMetricsStoreReady } = useVmMetricsStore().subscribe()
|
||||
|
||||
const isReady = logicAnd(isVmStoreReady, isHostStoreReady, isVmMetricsStoreReady)
|
||||
|
||||
const nPCpu = computed(() => runningHosts.value.reduce((total, host) => total + Number(host.cpu_info.cpu_count), 0))
|
||||
|
||||
const nVCpuInUse = computed(() => {
|
||||
@@ -75,7 +77,7 @@ const nVCpuInUse = computed(() => {
|
||||
const value = computed(() => Math.round(percent(nVCpuInUse.value, nPCpu.value)))
|
||||
const maxValue = computed(() => Math.ceil(value.value / 100) * 100)
|
||||
const state = computed(() => (value.value > 100 ? 'warning' : 'success'))
|
||||
const isReady = logicAnd(isVmStoreReady, isHostStoreReady, isVmMetricsStoreReady)
|
||||
|
||||
const hasError = computed(() => hostStoreHasError.value || vmStoreHasError.value)
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,31 +1,6 @@
|
||||
import type { RawObjectType, XenApiMessage } from '@/libs/xen-api/xen-api.types'
|
||||
import type { XenApiAlarm, XenApiAlarmType } from '@/types/xen-api'
|
||||
|
||||
export const messageToAlarm = <RelationType extends RawObjectType>(
|
||||
message: XenApiMessage<RelationType> | undefined
|
||||
): XenApiAlarm<RelationType> | undefined => {
|
||||
if (message === undefined || message.name !== 'ALARM') {
|
||||
return
|
||||
}
|
||||
|
||||
return {
|
||||
...message,
|
||||
...parseAlarmBody(message.body),
|
||||
}
|
||||
}
|
||||
|
||||
export const messagesToAlarms = (messages: XenApiMessage<any>[]) => {
|
||||
return messages.reduce((acc, message) => {
|
||||
const alarm = messageToAlarm(message)
|
||||
|
||||
if (alarm !== undefined) {
|
||||
acc.push(alarm)
|
||||
}
|
||||
|
||||
return acc
|
||||
}, [] as XenApiAlarm<any>[])
|
||||
}
|
||||
|
||||
const parseXml = (xml: string) => {
|
||||
const parser = new DOMParser()
|
||||
const dom = parser.parseFromString(xml, 'text/xml')
|
||||
@@ -68,3 +43,28 @@ export const parseAlarmBody = (body: string): { level: number; type: XenApiAlarm
|
||||
triggerLevel: parseFloat(document.triggerLevel ?? '0'),
|
||||
}
|
||||
}
|
||||
|
||||
export const messageToAlarm = <RelationType extends RawObjectType>(
|
||||
message: XenApiMessage<RelationType> | undefined
|
||||
): XenApiAlarm<RelationType> | undefined => {
|
||||
if (message === undefined || message.name !== 'ALARM') {
|
||||
return
|
||||
}
|
||||
|
||||
return {
|
||||
...message,
|
||||
...parseAlarmBody(message.body),
|
||||
}
|
||||
}
|
||||
|
||||
export const messagesToAlarms = (messages: XenApiMessage<any>[]) => {
|
||||
return messages.reduce((acc, message) => {
|
||||
const alarm = messageToAlarm(message)
|
||||
|
||||
if (alarm !== undefined) {
|
||||
acc.push(alarm)
|
||||
}
|
||||
|
||||
return acc
|
||||
}, [] as XenApiAlarm<any>[])
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ const consoleContainer = ref<HTMLDivElement | null>(null)
|
||||
let vncClient: VncClient | undefined
|
||||
let nConnectionAttempts = 0
|
||||
|
||||
const handleDisconnectionEvent = () => {
|
||||
function handleDisconnectionEvent() {
|
||||
clearVncClient()
|
||||
|
||||
nConnectionAttempts++
|
||||
@@ -41,9 +41,11 @@ const handleDisconnectionEvent = () => {
|
||||
createVncConnection()
|
||||
}
|
||||
|
||||
const handleConnectionEvent = () => (nConnectionAttempts = 0)
|
||||
function handleConnectionEvent() {
|
||||
nConnectionAttempts = 0
|
||||
}
|
||||
|
||||
const clearVncClient = () => {
|
||||
function clearVncClient() {
|
||||
if (vncClient === undefined) {
|
||||
return
|
||||
}
|
||||
@@ -55,7 +57,7 @@ const clearVncClient = () => {
|
||||
vncClient = undefined
|
||||
}
|
||||
|
||||
const createVncConnection = async () => {
|
||||
async function createVncConnection() {
|
||||
if (nConnectionAttempts !== 0) {
|
||||
await promiseTimeout(FIBONACCI_MS_ARRAY[nConnectionAttempts - 1])
|
||||
|
||||
|
||||
@@ -76,12 +76,12 @@ const interactions = computed<Interaction[]>(() => [
|
||||
|
||||
const tableName = inject<string>('tableName')
|
||||
|
||||
const columnName = `${tableName}__${props.id}`
|
||||
|
||||
const currentInteraction = computed(() =>
|
||||
interactions.value.find(interaction => router.currentRoute.value.query[columnName] === interaction.id)
|
||||
)
|
||||
|
||||
const columnName = `${tableName}__${props.id}`
|
||||
|
||||
const updateInteraction = (interaction: Interaction) => {
|
||||
router.replace({
|
||||
query: {
|
||||
|
||||
Reference in New Issue
Block a user