Skip to content

Commit

Permalink
Merge pull request #296 from performant-software/feature/udf35_fuzzy_…
Browse files Browse the repository at this point in the history
…dates

UDF #35 - Fuzzy Dates
  • Loading branch information
dleadbetter authored Sep 11, 2024
2 parents bb93af7 + 61afe39 commit 552e9ea
Show file tree
Hide file tree
Showing 14 changed files with 75 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": "2.2.10",
"version": "2.2.11",
"description": "A package of components to allow user to configure dropdown elements. Use with the \"controlled_vocabulary\" gem.",
"license": "MIT",
"main": "./dist/index.cjs.js",
Expand All @@ -23,8 +23,8 @@
"underscore": "^1.13.2"
},
"peerDependencies": {
"@performant-software/semantic-components": "^2.2.10",
"@performant-software/shared-components": "^2.2.10",
"@performant-software/semantic-components": "^2.2.11",
"@performant-software/shared-components": "^2.2.11",
"react": ">= 16.13.1 < 19.0.0",
"react-dom": ">= 16.13.1 < 19.0.0"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/core-data/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/core-data",
"version": "2.2.10",
"version": "2.2.11",
"description": "A package of components used with the Core Data platform.",
"license": "MIT",
"main": "./dist/index.cjs.js",
Expand Down Expand Up @@ -40,8 +40,8 @@
"underscore": "^1.13.2"
},
"peerDependencies": {
"@performant-software/geospatial": "^2.2.10",
"@performant-software/shared-components": "^2.2.10",
"@performant-software/geospatial": "^2.2.11",
"@performant-software/shared-components": "^2.2.11",
"@peripleo/maplibre": "^0.5.2",
"@peripleo/peripleo": "^0.5.2",
"react": ">= 16.13.1 < 19.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/geospatial/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/geospatial",
"version": "2.2.10",
"version": "2.2.11",
"description": "A package of components for all things map-related.",
"license": "MIT",
"main": "./dist/index.cjs.js",
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": "2.2.10",
"version": "2.2.11",
"description": "A package of shared components based on the Semantic UI Framework.",
"license": "MIT",
"main": "./dist/index.cjs.js",
Expand Down Expand Up @@ -35,7 +35,7 @@
"zotero-translation-client": "^5.0.1"
},
"peerDependencies": {
"@performant-software/shared-components": "^2.2.10",
"@performant-software/shared-components": "^2.2.11",
"@samvera/clover-iiif": "^2.3.2",
"react": ">= 16.13.1 < 19.0.0",
"react-dnd": "^11.1.3",
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": "2.2.10",
"version": "2.2.11",
"description": "A package of shared, framework agnostic, components.",
"license": "MIT",
"main": "./dist/index.cjs.js",
Expand Down
29 changes: 20 additions & 9 deletions packages/shared/src/transforms/FuzzyDate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
// @flow

class FuzzyDate {
/**
* Returns the passed fuzzy date as a data object.
*
* @param date
*
* @returns {{end_date, _destroy, accuracy, description, range, id, start_date}}
*/
toData(date) {
return {
id: date.id,
accuracy: date.accuracy,
description: date.description,
end_date: date.endDate,
range: date.range,
start_date: date.startDate,
_destroy: date._destroy
};
}

/**
* Returns the passed date as a FuzzyDate input date.
*
Expand Down Expand Up @@ -40,15 +59,7 @@ class FuzzyDate {
}

return {
[attribute]: {
id: date.id,
accuracy: date.accuracy,
description: date.description,
end_date: date.endDate,
range: date.range,
start_date: date.startDate,
_destroy: date._destroy
}
[attribute]: this.toData(date)
};
}
}
Expand Down
12 changes: 12 additions & 0 deletions packages/storybook/.storybook/routes/UserDefinedFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,50 @@ const addRoutes = (router) => {

router.get('/user_defined_fields/user_defined_fields', (request, response) => {
const fields = [{
uuid: '1a82328e-3642-4fc6-9045-f42f48e3a415',
table_name: 'People',
column_name: 'First name',
data_type: 'String',
required: true,
order: 10
}, {
uuid: 'b1956bf4-625f-4ce9-aa44-6c7ef621d7e6',
table_name: 'People',
column_name: 'Last name',
data_type: 'String',
required: true,
order: 20
}, {
uuid: 'e399563e-46cb-4c28-a717-6d98823abfc5',
table_name: 'People',
column_name: 'Date of birth',
data_type: 'Date',
order: 30
}, {
uuid: '3aefc504-737d-4771-806c-e55ce84ef4fe',
table_name: 'People',
column_name: 'Biography',
data_type: 'RichText',
order: 40
}, {
uuid: '378091ba-f053-48a4-905c-cc8337992db7',
table_name: 'People',
column_name: 'Favorite color',
data_type: 'Select',
order: 50,
options: ['Red', 'Blue', 'Green', 'Orange', 'Yellow']
}, {
uuid: 'dd83405b-0b5b-4a11-9f51-5fd744fc316d',
table_name: 'People',
column_name: 'Year of service',
data_type: 'Number',
order: 60
}, {
uuid: '4c1557ae-1321-4a58-9096-7cfd2accf394',
table_name: 'People',
column_name: 'Fuzzy Date',
data_type: 'FuzzyDate',
order: 70
}];

response.send({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@ export default {
};

export const Default = () => {
const [data, setData] = useState({
'First name': 'Bob',
'Last name': 'Smith'
});
const [data, setData] = useState({});

return (
<Form>
<UserDefinedFieldsForm
data={data}
isError={() => false}
onChange={(value) => setData(value)}
onChange={setData}
/>
</Form>
);
Expand Down
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": "2.2.10",
"version": "2.2.11",
"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": "./dist/index.cjs.js",
Expand All @@ -23,8 +23,8 @@
"underscore": "^1.13.2"
},
"peerDependencies": {
"@performant-software/semantic-components": "^2.2.10",
"@performant-software/shared-components": "^2.2.10",
"@performant-software/semantic-components": "^2.2.11",
"@performant-software/shared-components": "^2.2.11",
"react": ">= 16.13.1 < 19.0.0",
"react-dom": ">= 16.13.1 < 19.0.0"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow

import { DatePicker } from '@performant-software/semantic-components';
import { RichTextArea } from '@performant-software/shared-components';
import { DatePicker, FuzzyDate } from '@performant-software/semantic-components';
import { FuzzyDateTransform, RichTextArea } from '@performant-software/shared-components';
import React, {
useCallback,
useEffect,
Expand Down Expand Up @@ -135,6 +135,23 @@ const UserDefinedFieldsForm: ComponentType<any> = (props: Props) => {
);
}

if (field.data_type === DataTypes.fuzzyDate) {
rendered = (
<Form.Input
error={isError(field)}
label={field.column_name}
required={field.required}
>
<FuzzyDate
centered={false}
date={FuzzyDateTransform.toFuzzyDate(fieldValue)}
onChange={(date) => onChange(field, FuzzyDateTransform.toData(date))}
title={field.column_name}
/>
</Form.Input>
);
}

if (field.data_type === DataTypes.boolean) {
rendered = (
<Form.Checkbox
Expand Down
1 change: 1 addition & 0 deletions packages/user-defined-fields/src/constants/DataTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const DataTypes = {
boolean: 'Boolean',
date: 'Date',
fuzzyDate: 'FuzzyDate',
number: 'Number',
richText: 'RichText',
select: 'Select',
Expand Down
7 changes: 6 additions & 1 deletion packages/user-defined-fields/src/hooks/UserDefinedFields.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow

import { BooleanIcon } from '@performant-software/semantic-components';
import { Date as DateUtils } from '@performant-software/shared-components';
import { Date as DateUtils, FuzzyDate as FuzzyDateUtils } from '@performant-software/shared-components';
import React, {
useCallback,
useEffect,
Expand Down Expand Up @@ -76,6 +76,11 @@ const useUserDefinedColumns = (defineableId, defineableType, options = {}) => {
...column,
resolve: (item) => DateUtils.formatDate(resolveValue(item, field))
});
} else if (field.data_type === DataTypes.fuzzyDate) {
columns.push({
...column,
resolve: (item) => FuzzyDateUtils.getDateView(resolveValue(item, field))
});
} else if (field.data_type !== DataTypes.richText) {
columns.push({
...column,
Expand Down
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": "2.2.10",
"version": "2.2.11",
"description": "A package of components used for data visualization",
"license": "MIT",
"main": "./dist/index.cjs.js",
Expand Down
2 changes: 1 addition & 1 deletion react-components.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"packages/user-defined-fields",
"packages/visualize"
],
"version": "2.2.10"
"version": "2.2.11"
}

0 comments on commit 552e9ea

Please sign in to comment.