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] State syncing utilities #53582

Merged
merged 66 commits into from
Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from 59 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
1abdc33
wip
Dosant Dec 18, 2019
e51820e
wip
Dosant Dec 18, 2019
e8ff873
wip
Dosant Dec 19, 2019
f4b1de8
Merge branch 'master' of github.com:elastic/kibana into dev/state-man…
Dosant Dec 19, 2019
69362ef
Make sure react router can work in both modes: hash and browser history
Dosant Dec 20, 2019
84a7052
Merge branch 'master' of github.com:elastic/kibana into dev/state-man…
Dosant Dec 20, 2019
a2a2ef6
restore url only if it is a appBasePath
Dosant Dec 20, 2019
0204cf6
Merge branch 'master' of github.com:elastic/kibana into dev/state-man…
Dosant Dec 23, 2019
de62c4f
Replicate shared global state
Dosant Dec 23, 2019
393ce2f
state-management/url unit tests
Dosant Dec 23, 2019
604d6be
distinct_until_changed_with_initial_value.ts test
Dosant Dec 23, 2019
9397f36
more tests
Dosant Dec 23, 2019
4cd4d3d
Merge branch 'master' of github.com:elastic/kibana into dev/state-man…
Dosant Dec 23, 2019
606423d
add test
Dosant Dec 24, 2019
22c876a
fix test fail caused by circular dep
Dosant Dec 24, 2019
dd53534
add test
Dosant Dec 24, 2019
70fb0ac
wip
Dosant Dec 24, 2019
ad38e63
Merge branch 'master' of github.com:elastic/kibana into dev/state-man…
Dosant Dec 24, 2019
39e1595
add simple demo
Dosant Dec 24, 2019
05437f2
Merge branch 'master' into dev/state-managment/state-sync
elasticmachine Dec 27, 2019
18bc378
Apply suggestions from code review
Dosant Dec 27, 2019
7074dd5
Merge branch 'dev/state-managment/state-sync' of github.com:Dosant/ki…
Dosant Dec 28, 2019
b9a67a3
Revert "Apply suggestions from code review"
Dosant Dec 28, 2019
e4ebf28
Merge branch 'master' into dev/state-managment/state-sync
elasticmachine Dec 30, 2019
cdd33c9
chore improvements from pr review
Dosant Dec 30, 2019
5afd027
better updateAsync explanation
Dosant Dec 30, 2019
a9b4112
improve condition for urlTracker and make to url take priority over s…
Dosant Dec 30, 2019
62fa220
revert
Dosant Dec 30, 2019
e773d93
fix lint
Dosant Dec 30, 2019
242be7d
createKbnGlobalStateSyncStrategy
Dosant Dec 30, 2019
2bd1a84
add test for kbnGlobalStateSyncStrategy
Dosant Dec 30, 2019
8e92701
split syncState into syncState and syncStates
Dosant Dec 30, 2019
6745916
make sure kbn_global_state_sync_strategy doesn’t skip url updates
Dosant Dec 30, 2019
3ae8860
fix imports order
Dosant Dec 30, 2019
4c9ab47
improve kbn global stgate sync strategy
Dosant Dec 30, 2019
bd98e21
Merge branch 'master' of github.com:elastic/kibana into dev/state-man…
Dosant Dec 31, 2019
d0dd8f7
better tests descriptions
Dosant Dec 31, 2019
79551a0
improve
Dosant Dec 31, 2019
ca84769
improve
Dosant Dec 31, 2019
7fad625
remove not needed state update
Dosant Dec 31, 2019
2b0f47a
Merge branch 'master' of github.com:elastic/kibana into dev/state-man…
Dosant Jan 2, 2020
8a45af4
Merge branch 'master' of github.com:elastic/kibana into dev/state-man…
Dosant Jan 3, 2020
5a4f475
make sure query strings are the same as angular’s
Dosant Jan 3, 2020
9c030c8
Add synchronous helpers to sync strategies
Dosant Jan 3, 2020
46d9936
Merge branch 'master' of github.com:elastic/kibana into dev/state-man…
Dosant Jan 3, 2020
15973f7
fix demo
Dosant Jan 3, 2020
5314eff
Merge branch 'master' of github.com:elastic/kibana into dev/state-man…
Dosant Jan 6, 2020
b09c7f2
Simplify state sync solution
Dosant Jan 6, 2020
9077df3
Merge branch 'master' of github.com:elastic/kibana into dev/state-man…
Dosant Jan 6, 2020
123c823
simplify
Dosant Jan 6, 2020
d41db09
improve
Dosant Jan 6, 2020
9029fd9
Improve: extend kbnUrlSyncStrategy with flush() api
Dosant Jan 6, 2020
505fca3
Merge branch 'master' of github.com:elastic/kibana into dev/state-man…
Dosant Jan 6, 2020
e666bac
improve and simplify
Dosant Jan 6, 2020
45112e5
Merge branch 'master' of github.com:elastic/kibana into dev/state-man…
Dosant Jan 6, 2020
55d1290
improve
Dosant Jan 6, 2020
edc4460
improve
Dosant Jan 7, 2020
0ab4686
Merge branch 'master' of github.com:elastic/kibana into dev/state-man…
Dosant Jan 7, 2020
fe813c3
improve
Dosant Jan 7, 2020
ca3ebb6
fix imports not from root in todo example
Dosant Jan 8, 2020
6488bf3
Merge branch 'master' of github.com:elastic/kibana into dev/state-man…
Dosant Jan 8, 2020
bbe5ace
Rename ‘SyncStrategy’ -> ‘StateStorage’
Dosant Jan 8, 2020
e133b90
Merge branch 'master' of github.com:elastic/kibana into dev/state-man…
Dosant Jan 9, 2020
4b1ffbc
nit improvements from review
Dosant Jan 9, 2020
e49d9ff
Merge branch 'master' of github.com:elastic/kibana into dev/state-man…
Dosant Jan 10, 2020
b8d808c
move useUrlTracker to kibana_react, as it is a react hook
Dosant Jan 10, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions examples/state_containers_examples/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "stateContainersExamples",
"version": "0.0.1",
"kibanaVersion": "kibana",
"configPath": ["state_containers_examples"],
"server": false,
"ui": true,
"requiredPlugins": [],
"optionalPlugins": []
}
17 changes: 17 additions & 0 deletions examples/state_containers_examples/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "state_containers_examples",
"version": "1.0.0",
"main": "target/examples/state_containers_examples",
"kibana": {
"version": "kibana",
"templateVersion": "1.0.0"
},
"license": "Apache-2.0",
"scripts": {
"kbn": "node ../../scripts/kbn.js",
"build": "rm -rf './target' && tsc"
},
"devDependencies": {
"typescript": "3.7.2"
}
}
69 changes: 69 additions & 0 deletions examples/state_containers_examples/public/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { AppMountParameters } from 'kibana/public';
import ReactDOM from 'react-dom';
import React from 'react';
import { createHashHistory, createBrowserHistory } from 'history';
import { TodoAppPage } from './todo';

export interface AppOptions {
appInstanceId: string;
appTitle: string;
historyType: History;
}

export enum History {
Browser,
Hash,
}

export const renderApp = (
{ appBasePath, element }: AppMountParameters,
{ appInstanceId, appTitle, historyType }: AppOptions
) => {
const history =
historyType === History.Browser
? createBrowserHistory({ basename: appBasePath })
: createHashHistory();
ReactDOM.render(
<TodoAppPage
history={history}
appInstanceId={appInstanceId}
appTitle={appTitle}
appBasePath={appBasePath}
isInitialRoute={() => {
const stripTrailingSlash = (path: string) =>
path.charAt(path.length - 1) === '/' ? path.substr(0, path.length - 1) : path;
const currentAppUrl = stripTrailingSlash(history.createHref(history.location));
if (historyType === History.Browser) {
// browser history
const basePath = stripTrailingSlash(appBasePath);
return currentAppUrl === basePath && !history.location.search && !history.location.hash;
} else {
// hashed history
return currentAppUrl === '#' && !history.location.search;
}
}}
/>,
element
);

return () => ReactDOM.unmountComponentAtNode(element);
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* under the License.
*/

declare module 'encode-uri-query' {
function encodeUriQuery(query: string, usePercentageSpace?: boolean): string;
// eslint-disable-next-line import/no-default-export
export default encodeUriQuery;
}
import { StateContainersExamplesPlugin } from './plugin';

export const plugin = () => new StateContainersExamplesPlugin();
52 changes: 52 additions & 0 deletions examples/state_containers_examples/public/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { AppMountParameters, CoreSetup, Plugin } from 'kibana/public';

export class StateContainersExamplesPlugin implements Plugin {
public setup(core: CoreSetup) {
core.application.register({
id: 'state-containers-example-browser-history',
title: 'State containers example - browser history routing',
async mount(params: AppMountParameters) {
const { renderApp, History } = await import('./app');
return renderApp(params, {
appInstanceId: '1',
appTitle: 'Routing with browser history',
historyType: History.Browser,
});
},
});
core.application.register({
id: 'state-containers-example-hash-history',
title: 'State containers example - hash history routing',
async mount(params: AppMountParameters) {
const { renderApp, History } = await import('./app');
return renderApp(params, {
appInstanceId: '2',
appTitle: 'Routing with hash history',
historyType: History.Hash,
});
},
});
}

public start() {}
public stop() {}
}
Loading