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

[State Management] Typescripify, jestify, simplify state_hashing and state_storage #51835

Merged
merged 11 commits into from
Dec 4, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ export class DashboardAppController {
new FilterStateManager(globalState, getAppState, filterManager);
const queryFilter = filterManager;

function getUnhashableStates(): State[] {
return [getAppState(), globalState].filter(Boolean);
}

let lastReloadRequestTime = 0;

const dash = ($scope.dash = $route.current.locals.dash);
Expand Down Expand Up @@ -753,7 +749,7 @@ export class DashboardAppController {
anchorElement,
allowEmbed: true,
allowShortUrl: !dashboardConfig.getHideWriteControls(),
shareableUrl: unhashUrl(window.location.href, getUnhashableStates()),
shareableUrl: unhashUrl(window.location.href),
objectId: dash.id,
objectType: 'dashboard',
sharingData: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import './np_core.test.mocks';

import 'ui/state_management/state_storage/mock';
import { DashboardStateManager } from './dashboard_state_manager';
import { getAppStateMock, getSavedDashboardMock } from './__tests__';
import { AppStateClass } from './legacy_imports';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import {
getRequestInspectorStats,
getResponseInspectorStats,
getServices,
getUnhashableStatesProvider,
hasSearchStategyForIndexPattern,
intervalOptions,
isDefaultTypeIndexPattern,
Expand Down Expand Up @@ -192,7 +191,6 @@ function discoverController(
uiCapabilities
) {
const responseHandler = vislibSeriesResponseHandlerProvider().handler;
const getUnhashableStates = Private(getUnhashableStatesProvider);

const queryFilter = Private(FilterBarQueryFilterProvider);

Expand Down Expand Up @@ -329,7 +327,7 @@ function discoverController(
anchorElement,
allowEmbed: false,
allowShortUrl: uiCapabilities.discover.createShortUrl,
shareableUrl: unhashUrl(window.location.href, getUnhashableStates()),
shareableUrl: unhashUrl(window.location.href),
objectId: savedSearch.id,
objectType: 'search',
sharingData: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import {
getServices,
angular,
absoluteToParsedUrl,
getUnhashableStatesProvider,
KibanaParsedUrl,
migrateLegacyQuery,
SavedObjectSaveModal,
Expand Down Expand Up @@ -165,7 +164,6 @@ function VisEditor(
localStorage,
) {
const queryFilter = Private(FilterBarQueryFilterProvider);
const getUnhashableStates = Private(getUnhashableStatesProvider);

// Retrieve the resolved SavedVis instance.
const savedVis = $route.current.locals.savedVis;
Expand Down Expand Up @@ -249,7 +247,7 @@ function VisEditor(
anchorElement,
allowEmbed: true,
allowShortUrl: capabilities.visualize.createShortUrl,
shareableUrl: unhashUrl(window.location.href, getUnhashableStates()),
shareableUrl: unhashUrl(window.location.href),
objectId: savedVis.id,
objectType: 'visualization',
sharingData: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,22 @@
import chrome from 'ui/chrome';
import { hashUrl } from 'ui/state_management/state_hashing';
import uiRoutes from 'ui/routes';
import { fatalError } from 'ui/notify';

uiRoutes.enable();
uiRoutes
.when('/', {
resolve: {
url: function (AppState, globalState, $window) {
const redirectUrl = chrome.getInjected('redirectUrl');
try {
const hashedUrl = hashUrl(redirectUrl);
const url = chrome.addBasePath(hashedUrl);

const hashedUrl = hashUrl([new AppState(), globalState], redirectUrl);
const url = chrome.addBasePath(hashedUrl);

$window.location = url;
$window.location = url;
} catch (e) {
fatalError(e);
}
}
}
});
4 changes: 1 addition & 3 deletions src/legacy/ui/public/chrome/api/sub_url_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@
import url from 'url';

import {
getUnhashableStatesProvider,
unhashUrl,
} from '../../state_management/state_hashing';

export function registerSubUrlHooks(angularModule, internals) {
angularModule.run(($rootScope, Private, $location) => {
const getUnhashableStates = Private(getUnhashableStatesProvider);
const subUrlRouteFilter = Private(SubUrlRouteFilterProvider);

function updateSubUrls() {
const urlWithHashes = window.location.href;
const urlWithStates = unhashUrl(urlWithHashes, getUnhashableStates());
const urlWithStates = unhashUrl(urlWithHashes);
internals.trackPossibleSubUrl(urlWithStates);
}

Expand Down
10 changes: 3 additions & 7 deletions src/legacy/ui/public/state_management/__tests__/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ import '../../private';
import { toastNotifications } from '../../notify';
import * as FatalErrorNS from '../../notify/fatal_error';
import { StateProvider } from '../state';
import {
unhashQueryString,
} from '../state_hashing';
import {
createStateHash,
isStateHash,
} from '../state_storage';
unhashQuery
} from '../state_hashing';
import { HashedItemStore } from '../state_storage/hashed_item_store';
import { StubBrowserStorage } from 'test_utils/stub_browser_storage';
import { EventsProvider } from '../../events';
Expand Down Expand Up @@ -60,9 +58,7 @@ describe('State Management', () => {
const hashedItemStore = new HashedItemStore(store);
const state = new State(param, initial, hashedItemStore);

const getUnhashedSearch = state => {
return unhashQueryString($location.search(), [ state ]);
};
const getUnhashedSearch = () => unhashQuery($location.search());

return { store, hashedItemStore, state, getUnhashedSearch };
};
Expand Down
10 changes: 5 additions & 5 deletions src/legacy/ui/public/state_management/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ import { createLegacyClass } from '../utils/legacy_class';
import { callEach } from '../utils/function';

import {
createStateHash,
HashedItemStoreSingleton,
isStateHash,
} from './state_storage';
import {
createStateHash,
isStateHash
} from './state_hashing';

export function StateProvider(Private, $rootScope, $location, stateManagementConfig, config, kbnUrl, $injector) {
const Events = Private(EventsProvider);
Expand Down Expand Up @@ -293,9 +295,7 @@ export function StateProvider(Private, $rootScope, $location, stateManagementCon

// We need to strip out Angular-specific properties.
const json = angular.toJson(state);
const hash = createStateHash(json, hash => {
return this._hashedItemStore.getItem(hash);
});
const hash = createStateHash(json);
const isItemSet = this._hashedItemStore.setItem(hash, json);

if (isItemSet) {
Expand Down

This file was deleted.

Loading