mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Dashboard: Fix UIDs are not preserved when importing/creating dashboards thru importing .json file (#38659)
* Dashboard: Fix UID not preserved on import * Import Dashboard: add e2e test to verify uid is preserved when importing dashboard * E2e: Use dynamic uid * Tests: fixes e2e test * Chore: adds back waits Co-authored-by: Hugo Häggmark <hugo.haggmark@gmail.com>
This commit is contained in:
parent
dc381dbf8e
commit
98dc925175
@ -7,7 +7,7 @@ type Panel = {
|
||||
[key: string]: unknown;
|
||||
};
|
||||
|
||||
type Dashboard = { title: string; panels: Panel[]; [key: string]: unknown };
|
||||
type Dashboard = { title: string; panels: Panel[]; uid: string; [key: string]: unknown };
|
||||
|
||||
/**
|
||||
* Smoke test a datasource by quickly importing a test dashboard for it
|
||||
@ -17,10 +17,13 @@ export const importDashboard = (dashboardToImport: Dashboard) => {
|
||||
e2e().visit(fromBaseUrl('/dashboard/import'));
|
||||
|
||||
// Note: normally we'd use 'click' and then 'type' here, but the json object is so big that using 'val' is much faster
|
||||
e2e.components.DashboardImportPage.textarea().click({ force: true }).invoke('val', JSON.stringify(dashboardToImport));
|
||||
e2e.components.DashboardImportPage.submit().click({ force: true });
|
||||
e2e.components.ImportDashboardForm.name().click({ force: true }).clear().type(dashboardToImport.title);
|
||||
e2e.components.ImportDashboardForm.submit().click({ force: true });
|
||||
e2e.components.DashboardImportPage.textarea()
|
||||
.should('be.visible')
|
||||
.click()
|
||||
.invoke('val', JSON.stringify(dashboardToImport));
|
||||
e2e.components.DashboardImportPage.submit().should('be.visible').click();
|
||||
e2e.components.ImportDashboardForm.name().should('be.visible').click().clear().type(dashboardToImport.title);
|
||||
e2e.components.ImportDashboardForm.submit().should('be.visible').click();
|
||||
e2e().wait(3000);
|
||||
|
||||
// save the newly imported dashboard to context so it'll get properly deleted later
|
||||
@ -35,21 +38,23 @@ export const importDashboard = (dashboardToImport: Dashboard) => {
|
||||
addedDashboards: [...addedDashboards, { title: dashboardToImport.title, uid }],
|
||||
});
|
||||
});
|
||||
|
||||
expect(dashboardToImport.uid).to.equal(uid);
|
||||
});
|
||||
|
||||
// inspect first panel and verify data has been processed for it
|
||||
e2e.components.Panels.Panel.title(dashboardToImport.panels[0].title).click({ force: true });
|
||||
e2e.components.Panels.Panel.headerItems('Inspect').click({ force: true });
|
||||
e2e.components.Tab.title('JSON').click({ force: true });
|
||||
e2e.components.Panels.Panel.title(dashboardToImport.panels[0].title).should('be.visible').click();
|
||||
e2e.components.Panels.Panel.headerItems('Inspect').should('be.visible').click();
|
||||
e2e.components.Tab.title('JSON').should('be.visible').click();
|
||||
e2e().wait(3000);
|
||||
e2e.components.PanelInspector.Json.content().contains('Panel JSON').click({ force: true });
|
||||
e2e.components.PanelInspector.Json.content().should('be.visible').contains('Panel JSON').click();
|
||||
e2e().wait(3000);
|
||||
e2e.components.Select.option().contains('Data').click({ force: true });
|
||||
e2e.components.Select.option().should('be.visible').contains('Data').click();
|
||||
e2e().wait(3000);
|
||||
|
||||
// ensures that panel has loaded without knowingly hitting an error
|
||||
// note: this does not prove that data came back as we expected it,
|
||||
// it could get `state: Done` for no data for example
|
||||
// but it ensures we didn't hit a 401 or 500 or something like that
|
||||
e2e.components.CodeEditor.container().contains('"state": "Done"');
|
||||
e2e.components.CodeEditor.container().should('be.visible').contains('"state": "Done"');
|
||||
};
|
||||
|
@ -94,7 +94,10 @@ export function importDashboard(importDashboardForm: ImportDashboardDTO): ThunkR
|
||||
});
|
||||
|
||||
const result = await getBackendSrv().post('api/dashboards/import', {
|
||||
dashboard: { ...dashboard, title: importDashboardForm.title, uid: importDashboardForm.uid },
|
||||
// uid: if user changed it, take the new uid from importDashboardForm,
|
||||
// else read it from original dashboard
|
||||
// by default the uid input is disabled, onSubmit ignores values from disabled inputs
|
||||
dashboard: { ...dashboard, title: importDashboardForm.title, uid: importDashboardForm.uid || dashboard.uid },
|
||||
overwrite: true,
|
||||
inputs: inputsToPersist,
|
||||
folderId: importDashboardForm.folder.id,
|
||||
|
Loading…
Reference in New Issue
Block a user