diff --git a/packages/controlled-vocabulary/package.json b/packages/controlled-vocabulary/package.json index d3bc996c..f72a0d73 100644 --- a/packages/controlled-vocabulary/package.json +++ b/packages/controlled-vocabulary/package.json @@ -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", @@ -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" }, diff --git a/packages/core-data/package.json b/packages/core-data/package.json index af07328c..888b15d2 100644 --- a/packages/core-data/package.json +++ b/packages/core-data/package.json @@ -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", @@ -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", diff --git a/packages/geospatial/package.json b/packages/geospatial/package.json index e9d91f7d..23b72b87 100644 --- a/packages/geospatial/package.json +++ b/packages/geospatial/package.json @@ -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", diff --git a/packages/semantic-ui/package.json b/packages/semantic-ui/package.json index 314af07e..e0f0f7e1 100644 --- a/packages/semantic-ui/package.json +++ b/packages/semantic-ui/package.json @@ -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", @@ -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", diff --git a/packages/semantic-ui/src/components/FileUploadModal.js b/packages/semantic-ui/src/components/FileUploadModal.js index 12bce2ba..a71418f2 100644 --- a/packages/semantic-ui/src/components/FileUploadModal.js +++ b/packages/semantic-ui/src/components/FileUploadModal.js @@ -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. */ @@ -38,6 +43,11 @@ type Props = { */ itemComponent: ComponentType, + /** + * Additional props to provide to the "itemComponent". + */ + itemComponentProps?: any, + /** * Callback fired when a file is added. */ @@ -58,6 +68,14 @@ type Props = { */ onSave: (items: Array) => Promise, + /** + * 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. */ @@ -266,7 +284,9 @@ const FileUploadModal: ComponentType = (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); @@ -281,7 +301,7 @@ const FileUploadModal: ComponentType = (props: Props) => { ...item, errors }; - }, [props.required]); + }, [props.onValidate, props.required]); /** * Validates the items on the state. @@ -428,6 +448,18 @@ const FileUploadModal: ComponentType = (props: Props) => { )} + { props.errors && ( + + + + + )} { hasUploadErrors && ( = (props: Props) => { > { _.map(items, (item, index) => ( _.contains(item.errors, key)} isRequired={(key) => !!(props.required && props.required[key])} item={item} @@ -492,6 +525,7 @@ const FileUploadModal: ComponentType = (props: Props) => { FileUploadModal.defaultProps = { closeOnComplete: true, + itemComponentProps: {}, strategy: Strategy.batch, showPageLoader: true }; diff --git a/packages/shared/package.json b/packages/shared/package.json index 36f0d6cb..e159d49a 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -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", diff --git a/packages/user-defined-fields/package.json b/packages/user-defined-fields/package.json index e66c28fd..532f61e3 100644 --- a/packages/user-defined-fields/package.json +++ b/packages/user-defined-fields/package.json @@ -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", @@ -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" }, diff --git a/packages/user-defined-fields/src/components/UserDefinedFieldsForm.js b/packages/user-defined-fields/src/components/UserDefinedFieldsForm.js index d5ec445f..6a45f512 100644 --- a/packages/user-defined-fields/src/components/UserDefinedFieldsForm.js +++ b/packages/user-defined-fields/src/components/UserDefinedFieldsForm.js @@ -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) => void, + required?: boolean, tableName?: string }; const UserDefinedFieldsForm: ComponentType = (props: Props) => { - const [fields, setFields] = useState([]); + const [fields, setFields] = useState(props.fields || []); /** * Returns the key for the passed field. @@ -166,10 +168,16 @@ const UserDefinedFieldsForm: ComponentType = (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 }; diff --git a/packages/user-defined-fields/src/index.js b/packages/user-defined-fields/src/index.js index ecaeb356..a8ffb58c 100644 --- a/packages/user-defined-fields/src/index.js +++ b/packages/user-defined-fields/src/index.js @@ -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'; diff --git a/packages/user-defined-fields/src/types/UserDefinedField.js b/packages/user-defined-fields/src/types/UserDefinedField.js new file mode 100644 index 00000000..95399567 --- /dev/null +++ b/packages/user-defined-fields/src/types/UserDefinedField.js @@ -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, + order: number +}; diff --git a/packages/visualize/package.json b/packages/visualize/package.json index 0b8b068f..fabe4900 100644 --- a/packages/visualize/package.json +++ b/packages/visualize/package.json @@ -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", diff --git a/react-components.json b/react-components.json index 60fab4f4..bda367bb 100644 --- a/react-components.json +++ b/react-components.json @@ -8,5 +8,5 @@ "packages/user-defined-fields", "packages/visualize" ], - "version": "2.2.4" + "version": "2.2.5" }