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

[#2152] improvement(dashboard): Add session cache to support refresh page of dashboard #2238

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions dashboard/src/main/webapp/src/components/LayoutPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,21 @@ export default {
}
}

function handleChangeServer(key) {
const handleChangeServer = (key) => {
currentServerStore.currentServer = key
}

async function getSelectCurrentServer() {
const res = await getAllCoordinatorAddrees()
const selectCurrentServer = res.data.data
currentServerStore.currentServer = Object.keys(selectCurrentServer)[0]
if (!currentServerStore.currentServer) {
currentServerStore.currentServer = Object.keys(selectCurrentServer)[0]
}
hostNameAndPorts.length = 0
Object.entries(selectCurrentServer).forEach(([key, value]) => {
hostNameAndPorts.push({ value: value, label: key })
})
hostNameAndPorts.sort((a, b) => a.label.localeCompare(b.label))
}

onMounted(() => {
Expand Down
10 changes: 4 additions & 6 deletions dashboard/src/main/webapp/src/pages/CoordinatorServerPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
</template>

<script>
import { ref, reactive, computed, onMounted } from 'vue'
import { ref, reactive, computed, onMounted, watch } from 'vue'
import { ElMessage } from 'element-plus'
import {
getCoordinatorConf,
Expand Down Expand Up @@ -196,11 +196,9 @@ export default {
/**
* The system obtains data from global variables and requests the interface to obtain new data after data changes.
*/
currentServerStore.$subscribe((mutable, state) => {
if (state.currentServer) {
getCoordinatorServerConfPage()
getCoorServerInfo()
}
watch(() => currentServerStore.currentServer, () => {
getCoordinatorServerConfPage()
getCoorServerInfo()
})

onMounted(() => {
Expand Down
11 changes: 8 additions & 3 deletions dashboard/src/main/webapp/src/store/useCurrentServerStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@
*/

import { defineStore } from 'pinia'
import { ref } from 'vue'
import { ref, watch } from 'vue'

/**
* Create a global shared repository that allows you to share state across components/pages.
* @type {StoreDefinition<"overall", _ExtractStateFromSetupStore<{currentServer: Ref<UnwrapRef<string>>}>, _ExtractGettersFromSetupStore<{currentServer: Ref<UnwrapRef<string>>}>, _ExtractActionsFromSetupStore<{currentServer: Ref<UnwrapRef<string>>}>>}
*/
export const useCurrentServerStore = defineStore('overall', () => {
const currentServer = ref('')
return { currentServer }
const currentServer = ref(sessionStorage.getItem('currentServer'))

watch(currentServer, (newVal) => {
sessionStorage.setItem('currentServer', newVal)
})

return { currentServer }
})
Loading