Skip to content

Commit 552e9ea

Browse files
authored
Merge pull request #296 from performant-software/feature/udf35_fuzzy_dates
UDF #35 - Fuzzy Dates
2 parents bb93af7 + 61afe39 commit 552e9ea

File tree

14 files changed

+75
-32
lines changed

14 files changed

+75
-32
lines changed

packages/controlled-vocabulary/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@performant-software/controlled-vocabulary",
3-
"version": "2.2.10",
3+
"version": "2.2.11",
44
"description": "A package of components to allow user to configure dropdown elements. Use with the \"controlled_vocabulary\" gem.",
55
"license": "MIT",
66
"main": "./dist/index.cjs.js",
@@ -23,8 +23,8 @@
2323
"underscore": "^1.13.2"
2424
},
2525
"peerDependencies": {
26-
"@performant-software/semantic-components": "^2.2.10",
27-
"@performant-software/shared-components": "^2.2.10",
26+
"@performant-software/semantic-components": "^2.2.11",
27+
"@performant-software/shared-components": "^2.2.11",
2828
"react": ">= 16.13.1 < 19.0.0",
2929
"react-dom": ">= 16.13.1 < 19.0.0"
3030
},

packages/core-data/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@performant-software/core-data",
3-
"version": "2.2.10",
3+
"version": "2.2.11",
44
"description": "A package of components used with the Core Data platform.",
55
"license": "MIT",
66
"main": "./dist/index.cjs.js",
@@ -40,8 +40,8 @@
4040
"underscore": "^1.13.2"
4141
},
4242
"peerDependencies": {
43-
"@performant-software/geospatial": "^2.2.10",
44-
"@performant-software/shared-components": "^2.2.10",
43+
"@performant-software/geospatial": "^2.2.11",
44+
"@performant-software/shared-components": "^2.2.11",
4545
"@peripleo/maplibre": "^0.5.2",
4646
"@peripleo/peripleo": "^0.5.2",
4747
"react": ">= 16.13.1 < 19.0.0",

packages/geospatial/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@performant-software/geospatial",
3-
"version": "2.2.10",
3+
"version": "2.2.11",
44
"description": "A package of components for all things map-related.",
55
"license": "MIT",
66
"main": "./dist/index.cjs.js",

packages/semantic-ui/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@performant-software/semantic-components",
3-
"version": "2.2.10",
3+
"version": "2.2.11",
44
"description": "A package of shared components based on the Semantic UI Framework.",
55
"license": "MIT",
66
"main": "./dist/index.cjs.js",
@@ -35,7 +35,7 @@
3535
"zotero-translation-client": "^5.0.1"
3636
},
3737
"peerDependencies": {
38-
"@performant-software/shared-components": "^2.2.10",
38+
"@performant-software/shared-components": "^2.2.11",
3939
"@samvera/clover-iiif": "^2.3.2",
4040
"react": ">= 16.13.1 < 19.0.0",
4141
"react-dnd": "^11.1.3",

packages/shared/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@performant-software/shared-components",
3-
"version": "2.2.10",
3+
"version": "2.2.11",
44
"description": "A package of shared, framework agnostic, components.",
55
"license": "MIT",
66
"main": "./dist/index.cjs.js",

packages/shared/src/transforms/FuzzyDate.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
// @flow
22

33
class FuzzyDate {
4+
/**
5+
* Returns the passed fuzzy date as a data object.
6+
*
7+
* @param date
8+
*
9+
* @returns {{end_date, _destroy, accuracy, description, range, id, start_date}}
10+
*/
11+
toData(date) {
12+
return {
13+
id: date.id,
14+
accuracy: date.accuracy,
15+
description: date.description,
16+
end_date: date.endDate,
17+
range: date.range,
18+
start_date: date.startDate,
19+
_destroy: date._destroy
20+
};
21+
}
22+
423
/**
524
* Returns the passed date as a FuzzyDate input date.
625
*
@@ -40,15 +59,7 @@ class FuzzyDate {
4059
}
4160

4261
return {
43-
[attribute]: {
44-
id: date.id,
45-
accuracy: date.accuracy,
46-
description: date.description,
47-
end_date: date.endDate,
48-
range: date.range,
49-
start_date: date.startDate,
50-
_destroy: date._destroy
51-
}
62+
[attribute]: this.toData(date)
5263
};
5364
}
5465
}

packages/storybook/.storybook/routes/UserDefinedFields.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,38 +32,50 @@ const addRoutes = (router) => {
3232

3333
router.get('/user_defined_fields/user_defined_fields', (request, response) => {
3434
const fields = [{
35+
uuid: '1a82328e-3642-4fc6-9045-f42f48e3a415',
3536
table_name: 'People',
3637
column_name: 'First name',
3738
data_type: 'String',
3839
required: true,
3940
order: 10
4041
}, {
42+
uuid: 'b1956bf4-625f-4ce9-aa44-6c7ef621d7e6',
4143
table_name: 'People',
4244
column_name: 'Last name',
4345
data_type: 'String',
4446
required: true,
4547
order: 20
4648
}, {
49+
uuid: 'e399563e-46cb-4c28-a717-6d98823abfc5',
4750
table_name: 'People',
4851
column_name: 'Date of birth',
4952
data_type: 'Date',
5053
order: 30
5154
}, {
55+
uuid: '3aefc504-737d-4771-806c-e55ce84ef4fe',
5256
table_name: 'People',
5357
column_name: 'Biography',
5458
data_type: 'RichText',
5559
order: 40
5660
}, {
61+
uuid: '378091ba-f053-48a4-905c-cc8337992db7',
5762
table_name: 'People',
5863
column_name: 'Favorite color',
5964
data_type: 'Select',
6065
order: 50,
6166
options: ['Red', 'Blue', 'Green', 'Orange', 'Yellow']
6267
}, {
68+
uuid: 'dd83405b-0b5b-4a11-9f51-5fd744fc316d',
6369
table_name: 'People',
6470
column_name: 'Year of service',
6571
data_type: 'Number',
6672
order: 60
73+
}, {
74+
uuid: '4c1557ae-1321-4a58-9096-7cfd2accf394',
75+
table_name: 'People',
76+
column_name: 'Fuzzy Date',
77+
data_type: 'FuzzyDate',
78+
order: 70
6779
}];
6880

6981
response.send({

packages/storybook/src/user-defined-fields/UserDefinedFieldsForm.stories.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,14 @@ export default {
1111
};
1212

1313
export const Default = () => {
14-
const [data, setData] = useState({
15-
'First name': 'Bob',
16-
'Last name': 'Smith'
17-
});
14+
const [data, setData] = useState({});
1815

1916
return (
2017
<Form>
2118
<UserDefinedFieldsForm
2219
data={data}
2320
isError={() => false}
24-
onChange={(value) => setData(value)}
21+
onChange={setData}
2522
/>
2623
</Form>
2724
);

packages/user-defined-fields/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@performant-software/user-defined-fields",
3-
"version": "2.2.10",
3+
"version": "2.2.11",
44
"description": "A package of components used for allowing end users to define fields on models. Use with the \"user_defined_fields\" gem.",
55
"license": "MIT",
66
"main": "./dist/index.cjs.js",
@@ -23,8 +23,8 @@
2323
"underscore": "^1.13.2"
2424
},
2525
"peerDependencies": {
26-
"@performant-software/semantic-components": "^2.2.10",
27-
"@performant-software/shared-components": "^2.2.10",
26+
"@performant-software/semantic-components": "^2.2.11",
27+
"@performant-software/shared-components": "^2.2.11",
2828
"react": ">= 16.13.1 < 19.0.0",
2929
"react-dom": ">= 16.13.1 < 19.0.0"
3030
},

packages/user-defined-fields/src/components/UserDefinedFieldsForm.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
22

3-
import { DatePicker } from '@performant-software/semantic-components';
4-
import { RichTextArea } from '@performant-software/shared-components';
3+
import { DatePicker, FuzzyDate } from '@performant-software/semantic-components';
4+
import { FuzzyDateTransform, RichTextArea } from '@performant-software/shared-components';
55
import React, {
66
useCallback,
77
useEffect,
@@ -135,6 +135,23 @@ const UserDefinedFieldsForm: ComponentType<any> = (props: Props) => {
135135
);
136136
}
137137

138+
if (field.data_type === DataTypes.fuzzyDate) {
139+
rendered = (
140+
<Form.Input
141+
error={isError(field)}
142+
label={field.column_name}
143+
required={field.required}
144+
>
145+
<FuzzyDate
146+
centered={false}
147+
date={FuzzyDateTransform.toFuzzyDate(fieldValue)}
148+
onChange={(date) => onChange(field, FuzzyDateTransform.toData(date))}
149+
title={field.column_name}
150+
/>
151+
</Form.Input>
152+
);
153+
}
154+
138155
if (field.data_type === DataTypes.boolean) {
139156
rendered = (
140157
<Form.Checkbox

0 commit comments

Comments
 (0)