aboutsummaryrefslogtreecommitdiffstats
path: root/client/js/app/src/app/pages/querybuilder/Components/Contexts/QueryInputContext.jsx
blob: 061b291e329317524533a3107c76397c7d885e15 (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
39
import React, { createContext, useState } from 'react';
import { levelZeroParameters } from 'app/pages/querybuilder/parameters';

export const QueryInputContext = createContext();

export const QueryInputProvider = (prop) => {
  // This is the id of the newest QueryInput, gets updated each time a new one is added
  const [id, setId] = useState(1);

  const firstChoice = levelZeroParameters[Object.keys(levelZeroParameters)[0]];

  const [inputs, setInputs] = useState([
    {
      id: '1',
      type: firstChoice.name,
      typeof: firstChoice.type,
      input: '',
      hasChildren: false,
      children: [],
    },
  ]);

  const [selectedItems, setSelectedItems] = useState([]);

  return (
    <QueryInputContext.Provider
      value={{
        inputs,
        setInputs,
        id,
        setId,
        selectedItems,
        setSelectedItems,
      }}
    >
      {prop.children}
    </QueryInputContext.Provider>
  );
};