@bigbinary/neeto-fields-frontend 1.0.2 → 1.0.4
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 +380 -2
- package/dist/index.cjs.js +4700 -221
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +4702 -224
- package/dist/index.js.map +1 -1
- package/package.json +5 -2
- package/types.d.ts +20 -1
package/README.md
CHANGED
|
@@ -1,10 +1,53 @@
|
|
|
1
1
|
# neeto-fields-nano
|
|
2
2
|
|
|
3
|
-
[](https://bigbinary.semaphoreci.com/projects/neeto-fields-engine)
|
|
4
|
-
|
|
5
3
|
**neeto-fields-nano** enables the management of dynamically added fields (often
|
|
6
4
|
referred as custom fields) for the resources across neeto products.
|
|
7
5
|
|
|
6
|
+
# Index
|
|
7
|
+
|
|
8
|
+
- [General information](#general-information)
|
|
9
|
+
- [Installation instructions](#installation-instructions)
|
|
10
|
+
- [Engine Installation](#engine-installation)
|
|
11
|
+
- [Frontend package Installation](#frontend-package-installation)
|
|
12
|
+
- Frontend package exports
|
|
13
|
+
- [Components](#components)
|
|
14
|
+
- [FieldsDashBoard](#1-fieldsdashboard)
|
|
15
|
+
- [AddField](#2-addfield)
|
|
16
|
+
- [FieldValuesContainer](#3-fieldvaluescontainer)
|
|
17
|
+
- [FieldInputs](#4-fieldinputs)
|
|
18
|
+
- [Functions](#functions)
|
|
19
|
+
- [mergeInitialValues](#1-neetofieldsutilsmergeinitialvalues)
|
|
20
|
+
- [transformValues](#2-neetofieldsutilstransformvalues)
|
|
21
|
+
- [Hooks](#hooks)
|
|
22
|
+
- [useFetchFields](#1-usefetchfields)
|
|
23
|
+
- [Customizability](#customizability)
|
|
24
|
+
- [Engine customizability](#engine-customizability)
|
|
25
|
+
- [Development instructions](#development-instructions)
|
|
26
|
+
- [Engine development](#engine-development)
|
|
27
|
+
- [Frontend package development](#frontend-package-development)
|
|
28
|
+
|
|
29
|
+
# General information
|
|
30
|
+
|
|
31
|
+
- This nano deals with fields and field values.
|
|
32
|
+
|
|
33
|
+
- Field has a `name`, `kind`, `resource_type` and `owner`.
|
|
34
|
+
|
|
35
|
+
- Field value has a `field` and `resource` item associated to it.
|
|
36
|
+
|
|
37
|
+
- `resource_type` is the type of resource for which we are creating the field.
|
|
38
|
+
It is used for the categorized fetching and rendering of the fields. _eg:
|
|
39
|
+
users, tickets, deals, etc_
|
|
40
|
+
|
|
41
|
+
- `owner` is basically scope of a field. It is whom to the field belongs. _eg:
|
|
42
|
+
Organization, Project, etc_
|
|
43
|
+
|
|
44
|
+
- `kind` is the nature of the data meant as value for the field. All available
|
|
45
|
+
`kinds` are:
|
|
46
|
+
|
|
47
|
+
`text`, `number`, `monetary`, `single_option`, `multi_option`, `date`, `time`,
|
|
48
|
+
`date_range`, `time_range`, `text_area`, `person`, `checkbox`, `regex`,
|
|
49
|
+
`integer`, `decimal`, `datetime`.
|
|
50
|
+
|
|
8
51
|
# Installation instructions
|
|
9
52
|
|
|
10
53
|
## Engine installation
|
|
@@ -89,6 +132,341 @@ Install the latest `neetoFields nano` package using the below command:
|
|
|
89
132
|
yarn add @bigbinary/neeto-fields-frontend
|
|
90
133
|
```
|
|
91
134
|
|
|
135
|
+
The frontend package exports 4 components, 2 utility functions and a hook.
|
|
136
|
+
|
|
137
|
+
## Components
|
|
138
|
+
|
|
139
|
+
### 1. `FieldsDashboard`
|
|
140
|
+
|
|
141
|
+
<div align="center">
|
|
142
|
+
<img src="https://i.ibb.co/8NYn403/Screenshot-2023-07-13-20-04-54.png" alt="Dashboard image"/>
|
|
143
|
+
</div>
|
|
144
|
+
|
|
145
|
+
The FieldsDashboard component serves as a dashboard for managing all
|
|
146
|
+
custom-field related operations. It functions without requiring any props by
|
|
147
|
+
default, but you can customize its behavior by passing optional props.
|
|
148
|
+
|
|
149
|
+
#### Props:
|
|
150
|
+
|
|
151
|
+
1. `rowData`: Represents the rowData for the table within the dashboard.
|
|
152
|
+
2. `buildColumnData` : A function that builds the column data (in neetoUI table
|
|
153
|
+
format) for the dashboard table. This function gets the `onDeleteClick`,
|
|
154
|
+
`onEditClick` callbacks and `defaultColumns` as arguments.
|
|
155
|
+
3. `showOwnersInMenu`: Accepts a boolean value. When set to `true`, the fields
|
|
156
|
+
are displayed in categorized form (side menu) based on owners. By default,
|
|
157
|
+
fields are categorized based on the resourceType.
|
|
158
|
+
4. `resourceType`: Explicitly specifies the `resource_type` of the fields to be
|
|
159
|
+
shown in the dashboard table. This prop is expected when `showOwnersInMenu`
|
|
160
|
+
is set to `true`.
|
|
161
|
+
5. `allowedKinds`:Specifies the list of field kinds allowed to be created.
|
|
162
|
+
6. `paneProps`: Props to be passed to the Add/Edit pane. It accepts `children`
|
|
163
|
+
to be rendered inside the pane and `validations` for the formik input fields
|
|
164
|
+
in the `children`. `validations` must be provided as a map with the field
|
|
165
|
+
name as key and the corresponding yup validation schema as the value.
|
|
166
|
+
7. `showStateFilter`: Boolean value which specifies whether to show or hide
|
|
167
|
+
state filters.
|
|
168
|
+
8. `fieldStatesTaxonomy`: Specifies the names to be rendered for `active` and
|
|
169
|
+
`inactive` states.
|
|
170
|
+
9. `breadcrumbs`: Specifies the breadcrumbs to be displayed on the dashboard
|
|
171
|
+
page.
|
|
172
|
+
|
|
173
|
+
#### Usage:
|
|
174
|
+
|
|
175
|
+
When Organization is the owner of the fields.
|
|
176
|
+
|
|
177
|
+
```jsx
|
|
178
|
+
import { FieldsDashboard } from "@bigbinary/neeto-fields-frontend";
|
|
179
|
+
|
|
180
|
+
<FieldsDashboard
|
|
181
|
+
allowedKinds={["text", "number"]}
|
|
182
|
+
buildColumnData={({ defaultColumns }) => [
|
|
183
|
+
...defaultColumns,
|
|
184
|
+
{
|
|
185
|
+
dataIndex: "isSystem",
|
|
186
|
+
index: "isSystem",
|
|
187
|
+
title: t("titles.systemField"),
|
|
188
|
+
render: boolVal => (boolVal ? "Yes" : "No"),
|
|
189
|
+
},
|
|
190
|
+
]}
|
|
191
|
+
fieldStatesTaxonomy={{ active: "Active", inactive: "Deactivated" }}
|
|
192
|
+
paneProps={{
|
|
193
|
+
children: <HostSpecificInputFields />,
|
|
194
|
+
validations: {
|
|
195
|
+
hostSpecificInputName: validationSchema,
|
|
196
|
+
},
|
|
197
|
+
}}
|
|
198
|
+
breadcrumbs={[
|
|
199
|
+
{
|
|
200
|
+
link: "/",
|
|
201
|
+
text: "Home",
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
link: "/",
|
|
205
|
+
text: "Settings",
|
|
206
|
+
},
|
|
207
|
+
]}
|
|
208
|
+
/>;
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
When Organization is not owner of the fields. Lets say the owner is Project.
|
|
212
|
+
|
|
213
|
+
```jsx
|
|
214
|
+
import { FieldsDashboard } from "@bigbinary/neeto-fields-frontend";
|
|
215
|
+
|
|
216
|
+
<FieldsDashboard
|
|
217
|
+
allowedKinds={["text", "number"]}
|
|
218
|
+
ownerId={projectId}
|
|
219
|
+
resourceType="tasks"
|
|
220
|
+
showOwnersInMenu
|
|
221
|
+
fieldStatesTaxonomy={{ active: "Active", inactive: "Deactivated" }}
|
|
222
|
+
paneProps={{
|
|
223
|
+
children: <HostSpecificInputFields />,
|
|
224
|
+
validations: {
|
|
225
|
+
hostSpecificInputName: validationSchema,
|
|
226
|
+
},
|
|
227
|
+
}}
|
|
228
|
+
breadcrumbs={[
|
|
229
|
+
{
|
|
230
|
+
link: "/",
|
|
231
|
+
text: "Home",
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
link: "/",
|
|
235
|
+
text: "Settings",
|
|
236
|
+
},
|
|
237
|
+
]}
|
|
238
|
+
/>;
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## 2. `AddField`
|
|
242
|
+
|
|
243
|
+
<div align="center">
|
|
244
|
+
<img src="https://s11.gifyu.com/images/SWngt.gif" alt="AddField component gif" width="700"/>
|
|
245
|
+
</div>
|
|
246
|
+
|
|
247
|
+
The `AddField` component consists of a button and a pane that opens when the
|
|
248
|
+
button is clicked.
|
|
249
|
+
|
|
250
|
+
#### Props:
|
|
251
|
+
|
|
252
|
+
1. `resourceType`: Specifies the resource_type of the field to be created via
|
|
253
|
+
the pane.
|
|
254
|
+
2. `allowedKinds`: Specifies the list of field kinds allowed to be created.
|
|
255
|
+
3. `children`: Children components for the pane.
|
|
256
|
+
4. `additionalValidations`: Validations for the formik fields in `children`.
|
|
257
|
+
|
|
258
|
+
#### Usage:
|
|
259
|
+
|
|
260
|
+
```jsx
|
|
261
|
+
import { AddField } from "@biginary/neeto-fields-frontend";
|
|
262
|
+
|
|
263
|
+
<AddField
|
|
264
|
+
allowedKinds={["text", "number"]}
|
|
265
|
+
resourceType="users"
|
|
266
|
+
additionalValidations={{
|
|
267
|
+
hostSpecificInputName: validationSchema,
|
|
268
|
+
}}
|
|
269
|
+
>
|
|
270
|
+
<HostSpecificInputFields />
|
|
271
|
+
</AddField>;
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## 3. `FieldValuesContainer`
|
|
275
|
+
|
|
276
|
+
<div align="center">
|
|
277
|
+
<img src="https://i.ibb.co/K6Gz0FF/Neeto-Fields-Nano-2023-07-13-19-57-27.png" alt="FieldValuesContainer Image" width="500"/>
|
|
278
|
+
</div>
|
|
279
|
+
|
|
280
|
+
The `FieldValuesContainer` component handles field values associated with a
|
|
281
|
+
specific resource.
|
|
282
|
+
|
|
283
|
+
#### Props:
|
|
284
|
+
|
|
285
|
+
1. `resourceType`: The type of resource.
|
|
286
|
+
2. `fieldValues`: Field values associated with the resource obtained from the
|
|
287
|
+
response.
|
|
288
|
+
3. `resourceId`: The ID of the resource.
|
|
289
|
+
4. `ownerId`:The ID of the owner. This prop is required only if the owner is not
|
|
290
|
+
an organization.
|
|
291
|
+
5. `queryKeysToBeInvalidatedOnSuccess`: An array of queryKeys that should be
|
|
292
|
+
invalidated when changing the field value.
|
|
293
|
+
6. `customComponents`: If the host application has any extra `kind` other than
|
|
294
|
+
the supported ones, you can specify the component to be displayed
|
|
295
|
+
corresponding to that kind using this prop. It takes the `kind` name as the
|
|
296
|
+
key and the component rendering callback function as the value. The callback
|
|
297
|
+
function can expect the `field` object as argument.
|
|
298
|
+
7. `className`: Class names for styling.
|
|
299
|
+
|
|
300
|
+
#### Usage:
|
|
301
|
+
|
|
302
|
+
Say the resource over here is a user.
|
|
303
|
+
|
|
304
|
+
```jsx
|
|
305
|
+
import { FieldValuesContainer } from "@bigbinary/neeto-fields-frontend";
|
|
306
|
+
|
|
307
|
+
<FieldValuesContainer
|
|
308
|
+
fieldValues={user.fieldValues} // We expect the user response from host's backend to send associated field_values with it.
|
|
309
|
+
queryKeysToBeInvalidatedOnSuccess={["users"]}
|
|
310
|
+
resourceId={user?.id}
|
|
311
|
+
resourceType="users"
|
|
312
|
+
customComponents={{
|
|
313
|
+
hostSpecificKindName: field => <HostSpecificInputFields />,
|
|
314
|
+
}}
|
|
315
|
+
/>;
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### 4. `FieldInputs`
|
|
319
|
+
|
|
320
|
+
<div align="center">
|
|
321
|
+
<img src="https://i.ibb.co/9TmXnCx/Neeto-Fields-Nano-2023-07-14-00-38-03.png" alt="FieldInputs image" width="400"/>
|
|
322
|
+
</div>
|
|
323
|
+
|
|
324
|
+
The FieldInputs component render the input UI for the fetched fields. It accepts
|
|
325
|
+
the following props:
|
|
326
|
+
|
|
327
|
+
#### Props:
|
|
328
|
+
|
|
329
|
+
1. `fields`: An array of all the fetched fields.
|
|
330
|
+
2. `customComponents`: If the host application has any extra kind other than the
|
|
331
|
+
supported ones, you can specify the component to be displayed corresponding
|
|
332
|
+
to that kind using this prop. It takes the kind name as the key and the
|
|
333
|
+
component rendering callback function as the value. The callback function can
|
|
334
|
+
expect the `field` object.
|
|
335
|
+
|
|
336
|
+
> :memo: **_Note:_**
|
|
337
|
+
>
|
|
338
|
+
> To initialize the values for this formik fields, you need to use
|
|
339
|
+
> [`mergeInitialValues`](#1-mergeinitialvaluesinitialvalues-fields) function.
|
|
340
|
+
>
|
|
341
|
+
> To submit the values from this formik form, you need to use
|
|
342
|
+
> [`transformValues`](#2-transformvaluesvalues) function to capture the right
|
|
343
|
+
> data from neeto-fields.
|
|
344
|
+
|
|
345
|
+
#### Usage:
|
|
346
|
+
|
|
347
|
+
```jsx
|
|
348
|
+
import {
|
|
349
|
+
FieldInputs,
|
|
350
|
+
useFetchFields,
|
|
351
|
+
neetoFieldsUtils,
|
|
352
|
+
} from "@bigbinary/neeto-fields-frontend";
|
|
353
|
+
|
|
354
|
+
const HostForm = () => {
|
|
355
|
+
const {
|
|
356
|
+
data: { fields },
|
|
357
|
+
} = useFetchFields({
|
|
358
|
+
resourceType: "users",
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
const initialValues = neetoFieldsUtils.mergeInitialValues({
|
|
362
|
+
initialValues: INITIAL_VALUES,
|
|
363
|
+
fields,
|
|
364
|
+
});
|
|
365
|
+
return (
|
|
366
|
+
<Form
|
|
367
|
+
formikProps={{
|
|
368
|
+
initialValues,
|
|
369
|
+
validationSchema: VALIDATION_SCHEMA,
|
|
370
|
+
onSubmit: values =>
|
|
371
|
+
onSubmit(neetoFieldsUtils.transformValues({ values, fields })),
|
|
372
|
+
enableReinitialize: true,
|
|
373
|
+
}}
|
|
374
|
+
>
|
|
375
|
+
{/* Other host specific input fields */}
|
|
376
|
+
|
|
377
|
+
<FieldInputs fields={fields} />
|
|
378
|
+
|
|
379
|
+
<Button type="submit" label="Submit" />
|
|
380
|
+
</Form>
|
|
381
|
+
);
|
|
382
|
+
};
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
## Functions
|
|
386
|
+
|
|
387
|
+
The package exports the `neetoFieldsUtils`, which contains two utility
|
|
388
|
+
functions.
|
|
389
|
+
|
|
390
|
+
### 1. `neetoFieldsUtils.mergeInitialValues`
|
|
391
|
+
|
|
392
|
+
This function builds the initial values for the Formik form that wraps the
|
|
393
|
+
`<FieldInputs />` component.
|
|
394
|
+
|
|
395
|
+
#### Arguments:
|
|
396
|
+
|
|
397
|
+
- `initialValues`: The initial value object without considering
|
|
398
|
+
`<FieldInputs />`
|
|
399
|
+
- `fields`: An array of all the fetched fields.
|
|
400
|
+
|
|
401
|
+
#### Usage:
|
|
402
|
+
|
|
403
|
+
```jsx
|
|
404
|
+
import { useFetchFields } from "@bigbinary/neeto-fields-frontend";
|
|
405
|
+
|
|
406
|
+
const {
|
|
407
|
+
data: { fields },
|
|
408
|
+
} = useFetchFields({ resourceType: "users" });
|
|
409
|
+
|
|
410
|
+
const initialValues = neetoFieldsUtils.mergeInitialValues({
|
|
411
|
+
initialValues: FORMIK_INITIAL_VALUES,
|
|
412
|
+
fields,
|
|
413
|
+
});
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
### 2. `neetoFieldsUtils.transformValues`
|
|
417
|
+
|
|
418
|
+
This function transforms the Formik form values and builds the `values` object
|
|
419
|
+
including the data from `<FieldInputs />`. This transformed object can be passed
|
|
420
|
+
to the `onSubmit` function of the Formik form.
|
|
421
|
+
|
|
422
|
+
#### Arguments:
|
|
423
|
+
|
|
424
|
+
- `values`: The Formik form values.
|
|
425
|
+
|
|
426
|
+
#### Usage:
|
|
427
|
+
|
|
428
|
+
```jsx
|
|
429
|
+
import { useFetchFields } from "@bigbinary/neeto-fields-frontend";
|
|
430
|
+
|
|
431
|
+
const {
|
|
432
|
+
data: { fields },
|
|
433
|
+
} = useFetchFields({ resourceType: "users" });
|
|
434
|
+
|
|
435
|
+
<Form
|
|
436
|
+
formikProps={{
|
|
437
|
+
initialValues,
|
|
438
|
+
validationSchema: VALIDATION_SCHEMA,
|
|
439
|
+
onSubmit: values =>
|
|
440
|
+
onSubmit(neetoFieldsUtils.transformValues({ values, fields })),
|
|
441
|
+
enableReinitialize: true,
|
|
442
|
+
}}
|
|
443
|
+
>
|
|
444
|
+
{/* Form's children */}
|
|
445
|
+
</Form>;
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
## Hooks
|
|
449
|
+
|
|
450
|
+
#### 1. `useFetchFields`
|
|
451
|
+
|
|
452
|
+
This is a React Query hook for fetching all the fields.
|
|
453
|
+
|
|
454
|
+
#### Arguments:
|
|
455
|
+
|
|
456
|
+
- `resourceType`: The resource_type of the fields to be fetched.
|
|
457
|
+
- `ownerId`: The ID of the owner in case the owner is not an organization.
|
|
458
|
+
|
|
459
|
+
#### Usage:
|
|
460
|
+
|
|
461
|
+
```jsx
|
|
462
|
+
const {
|
|
463
|
+
data: { fields },
|
|
464
|
+
} = useFetchFields({
|
|
465
|
+
resourceType: "users",
|
|
466
|
+
ownerId: "ownerId",
|
|
467
|
+
});
|
|
468
|
+
```
|
|
469
|
+
|
|
92
470
|
# Customizability
|
|
93
471
|
|
|
94
472
|
## Engine customizability
|