Skip to content

Commit af432ef

Browse files
Merge branch 'actions/license-checks' into actions/initial-action-type-licenses
2 parents b6d5c0e + a3be4e2 commit af432ef

File tree

531 files changed

+63710
-20427
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

531 files changed

+63710
-20427
lines changed

examples/ui_action_examples/public/hello_world_action.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,16 @@ import { toMountPoint } from '../../../src/plugins/kibana_react/public';
2424

2525
export const HELLO_WORLD_ACTION_TYPE = 'HELLO_WORLD_ACTION_TYPE';
2626

27-
export const createHelloWorldAction = (openModal: OverlayStart['openModal']) =>
28-
createAction<{}>({
27+
interface StartServices {
28+
openModal: OverlayStart['openModal'];
29+
}
30+
31+
export const createHelloWorldAction = (getStartServices: () => Promise<StartServices>) =>
32+
createAction({
2933
type: HELLO_WORLD_ACTION_TYPE,
3034
getDisplayName: () => 'Hello World!',
3135
execute: async () => {
36+
const { openModal } = await getStartServices();
3237
const overlay = openModal(
3338
toMountPoint(
3439
<EuiModalBody>

examples/ui_action_examples/public/plugin.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,34 @@
1717
* under the License.
1818
*/
1919

20-
import { Plugin, CoreSetup, CoreStart } from '../../../src/core/public';
21-
import { UiActionsSetup, UiActionsStart } from '../../../src/plugins/ui_actions/public';
22-
import { createHelloWorldAction, HELLO_WORLD_ACTION_TYPE } from './hello_world_action';
23-
import { helloWorldTrigger } from './hello_world_trigger';
20+
import { Plugin, CoreSetup } from '../../../src/core/public';
21+
import { UiActionsSetup } from '../../../src/plugins/ui_actions/public';
22+
import { createHelloWorldAction } from './hello_world_action';
23+
import { helloWorldTrigger, HELLO_WORLD_TRIGGER_ID } from './hello_world_trigger';
2424

2525
interface UiActionExamplesSetupDependencies {
2626
uiActions: UiActionsSetup;
2727
}
2828

29-
interface UiActionExamplesStartDependencies {
30-
uiActions: UiActionsStart;
29+
declare module '../../../src/plugins/ui_actions/public' {
30+
export interface TriggerContextMapping {
31+
[HELLO_WORLD_TRIGGER_ID]: undefined;
32+
}
3133
}
3234

3335
export class UiActionExamplesPlugin
34-
implements
35-
Plugin<void, void, UiActionExamplesSetupDependencies, UiActionExamplesStartDependencies> {
36+
implements Plugin<void, void, UiActionExamplesSetupDependencies> {
3637
public setup(core: CoreSetup, { uiActions }: UiActionExamplesSetupDependencies) {
3738
uiActions.registerTrigger(helloWorldTrigger);
38-
uiActions.attachAction(helloWorldTrigger.id, HELLO_WORLD_ACTION_TYPE);
39-
}
4039

41-
public start(coreStart: CoreStart, deps: UiActionExamplesStartDependencies) {
42-
deps.uiActions.registerAction(createHelloWorldAction(coreStart.overlays.openModal));
40+
const helloWorldAction = createHelloWorldAction(async () => ({
41+
openModal: (await core.getStartServices())[0].overlays.openModal,
42+
}));
43+
44+
uiActions.registerAction(helloWorldAction);
45+
uiActions.attachAction(helloWorldTrigger.id, helloWorldAction.id);
4346
}
4447

48+
public start() {}
4549
public stop() {}
4650
}

examples/ui_actions_explorer/public/actions/actions.tsx

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,18 @@ export const EDIT_USER_ACTION = 'EDIT_USER_ACTION';
3434
export const PHONE_USER_ACTION = 'PHONE_USER_ACTION';
3535
export const SHOWCASE_PLUGGABILITY_ACTION = 'SHOWCASE_PLUGGABILITY_ACTION';
3636

37-
export const showcasePluggability = createAction<{}>({
37+
export const showcasePluggability = createAction({
3838
type: SHOWCASE_PLUGGABILITY_ACTION,
3939
getDisplayName: () => 'This is pluggable! Any plugin can inject their actions here.',
40-
execute: async ({}) => alert("Isn't that cool?!"),
40+
execute: async () => alert("Isn't that cool?!"),
4141
});
4242

43-
export const makePhoneCallAction = createAction<{ phone: string }>({
43+
export type PhoneContext = string;
44+
45+
export const makePhoneCallAction = createAction<PhoneContext>({
4446
type: CALL_PHONE_NUMBER_ACTION,
4547
getDisplayName: () => 'Call phone number',
46-
execute: async ({ phone }) => alert(`Pretend calling ${phone}...`),
48+
execute: async phone => alert(`Pretend calling ${phone}...`),
4749
});
4850

4951
export const lookUpWeatherAction = createAction<{ country: string }>({
@@ -55,11 +57,13 @@ export const lookUpWeatherAction = createAction<{ country: string }>({
5557
},
5658
});
5759

58-
export const viewInMapsAction = createAction<{ country: string }>({
60+
export type CountryContext = string;
61+
62+
export const viewInMapsAction = createAction<CountryContext>({
5963
type: VIEW_IN_MAPS_ACTION,
6064
getIconType: () => 'popout',
6165
getDisplayName: () => 'View in maps',
62-
execute: async ({ country }) => {
66+
execute: async country => {
6367
window.open(`https://www.google.com/maps/place/${country}`, '_blank');
6468
},
6569
});
@@ -110,11 +114,13 @@ export const createEditUserAction = (getOpenModal: () => Promise<OverlayStart['o
110114
},
111115
});
112116

117+
export interface UserContext {
118+
user: User;
119+
update: (user: User) => void;
120+
}
121+
113122
export const createPhoneUserAction = (getUiActionsApi: () => Promise<UiActionsStart>) =>
114-
createAction<{
115-
user: User;
116-
update: (user: User) => void;
117-
}>({
123+
createAction<UserContext>({
118124
type: PHONE_USER_ACTION,
119125
getDisplayName: () => 'Call phone number',
120126
isCompatible: async ({ user }) => user.phone !== undefined,
@@ -126,6 +132,8 @@ export const createPhoneUserAction = (getUiActionsApi: () => Promise<UiActionsSt
126132
// to the phone number trigger.
127133
// TODO: we need to figure out the best way to handle these nested actions however, since
128134
// we don't want multiple context menu's to pop up.
129-
(await getUiActionsApi()).executeTriggerActions(PHONE_TRIGGER, { phone: user.phone });
135+
if (user.phone !== undefined) {
136+
(await getUiActionsApi()).executeTriggerActions(PHONE_TRIGGER, user.phone);
137+
}
130138
},
131139
});

examples/ui_actions_explorer/public/app.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const ActionsExplorer = ({ uiActionsApi, openModal }: Props) => {
6060
</EuiText>
6161
<EuiButton
6262
data-test-subj="emitHelloWorldTrigger"
63-
onClick={() => uiActionsApi.executeTriggerActions(HELLO_WORLD_TRIGGER_ID, {})}
63+
onClick={() => uiActionsApi.executeTriggerActions(HELLO_WORLD_TRIGGER_ID, undefined)}
6464
>
6565
Say hello world!
6666
</EuiButton>

examples/ui_actions_explorer/public/plugin.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ import {
3535
makePhoneCallAction,
3636
showcasePluggability,
3737
SHOWCASE_PLUGGABILITY_ACTION,
38+
UserContext,
39+
CountryContext,
40+
PhoneContext,
3841
} from './actions/actions';
3942

4043
interface StartDeps {
@@ -45,6 +48,14 @@ interface SetupDeps {
4548
uiActions: UiActionsSetup;
4649
}
4750

51+
declare module '../../../src/plugins/ui_actions/public' {
52+
export interface TriggerContextMapping {
53+
[USER_TRIGGER]: UserContext;
54+
[COUNTRY_TRIGGER]: CountryContext;
55+
[PHONE_TRIGGER]: PhoneContext;
56+
}
57+
}
58+
4859
export class UiActionsExplorerPlugin implements Plugin<void, void, {}, StartDeps> {
4960
public setup(core: CoreSetup<{ uiActions: UiActionsStart }>, deps: SetupDeps) {
5061
deps.uiActions.registerTrigger({

examples/ui_actions_explorer/public/trigger_context_example.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ const createRowData = (
4747
<Fragment>
4848
<EuiButtonEmpty
4949
onClick={() => {
50-
uiActionsApi.executeTriggerActions(COUNTRY_TRIGGER, {
51-
country: user.countryOfResidence,
52-
});
50+
uiActionsApi.executeTriggerActions(COUNTRY_TRIGGER, user.countryOfResidence);
5351
}}
5452
>
5553
{user.countryOfResidence}
@@ -59,10 +57,9 @@ const createRowData = (
5957
phone: (
6058
<Fragment>
6159
<EuiButtonEmpty
60+
disabled={user.phone === undefined}
6261
onClick={() => {
63-
uiActionsApi.executeTriggerActions(PHONE_TRIGGER, {
64-
phone: user.phone,
65-
});
62+
uiActionsApi.executeTriggerActions(PHONE_TRIGGER, user.phone!);
6663
}}
6764
>
6865
{user.phone}

package.json

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,31 +77,23 @@
7777
"url": "https://github.com/elastic/kibana.git"
7878
},
7979
"resolutions": {
80-
"**/@apollo/client": "^3.0.0-beta.37",
81-
"**/@graphql-toolkit/common": "^0.9.7",
82-
"**/@graphql-toolkit/core": "^0.9.7",
83-
"**/@graphql-toolkit/graphql-file-loader": "^0.9.7",
84-
"**/@graphql-toolkit/json-file-loader": "^0.9.7",
85-
"**/@graphql-toolkit/schema-merging": "^0.9.7",
86-
"**/@graphql-toolkit/url-loader": "^0.9.7",
8780
"**/@types/node": "10.12.27",
8881
"**/@types/react": "^16.9.19",
8982
"**/@types/react-router": "^5.1.3",
9083
"**/@types/hapi": "^17.0.18",
9184
"**/@types/angular": "^1.6.56",
9285
"**/@types/hoist-non-react-statics": "^3.3.1",
93-
"**/apollo-link": "^1.2.13",
94-
"**/deepmerge": "^4.2.2",
95-
"**/fast-deep-equal": "^3.1.1",
96-
"**/fast-glob": "3.1.1",
86+
"**/typescript": "3.7.2",
87+
"**/graphql-toolkit/lodash": "^4.17.13",
9788
"**/hoist-non-react-statics": "^3.3.2",
9889
"**/isomorphic-git/**/base64-js": "^1.2.1",
9990
"**/image-diff/gm/debug": "^2.6.9",
10091
"**/react-dom": "^16.12.0",
10192
"**/react": "^16.12.0",
10293
"**/react-test-renderer": "^16.12.0",
94+
"**/deepmerge": "^4.2.2",
10395
"**/serialize-javascript": "^2.1.1",
104-
"**/typescript": "3.7.2"
96+
"**/fast-deep-equal": "^3.1.1"
10597
},
10698
"workspaces": {
10799
"packages": [
@@ -333,6 +325,7 @@
333325
"@types/getopts": "^2.0.1",
334326
"@types/glob": "^7.1.1",
335327
"@types/globby": "^8.0.0",
328+
"@types/graphql": "^0.13.2",
336329
"@types/hapi": "^17.0.18",
337330
"@types/hapi-auth-cookie": "^9.1.0",
338331
"@types/has-ansi": "^3.0.0",
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
import moment, { Moment } from 'moment-timezone';
20+
import { METRIC_TYPE } from './';
21+
22+
export interface ApplicationUsageCurrent {
23+
type: METRIC_TYPE.APPLICATION_USAGE;
24+
appId: string;
25+
startTime: Moment;
26+
numberOfClicks: number;
27+
}
28+
29+
export class ApplicationUsage {
30+
private currentUsage?: ApplicationUsageCurrent;
31+
32+
public start() {
33+
// Count any clicks and assign it to the current app
34+
if (window)
35+
window.addEventListener(
36+
'click',
37+
() => this.currentUsage && this.currentUsage.numberOfClicks++
38+
);
39+
}
40+
41+
public appChanged(appId?: string) {
42+
const currentUsage = this.currentUsage;
43+
44+
if (appId) {
45+
this.currentUsage = {
46+
type: METRIC_TYPE.APPLICATION_USAGE,
47+
appId,
48+
startTime: moment(),
49+
numberOfClicks: 0,
50+
};
51+
} else {
52+
this.currentUsage = void 0;
53+
}
54+
return currentUsage;
55+
}
56+
}

packages/kbn-analytics/src/metrics/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@
1919

2020
import { UiStatsMetric } from './ui_stats';
2121
import { UserAgentMetric } from './user_agent';
22+
import { ApplicationUsageCurrent } from './application_usage';
2223

2324
export { UiStatsMetric, createUiStatsMetric, UiStatsMetricType } from './ui_stats';
2425
export { Stats } from './stats';
2526
export { trackUsageAgent } from './user_agent';
27+
export { ApplicationUsage, ApplicationUsageCurrent } from './application_usage';
2628

27-
export type Metric = UiStatsMetric | UserAgentMetric;
29+
export type Metric = UiStatsMetric | UserAgentMetric | ApplicationUsageCurrent;
2830
export enum METRIC_TYPE {
2931
COUNT = 'count',
3032
LOADED = 'loaded',
3133
CLICK = 'click',
3234
USER_AGENT = 'user_agent',
35+
APPLICATION_USAGE = 'application_usage',
3336
}

packages/kbn-analytics/src/report.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* under the License.
1818
*/
1919

20+
import moment from 'moment-timezone';
2021
import { UnreachableCaseError, wrapArray } from './util';
2122
import { Metric, Stats, UiStatsMetricType, METRIC_TYPE } from './metrics';
2223
const REPORT_VERSION = 1;
@@ -42,6 +43,13 @@ export interface Report {
4243
appName: string;
4344
}
4445
>;
46+
application_usage?: Record<
47+
string,
48+
{
49+
minutesOnScreen: number;
50+
numberOfClicks: number;
51+
}
52+
>;
4553
}
4654

4755
export class ReportManager {
@@ -57,10 +65,11 @@ export class ReportManager {
5765
this.report = ReportManager.createReport();
5866
}
5967
public isReportEmpty(): boolean {
60-
const { uiStatsMetrics, userAgent } = this.report;
68+
const { uiStatsMetrics, userAgent, application_usage: appUsage } = this.report;
6169
const noUiStats = !uiStatsMetrics || Object.keys(uiStatsMetrics).length === 0;
6270
const noUserAgent = !userAgent || Object.keys(userAgent).length === 0;
63-
return noUiStats && noUserAgent;
71+
const noAppUsage = !appUsage || Object.keys(appUsage).length === 0;
72+
return noUiStats && noUserAgent && noAppUsage;
6473
}
6574
private incrementStats(count: number, stats?: Stats): Stats {
6675
const { min = 0, max = 0, sum = 0 } = stats || {};
@@ -92,6 +101,8 @@ export class ReportManager {
92101
const { appName, eventName, type } = metric;
93102
return `${appName}-${type}-${eventName}`;
94103
}
104+
case METRIC_TYPE.APPLICATION_USAGE:
105+
return metric.appId;
95106
default:
96107
throw new UnreachableCaseError(metric);
97108
}
@@ -129,6 +140,20 @@ export class ReportManager {
129140
};
130141
return;
131142
}
143+
case METRIC_TYPE.APPLICATION_USAGE:
144+
const { numberOfClicks, startTime } = metric;
145+
const minutesOnScreen = moment().diff(startTime, 'minutes', true);
146+
147+
report.application_usage = report.application_usage || {};
148+
const appExistingData = report.application_usage[key] || {
149+
minutesOnScreen: 0,
150+
numberOfClicks: 0,
151+
};
152+
report.application_usage[key] = {
153+
minutesOnScreen: appExistingData.minutesOnScreen + minutesOnScreen,
154+
numberOfClicks: appExistingData.numberOfClicks + numberOfClicks,
155+
};
156+
break;
132157
default:
133158
throw new UnreachableCaseError(metric);
134159
}

0 commit comments

Comments
 (0)