Skip to content
Snippets Groups Projects
Unverified Commit 447c7ba6 authored by Emmad Usmani's avatar Emmad Usmani Committed by GitHub
Browse files

make initial card position independent of other tabs (#30464)

parent 429eb678
No related branches found
No related tags found
No related merge requests found
......@@ -23,6 +23,22 @@ function generateTemporaryDashcardId() {
return tempId--;
}
function getExistingDashCards(state, dashId, tabId) {
const { dashboards, dashcards } = state.dashboard;
const dashboard = dashboards[dashId];
return dashboard.ordered_cards
.map(id => dashcards[id])
.filter(dc => {
if (dc.isRemoved) {
return false;
}
if (tabId != null) {
return dc.dashboard_tab_id === tabId;
}
return true;
});
}
export const addCardToDashboard =
({ dashId, cardId, tabId }) =>
async (dispatch, getState) => {
......@@ -30,12 +46,6 @@ export const addCardToDashboard =
const card = Questions.selectors
.getObject(getState(), { entityId: cardId })
.card();
const { dashboards, dashcards } = getState().dashboard;
const dashboard = dashboards[dashId];
const existingCards = dashboard.ordered_cards
.map(id => dashcards[id])
.filter(dc => !dc.isRemoved);
const { visualization } = getVisualizationRaw([{ card }]);
const createdCardSize = visualization.defaultSize || DEFAULT_CARD_SIZE;
......@@ -47,7 +57,7 @@ export const addCardToDashboard =
card: card,
series: [],
...getPositionForNewDashCard(
existingCards,
getExistingDashCards(getState(), dashId, tabId),
createdCardSize.width,
createdCardSize.height,
),
......@@ -66,12 +76,6 @@ export const addDashCardToDashboard = function ({
tabId,
}) {
return function (dispatch, getState) {
const { dashboards, dashcards } = getState().dashboard;
const dashboard = dashboards[dashId];
const existingCards = dashboard.ordered_cards
.map(id => dashcards[id])
.filter(dc => !dc.isRemoved);
const { visualization } = getVisualizationRaw([dashcardOverrides]);
const createdCardSize = visualization.defaultSize || DEFAULT_CARD_SIZE;
......@@ -83,7 +87,7 @@ export const addDashCardToDashboard = function ({
dashboard_tab_id: tabId ?? null,
series: [],
...getPositionForNewDashCard(
existingCards,
getExistingDashCards(getState(), dashId, tabId),
createdCardSize.width,
createdCardSize.height,
),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment