-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(exhook): show worst status is status component
- Loading branch information
1 parent
ad45186
commit 95da6b1
Showing
6 changed files
with
119 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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,59 @@ | ||
import { ExhookStatus, NodeStatusClass } from '@/types/enum' | ||
import { Exhook } from '@/types/systemModule' | ||
import useI18nTl from '../useI18nTl' | ||
|
||
export default (): { | ||
getTheWorstStatus: (exhook: Exhook) => ExhookStatus | ||
statusText: (status: ExhookStatus) => string | ||
statusTextClass: (status: ExhookStatus) => NodeStatusClass | ||
} => { | ||
const { t, tl } = useI18nTl('Exhook') | ||
|
||
const getTheWorstStatus = (exhook: Exhook) => { | ||
const { node_status } = exhook | ||
if (!node_status || node_status.length === 0) { | ||
return ExhookStatus.Error | ||
} | ||
let ret = ExhookStatus.Connected | ||
// The order cannot be changed | ||
|
||
const badStatusArr = [ | ||
ExhookStatus.Connected, | ||
ExhookStatus.Connecting, | ||
ExhookStatus.Unconnected, | ||
ExhookStatus.Disable, | ||
ExhookStatus.Error, | ||
] | ||
for (const currentBadStatus of badStatusArr) { | ||
if (node_status.some(({ status }) => status === currentBadStatus)) { | ||
ret = currentBadStatus | ||
break | ||
} | ||
} | ||
return ret | ||
} | ||
|
||
const statusText = (status: ExhookStatus) => | ||
({ | ||
[ExhookStatus.Connected]: t('RuleEngine.connected'), | ||
[ExhookStatus.Connecting]: t('RuleEngine.connecting'), | ||
[ExhookStatus.Unconnected]: t('RuleEngine.disconnected'), | ||
[ExhookStatus.Disable]: tl('disabled'), | ||
[ExhookStatus.Error]: tl('error'), | ||
}[status] || 'unknown') | ||
|
||
const statusTextClass = (status: ExhookStatus): NodeStatusClass => | ||
({ | ||
[ExhookStatus.Connected]: NodeStatusClass.Success, | ||
[ExhookStatus.Connecting]: NodeStatusClass.Warning, | ||
[ExhookStatus.Unconnected]: NodeStatusClass.Danger, | ||
[ExhookStatus.Disable]: NodeStatusClass.Danger, | ||
[ExhookStatus.Error]: NodeStatusClass.Danger, | ||
}[status] || NodeStatusClass.Danger) | ||
|
||
return { | ||
getTheWorstStatus, | ||
statusText, | ||
statusTextClass, | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -399,4 +399,8 @@ export default { | |
zh: '是否启用', | ||
en: 'Enable', | ||
}, | ||
rate: { | ||
zh: '速率', | ||
en: 'Rate', | ||
}, | ||
} |
This file contains 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 |
---|---|---|
|
@@ -123,4 +123,8 @@ export default { | |
zh: '禁用', | ||
en: 'Disabled', | ||
}, | ||
rateUnit: { | ||
zh: '次/秒', | ||
en: 'time/s', | ||
}, | ||
} |
This file contains 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 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,47 @@ | ||
<template> | ||
<el-table-column class="exhook-item-msg" type="expand"> | ||
<template #default="{ row }"> | ||
<el-row :gutter="26" v-if="row?.node_status && Array.isArray(row.node_status)"> | ||
<el-col :span="8" v-for="{ node, status } in row.node_status" :key="node"> | ||
<el-card> | ||
<el-descriptions :title="node" direction="vertical" :column="1" border> | ||
<el-descriptions-item :label="tl('status')"> | ||
{{ statusText(status) }} | ||
</el-descriptions-item> | ||
<el-descriptions-item :label="t('RuleEngine.success')"> | ||
{{ getNodeMetrics(row.node).succeed }} | ||
</el-descriptions-item> | ||
<el-descriptions-item :label="t('RuleEngine.failure')"> | ||
{{ getNodeMetrics(row.node).failed }} | ||
</el-descriptions-item> | ||
<el-descriptions-item :label="t('Base.rate')"> | ||
{{ getNodeMetrics(row.node).rate }} {{ t('Exhook.rateUnit') }} | ||
</el-descriptions-item> | ||
</el-descriptions> | ||
</el-card> | ||
</el-col> | ||
</el-row> | ||
</template> | ||
</el-table-column> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import useI18nTl from '@/hooks/useI18nTl' | ||
import { Exhook } from '@/types/systemModule' | ||
import { defineProps, PropType } from 'vue' | ||
import useExhookItemStatus from '@/hooks/Exhook/useExhookItemStatus' | ||
const props = defineProps({ | ||
exhook: { | ||
type: Object as PropType<Exhook>, | ||
}, | ||
}) | ||
const { tl, t } = useI18nTl('Base') | ||
const { statusText } = useExhookItemStatus() | ||
const getNodeMetrics = (exhook, node) => { | ||
const target = props.exhook?.node_metrics.find((item) => item.node === node) | ||
return target ? target : {} | ||
} | ||
</script> |
This file contains 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