fix: refresh dashboards with current selectors (#64)

This commit is contained in:
Fine0830 2022-04-12 16:29:33 +08:00 committed by GitHub
parent 5dfbbacd14
commit 2dd9df19d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 83 additions and 34 deletions

View File

@ -77,13 +77,13 @@ import { Languages } from "@/constants/data";
import Selector from "@/components/Selector.vue";
const { t, locale } = useI18n();
const appStore = useAppStoreWithOut();
const state = reactive<{ timer: ReturnType<typeof setInterval> | null }>({
timer: null,
});
const lang = ref<string>(locale.value || "en");
const autoTime = ref<number>(6);
const auto = ref<boolean>(false);
const appStore = useAppStoreWithOut();
const auto = ref<boolean>(appStore.autoRefresh || false);
const utcArr = appStore.utc.split(":");
const utcHour = ref<number>(isNaN(Number(utcArr[0])) ? 0 : Number(utcArr[0]));
const utcMin = ref<number>(isNaN(Number(utcArr[1])) ? 0 : Number(utcArr[1]));

View File

@ -53,9 +53,7 @@ export default defineComponent({
const { t } = useI18n();
const dashboardStore = useDashboardStore();
const selectorStore = useSelectorStore();
// function layoutUpdatedEvent(newLayout: LayoutConfig[]) {
// dashboardStore.setLayout(newLayout);
// }
function clickGrid(item: LayoutConfig) {
dashboardStore.activeGridItem(item.i);
dashboardStore.selectWidget(item);

View File

@ -217,6 +217,16 @@ async function setSelector() {
return;
}
let currentService, currentDestService;
if (states.currentService) {
for (const d of selectorStore.services) {
if (d.value === states.currentService) {
currentService = d;
}
if (d.value === states.currentDestService) {
currentDestService = d;
}
}
} else {
for (const d of selectorStore.services) {
if (d.id === String(params.serviceId)) {
currentService = d;
@ -225,6 +235,7 @@ async function setSelector() {
currentDestService = d;
}
}
}
selectorStore.setCurrentService(currentService);
selectorStore.setCurrentDestService(currentDestService);
states.currentService =
@ -244,9 +255,14 @@ async function setSourceSelector() {
return;
}
const pod = params.podId || selectorStore.pods[0].id;
const currentPod = selectorStore.pods.find(
(d: { id: string }) => d.id === pod
let currentPod;
if (states.currentPod) {
currentPod = selectorStore.pods.find(
(d: { id: string }) => d.label === states.currentPod
);
} else {
currentPod = selectorStore.pods.find((d: { id: string }) => d.id === pod);
}
if (currentPod) {
selectorStore.setCurrentPod(currentPod);
states.currentPod = currentPod.label;
@ -267,9 +283,16 @@ async function setDestSelector() {
return;
}
const destPod = params.destPodId || selectorStore.destPods[0].id;
const currentDestPod = selectorStore.destPods.find(
let currentDestPod = "";
if (states.currentDestPod) {
currentDestPod = selectorStore.pods.find(
(d: { id: string }) => d.label === states.currentDestPod
);
} else {
currentDestPod = selectorStore.destPods.find(
(d: { id: string }) => d.id === destPod
);
}
if (currentDestPod) {
selectorStore.setCurrentDestPod(currentDestPod);
states.currentDestPod = currentDestPod.label;
@ -291,12 +314,24 @@ async function getServices() {
ElMessage.error(json.errors);
return;
}
selectorStore.setCurrentService(
selectorStore.services.length ? selectorStore.services[0] : null
let s;
if (states.currentService) {
s = (selectorStore.services || []).find(
(d) => d.label === states.currentService
);
selectorStore.setCurrentDestService(
selectorStore.services.length ? selectorStore.services[1] : null
} else {
s = (selectorStore.services || []).find((d, index) => index === 0);
}
selectorStore.setCurrentService(s || null);
let d;
if (states.currentService) {
d = (selectorStore.services || []).find(
(d) => d.label === states.currentDestService
);
} else {
d = (selectorStore.services || []).find((d, index) => index === 1);
}
selectorStore.setCurrentDestService(d || null);
if (!selectorStore.currentService) {
return;
}
@ -447,18 +482,26 @@ async function fetchPods(
case EntityType[2].value:
resp = await selectorStore.getEndpoints({ serviceId, ...param });
if (setPod) {
selectorStore.setCurrentPod(
selectorStore.pods.length ? selectorStore.pods[0] : null
);
let p;
if (states.currentPod) {
p = selectorStore.pods.find((d) => d.label === states.currentPod);
} else {
p = selectorStore.pods.find((d, index) => index === 0);
}
selectorStore.setCurrentPod(p || null);
states.currentPod = selectorStore.currentPod.label;
}
break;
case EntityType[3].value:
resp = await selectorStore.getServiceInstances({ serviceId });
if (setPod) {
selectorStore.setCurrentPod(
selectorStore.pods.length ? selectorStore.pods[0] : null
);
let p;
if (states.currentPod) {
p = selectorStore.pods.find((d) => d.label === states.currentPod);
} else {
p = selectorStore.pods.find((d, index) => index === 0);
}
selectorStore.setCurrentPod(p || null);
states.currentPod = selectorStore.currentPod.label;
}
break;
@ -469,9 +512,13 @@ async function fetchPods(
...param,
});
if (setPod) {
selectorStore.setCurrentDestPod(
selectorStore.destPods.length ? selectorStore.destPods[0] : null
);
let p;
if (states.currentDestPod) {
p = selectorStore.pods.find((d) => d.label === states.currentDestPod);
} else {
p = selectorStore.pods.find((d, index) => index === 0);
}
selectorStore.setCurrentDestPod(p || null);
states.currentDestPod = selectorStore.currentDestPod.label;
}
break;
@ -481,9 +528,13 @@ async function fetchPods(
isRelation: true,
});
if (setPod) {
selectorStore.setCurrentDestPod(
selectorStore.destPods.length ? selectorStore.destPods[0] : null
);
let p;
if (states.currentDestPod) {
p = selectorStore.pods.find((d) => d.label === states.currentDestPod);
} else {
p = selectorStore.pods.find((d, index) => index === 0);
}
selectorStore.setCurrentDestPod(p || null);
states.currentDestPod = selectorStore.currentDestPod.label;
}
break;