Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor editing dashboard's cards #29641

Merged
merged 32 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
eaed96a
BE: MVP to bulk create/delete APIs
qnkhuat Mar 29, 2023
8a3438c
tests fixes
qnkhuat Mar 29, 2023
635ce33
test fixes
qnkhuat Mar 29, 2023
40fa70a
use bulk cards insert everywhere
qnkhuat Mar 29, 2023
2753b97
bulk everything -- add dashcards
qnkhuat Mar 30, 2023
470a9d8
bulk everything for real now(previously only bulk for post/update cards)
qnkhuat Mar 30, 2023
5656423
test fixes
qnkhuat Mar 31, 2023
d0c7821
Overload POST/DELETE into PUT /dashboard/:id/cards
qnkhuat Mar 31, 2023
e79d7fc
Merge branch 'master' into dashboard-bulk-create-delete
qnkhuat Mar 31, 2023
2deb9ed
tests fixes
qnkhuat Apr 3, 2023
8cdab45
rearrange tests
qnkhuat Apr 3, 2023
32df5cf
remove inline defs and fix kondo
qnkhuat Apr 3, 2023
89eef9d
fix can't prune cards
qnkhuat Apr 4, 2023
4e422aa
use malli for schema
qnkhuat Apr 4, 2023
5f07941
generalize the classify changes function
qnkhuat Apr 4, 2023
36d83d1
Merge branch 'master' into dashboard-bulk-create-delete
qnkhuat Apr 4, 2023
d7bd103
optimize DB calls
qnkhuat Apr 5, 2023
ae3ee94
makes sure we dissoc id when create cards and makes side-affects func…
qnkhuat Apr 6, 2023
5861ac5
makes sure we dissoc id when create cards and makes side-affects func…
qnkhuat Apr 6, 2023
af798f3
refactor `saveDashboardAndCards` thunk to use new `PUT` endpoint for …
EmmadUsmani Apr 6, 2023
0d7da01
resolve Tamas's comments
qnkhuat Apr 10, 2023
eb0bf80
add archive check test
qnkhuat Apr 10, 2023
7992db9
unwrap message from failed test
qnkhuat Apr 10, 2023
c4b3307
test fixes 🤨
qnkhuat Apr 10, 2023
d819fd0
fix e2e tests
EmmadUsmani Apr 10, 2023
c54f382
fix e2e test
EmmadUsmani Apr 10, 2023
86050e7
refactor the classify-changes to make it more readable
qnkhuat Apr 11, 2023
ac0d875
fixes failed to compile
qnkhuat Apr 11, 2023
9259ab4
fix revision history on FE
EmmadUsmani Apr 11, 2023
082a3cc
update e2e helper names
EmmadUsmani Apr 12, 2023
e35cc07
(hopefully) fix `line_chart.cy.spec.js`
EmmadUsmani Apr 13, 2023
e553c2f
- rename functions with cards -> dashcards
qnkhuat Apr 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@ Cypress.Commands.add(
({ body: { id: questionId } }) => {
cy.createDashboard(dashboardDetails).then(
({ body: { id: dashboardId } }) => {
cy.request("POST", `/api/dashboard/${dashboardId}/cards`, {
cardId: questionId,
// Add sane defaults for the dashboard card size and position
row: 0,
col: 0,
size_x: 8,
size_y: 6,
});
cy.request("PUT", `/api/dashboard/${dashboardId}/cards`, {
cards: [
{
id: -1,
metamben marked this conversation as resolved.
Show resolved Hide resolved
card_id: questionId,
// Add sane defaults for the dashboard card size and position
row: 0,
col: 0,
size_x: 8,
size_y: 6,
},
],
}).then(response => ({
...response,
body: response.body[0],
}));
},
);
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
Cypress.Commands.add(
"createQuestionAndAddToDashboard",
(query, dashboardId) => {
return (
query.native ? cy.createNativeQuestion(query) : cy.createQuestion(query)
).then(response => {
return cy
.request("POST", `/api/dashboard/${dashboardId}/cards`, {
cardId: response.body.id,
// Add sane defaults for the dashboard card size and position
row: 0,
col: 0,
size_x: 8,
size_y: 6,
})
.then(() => response.body);
});
},
(query, dashboardId, card) =>
(query.native
? cy.createNativeQuestion(query)
: cy.createQuestion(query)
).then(({ body: { id: card_id } }) =>
cy
.request(`/api/dashboard/${dashboardId}`)
.then(({ body: { ordered_cards } }) =>
cy
.request("PUT", `/api/dashboard/${dashboardId}/cards`, {
cards: [
...ordered_cards,
{
id: -1,
card_id,
// Add sane defaults for the dashboard card size and position
row: 0,
col: 0,
size_x: 8,
size_y: 8,
...card,
},
],
})
.then(response => ({
...response,
body: response.body[0],
})),
),
),
);
27 changes: 18 additions & 9 deletions e2e/support/commands/api/composite/createQuestionAndDashboard.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
Cypress.Commands.add(
"createQuestionAndDashboard",
({ questionDetails, dashboardDetails } = {}) => {
({ questionDetails, dashboardDetails, cardDetails } = {}) => {
cy.createQuestion(questionDetails).then(({ body: { id: questionId } }) => {
cy.createDashboard(dashboardDetails).then(
({ body: { id: dashboardId } }) => {
cy.request("POST", `/api/dashboard/${dashboardId}/cards`, {
cardId: questionId,
// Add sane defaults for the dashboard card size
row: 0,
col: 0,
size_x: 8,
size_y: 6,
});
cy.request("PUT", `/api/dashboard/${dashboardId}/cards`, {
cards: [
{
id: -1,
card_id: questionId,
// Add sane defaults for the dashboard card size
row: 0,
col: 0,
size_x: 8,
size_y: 6,
...cardDetails,
},
],
}).then(response => ({
...response,
body: response.body[0],
}));
},
);
});
Expand Down
40 changes: 40 additions & 0 deletions e2e/support/helpers/e2e-dashboard-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,46 @@ export function getDashboardCard(index = 0) {
return cy.get(".DashCard").eq(index);
}

function getDashCardApiUrl(dashId) {
return `/api/dashboard/${dashId}/cards`;
}

const DEFAULT_CARD = {
id: -1,
row: 0,
col: 0,
size_x: 8,
size_y: 8,
visualization_settings: {},
parameter_mappings: [],
};

export function addOrUpdateDashboardCard({ card_id, dashboard_id, card }) {
return cy
.request("PUT", getDashCardApiUrl(dashboard_id), {
cards: [
{
...DEFAULT_CARD,
card_id,
...card,
},
],
})
.then(response => ({
...response,
body: response.body[0],
}));
}
/**
* Replaces all the cards on a dashboard with the array given in the `cards` parameter.
* Can be used to remove cards (exclude from array), or add/update them.
*/
export function updateDashboardCards({ dashboard_id, cards }) {
return cy.request("PUT", getDashCardApiUrl(dashboard_id), {
cards: cards.map(card => ({ ...DEFAULT_CARD, ...card })),
});
}

export function showDashboardCardActions(index = 0) {
getDashboardCard(index).realHover();
}
Expand Down
39 changes: 7 additions & 32 deletions e2e/support/integration/visit-dashboard.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
import { addOrUpdateDashboardCard } from "e2e/support/helpers";

const { PEOPLE_ID, PRODUCTS_ID, PRODUCTS } = SAMPLE_DATABASE;

Expand Down Expand Up @@ -66,32 +67,6 @@ export function setup() {
);
}

function addCardToDashboard({ card_id, dashboard_id, card } = {}) {
const url = `/api/dashboard/${dashboard_id}/cards`;

return cy
.request("POST", url, {
cardId: card_id,
})
.then(({ body: { id } }) => {
cy.request("PUT", url, {
cards: [
{
id,
card_id,
row: 0,
col: 0,
size_x: 8,
size_y: 8,
visualization_settings: {},
parameter_mappings: [],
...card,
},
],
});
});
}

function addEmptyDashboard(name, alias) {
return cy.createDashboard(name).then(({ body: { id } }) => {
cy.wrap(id).as(alias);
Expand All @@ -100,7 +75,7 @@ function addEmptyDashboard(name, alias) {

function addMarkdownDashboard(name, alias) {
return cy.createDashboard(name).then(({ body: { id: dashboard_id } }) => {
addCardToDashboard({
addOrUpdateDashboardCard({
card_id: null,
dashboard_id,
card: {
Expand Down Expand Up @@ -150,7 +125,7 @@ function addNativeDashboard(name, alias) {

function addMultiDashboard(name, alias) {
return cy.createDashboard(name).then(({ body: { id: dashboard_id } }) => {
addCardToDashboard({
addOrUpdateDashboardCard({
card_id: null,
dashboard_id,
card: {
Expand All @@ -165,7 +140,7 @@ function addMultiDashboard(name, alias) {

cy.createNativeQuestion(nativeQuestionDetails).then(
({ body: { id: card_id } }) => {
addCardToDashboard({
addOrUpdateDashboardCard({
card_id,
dashboard_id,
card: { row: 2, col: 0, size_x: 9, size_y: 8 },
Expand All @@ -174,23 +149,23 @@ function addMultiDashboard(name, alias) {
);

cy.createQuestion(modelDetails).then(({ body: { id: card_id } }) => {
addCardToDashboard({
addOrUpdateDashboardCard({
card_id,
dashboard_id,
card: { row: 2, col: 10, size_x: 9, size_y: 8 },
});
});

cy.createQuestion(questionDetails).then(({ body: { id: card_id } }) => {
addCardToDashboard({
addOrUpdateDashboardCard({
card_id,
dashboard_id,
card: { row: 11, col: 0, size_x: 12, size_y: 8 },
});
});

cy.createQuestion(pivotTable).then(({ body: { id: card_id } }) => {
addCardToDashboard({
addOrUpdateDashboardCard({
card_id,
dashboard_id,
card: { row: 11, col: 12, size_x: 6, size_y: 8 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
visitQuestionAdhoc,
popover,
visitDashboard,
addOrUpdateDashboardCard,
} from "e2e/support/helpers";

import { SAMPLE_DB_ID } from "e2e/support/cypress_data";
Expand Down Expand Up @@ -72,17 +73,15 @@ function saveQuestion(name) {
}

function addQuestionToDashboardAndVisit() {
cy.createDashboard().then(({ body: { id } }) => {
cy.get("@questionId").then(cardId => {
cy.request("POST", `/api/dashboard/${id}/cards`, {
cardId,
row: 0,
col: 0,
size_x: 16,
size_y: 10,
cy.createDashboard().then(({ body: { id: dashboard_id } }) => {
cy.get("@questionId").then(card_id => {
addOrUpdateDashboardCard({
card_id,
dashboard_id,
card: { size_x: 16, size_y: 10 },
});
});

visitDashboard(id);
visitDashboard(dashboard_id);
});
}
33 changes: 19 additions & 14 deletions e2e/test/scenarios/dashboard-filters/parameters.cy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getDashboardCard,
selectDashboardFilter,
saveDashboard,
updateDashboardCards,
} from "e2e/support/helpers";
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
import { SAMPLE_DB_ID } from "e2e/support/cypress_data";
Expand All @@ -25,20 +26,24 @@ describe("scenarios > dashboard > parameters", () => {

cy.createDashboard({ name: "my dash" }).then(({ body: { id } }) => {
// add the same question twice
cy.request("POST", `/api/dashboard/${id}/cards`, {
cardId: 2, // Orders, count
row: 0,
col: 0,
size_x: 4,
size_y: 4,
});

cy.request("POST", `/api/dashboard/${id}/cards`, {
cardId: 2,
row: 0,
col: 4,
size_x: 4,
size_y: 4,
updateDashboardCards({
dashboard_id: id,
cards: [
{
card_id: 2,
row: 0,
col: 0,
size_x: 4,
size_y: 4,
},
{
card_id: 2,
row: 0,
col: 4,
size_x: 4,
size_y: 4,
},
],
});

visitDashboard(id);
Expand Down