Skip to content

Commit 60cc491

Browse files
committed
partial progress, dashboard drilldowns
1 parent 58731fa commit 60cc491

File tree

2 files changed

+154
-0
lines changed

2 files changed

+154
-0
lines changed
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import React from 'react';
8+
import { EuiFormRow, EuiSelect, EuiSwitch } from '@elastic/eui';
9+
import { AdvancedUiActionsActionFactoryDefinition } from '../../../../../advanced_ui_actions/public';
10+
import {
11+
// UiActionsActionDefinition,
12+
UiActionsCollectConfigProps,
13+
} from '../../../../../../../src/plugins/ui_actions/public';
14+
import { reactToUiComponent } from '../../../../../../../src/plugins/kibana_react/public';
15+
16+
/*
17+
import {
18+
SavedObjectLoader,
19+
SavedObjectKibanaServices,
20+
} from '../../../../../../../src/plugins/saved_objects/public';
21+
*/
22+
23+
export const dashboards = [
24+
{ id: 'dashboard1', title: 'Dashboard 1' },
25+
{ id: 'dashboard2', title: 'Dashboard 2' },
26+
];
27+
28+
// todo load list of dashboards
29+
/*
30+
const DashboardDrilldownCollectConfig = (dashboardLoader: SavedObjectLoader) => (
31+
props: UiActionsCollectConfigProps<DashboardDrilldownConfig>
32+
) => {
33+
console.log('DashboardDrilldownCollectConfig');
34+
dashboardLoader.find().then(item => console.log('HERE HERE', item));
35+
*/
36+
const DashboardDrilldownCollectConfig = (
37+
props: UiActionsCollectConfigProps<DashboardDrilldownConfig>
38+
) => {
39+
const config = props.config ?? {
40+
dashboardId: undefined,
41+
useCurrentDashboardDataRange: true,
42+
useCurrentDashboardFilters: true,
43+
};
44+
return (
45+
<>
46+
<EuiFormRow label="Choose destination dashboard:">
47+
<EuiSelect
48+
name="selectDashboard"
49+
hasNoInitialSelection={true}
50+
options={dashboards.map(({ id, title }) => ({ value: id, text: title }))}
51+
value={config.dashboardId}
52+
onChange={e => {
53+
props.onConfig({ ...config, dashboardId: e.target.value });
54+
}}
55+
/>
56+
</EuiFormRow>
57+
<EuiFormRow hasChildLabel={false}>
58+
<EuiSwitch
59+
name="useCurrentFilters"
60+
label="Use current dashboard's filters"
61+
checked={config.useCurrentDashboardFilters}
62+
onChange={() =>
63+
props.onConfig({
64+
...config,
65+
useCurrentDashboardFilters: !config.useCurrentDashboardFilters,
66+
})
67+
}
68+
/>
69+
</EuiFormRow>
70+
<EuiFormRow hasChildLabel={false}>
71+
<EuiSwitch
72+
name="useCurrentDateRange"
73+
label="Use current dashboard's date range"
74+
checked={config.useCurrentDashboardDataRange}
75+
onChange={() =>
76+
props.onConfig({
77+
...config,
78+
useCurrentDashboardDataRange: !config.useCurrentDashboardDataRange,
79+
})
80+
}
81+
/>
82+
</EuiFormRow>
83+
</>
84+
);
85+
};
86+
87+
interface DashboardDrilldownConfig {
88+
dashboardId?: string;
89+
useCurrentDashboardFilters: boolean;
90+
useCurrentDashboardDataRange: boolean;
91+
}
92+
93+
/*
94+
export function createSavedDashboardLoader(services: SavedObjectKibanaServices) {
95+
const SavedDashboard = createSavedDashboardClass(services);
96+
return new SavedObjectLoader(SavedDashboard, services.savedObjectsClient, services.chrome);
97+
}
98+
99+
100+
export const DashboardDrilldownActionFactory = (
101+
services: SavedObjectKibanaServices
102+
):
103+
*/
104+
105+
interface DashboardDrilldownActionContext {
106+
embeddable: string;
107+
timeFieldName: string;
108+
data: any;
109+
}
110+
111+
export const DashboardDrilldownActionFactory: AdvancedUiActionsActionFactoryDefinition<
112+
DashboardDrilldownConfig, // config
113+
any, // FactoryConfig
114+
any // ActionContext
115+
> = {
116+
id: 'dashboardDrilldown',
117+
getDisplayName: () => 'Go to Dashboard',
118+
getIconType: () => 'dashboardApp',
119+
// create(): UiActionsActionDefinition<DashboardDrilldownConfig> {
120+
create() {
121+
return {
122+
id: 'drilldown',
123+
order: 1,
124+
async execute(thing: DashboardDrilldownActionContext) {
125+
alert('Go to another drilldown');
126+
},
127+
};
128+
},
129+
createConfig() {
130+
// console.log('createConfig');
131+
return {
132+
dashboardId: '123',
133+
useCurrentDashboardDataRange: true,
134+
useCurrentDashboardFilters: true,
135+
};
136+
},
137+
isConfigValid(config: DashboardDrilldownConfig) {
138+
if (!config.dashboardId) return false;
139+
return true;
140+
},
141+
CollectConfig: reactToUiComponent(DashboardDrilldownCollectConfig),
142+
// CollectConfig: reactToUiComponent(DashboardDrilldownCollectConfig(dashboardLoader)),
143+
order: 5,
144+
isCompatible(context?: object): Promise<boolean> {
145+
return Promise.resolve(true);
146+
},
147+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
export { DashboardDrilldownActionFactory } from './dashboard_drilldown_action_factory';

0 commit comments

Comments
 (0)