mirror of
https://github.com/openobserve/openobserve.git
synced 2026-11-05 08:09:22 +00:00
- dashboard show time range differ warning when cache data is used <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a button to notify users when displayed data is cached and differs from the selected time range. - Added a new event to handle updates regarding cached data differences in the dashboard components. - **Enhancements** - Improved caching mechanism to include time range specifications for better data management. - Enhanced responsiveness of components to changes in cached data states. - **Bug Fixes** - Streamlined handling of null values in configuration options to prevent undefined values from affecting logic. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
100 lines
2.3 KiB
TypeScript
100 lines
2.3 KiB
TypeScript
/**
|
|
* This is the cache object which is used to store the panel level cache data
|
|
* Ex:
|
|
* {
|
|
* "folder1": {
|
|
* "dashboard1": {
|
|
* "panel1": {
|
|
* "key": {}, // Data against which the cache is stored
|
|
* "value": {} // The cache to restore
|
|
* }
|
|
* }
|
|
* }
|
|
* }
|
|
*/
|
|
const cache: any = {};
|
|
|
|
declare global {
|
|
interface Window {
|
|
_o2_removeDashboardCache: () => void;
|
|
_o2_getDashboardCache: () => any;
|
|
}
|
|
}
|
|
|
|
window._o2_removeDashboardCache = () => {
|
|
// empty the cache object by removing all keys
|
|
// as we can not reassign const
|
|
Object.keys(cache).forEach((key) => {
|
|
delete cache[key];
|
|
});
|
|
};
|
|
|
|
window._o2_getDashboardCache = () => {
|
|
// empty the cache object by removing all keys
|
|
// as we can not reassign const
|
|
return JSON.parse(JSON.stringify(cache));
|
|
};
|
|
/**
|
|
* Use Panel Cache Data on a per dashboard basis in combination with folderid, dashboard id and panel id
|
|
*/
|
|
export const usePanelCache = (
|
|
folderId: string,
|
|
dashboardId: string,
|
|
panelId: string,
|
|
) => {
|
|
if (!(folderId && dashboardId && panelId)) {
|
|
const savePanelCache = (data: any) => {
|
|
// do nothing
|
|
};
|
|
|
|
const getPanelCache = () => {
|
|
return null;
|
|
};
|
|
|
|
return {
|
|
savePanelCache,
|
|
getPanelCache,
|
|
};
|
|
}
|
|
|
|
// create nested paths as required
|
|
const createNestedPathsIfRequired = () => {
|
|
// check if cache is there or not
|
|
if (cache?.[folderId]?.[dashboardId]?.[panelId]) {
|
|
return;
|
|
}
|
|
|
|
// create nested paths as required
|
|
if (!cache[folderId]) {
|
|
cache[folderId] = {};
|
|
}
|
|
|
|
if (!cache[folderId][dashboardId]) {
|
|
cache[folderId][dashboardId] = {};
|
|
}
|
|
|
|
if (!cache[folderId][dashboardId][panelId]) {
|
|
cache[folderId][dashboardId][panelId] = {};
|
|
}
|
|
};
|
|
|
|
const savePanelCache = (key: any, data: any, cacheTimeRange: any) => {
|
|
createNestedPathsIfRequired();
|
|
|
|
cache[folderId][dashboardId][panelId] = {
|
|
key: JSON.parse(JSON.stringify(key)), // deep copy key,
|
|
value: JSON.parse(JSON.stringify(data)), // deep copy data
|
|
cacheTimeRange: JSON.parse(JSON.stringify(cacheTimeRange)),
|
|
};
|
|
};
|
|
|
|
const getPanelCache = () => {
|
|
return cache?.[folderId]?.[dashboardId]?.[panelId];
|
|
};
|
|
|
|
return {
|
|
savePanelCache,
|
|
getPanelCache,
|
|
};
|
|
};
|