Skip to content

Commit

Permalink
Merge pull request #1 from crob611/master
Browse files Browse the repository at this point in the history
Switch to legacy plugin
  • Loading branch information
cqliu1 authored Feb 7, 2020
2 parents 1314b36 + 9642463 commit d28bb2a
Show file tree
Hide file tree
Showing 6 changed files with 5,549 additions and 48 deletions.
31 changes: 4 additions & 27 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,19 @@
/*
* 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.
*/

export default function(kibana) {
return new kibana.Plugin({
// Tell Kibana that this plugin needs canvas and the Kibana interpreter
require: ['interpreter', 'canvas'],

// The name of your plugin. Make this whatever you want.
name: 'canvas_multi_filter',

name: 'canvas-multi-filter',
uiExports: {
// Tell Kibana that the files in `/public` should be loaded into the
// browser only when the user is in the Canvas app.
canvas: ['plugins/canvas_multi_filter'],
canvas: ['plugins/canvas-multi-filter'],
},

// Enable the plugin by default
config(Joi) {
console.log('REGISTERING CANVAS MULTI FILTER');
return Joi.object({
enabled: Joi.boolean().default(true),
}).default();
},

init(server) {},
});
}
8 changes: 0 additions & 8 deletions kibana.json

This file was deleted.

36 changes: 36 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "canvas-multi-filter",
"version": "0.0.0",
"description": "Enables a MultiFilter component for Canvas",
"main": "index.js",
"kibana": {
"version": "8.0.0",
"templateVersion": "1.0.0"
},
"scripts": {
"preinstall": "node ../../preinstall_check",
"kbn": "node ../../scripts/kbn",
"es": "node ../../scripts/es",
"lint": "eslint .",
"start": "plugin-helpers start",
"test:server": "plugin-helpers test:server",
"test:browser": "plugin-helpers test:browser",
"build": "plugin-helpers build"
},
"devDependencies": {
"@elastic/eslint-config-kibana": "link:../../packages/eslint-config-kibana",
"@elastic/eslint-import-resolver-kibana": "link:../../packages/kbn-eslint-import-resolver-kibana",
"@kbn/expect": "link:../../packages/kbn-expect",
"@kbn/plugin-helpers": "link:../../packages/kbn-plugin-helpers",
"babel-eslint": "^10.0.1",
"eslint": "^5.16.0",
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jest": "^22.4.1",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-mocha": "^5.3.0",
"eslint-plugin-no-unsanitized": "^3.0.2",
"eslint-plugin-prefer-object-spread": "^1.2.1",
"eslint-plugin-react": "^7.12.4"
}
}
6 changes: 3 additions & 3 deletions public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@
import { multiFilter as multiFilterRenderer } from './renderer';
import { multiFilter as multiFilterElement } from './element';
import { multiFilterControl as multiFitlerControlFn } from './function';
import { multiFilterControl as multiFitlerControlView } from './view';
import { multifilterControl as multiFilterControlView } from './view';

const elements = [multiFilterElement];

const browserFunctions = [multiFitlerControlFn];

const views = [multiFitlerControlView];
const views = [multiFilterControlView];

const renderers = [multiFilterRenderer];

// Register our elements and browserFunctions with the Canvas interpreter.
kbnInterpreter.register({
elements,
browserFunctions,
views,
viewUIs: views,
renderers,
});
18 changes: 8 additions & 10 deletions public/renderer/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import React, { useState } from 'react';
import { EuiComboBox } from '@elastic/eui';

export const MultiFilter = ({ datatable, selected = [], onChange }) => {
export const MultiFilter = ({ datatable, columns, selected = [], onChange }) => {
const toOption = value => ({
label: value.column + ':' + value.value,
value,
Expand All @@ -29,15 +29,13 @@ export const MultiFilter = ({ datatable, selected = [], onChange }) => {
const [selectedOptions, setSelectedOptions] = useState(selected.map(toOption));

// Create a collection of groupings of options
const groupings =
((acc, column) => {
const objs = datatable.rows.map(row => ({ column, value: row[column] }));
acc[column] = Array.from(new Set(objs.map(item => item.value))).map(value =>
objs.find(item => item.value === value)
);
return acc;
},
{});
const groupings = columns.reduce((acc, column) => {
const objs = datatable.rows.map(row => ({ column, value: row[column] }));
acc[column] = Array.from(new Set(objs.map(item => item.value))).map(value =>
objs.find(item => item.value === value)
);
return acc;
}, {});

// Create the appropriately-shaped choices for the drop down.
const options = Object.keys(groupings).map(group => ({
Expand Down
Loading

0 comments on commit d28bb2a

Please sign in to comment.