Skip to content

Commit

Permalink
Merge pull request #170 from performant-software/feature/udf3_search_…
Browse files Browse the repository at this point in the history
…filter

UDF #3 - Search/sort
  • Loading branch information
dleadbetter authored Sep 26, 2022
2 parents 0402b75 + 3bb7bd3 commit 23e3dee
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 32 deletions.
6 changes: 3 additions & 3 deletions packages/controlled-vocabulary/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/controlled-vocabulary",
"version": "0.6.2-beta.5",
"version": "1.0.0",
"description": "A package of components to allow user to configure dropdown elements. Use with the \"controlled_vocabulary\" gem.",
"license": "MIT",
"main": "./build/index.js",
Expand All @@ -12,8 +12,8 @@
"build": "webpack --mode production && flow-copy-source -v src types"
},
"dependencies": {
"@performant-software/semantic-components": "^0.6.2-beta.5",
"@performant-software/shared-components": "^0.6.2-beta.5",
"@performant-software/semantic-components": "^1.0.0",
"@performant-software/shared-components": "^1.0.0",
"i18next": "^21.9.2",
"semantic-ui-react": "^2.1.2",
"underscore": "^1.13.2"
Expand Down
4 changes: 2 additions & 2 deletions packages/semantic-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/semantic-components",
"version": "0.6.2-beta.5",
"version": "1.0.0",
"description": "A package of shared components based on the Semantic UI Framework.",
"license": "MIT",
"main": "./build/index.js",
Expand All @@ -12,7 +12,7 @@
"build": "webpack --mode production && flow-copy-source -v src types"
},
"dependencies": {
"@performant-software/shared-components": "^0.6.2-beta.5",
"@performant-software/shared-components": "^1.0.0",
"@react-google-maps/api": "^2.8.1",
"axios": "^0.26.1",
"i18next": "^19.4.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/shared-components",
"version": "0.6.2-beta.5",
"version": "1.0.0",
"description": "A package of shared, framework agnostic, components.",
"license": "MIT",
"main": "./build/index.js",
Expand Down
53 changes: 53 additions & 0 deletions packages/user-defined-fields/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#UserDefinedFields
This package is designed to be used with the [user_defined_fields](https://github.com/performant-software/user-defined-fields) Rails gem. The idea is to allow users to define what type of metadata they want to collection about specific models and use these components to add, remove, and modify the configuration of the fields.

## Installation

```bash
yarn add @performant-software/user-defined-fields
```

or

```bash
npm install @performant-software/user-defined-fields
```

## Components
To load user defined fields directly from the API endpoint, use the `UserDefinedFieldsList` component.

```jsx
<UserDefinedFieldsList />
```

To add the user defined fields from nested attributes of a parent record, use the `UserDefinedFieldsEmbeddedList` component.

```jsx
<UserDefinedFieldsEmbeddedList
items={props.item.user_defined_fields}
onDelete={props.onDeleteChildAssociation.bind(this, 'user_defined_fields')}
onSave={props.onSaveChildAssociation.bind(this, 'user_defined_fields')}
/>
```

## Services

```javascript
// Fetch the list of user defined fields
UserDefinedFieldsService.fetchAll(params)

// Fetch a single user defined field
UserDefinedFieldsService.fetchOne(id)

// Save a user defined field
UserDefinedFieldsService.save(udf)

// Delete a user defined field
UserDefinedFieldsService.delete(udf)

// Fetch a list of tables to which user defined fields can be added
UserDefinedFieldsService.fetchTables()

// Fetch a list of allowed data types
UserDefinedFieldsService.fetchDataTypes()
```
6 changes: 3 additions & 3 deletions packages/user-defined-fields/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/user-defined-fields",
"version": "0.6.2-beta.5",
"version": "1.0.0",
"description": "A package of components used for allowing end users to define fields on models. Use with the \"user_defined_fields\" gem.",
"license": "MIT",
"main": "./build/index.js",
Expand All @@ -9,8 +9,8 @@
"build": "webpack --mode production && flow-copy-source -v src types"
},
"dependencies": {
"@performant-software/semantic-components": "^0.6.2-beta.5",
"@performant-software/shared-components": "^0.6.2-beta.5",
"@performant-software/semantic-components": "^1.0.0",
"@performant-software/shared-components": "^1.0.0",
"i18next": "^21.9.1",
"semantic-ui-react": "^2.1.2",
"underscore": "^1.13.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ const UserDefinedFieldModal: ComponentType<any> = (props) => {
label={i18n.t('UserDefinedFieldModal.labels.required')}
onChange={props.onCheckboxInputChange.bind(this, 'required')}
/>
<Form.Checkbox
error={props.isError('searchable')}
checked={props.item.searchable}
label={i18n.t('UserDefinedFieldModal.labels.searchable')}
onChange={props.onCheckboxInputChange.bind(this, 'searchable')}
/>
{ props.item.data_type === DataTypes.select && (
<Form.Checkbox
error={props.isError('allow_multiple')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const UserDefinedFieldsForm: ComponentType<any> = (props: Props) => {
required={field.required}
>
<DatePicker
onChange={(date) => onChange(field, date && date.toString())}
onChange={(date) => onChange(field, date && date.toISOString())}
value={fieldValue && new Date(fieldValue)}
/>
</Form.Input>
Expand Down
1 change: 1 addition & 0 deletions packages/user-defined-fields/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"dataType": "Data type",
"name": "Name",
"required": "Required",
"searchable": "Searchable",
"table": "Table"
},
"title": {
Expand Down
1 change: 1 addition & 0 deletions packages/user-defined-fields/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export { default as UserDefinedFieldsList } from './components/UserDefinedFields
export { default as UserDefinedFieldsService } from './services/UserDefinedFields';

// Transforms
export { default as FieldableTransform } from './transforms/Fieldable';
export { default as UserDefinedFieldTransform } from './transforms/UserDefinedField';
export { default as UserDefinedFieldsTransform } from './transforms/UserDefinedFields';

Expand Down
27 changes: 27 additions & 0 deletions packages/user-defined-fields/src/transforms/Fieldable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// @flow

import { Form as FormUtils } from '@performant-software/shared-components';
import _ from 'underscore';

/**
* Class responsible for transforming fieldable data.
*/
class Fieldable {
/**
* Converts the "user_defined" data for the passed fieldable item into form data.
*
* @param formData
* @param prefix
* @param item
*/
toFormData(formData, prefix, item) {
const { user_defined: userDefined } = item;

_.each(_.keys(userDefined), (key) => {
FormUtils.setAttribute(formData, `${prefix}[user_defined]`, userDefined, key);
});
}
}

const FieldableTransform: Fieldable = new Fieldable();
export default FieldableTransform;
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class UserDefinedField extends BaseTransform {
'column_name',
'data_type',
'required',
'searchable',
'allow_multiple',
'options'
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class UserDefinedFields extends NestedAttributesTransform {
'column_name',
'data_type',
'required',
'searchable',
'allow_multiple',
'options',
'_destroy'
Expand Down
21 changes: 1 addition & 20 deletions packages/user-defined-fields/src/utils/UserDefinedFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,6 @@ const resolveError = ({ key, error }: ErrorProps): ErrorReturn => {
};
};

/**
* Returns the value for the user defined field at the passed key for the passed item.
*
* @param item
* @param key
*
* @returns {*}
*/
const resolveValue = (item: Item, key: string): string => {
let userDefined = {};

if (_.isString(item.user_defined)) {
userDefined = JSON.parse(item.user_defined || '{}');
}

return userDefined[key];
};

export default {
resolveError,
resolveValue
resolveError
};
2 changes: 1 addition & 1 deletion packages/visualize/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/visualize",
"version": "0.6.2-beta.5",
"version": "1.0.0",
"description": "A package of components used for data visualization",
"license": "MIT",
"main": "./build/index.js",
Expand Down
2 changes: 1 addition & 1 deletion react-components.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"packages/user-defined-fields",
"packages/visualize"
],
"version": "0.6.2-beta.5"
"version": "1.0.0"
}

0 comments on commit 23e3dee

Please sign in to comment.