@bsol-oss/react-datatable5 10.0.0 → 11.0.0-beta.0

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.
package/README.md CHANGED
@@ -90,3 +90,189 @@ For more details of props and examples, please review the stories in storybook p
90
90
  npm install
91
91
  npm run storybook
92
92
  ```
93
+
94
+ # Form
95
+
96
+ Form component can help create a object to submit an network request.
97
+
98
+ - Wrap form with confirmation, submit success and error handling ui by default
99
+ - Use `i18next` by default to display `column_id` and text in form in multiple language.
100
+ - Use `axios` by default to submit a request.
101
+
102
+
103
+ ## Usage
104
+
105
+ ```tsx
106
+ <Form
107
+ schema={someSchema as JSONSchema7}
108
+ serverUrl={"http://localhost:8081"}
109
+ />
110
+ ```
111
+
112
+ ## Set up
113
+
114
+ ### Providers
115
+
116
+ You MUST provide all three provider from packages `i18next`, `@tanstack/react-query`, and `@chakra-ui/react`
117
+
118
+ ```tsx
119
+ <Provider>
120
+ <QueryClientProvider client={queryClient}>
121
+ <I18nextProvider i18n={i18n}>
122
+ <SomeForm />
123
+ </I18nextProvider>
124
+ </QueryClientProvider>
125
+ </Provider>
126
+ ```
127
+
128
+ ### Schema
129
+
130
+ You MUST provide a `schema` props to specify the inputs in a form. You MUST specify the keyword `type` as `object`.
131
+
132
+ Currently, The `Form` component provide LIMITED json schema attributes in this release. Please check the below list to acknowledge the supported Keywords, and the intended keywords to support future releases.
133
+
134
+ The example of a valid `schema` object
135
+
136
+ ```tsx
137
+ const schema = {
138
+ type: "object",
139
+ title: "core_memberships",
140
+ required: ["id"],
141
+ properties: {
142
+ id: {
143
+ type: "string",
144
+ },
145
+ remarks: {
146
+ type: "string",
147
+ },
148
+ }
149
+ }
150
+ const SomeForm = () => {
151
+ return (
152
+ <Form
153
+ schema={schema as JSONSchema7}
154
+ serverUrl={"http://localhost:8081"}
155
+ />
156
+ )
157
+ }
158
+ ```
159
+
160
+ ## Supported Keywords
161
+
162
+ ### `title`
163
+
164
+ You MUST provide the `title` keyword to specifies the string id that will be used in `i18n` translate.
165
+
166
+ The value must be in type `string`.
167
+
168
+ ### `required`
169
+
170
+ You MAY provide the `required` keyword to specifies the input that are required to fill before confirmation.
171
+
172
+ The value must be in type `array` of `string`.
173
+
174
+ ### `properties`
175
+
176
+ You MUST provide the `properties` keywords to specifies the fields that the form should appear.
177
+
178
+ The value must be in type `object`. The keys in this object specifies the column id and the values its related properties. Check the sections **Column Keywords** show the supported column keywords.
179
+
180
+
181
+ ## Column Keywords
182
+
183
+ ### `type`
184
+
185
+ You MUST provide the `type` keywords to specifies the value type that the column should create. Some value types may include different inputs by specify the `variant` keywords.
186
+
187
+ Check the sections **Value types** show the supported keywords and input variants for each value type.
188
+
189
+ Supported value types: `array`, `string`, `number`, `boolean`, `integer`, `object`;
190
+
191
+ ## Value types
192
+
193
+ This sections show the supported keywords and input variants for each value type.
194
+
195
+ ### `string`
196
+
197
+ For input types `string`, it will generate a string input by default.
198
+
199
+ If you specify the `variant` keyword, it will render a picker to fill a string that requires a format.
200
+
201
+ Supported variants in `string`: `id-picker`, `date_picker`
202
+
203
+ #### `id-picker`
204
+
205
+ For string input variant `id-picker`, it will generate a selector that can pop up a search to help the selection. After the user select a options, the input will show the selected record, and save its correspond string value in the form object.
206
+
207
+ You MUST include the keyword `foreign_key` and a object with keys `display_column`, `table`, `column`. The `display_column` key is the column that show the label for that value to user, and `column` key is the column that its value should set in this input.
208
+
209
+ You MUST include a `/api/g` api that could accept the following request in order to search for a record.
210
+
211
+ ```ts
212
+ const requestConfig = {
213
+ method: "GET",
214
+ url: `${serverUrl}/api/g/${table}`,
215
+ params: {
216
+ searching,
217
+ where,
218
+ limit,
219
+ offset
220
+ },
221
+ }
222
+ ```
223
+
224
+ The example valid schema that use `id=picker` variant.
225
+
226
+ ```tsx
227
+ const eventsFilesSchema = {
228
+ type: "object",
229
+ title: "events_files",
230
+ required: ["event_id", "file_id"],
231
+ properties: {
232
+ file_id: {
233
+ type: "array",
234
+ variant: "file-picker",
235
+ },
236
+ event_id: {
237
+ type: "string",
238
+ variant: "id-picker",
239
+ foreign_key: {
240
+ display_column: "event_name",
241
+ table: "core_events",
242
+ column: "id",
243
+ },
244
+ },
245
+ },
246
+ }
247
+ ```
248
+
249
+ ### `number`
250
+
251
+ For value type `number`, it will generate a number input by default.
252
+
253
+ Currently no supported variants.
254
+
255
+ ### `boolean`
256
+
257
+ For value type `boolean`, it will generate a checkbox by default.
258
+
259
+ Currently no supported variants.
260
+
261
+
262
+ ### `array`
263
+
264
+ For value type `array`, by default it will generate NO input.
265
+
266
+ You MUST specify the `variant` keyword to display a relevant input.
267
+
268
+ Supported variant in `array`: `id-picker`, `file-picker`
269
+
270
+ ### `object`
271
+
272
+ For value type `object`, by default it will generate a input that can input key value pairs.
273
+
274
+ It is NOT RECOMMENDED to use the default input, Later release may include a json editor by default.
275
+
276
+ ### Intented Support Keywords in Future Release
277
+
278
+ (TBC)
package/dist/index.d.ts CHANGED
@@ -11,6 +11,7 @@ import { RankingInfo } from '@tanstack/match-sorter-utils';
11
11
  import { UseQueryResult } from '@tanstack/react-query';
12
12
  import { JSONSchema7 } from 'json-schema';
13
13
  import { ForeignKeyProps } from '@/components/Form/components/StringInputField';
14
+ import { AxiosRequestConfig } from 'axios';
14
15
  import * as react_hook_form from 'react-hook-form';
15
16
  import { FieldValues, UseFormReturn, SubmitHandler } from 'react-hook-form';
16
17
  import { RenderProps, Props } from '@bsol-oss/dayzed-react19';
@@ -458,6 +459,7 @@ declare const GlobalFilter: () => react_jsx_runtime.JSX.Element;
458
459
  interface FormProps<TData extends FieldValues> {
459
460
  schema: JSONSchema7;
460
461
  serverUrl: string;
462
+ requestUrl?: string;
461
463
  idMap: Record<string, object>;
462
464
  setIdMap: Dispatch<SetStateAction<Record<string, object>>>;
463
465
  form: UseFormReturn;
@@ -465,8 +467,8 @@ interface FormProps<TData extends FieldValues> {
465
467
  order?: string[];
466
468
  ignore?: string[];
467
469
  onSubmit?: SubmitHandler<TData>;
468
- preLoadedValues?: object;
469
470
  rowNumber?: number | string;
471
+ requestOptions?: AxiosRequestConfig;
470
472
  }
471
473
  interface CustomJSONSchema7Definition extends JSONSchema7 {
472
474
  variant: string;
@@ -477,7 +479,7 @@ interface CustomJSONSchema7Definition extends JSONSchema7 {
477
479
  gridRow: string;
478
480
  foreign_key: ForeignKeyProps;
479
481
  }
480
- declare const Form: <TData extends FieldValues>({ schema, idMap, setIdMap, form, serverUrl, translate, order, ignore, onSubmit, preLoadedValues, rowNumber, }: FormProps<TData>) => react_jsx_runtime.JSX.Element;
482
+ declare const Form: <TData extends FieldValues>({ schema, idMap, setIdMap, form, serverUrl, translate, order, ignore, onSubmit, preLoadedValues, rowNumber, requestOptions, }: FormProps<TData>) => react_jsx_runtime.JSX.Element;
481
483
 
482
484
  interface UseFormProps {
483
485
  preLoadedValues?: FieldValues | undefined;
package/dist/index.js CHANGED
@@ -3555,11 +3555,12 @@ const ErrorAlert = ({ showMessage = true }) => {
3555
3555
  const SchemaFormContext = React.createContext({
3556
3556
  schema: {},
3557
3557
  serverUrl: "",
3558
+ requestUrl: "",
3558
3559
  order: [],
3559
3560
  ignore: [],
3560
3561
  onSubmit: async () => { },
3561
3562
  rowNumber: 0,
3562
- displayText: {},
3563
+ requestOptions: {},
3563
3564
  });
3564
3565
 
3565
3566
  const PopoverContent = React__namespace.forwardRef(function PopoverContent(props, ref) {
@@ -3586,10 +3587,11 @@ const Field = React__namespace.forwardRef(function Field(props, ref) {
3586
3587
  });
3587
3588
 
3588
3589
  const useSchemaContext = () => {
3589
- const { schema, serverUrl, order, ignore, onSubmit, rowNumber, idMap, setIdMap, translate, } = React.useContext(SchemaFormContext);
3590
+ const { schema, serverUrl, requestUrl, order, ignore, onSubmit, rowNumber, idMap, setIdMap, translate, requestOptions, } = React.useContext(SchemaFormContext);
3590
3591
  return {
3591
3592
  schema,
3592
3593
  serverUrl,
3594
+ requestUrl,
3593
3595
  order,
3594
3596
  ignore,
3595
3597
  onSubmit,
@@ -3597,6 +3599,7 @@ const useSchemaContext = () => {
3597
3599
  idMap,
3598
3600
  setIdMap,
3599
3601
  translate,
3602
+ requestOptions,
3600
3603
  };
3601
3604
  };
3602
3605
 
@@ -3610,10 +3613,6 @@ const getTableData = async ({ serverUrl, in_table, searching = "", where = [], l
3610
3613
  const options = {
3611
3614
  method: "GET",
3612
3615
  url: `${serverUrl}/api/g/${in_table}`,
3613
- headers: {
3614
- Apikey: "YOUR_SECRET_TOKEN",
3615
- "Content-Type": "application/json",
3616
- },
3617
3616
  params: {
3618
3617
  searching,
3619
3618
  where,
@@ -4541,7 +4540,7 @@ const idPickerSanityCheck = (column, foreign_key) => {
4541
4540
  }
4542
4541
  };
4543
4542
  const FormInternal = () => {
4544
- const { schema, serverUrl, order, ignore, onSubmit, rowNumber, idMap, translate, } = useSchemaContext();
4543
+ const { schema, requestUrl, order, ignore, onSubmit, rowNumber, idMap, translate, requestOptions, } = useSchemaContext();
4545
4544
  const methods = reactHookForm.useFormContext();
4546
4545
  const [isSuccess, setIsSuccess] = React.useState(false);
4547
4546
  const [isError, setIsError] = React.useState(false);
@@ -4580,12 +4579,9 @@ const FormInternal = () => {
4580
4579
  const defaultSubmitPromise = (data) => {
4581
4580
  const options = {
4582
4581
  method: "POST",
4583
- url: `${serverUrl}/api/g/${schema.title}`,
4584
- headers: {
4585
- Apikey: "YOUR_SECRET_TOKEN",
4586
- "Content-Type": "application/json",
4587
- },
4582
+ url: `${requestUrl}`,
4588
4583
  data: clearEmptyString(data),
4584
+ ...requestOptions,
4589
4585
  };
4590
4586
  return axios.request(options);
4591
4587
  };
@@ -4772,7 +4768,7 @@ const FormInternal = () => {
4772
4768
  methods.handleSubmit(onValid)();
4773
4769
  }, formNoValidate: true, children: translate.t("submit") })] }), isError && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: ["isError", jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [" ", `${error}`] })] }))] }));
4774
4770
  };
4775
- const Form = ({ schema, idMap, setIdMap, form, serverUrl, translate, order = [], ignore = [], onSubmit = undefined, preLoadedValues = {}, rowNumber = undefined, }) => {
4771
+ const Form = ({ schema, idMap, setIdMap, form, serverUrl, translate, order = [], ignore = [], onSubmit = undefined, preLoadedValues = {}, rowNumber = undefined, requestOptions = {}, }) => {
4776
4772
  const { properties } = schema;
4777
4773
  idListSanityCheck("order", order, properties);
4778
4774
  idListSanityCheck("ignore", ignore, properties);
@@ -4788,6 +4784,7 @@ const Form = ({ schema, idMap, setIdMap, form, serverUrl, translate, order = [],
4788
4784
  idMap,
4789
4785
  setIdMap,
4790
4786
  translate,
4787
+ requestOptions,
4791
4788
  }, children: jsxRuntime.jsx(reactHookForm.FormProvider, { ...form, children: jsxRuntime.jsx(FormInternal, {}) }) }));
4792
4789
  };
4793
4790
 
package/dist/index.mjs CHANGED
@@ -3535,11 +3535,12 @@ const ErrorAlert = ({ showMessage = true }) => {
3535
3535
  const SchemaFormContext = createContext({
3536
3536
  schema: {},
3537
3537
  serverUrl: "",
3538
+ requestUrl: "",
3538
3539
  order: [],
3539
3540
  ignore: [],
3540
3541
  onSubmit: async () => { },
3541
3542
  rowNumber: 0,
3542
- displayText: {},
3543
+ requestOptions: {},
3543
3544
  });
3544
3545
 
3545
3546
  const PopoverContent = React.forwardRef(function PopoverContent(props, ref) {
@@ -3566,10 +3567,11 @@ const Field = React.forwardRef(function Field(props, ref) {
3566
3567
  });
3567
3568
 
3568
3569
  const useSchemaContext = () => {
3569
- const { schema, serverUrl, order, ignore, onSubmit, rowNumber, idMap, setIdMap, translate, } = useContext(SchemaFormContext);
3570
+ const { schema, serverUrl, requestUrl, order, ignore, onSubmit, rowNumber, idMap, setIdMap, translate, requestOptions, } = useContext(SchemaFormContext);
3570
3571
  return {
3571
3572
  schema,
3572
3573
  serverUrl,
3574
+ requestUrl,
3573
3575
  order,
3574
3576
  ignore,
3575
3577
  onSubmit,
@@ -3577,6 +3579,7 @@ const useSchemaContext = () => {
3577
3579
  idMap,
3578
3580
  setIdMap,
3579
3581
  translate,
3582
+ requestOptions,
3580
3583
  };
3581
3584
  };
3582
3585
 
@@ -3590,10 +3593,6 @@ const getTableData = async ({ serverUrl, in_table, searching = "", where = [], l
3590
3593
  const options = {
3591
3594
  method: "GET",
3592
3595
  url: `${serverUrl}/api/g/${in_table}`,
3593
- headers: {
3594
- Apikey: "YOUR_SECRET_TOKEN",
3595
- "Content-Type": "application/json",
3596
- },
3597
3596
  params: {
3598
3597
  searching,
3599
3598
  where,
@@ -4521,7 +4520,7 @@ const idPickerSanityCheck = (column, foreign_key) => {
4521
4520
  }
4522
4521
  };
4523
4522
  const FormInternal = () => {
4524
- const { schema, serverUrl, order, ignore, onSubmit, rowNumber, idMap, translate, } = useSchemaContext();
4523
+ const { schema, requestUrl, order, ignore, onSubmit, rowNumber, idMap, translate, requestOptions, } = useSchemaContext();
4525
4524
  const methods = useFormContext();
4526
4525
  const [isSuccess, setIsSuccess] = useState(false);
4527
4526
  const [isError, setIsError] = useState(false);
@@ -4560,12 +4559,9 @@ const FormInternal = () => {
4560
4559
  const defaultSubmitPromise = (data) => {
4561
4560
  const options = {
4562
4561
  method: "POST",
4563
- url: `${serverUrl}/api/g/${schema.title}`,
4564
- headers: {
4565
- Apikey: "YOUR_SECRET_TOKEN",
4566
- "Content-Type": "application/json",
4567
- },
4562
+ url: `${requestUrl}`,
4568
4563
  data: clearEmptyString(data),
4564
+ ...requestOptions,
4569
4565
  };
4570
4566
  return axios.request(options);
4571
4567
  };
@@ -4752,7 +4748,7 @@ const FormInternal = () => {
4752
4748
  methods.handleSubmit(onValid)();
4753
4749
  }, formNoValidate: true, children: translate.t("submit") })] }), isError && (jsxs(Fragment, { children: ["isError", jsxs(Fragment, { children: [" ", `${error}`] })] }))] }));
4754
4750
  };
4755
- const Form = ({ schema, idMap, setIdMap, form, serverUrl, translate, order = [], ignore = [], onSubmit = undefined, preLoadedValues = {}, rowNumber = undefined, }) => {
4751
+ const Form = ({ schema, idMap, setIdMap, form, serverUrl, translate, order = [], ignore = [], onSubmit = undefined, preLoadedValues = {}, rowNumber = undefined, requestOptions = {}, }) => {
4756
4752
  const { properties } = schema;
4757
4753
  idListSanityCheck("order", order, properties);
4758
4754
  idListSanityCheck("ignore", ignore, properties);
@@ -4768,6 +4764,7 @@ const Form = ({ schema, idMap, setIdMap, form, serverUrl, translate, order = [],
4768
4764
  idMap,
4769
4765
  setIdMap,
4770
4766
  translate,
4767
+ requestOptions,
4771
4768
  }, children: jsx(FormProvider, { ...form, children: jsx(FormInternal, {}) }) }));
4772
4769
  };
4773
4770
 
@@ -1,4 +1,5 @@
1
1
  import { ForeignKeyProps } from "@/components/Form/components/StringInputField";
2
+ import { AxiosRequestConfig } from "axios";
2
3
  import { JSONSchema7 } from "json-schema";
3
4
  import { Dispatch, SetStateAction } from "react";
4
5
  import { FieldValues, SubmitHandler, UseFormReturn } from "react-hook-form";
@@ -6,6 +7,7 @@ import { UseTranslationResponse } from "react-i18next";
6
7
  export interface FormProps<TData extends FieldValues> {
7
8
  schema: JSONSchema7;
8
9
  serverUrl: string;
10
+ requestUrl?: string;
9
11
  idMap: Record<string, object>;
10
12
  setIdMap: Dispatch<SetStateAction<Record<string, object>>>;
11
13
  form: UseFormReturn;
@@ -13,8 +15,8 @@ export interface FormProps<TData extends FieldValues> {
13
15
  order?: string[];
14
16
  ignore?: string[];
15
17
  onSubmit?: SubmitHandler<TData>;
16
- preLoadedValues?: object;
17
18
  rowNumber?: number | string;
19
+ requestOptions?: AxiosRequestConfig;
18
20
  }
19
21
  export interface CustomJSONSchema7Definition extends JSONSchema7 {
20
22
  variant: string;
@@ -25,4 +27,4 @@ export interface CustomJSONSchema7Definition extends JSONSchema7 {
25
27
  gridRow: string;
26
28
  foreign_key: ForeignKeyProps;
27
29
  }
28
- export declare const Form: <TData extends FieldValues>({ schema, idMap, setIdMap, form, serverUrl, translate, order, ignore, onSubmit, preLoadedValues, rowNumber, }: FormProps<TData>) => import("react/jsx-runtime").JSX.Element;
30
+ export declare const Form: <TData extends FieldValues>({ schema, idMap, setIdMap, form, serverUrl, translate, order, ignore, onSubmit, preLoadedValues, rowNumber, requestOptions, }: FormProps<TData>) => import("react/jsx-runtime").JSX.Element;
@@ -1,3 +1,4 @@
1
+ import { AxiosRequestConfig } from "axios";
1
2
  import { JSONSchema7 } from "json-schema";
2
3
  import { Dispatch, SetStateAction } from "react";
3
4
  import { FieldValues } from "react-hook-form";
@@ -5,6 +6,7 @@ import { UseTranslationResponse } from "react-i18next";
5
6
  export interface SchemaFormContext<TData extends FieldValues> {
6
7
  schema: JSONSchema7;
7
8
  serverUrl: string;
9
+ requestUrl: string;
8
10
  order: string[];
9
11
  ignore: string[];
10
12
  onSubmit?: (data: TData) => Promise<void>;
@@ -12,5 +14,6 @@ export interface SchemaFormContext<TData extends FieldValues> {
12
14
  idMap: Record<string, object>;
13
15
  setIdMap: Dispatch<SetStateAction<Record<string, object>>>;
14
16
  translate: UseTranslationResponse<any, any>;
17
+ requestOptions: AxiosRequestConfig;
15
18
  }
16
19
  export declare const SchemaFormContext: import("react").Context<SchemaFormContext<unknown>>;
@@ -2,6 +2,7 @@
2
2
  export declare const useSchemaContext: () => {
3
3
  schema: import("json-schema").JSONSchema7;
4
4
  serverUrl: string;
5
+ requestUrl: string;
5
6
  order: string[];
6
7
  ignore: string[];
7
8
  onSubmit: ((data: unknown) => Promise<void>) | undefined;
@@ -9,4 +10,5 @@ export declare const useSchemaContext: () => {
9
10
  idMap: Record<string, object>;
10
11
  setIdMap: import("react").Dispatch<import("react").SetStateAction<Record<string, object>>>;
11
12
  translate: import("react-i18next").UseTranslationResponse<any, any>;
13
+ requestOptions: import("axios").AxiosRequestConfig<any>;
12
14
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsol-oss/react-datatable5",
3
- "version": "10.0.0",
3
+ "version": "11.0.0-beta.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",