Skip to content

Commit

Permalink
Merge pull request #288 from performant-software/feature/cdc237_image…
Browse files Browse the repository at this point in the history
…_upload

CDC #237 - Image Upload
  • Loading branch information
dleadbetter authored Jul 16, 2024
2 parents a2e965f + a453275 commit d1ed63e
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 18 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.4",
"version": "2.2.5",
"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.4",
"@performant-software/shared-components": "^2.2.4",
"@performant-software/semantic-components": "^2.2.5",
"@performant-software/shared-components": "^2.2.5",
"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.4",
"version": "2.2.5",
"description": "A package of components used with the Core Data platform.",
"license": "MIT",
"main": "./dist/index.cjs.js",
Expand Down Expand Up @@ -37,8 +37,8 @@
"underscore": "^1.13.2"
},
"peerDependencies": {
"@performant-software/shared-components": "^2.2.4",
"@performant-software/geospatial": "^2.2.4",
"@performant-software/shared-components": "^2.2.5",
"@performant-software/geospatial": "^2.2.5",
"@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.4",
"version": "2.2.5",
"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.4",
"version": "2.2.5",
"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.4",
"@performant-software/shared-components": "^2.2.5",
"@samvera/clover-iiif": "^2.3.2",
"react": ">= 16.13.1 < 19.0.0",
"react-dnd": "^11.1.3",
Expand Down
38 changes: 36 additions & 2 deletions packages/semantic-ui/src/components/FileUploadModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ type Props = {
*/
closeOnComplete?: boolean,

/**
* An error message to display at the top of the modal.
*/
errors?: string,

/**
* Component to render at top of modal.
*/
Expand All @@ -38,6 +43,11 @@ type Props = {
*/
itemComponent: ComponentType<any>,

/**
* Additional props to provide to the "itemComponent".
*/
itemComponentProps?: any,

/**
* Callback fired when a file is added.
*/
Expand All @@ -58,6 +68,14 @@ type Props = {
*/
onSave: (items: Array<any>) => Promise<any>,

/**
* Callback fired when an item is validated. If the return value is `true`, the item will pass validation.
*
* @param item
* @param key
*/
onValidate?: (item: any, key: string) => boolean,

/**
* An object with keys containing the names of properties that are required.
*/
Expand Down Expand Up @@ -266,7 +284,9 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
const value = item[key];
let invalid;

if (_.isNumber(value)) {
if (props.onValidate) {
invalid = props.onValidate(item, key);
} else if (_.isNumber(value)) {
invalid = _.isEmpty(value.toString());
} else {
invalid = _.isEmpty(value);
Expand All @@ -281,7 +301,7 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
...item,
errors
};
}, [props.required]);
}, [props.onValidate, props.required]);

/**
* Validates the items on the state.
Expand Down Expand Up @@ -428,6 +448,18 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
</Message.List>
</Message>
)}
{ props.errors && (
<Message
error
>
<Message.Header
content={i18n.t('FileUploadModal.errors.header')}
/>
<Message.List
items={props.errors}
/>
</Message>
)}
{ hasUploadErrors && (
<Message
content={i18n.t('FileUploadModal.errors.upload.content')}
Expand All @@ -453,6 +485,7 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
>
{ _.map(items, (item, index) => (
<UploadItem
{...props.itemComponentProps}
isError={(key) => _.contains(item.errors, key)}
isRequired={(key) => !!(props.required && props.required[key])}
item={item}
Expand Down Expand Up @@ -492,6 +525,7 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {

FileUploadModal.defaultProps = {
closeOnComplete: true,
itemComponentProps: {},
strategy: Strategy.batch,
showPageLoader: true
};
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.4",
"version": "2.2.5",
"description": "A package of shared, framework agnostic, components.",
"license": "MIT",
"main": "./dist/index.cjs.js",
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.4",
"version": "2.2.5",
"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.4",
"@performant-software/shared-components": "^2.2.4",
"@performant-software/semantic-components": "^2.2.5",
"@performant-software/shared-components": "^2.2.5",
"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
Expand Up @@ -17,14 +17,16 @@ type Props = {
data: any,
defineableId?: number,
defineableType?: string,
fields?: Array,
isError: (key: string) => boolean,
onChange: (obj: any) => void,
onClearValidationError: (...keys: Array<string>) => void,
required?: boolean,
tableName?: string
};

const UserDefinedFieldsForm: ComponentType<any> = (props: Props) => {
const [fields, setFields] = useState([]);
const [fields, setFields] = useState(props.fields || []);

/**
* Returns the key for the passed field.
Expand Down Expand Up @@ -166,10 +168,16 @@ const UserDefinedFieldsForm: ComponentType<any> = (props: Props) => {
* Fetches the user defined fields when the component mounts.
*/
useEffect(() => {
// If the fields have been provided as a prop, there is no need to query them here.
if (!_.isEmpty(fields)) {
return;
}

const params = {
defineable_id: props.defineableId,
defineable_type: props.defineableType,
per_page: 0,
required: props.required,
sort_by: 'order',
table_name: props.tableName
};
Expand Down
3 changes: 3 additions & 0 deletions packages/user-defined-fields/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ export { default as FieldableTransform } from './transforms/Fieldable';
export { default as UserDefinedFieldTransform } from './transforms/UserDefinedField';
export { default as UserDefinedFieldsTransform } from './transforms/UserDefinedFields';

// Types
export type { UserDefinedField } from './types/UserDefinedField';

// Utils
export { default as UserDefinedFields } from './utils/UserDefinedFields';
15 changes: 15 additions & 0 deletions packages/user-defined-fields/src/types/UserDefinedField.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @flow

export type UserDefinedField = {
id: number,
defineable_id: number,
defineable_type: string,
column_name: string,
table_name: string,
data_type: string,
required: boolean,
searchable: boolean,
allow_multiple: boolean,
options: Array<string>,
order: number
};
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.4",
"version": "2.2.5",
"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.4"
"version": "2.2.5"
}

0 comments on commit d1ed63e

Please sign in to comment.