Skip to content

Commit

Permalink
feat(monitoring): Node and group add memory function
Browse files Browse the repository at this point in the history
  • Loading branch information
orangegzx authored and ysfscream committed Jul 24, 2023
1 parent 465de41 commit f6b8164
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
20 changes: 17 additions & 3 deletions src/composables/data/useDataMonitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ export default () => {
}

const groupIsDeleted = async () => {
currentGroup.value.groupName = ''
currentGroup.value = {
node: currentGroup.value.node,
groupName: '',
}
totalData.value = []
await getGroupList(currentGroup.value.node)
}
Expand Down Expand Up @@ -279,7 +282,11 @@ export default () => {
const selectedNodeChanged = async (nodeName: string) => {
if (nodeName) {
try {
currentGroup.value.node = nodeName
currentGroup.value = {
...currentGroup.value,
node: nodeName,
}

selectedGroup = undefined
totalData.value = []

Expand All @@ -290,7 +297,10 @@ export default () => {
groupList.value = []
}
} else {
currentGroup.value.groupName = ''
currentGroup.value = {
node: currentGroup.value.node,
groupName: '',
}
resetKeywordSearch()
groupList.value = []
totalData.value = []
Expand All @@ -301,6 +311,10 @@ export default () => {

// change group
const selectedGroupChanged = async (groupName: string) => {
currentGroup.value = {
node: currentGroup.value.node,
groupName,
}
resetKeywordSearch()

if (groupName) {
Expand Down
8 changes: 3 additions & 5 deletions src/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createStore } from 'vuex'
import { getToken, setToken, clearLocalStorage } from '@/utils/user'
import { getToken, setToken, clearLocalStorage, getNodeGroupData, setNodeGroupData } from '@/utils/user'
import { DEFAULT_LANG } from '@/utils/constants'

interface paginationInfo {
Expand Down Expand Up @@ -43,10 +43,7 @@ export default createStore<State>({
pageSize: 30,
total: 0,
},
nodeGroupMemory: {
node: '',
groupName: '',
},
nodeGroupMemory: getNodeGroupData(),
axiosPromiseCancel: [],
}
},
Expand Down Expand Up @@ -78,6 +75,7 @@ export default createStore<State>({
},
SET_NODE_GROUP(state, data: NodeGroup) {
state.nodeGroupMemory = data
setNodeGroupData(data)
},
ADD_AXIOS_PROMISE_CANCEL(state, data: any) {
state.axiosPromiseCancel.push(data)
Expand Down
14 changes: 14 additions & 0 deletions src/utils/user.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const LOCAL_STORAGE_TOKEN_KEY = 'token'
export const LOCAL_STORAGE_BREADCRUMB = 'breadcrumbs'
export const LOCAL_STORAGE_NODE_GROUP = 'nodeGroupData'

export const getToken = (): string | null => window.localStorage.getItem(LOCAL_STORAGE_TOKEN_KEY)

Expand All @@ -20,3 +21,16 @@ export const getBreadcrumbFullPaths = (): string => {
const res: string = window.localStorage.getItem(LOCAL_STORAGE_BREADCRUMB) || ''
return res
}

interface NodeGroup {
node: string
groupName: string
}
export const setNodeGroupData = (data: NodeGroup): void => {
window.localStorage.setItem(LOCAL_STORAGE_NODE_GROUP, JSON.stringify(data))
}
export const getNodeGroupData = (): NodeGroup => {
const res: NodeGroup =
JSON.parse(window.localStorage.getItem(LOCAL_STORAGE_NODE_GROUP) || '{"node":"","groupName":""}') || ''
return res
}

0 comments on commit f6b8164

Please sign in to comment.