Skip to content

Commit 6a61c2a

Browse files
author
guyplusplus
committed
Working plugin
1 parent c7aec60 commit 6a61c2a

11 files changed

+266
-215
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Kibana Plugin - Custom Form Filter Visualization
22

3-
This project is a simple tutorial for Kibana new comers trying to developer their own vizualisation plugin. The actual usecase is to create a custom form to filter data to help end-users search their data.
3+
This project is a simple tutorial for Kibana new comers trying to developer their own vizualisation plugin. The actual usecase of this plugin is to create a custom form to filter data and tailor dashboard output.
44

55
This plugin is a demo for the accounts data which can be downloaded from elastic web site [here](https://download.elastic.co/demos/kibana/gettingstarted/accounts.zip) then uploaded via `curl -H 'Content-Type: application/x-ndjson' -XPOST 'localhost:9200/bank/account/_bulk?pretty' --data-binary @accounts.json`.
66

7-
As plugin architecture is being under heavy redesign in 7.x and documentation is rather obscure, I did my best to create something simple that works.
7+
As plugin architecture is being under heavy redesign in 7.x and documentation is rather obscure, I did my best to create something simple that works. The code is also basic, I am JavaScript beginner!
88

99
This repository is for Kibana v7.7 while [this repository](https://github.com/guyplusplus/Kibana-Plugin-Custom-Form-Filter-Visualization-Legacy) is for 7.6.2 legacy architecture.
1010

@@ -132,9 +132,11 @@ The form code looks like this and is very simple to modify, based on EUI React c
132132
</div>
133133
```
134134

135+
I use [Microsoft Code](https://code.visualstudio.com/) to edit code and [Google Chrome](https://www.google.com/chrome/) to debug.
136+
135137
## Packaging the plugin as a zip file
136138

137-
Simply add the plugin directory inside a `kibana` folder and zip the file. Do not include the `kibana/target` directory. The zip structure is
139+
Simply add the plugin directory inside a `kibana` folder and zip the file. Do not include the `my-plugin/target` directory in the zip file. The zip structure is
138140

139141
```
140142
my-plugin_7.7.0.zip
@@ -153,8 +155,8 @@ my-plugin_7.7.0.zip
153155
The plugin can then be installed like this for an apt installed Kibana.
154156

155157
```
156-
$ sudo ./bin/kibana-plugin --allow-root install file:///home/john/downloads/kbn_tp_custom_form_filter_accounts_7.7.0_1.0.0.zip
157-
$ sudo ./bin/kibana-plugin --allow-root install https://github.com/guyplusplus/Kibana-Plugin-Custom-Form-Filter-Visualization/releases/download/1.0.0/kbn_tp_custom_form_filter_accounts_7.7.0_1.0.0.zip
158+
$ sudo ./bin/kibana-plugin --allow-root install file:///home/john/downloads/vis_type_custom_form_filter_accounts_7.7.0_1.0.0.zip
159+
$ sudo ./bin/kibana-plugin --allow-root install https://github.com/guyplusplus/Kibana-Plugin-Custom-Form-Filter-Visualization/releases/download/1.0.0/vis_type_custom_form_filter_accounts_7.7.0_1.0.0.zip
158160
```
159161

160162
Deleting then installing the plugin often fails for me. I fix it by running this command.

vis_type_custom_form_filter_accounts/kibana.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
"version": "kibana",
44
"ui": true,
55
"server": true,
6-
"requiredPlugins": ["expressions", "visualizations"]
6+
"requiredPlugins": ["expressions", "visualizations", "data"]
77
}

vis_type_custom_form_filter_accounts/public/custom_form_filter_accounts_options.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
EuiFieldNumber,
2323
EuiFormRow
2424
} from '@elastic/eui';
25-
import { VisOptionsProps } from 'src/plugins/vis_default_editor/public';
25+
import { VisOptionsProps } from '../../../src/plugins/vis_default_editor/public';
2626
import { CustomFormFilterAccountsVisParams } from './types';
2727

2828

@@ -37,7 +37,7 @@ function CustomFormFilterAccountsOptions({ stateParams, setValue }: VisOptionsPr
3737
<EuiFormRow label="Maximum Balance">
3838
<EuiFieldNumber
3939
value={stateParams.maximumBalance}
40-
onChange={({ target: { value } }) => onCustomFormFilterAccountsUpdate(value)}
40+
onChange={({ target: { value } }) => onCustomFormFilterAccountsUpdate(Number(value))}
4141
step={1000}
4242
/>
4343
</EuiFormRow>

vis_type_custom_form_filter_accounts/public/custom_form_filter_accounts_vis.ts

Lines changed: 0 additions & 59 deletions
This file was deleted.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
20+
import React from 'react';
21+
import { KibanaContextProvider } from '../../../src/plugins/kibana_react/public';
22+
import { DefaultEditorSize } from '../../../src/plugins/vis_default_editor/public';
23+
import { DataPublicPluginSetup } from '../../../src/plugins/data/public';
24+
import { ExprVis, VisParams } from '../../../src/plugins/visualizations/public';
25+
import { CustomFormFilterAccountsVisWrapper } from './custom_form_filter_accounts_vis_controller';
26+
import { CustomFormFilterAccountsOptions } from './custom_form_filter_accounts_options';
27+
import { CustomFormFilterAccountsVisDependencies } from './plugin';
28+
29+
export interface CustomFormFilterAccountsVisComponentProp {
30+
vis: ExprVis;
31+
data: DataPublicPluginSetup;
32+
visParams: VisParams;
33+
}
34+
35+
export function getCustomFormFilterAccountsVisDefinition(dependencies: CustomFormFilterAccountsVisDependencies) {
36+
37+
return {
38+
name: 'customFormFilterAccounts',
39+
title: 'Form - Accounts',
40+
isAccessible: true,
41+
icon: 'visText',
42+
description: 'This sample custom visualization plugin contains a simple UI to adjust filter for accounts test data',
43+
visConfig: {
44+
defaults: {
45+
filterCounter: 0, //0=no action -1=delete all filters,1=first time to add filters with clicking 'Apply filter', then 2 onward each time this button is click
46+
age: 20,
47+
minimumBalance: null,
48+
maximumBalance: 100000,
49+
},
50+
component: (props: CustomFormFilterAccountsVisComponentProp) => (
51+
<KibanaContextProvider services={{ ...dependencies }}>
52+
<CustomFormFilterAccountsVisWrapper {...props} />
53+
</KibanaContextProvider>
54+
),
55+
},
56+
editorConfig: {
57+
optionTabs: [
58+
{
59+
name: 'options',
60+
title: 'Options',
61+
editor: CustomFormFilterAccountsOptions,
62+
},
63+
],
64+
enableAutoApply: false,
65+
defaultSize: DefaultEditorSize.LARGE,
66+
},
67+
options: {
68+
showIndexSelection: false,
69+
showTimePicker: true,
70+
showFilterBar: true,
71+
},
72+
requestHandler: 'none',
73+
responseHandler: 'none',
74+
};
75+
}

0 commit comments

Comments
 (0)