Skip to content

Commit

Permalink
[8.9] [Dashboard] Fix missing state on short URL alias match redirect (
Browse files Browse the repository at this point in the history
…#163658) (#163746)

# Backport

This will backport the following commits from `main` to `8.9`:
- [[Dashboard] Fix missing state on short URL alias match redirect
(#163658)](#163658)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Devon
Thomson","email":"devon.thomson@elastic.co"},"sourceCommit":{"committedDate":"2023-08-11T16:15:18Z","message":"[Dashboard]
Fix missing state on short URL alias match redirect (#163658)\n\nFixes
an issue where URL state from short URLs could be lost on an alias match
redirect.","sha":"4de61111b14b59d2b57758a35ef47618c3a9ba46","branchLabelMapping":{"^v8.10.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Dashboard","release_note:fix","Team:Presentation","loe:hours","impact:high","backport:prev-minor","v8.10.0","v8.9.2"],"number":163658,"url":"#163658
Fix missing state on short URL alias match redirect (#163658)\n\nFixes
an issue where URL state from short URLs could be lost on an alias match
redirect.","sha":"4de61111b14b59d2b57758a35ef47618c3a9ba46"}},"sourceBranch":"main","suggestedTargetBranches":["8.9"],"targetPullRequestStates":[{"branch":"main","label":"v8.10.0","labelRegex":"^v8.10.0$","isSourceBranch":true,"state":"MERGED","url":"#163658
Fix missing state on short URL alias match redirect (#163658)\n\nFixes
an issue where URL state from short URLs could be lost on an alias match
redirect.","sha":"4de61111b14b59d2b57758a35ef47618c3a9ba46"}},{"branch":"8.9","label":"v8.9.2","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
  • Loading branch information
ThomThomson committed Aug 11, 2023
1 parent f237760 commit b177676
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Expand Up @@ -51,14 +51,32 @@ test('throws error when provided validation function returns invalid', async ()
}).rejects.toThrow('Dashboard failed saved object result validation');
});

test('returns undefined when provided validation function returns redireted', async () => {
test('returns undefined when provided validation function returns redirected', async () => {
const creationOptions: DashboardCreationOptions = {
validateLoadedSavedObject: jest.fn().mockImplementation(() => 'redirected'),
};
const dashboard = await createDashboard(creationOptions, 0, 'test-id');
expect(dashboard).toBeUndefined();
});

/**
* Because the getInitialInput function may have side effects, we only want to call it once we are certain that the
* the loaded saved object passes validation.
*
* This is especially relevant in the Dashboard App case where calling the getInitialInput function removes the _a
* param from the URL. In alais match situations this caused a bug where the state from the URL wasn't properly applied
* after the redirect.
*/
test('does not get initial input when provided validation function returns redirected', async () => {
const creationOptions: DashboardCreationOptions = {
validateLoadedSavedObject: jest.fn().mockImplementation(() => 'redirected'),
getInitialInput: jest.fn(),
};
const dashboard = await createDashboard(creationOptions, 0, 'test-id');
expect(dashboard).toBeUndefined();
expect(creationOptions.getInitialInput).not.toHaveBeenCalled();
});

test('pulls state from dashboard saved object when given a saved object id', async () => {
pluginServices.getServices().dashboardContentManagement.loadDashboardState = jest
.fn()
Expand Down
Expand Up @@ -137,7 +137,6 @@ export const initializeDashboard = async ({
useUnifiedSearchIntegration,
useSessionStorageIntegration,
} = creationOptions ?? {};
const overrideInput = getInitialInput?.();

// --------------------------------------------------------------------------------------
// Run validation.
Expand All @@ -161,6 +160,7 @@ export const initializeDashboard = async ({
// --------------------------------------------------------------------------------------
// Combine input from saved object, session storage, & passed input to create initial input.
// --------------------------------------------------------------------------------------
const overrideInput = getInitialInput?.();
const initialInput: DashboardContainerInput = cloneDeep({
...DEFAULT_DASHBOARD_INPUT,
...(loadDashboardReturn?.dashboardInput ?? {}),
Expand Down

0 comments on commit b177676

Please sign in to comment.