Skip to content

Commit

Permalink
Limit selection to one value per field
Browse files Browse the repository at this point in the history
  • Loading branch information
cqliu1 committed Feb 10, 2020
1 parent 1b8ea0c commit f5422c2
Show file tree
Hide file tree
Showing 2 changed files with 297 additions and 83 deletions.
14 changes: 14 additions & 0 deletions public/renderer/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import React, { useState } from 'react';
import { get } from 'lodash';
import { EuiComboBox } from '@elastic/eui';

export const MultiFilter = ({
Expand Down Expand Up @@ -49,6 +50,19 @@ export const MultiFilter = ({
}));

const onChangeHandler = items => {
if (items.length > 0) {
// Keep only latest selected value per column
items = items.reduce((acc, item) => {
const selectionIndex = acc.findIndex(
option => get(option, 'value.column') === get(item, 'value.column')
);
if (selectionIndex !== -1) {
acc[selectionIndex] = item;
return acc;
}
return acc.concat(item);
}, []);
}
setSelectedOptions(items);
};

Expand Down
Loading

0 comments on commit f5422c2

Please sign in to comment.