fix: dashboard org redirection fixes (#5169)

- #5163 
- #2236 

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
	- Enhanced logic to prevent navigation to empty dashboards.
	- Improved routing when returning to the dashboard list.
	- Added organization identifier to routing for adding panels.

- **Bug Fixes**
- Added checks to handle undefined or empty dashboard data in the
`AddPanel` component.
- Refined error handling for panel operations, ensuring better user
feedback.

- **Documentation**
- Updated method signatures to reflect changes in navigation and data
handling logic.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: ktx-abhay <abhay.padamani@kiara.tech>
Co-authored-by: ktx-vaidehi <vaidehi.akhani@kiara.tech>
This commit is contained in:
ktx-kirtan
2024-11-28 12:49:13 +05:30
committed by GitHub
co-authored by ktx-abhay ktx-vaidehi
parent d33b39f840
commit ceac2b0f57
4 changed files with 38 additions and 5 deletions
+2 -2
View File
@@ -197,7 +197,7 @@ function findDashboard(dashboardId: string, store: any, folderId: any) {
export const getTabDataFromTabId = (dashboardData: any, tabId: any) => {
// find tab from tabId
return dashboardData.tabs.find((tab: any) => tab.tabId == tabId);
return dashboardData?.tabs?.find((tab: any) => tab.tabId == tabId);
};
const getMaxIAndMaxYFromTab = (tab: any) => {
@@ -575,7 +575,7 @@ export const getPanel = async (
// find tab from tabId
const tab = getTabDataFromTabId(currentDashboard, tabId);
const paneldata = tab.panels?.find((it: any) => it.id == panelId);
const paneldata = tab?.panels?.find((it: any) => it?.id == panelId);
return paneldata;
} catch (error) {
throw error;
@@ -441,6 +441,7 @@ export default defineComponent({
return router.push({
path: "/dashboards/add_panel",
query: {
org_identifier: store.state.selectedOrganization.identifier,
dashboard: route.query.dashboard,
folder: route.query.folder ?? "default",
tab: route.query.tab ?? props.dashboardData.panels[0]?.tabId,
+10 -1
View File
@@ -534,6 +534,15 @@ export default defineComponent({
route.query.folder ?? "default",
);
if (
!currentDashboardData?.data ||
typeof currentDashboardData.data !== "object" ||
!Object.keys(currentDashboardData.data).length
) {
goBackToDashboardList();
return;
}
// set selected tab from query params
const selectedTab = currentDashboardData?.data?.tabs?.find(
(tab: any) => tab.tabId === route.query.tab,
@@ -683,7 +692,6 @@ export default defineComponent({
return router.push({
path: "/dashboards",
query: {
dashboard: route.query.dashboard,
folder: route.query.folder ?? "default",
},
});
@@ -694,6 +702,7 @@ export default defineComponent({
return router.push({
path: "/dashboards/add_panel",
query: {
org_identifier: store.state.selectedOrganization.identifier,
dashboard: route.query.dashboard,
folder: route.query.folder ?? "default",
tab: route.query.tab ?? currentDashboardData.data.tabs[0].tabId,
+25 -2
View File
@@ -563,7 +563,7 @@ export default defineComponent({
Object.assign(
dashboardPanelData.data,
JSON.parse(JSON.stringify(panelData))
JSON.parse(JSON.stringify(panelData ?? {})),
);
// check if vrl function exists
@@ -636,6 +636,18 @@ export default defineComponent({
// console.time("AddPanel:loadDashboard:after");
currentDashboardData.data = data;
if (
!currentDashboardData?.data ||
typeof currentDashboardData.data !== "object" ||
!Object.keys(currentDashboardData.data).length
) {
window.removeEventListener("beforeunload", beforeUnloadHandler);
forceSkipBeforeUnloadListener = true;
goBack();
return;
}
// if variables data is null, set it to empty list
if (
!(
@@ -814,7 +826,7 @@ export default defineComponent({
org_identifier: store.state.selectedOrganization.identifier,
dashboard: route.query.dashboard,
folder: route.query.folder,
tab: route.query.tab ?? currentDashboardData.data.tabs[0].tabId,
tab: route.query.tab ?? currentDashboardData?.data?.tabs?.[0]?.tabId,
},
});
};
@@ -843,7 +855,18 @@ export default defineComponent({
return;
};
// this is used to set to true, when we know we have to force the navigation
// in cases where org is changed, we need to force a nvaigation, without warning
let forceSkipBeforeUnloadListener = false;
onBeforeRouteLeave((to, from, next) => {
// check if it is a force navigation, then allow
if(forceSkipBeforeUnloadListener) {
next()
return;
}
// else continue to warn user
if (from.path === "/dashboards/add_panel" && isPanelConfigChanged.value) {
const confirmMessage = t("dashboard.unsavedMessage");
if (window.confirm(confirmMessage)) {