@galadrim/galadmin 0.1.200 → 0.1.202

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,6 +6,7 @@ import AddressInput from "./inputs/AddressInput";
6
6
  import FileInput from "./inputs/FileInput";
7
7
  import ForeignSelectInput from "./inputs/ForeignSelectInput";
8
8
  import ForeignDatalistInput from "./inputs/ForeignDatalistInput";
9
+ import AutocompleteInput from "./inputs/AutocompleteInput";
9
10
 
10
11
  export default ({ column, onChange, initialData }) => {
11
12
  const { dataType } = column;
@@ -30,7 +31,7 @@ export default ({ column, onChange, initialData }) => {
30
31
  <select
31
32
  onChange={(e) => onChange({ [column.name]: parseInt(e.target.value) })}
32
33
  defaultValue={
33
- defaultValue ? "1" : (defaultValue === null && column.optional) ? "NULL" : "0"
34
+ defaultValue ? "1" : ((defaultValue === null || defaultValue === undefined) && column.optional) ? "NULL" : "0"
34
35
  }
35
36
  >
36
37
  {column.optional ? <option value="NULL">-</option> : null}
@@ -168,6 +169,14 @@ export default ({ column, onChange, initialData }) => {
168
169
  defaultValue={initialData?.[column.name]?.join(", ")}
169
170
  />
170
171
  );
172
+ } else if (dataType === "autocompleteText") {
173
+ return (
174
+ <AutocompleteInput
175
+ column={column}
176
+ onChange={onChange}
177
+ initialData={initialData}
178
+ />
179
+ );
171
180
  } else {
172
181
  return (
173
182
  <input
@@ -0,0 +1,33 @@
1
+ import axios from "axios";
2
+ import { useEffect, useState } from "react";
3
+
4
+ export default ({ column, onChange, initialData }) => {
5
+ const [options, setOptions] = useState([])
6
+ const id = Math.random().toString(36).substring(2, 15);
7
+
8
+ useEffect(() => {
9
+ axios.get("/customQuery", {
10
+ params: {
11
+ query: column.autocompleteListQuery
12
+ }
13
+ }).then((response) => {
14
+ setOptions(response.data)
15
+ })
16
+ }, [])
17
+
18
+ return (
19
+ <>
20
+ <input
21
+ type="text"
22
+ onChange={(e) => onChange({ [column.name]: e.target.value })}
23
+ defaultValue={initialData?.[column.name]}
24
+ list={id}
25
+ />
26
+ <datalist id={id}>
27
+ {options.map((option) => (
28
+ <option value={option} key={option}></option>
29
+ ))}
30
+ </datalist>
31
+ </>
32
+ );
33
+ }
@@ -119,6 +119,12 @@ export type FileColumn = {
119
119
  name: string;
120
120
  } & FileUploadProperties;
121
121
 
122
+ export type AutocompleteColumn = {
123
+ dataType: "autocompleteText";
124
+ name: string;
125
+ autocompleteListQuery: string;
126
+ };
127
+
122
128
  export type FileUploadProperties = {
123
129
  publicPath?: string;
124
130
  subdirectory?: string;
@@ -155,6 +161,7 @@ export type Column = BaseTypeColumn &
155
161
  | BetterRichTextColumn
156
162
  | TextareaColumn
157
163
  | FileColumn
164
+ | AutocompleteColumn
158
165
  );
159
166
 
160
167
  export type CreateType = {