Skip to content

Commit

Permalink
replace function to retrive name and type options and change onClear …
Browse files Browse the repository at this point in the history
…name behaviour (#171)
  • Loading branch information
Bianca Del Carretto committed Jun 20, 2020
1 parent d7579af commit 3841f28
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
28 changes: 12 additions & 16 deletions src/components/DomEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,18 @@ function DomEvents() {
}
}, []);

const typeOptions = Object.values(buffer.current).reduce(
(acc, { event }) =>
acc.findIndex((evtIncluded) => evtIncluded.value === event.EventType) ===
-1
? [...acc, { label: event.EventType, value: event.EventType }]
: acc,
[],
);

const nameOptions = Object.values(buffer.current).reduce(
(acc, { event }) =>
acc.findIndex((evtIncluded) => evtIncluded.value === event.name) === -1
? [...acc, { label: event.name, value: event.name }]
: acc,
[],
);
const bufferValues = Object.values(buffer.current);
const getUniqueEventsByProperty = (property) => [
...new Set(bufferValues.map(({ event }) => event[property])),
];
const getOptionsByProperty = (property) =>
getUniqueEventsByProperty(property).map((eventProperty) => ({
label: eventProperty,
value: eventProperty,
}));

const typeOptions = getOptionsByProperty('EventType');
const nameOptions = getOptionsByProperty('name');

return (
<div className="flex flex-col h-auto md:h-full w-full">
Expand Down
8 changes: 2 additions & 6 deletions src/components/DomEventsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,12 @@ const DomEventsTable = ({
const listRef = useRef();
const [selectedTypes, setSelectedTypes] = useState(typeOptions);
const [selectedNames, setSelectedNames] = useState(defaultNamesOptions);
const onChangeHandler = (fieldName) => (selectedOptions, { action }) => {
const onChangeHandler = (fieldName) => (selectedOptions) => {
if (fieldName === 'type') {
setSelectedTypes(selectedOptions);
}
if (fieldName === 'name') {
if (action === 'clear') {
setSelectedNames(defaultNamesOptions);
} else {
setSelectedNames(selectedOptions);
}
setSelectedNames(selectedOptions);
}
};

Expand Down

0 comments on commit 3841f28

Please sign in to comment.