Skip to content

Commit

Permalink
Merge pull request #275 from performant-software/feature/cdc27_events
Browse files Browse the repository at this point in the history
CDC #27 - Events
  • Loading branch information
dleadbetter authored Apr 18, 2024
2 parents 1225737 + 6368c7a commit 4ceb914
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 14 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.1.2",
"version": "2.1.3",
"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.1.2",
"@performant-software/shared-components": "^2.1.2",
"@performant-software/semantic-components": "^2.1.3",
"@performant-software/shared-components": "^2.1.3",
"react": ">= 16.13.1 < 19.0.0",
"react-dom": ">= 16.13.1 < 19.0.0"
},
Expand Down
4 changes: 2 additions & 2 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.1.2",
"version": "2.1.3",
"description": "A package of components used with the Core Data platform.",
"license": "MIT",
"main": "./dist/index.cjs.js",
Expand Down Expand Up @@ -38,7 +38,7 @@
"underscore": "^1.13.2"
},
"peerDependencies": {
"@performant-software/geospatial": "^2.1.2",
"@performant-software/geospatial": "^2.1.3",
"@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.1.2",
"version": "2.1.3",
"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.1.2",
"version": "2.1.3",
"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.1.2",
"@performant-software/shared-components": "^2.1.3",
"@samvera/clover-iiif": "^2.3.2",
"react": ">= 16.13.1 < 19.0.0",
"react-dnd": "^11.1.3",
Expand Down
2 changes: 2 additions & 0 deletions packages/semantic-ui/src/components/FuzzyDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type DateComponent = {

type Props = {
calendar?: string,
centered?: boolean,
date: DateInput,
description?: boolean,
locale?: string,
Expand Down Expand Up @@ -339,6 +340,7 @@ class FuzzyDate extends Component<Props, State> {
{ (mountNode) => (
<Modal
as={Form}
centered={this.props.centered}
className='fuzzy-date-modal'
mountNode={mountNode}
open={this.state.modal}
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.1.2",
"version": "2.1.3",
"description": "A package of shared, framework agnostic, components.",
"license": "MIT",
"main": "./dist/index.cjs.js",
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export { default as BaseService } from './services/BaseService';
export { default as Attachments } from './transforms/Attachments';
export { default as BaseTransform } from './transforms/BaseTransform';
export { default as FormDataTransform } from './transforms/FormDataTransform';
export { default as FuzzyDateTransform } from './transforms/FuzzyDate';
export { default as NestedAttributesTransform } from './transforms/NestedAttributesTransform';

// Utils
Expand All @@ -32,6 +33,7 @@ export { default as Date } from './utils/Date';
export { default as useDragDrop } from './utils/DragDrop';
export { default as Element } from './utils/Element';
export { default as Form } from './utils/Form';
export { default as FuzzyDate } from './utils/FuzzyDate';
export { default as Hooks } from './utils/Hooks';
export { default as IIIF } from './utils/IIIF';
export { default as Map } from './utils/Map';
Expand Down
57 changes: 57 additions & 0 deletions packages/shared/src/transforms/FuzzyDate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// @flow

class FuzzyDate {
/**
* Returns the passed date as a FuzzyDate input date.
*
* @param date
*
* @returns {{endDate: *, _destroy, accuracy, description, range, id, startDate: *}|null}
*/
toFuzzyDate(date) {
if (!date) {
return null;
}

return {
id: date.id,
accuracy: date.accuracy,
description: date.description,
endDate: date.end_date,
range: date.range,
startDate: date.start_date,
_destroy: date._destroy
};
}

/**
* Returns the passed FuzzyDateable object for PUT/POST requests.
*
* @param dateable
* @param attribute
*
* @returns {{}}
*/
toPayload(dateable, attribute) {
const date = dateable[attribute];

if (!date) {
return null;
}

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
}
};
}
}

const FuzzyDateTransform: FuzzyDate = new FuzzyDate();
export default FuzzyDateTransform;
58 changes: 58 additions & 0 deletions packages/shared/src/utils/FuzzyDate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// @flow

import _ from 'underscore';
import Calendar from './Calendar';
import Browser from './Browser';

const DATE_SEPARATOR = ' - ';

const DEFAULT_CALENDAR = Calendar.Calendars.gregorian;

/**
* Returns a view for the passed fuzzy date object and calendar.
*
* @param date
* @param calendar
*
* @returns {null|string|*}
*/
const getDateView = (date, cal = null) => {
if (!date) {
return null;
}

if (!(date.description || date.start_date)) {
return null;
}

let calendar = cal;

if (!calendar) {
const locale = Browser.isBrowser() && navigator.language;
calendar = new Calendar(locale, DEFAULT_CALENDAR);
}

// Use the description, if provided
if (date.description) {
return date.description;
}

// Otherwise, format the start and end dates
const dateView = [];

if (date.start_date) {
const parsed = calendar.parseDate(date.start_date);
dateView.push(calendar.format(parsed, date.accuracy));
}

if (date.range && date.end_date) {
const parsed = calendar.parseDate(date.end_date);
dateView.push(calendar.format(parsed, date.accuracy));
}

return _.isEmpty(dateView) ? null : dateView.join(DATE_SEPARATOR);
};

export default {
getDateView
};
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.1.2",
"version": "2.1.3",
"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.1.2",
"@performant-software/shared-components": "^2.1.2",
"@performant-software/semantic-components": "^2.1.3",
"@performant-software/shared-components": "^2.1.3",
"react": ">= 16.13.1 < 19.0.0",
"react-dom": ">= 16.13.1 < 19.0.0"
},
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.1.2",
"version": "2.1.3",
"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.1.2"
"version": "2.1.3"
}

0 comments on commit 4ceb914

Please sign in to comment.