aboutsummaryrefslogtreecommitdiffstats
path: root/client/js/app/src/app/pages/querybuilder/Components/Text/SimpleDropDownForm.jsx
blob: 01288cea44fc26a6258e7e01806c32d3117b3447 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import React, { useContext, useEffect } from 'react';
import { QueryInputContext } from '../Contexts/QueryInputContext';

export default function SimpleDropDownForm({
  choices,
  id,
  className = 'input',
  onChange,
  value,
}) {
  const { selectedItems } = useContext(QueryInputContext);

  //FIXME: using the filtered list to render options results in dropdown not changing the displayed selection to what was actually selected.
  let filtered = Object.keys(choices).filter(
    (choice) => !selectedItems.includes(choice)
  );
  useEffect(() => {
    filtered = Object.keys(choices).filter(
      (choice) => !selectedItems.includes(choice)
    );
  }, [selectedItems]);

  const options = Object.keys(choices).map((choice) => {
    return (
      <option className="options" key={choice} value={choices[choice].name}>
        {choices[choice].name}
      </option>
    );
  });

  return (
    <form id={id}>
      <select className={className} id={id} value={value} onChange={onChange}>
        {options}
      </select>
    </form>
  );
}