refactor: added check for dashboard length (#2997)

Co-authored-by: Palash Gupta <palashgdev@gmail.com>
This commit is contained in:
Rajat Dabade 2023-07-10 11:18:33 +05:30 committed by GitHub
parent e3e0787459
commit c0d10f0d88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,24 +7,27 @@ export const getDashboardVariables = (): Record<string, unknown> => {
globalTime, globalTime,
dashboards: { dashboards }, dashboards: { dashboards },
} = store.getState(); } = store.getState();
const [selectedDashboard] = dashboards || []; if (dashboards.length > 0) {
const { const [selectedDashboard] = dashboards || [];
data: { variables = {} }, const {
} = selectedDashboard; data: { variables = {} },
} = selectedDashboard;
const { start, end } = getStartEndRangeTime({ const { start, end } = getStartEndRangeTime({
type: 'GLOBAL_TIME', type: 'GLOBAL_TIME',
interval: globalTime.selectedTime, interval: globalTime.selectedTime,
}); });
const variablesTuple: Record<string, unknown> = { const variablesTuple: Record<string, unknown> = {
SIGNOZ_START_TIME: parseInt(start, 10) * 1e3, SIGNOZ_START_TIME: parseInt(start, 10) * 1e3,
SIGNOZ_END_TIME: parseInt(end, 10) * 1e3, SIGNOZ_END_TIME: parseInt(end, 10) * 1e3,
}; };
Object.keys(variables).forEach((key) => { Object.keys(variables).forEach((key) => {
variablesTuple[key] = variables[key].selectedValue; variablesTuple[key] = variables[key].selectedValue;
}); });
return variablesTuple; return variablesTuple;
}
return {};
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }