Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed(monitoring): there is data legacy in the search node or group name, after deleting the node, and so on. #390

Merged
merged 2 commits into from
May 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 48 additions & 16 deletions src/composables/data/useDataMonitoring.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { queryGroupList, queryTagList } from '@/api/config'
import { queryGroupList, queryTagList, querySouthDriverList } from '@/api/config'
import { getMonitoringData } from '@/api/data'
import useSouthDriver from '@/composables/config/useSouthDriver'
import useWriteDataCheckNParse from '@/composables/data/useWriteDataCheckNParse'
import type { GroupData, TagForm } from '@/types/config'
import type { GroupData, TagForm, RawDriverData } from '@/types/config'
import type { TagDataInMonitoring } from '@/types/data'
import { TagAttributeType, TagType } from '@/types/enums'
import { paginate, listOrderByKey } from '@/utils/utils'
Expand All @@ -29,7 +28,7 @@ export default () => {
const { t } = useI18n()
const store = useStore()

const { totalSouthDriverList: nodeList } = useSouthDriver()
const nodeList: Ref<Array<RawDriverData>> = ref([])
const groupList: Ref<Array<GroupData>> = ref([])

const { findLabelByValue: findTagTypeLabelByValue } = useTagTypeSelect()
Expand Down Expand Up @@ -105,7 +104,7 @@ export default () => {

const reSubAfterReturnError = async () => {
const { groupName, lastTimestamp, count } = reSubCount
const { node, groupName: currentGroupName } = currentGroup.value
const { groupName: currentGroupName } = currentGroup.value
let canReSubAndRequest = false
if (Date.now() - lastTimestamp < 500 && groupName === currentGroupName && count < 3) {
canReSubAndRequest = true
Expand Down Expand Up @@ -228,6 +227,18 @@ export default () => {
keywordSearch.value = ''
}

const initCurrentGroupName = async () => {
const { node, groupName } = currentGroup.value

// reset default value when remove a node.
const group = groupList.value.find(({ name }) => name === groupName)
currentGroup.value.groupName = group?.name || ''

if (node && currentGroup.value.groupName) {
await getTagList()
}
}

// change node
const selectedNodeChanged = async (nodeName: string) => {
if (nodeName) {
Expand All @@ -237,10 +248,9 @@ export default () => {
totalData.value = []

const data = await queryGroupList(currentGroup.value.node.toString())
const isExistGroup = data.find((group) => group.name === currentGroup.value.groupName)
currentGroup.value.groupName = isExistGroup?.name || ''

groupList.value = data

await initCurrentGroupName()
} catch (error) {
groupList.value = []
}
Expand Down Expand Up @@ -304,18 +314,40 @@ export default () => {
return item.attribute && item.attribute.some((attr) => attr === TagAttributeType.Write)
}

const initTagList = async () => {
const { node, groupName } = currentGroup.value
if (node) {
await selectedNodeChanged(node)
const getSouthNodeList = async () => {
try {
nodeList.value = await querySouthDriverList()
return Promise.resolve(nodeList.value)
} catch (error) {
nodeList.value = []
return Promise.reject(error)
}
if (node && groupName) {
await getTagList()
}

const initCurrentNode = async () => {
const { node } = currentGroup.value

// reset default value when remove a node.
if (node && !currentNodeName.value) {
currentGroup.value = {
node: '',
groupName: '',
}
}

if (currentGroup.value.node) {
await selectedNodeChanged(node)
}
}

const initTagList = async () => {
await initCurrentNode()
await initCurrentGroupName()
}

onMounted(() => {
initTagList()
onMounted(async () => {
await getSouthNodeList()
await initTagList()
})

onUnmounted(() => {
Expand Down