diff --git a/packages/core/helper-plugin/lib/src/components/RelationInput/RelationInput.js b/packages/core/helper-plugin/lib/src/components/RelationInput/RelationInput.js new file mode 100644 index 0000000000..817fba7067 --- /dev/null +++ b/packages/core/helper-plugin/lib/src/components/RelationInput/RelationInput.js @@ -0,0 +1,71 @@ +import PropTypes from 'prop-types'; +import React from 'react'; + +import { Badge } from '@strapi/design-system/Badge'; +import { Box } from '@strapi/design-system/Box'; +import { BaseLink } from '@strapi/design-system/BaseLink'; + +import { RelationItem } from './components/RelationItem'; +import { RelationList } from './components/RelationList'; + +export const RelationInput = ({ name, relations }) => { + return ( + + + {relations.isSuccess && + relations.data.pages.flatMap(({ isDraft, href, title, id }) => { + const badgeColor = isDraft ? 'secondary' : 'success'; + + return ( + + {href ? {title} : title} + + + {isDraft ? 'Draft' : 'Published'} + + + ); + })} + + + ); +}; + +const RelationTypeDef = PropTypes.shape({ + id: PropTypes.number.isRequired, + isDraft: PropTypes.bool, + href: PropTypes.string, + title: PropTypes.string.isRequired, +}); + +const ReactQueryRelationResult = PropTypes.shape({ + data: PropTypes.shape({ + pages: PropTypes.arrayOf(RelationTypeDef), + }), + isLoading: PropTypes.bool.isRequired, + isSuccess: PropTypes.bool.isRequired, +}); + +RelationInput.defaultProps = { + relations: [], + searchResults: [], + relationsToDisplay: 5, +}; + +RelationInput.propTypes = { + description: PropTypes.string.isRequired, + label: PropTypes.string.isRequired, + name: PropTypes.string.isRequired, + onRelationAdd: PropTypes.func.isRequired, + onRelationRemove: PropTypes.func.isRequired, + onRelationLoadMore: PropTypes.func.isRequired, + onSearchNextPage: PropTypes.func.isRequired, + searchResults: PropTypes.arrayOf(RelationTypeDef), + relations: ReactQueryRelationResult, + relationsToDisplay: PropTypes.number, +}; diff --git a/packages/core/helper-plugin/lib/src/components/RelationInput/index.js b/packages/core/helper-plugin/lib/src/components/RelationInput/index.js index 5b1dc7f66e..c97eb515a0 100644 --- a/packages/core/helper-plugin/lib/src/components/RelationInput/index.js +++ b/packages/core/helper-plugin/lib/src/components/RelationInput/index.js @@ -1,2 +1,3 @@ -export * from './components/RelationItem'; -export * from './components/RelationList'; +import { RelationInput } from './RelationInput'; + +export default RelationInput; diff --git a/packages/core/helper-plugin/lib/src/index.js b/packages/core/helper-plugin/lib/src/index.js index 875465e66d..51eaebca94 100644 --- a/packages/core/helper-plugin/lib/src/index.js +++ b/packages/core/helper-plugin/lib/src/index.js @@ -68,6 +68,7 @@ export { default as ReactSelect } from './components/ReactSelect'; export { default as ReactSelectAsync } from './components/ReactSelect/Async'; export { default as Link } from './components/Link'; export { default as LinkButton } from './components/LinkButton'; +export { default as RelationInput } from './components/RelationInput'; // New icons export { default as SortIcon } from './icons/SortIcon';