From b5051bd681c9c8707b53026091126d9f0a3b5307 Mon Sep 17 00:00:00 2001 From: Peter Date: Wed, 23 Feb 2022 13:30:42 +0100 Subject: [PATCH 1/3] ERM-1958: Write registry entry for Organization lookup --- OrganizationLookup.js | 134 +++++++++++++++++++++++ index.js | 10 ++ package.json | 5 +- setUpRegistry.js | 19 ++++ translations/ui-organizations/en_US.json | 10 +- 5 files changed, 175 insertions(+), 3 deletions(-) create mode 100644 OrganizationLookup.js create mode 100644 setUpRegistry.js diff --git a/OrganizationLookup.js b/OrganizationLookup.js new file mode 100644 index 00000000..96954b69 --- /dev/null +++ b/OrganizationLookup.js @@ -0,0 +1,134 @@ +import React, { useRef } from 'react'; +import PropTypes from 'prop-types'; + +import { FormattedMessage } from 'react-intl'; + +import { + Button, + Card, + Col, + KeyValue, + Layout, + NoValue, + Row, + Tooltip, +} from '@folio/stripes/components'; + +import { AppIcon, Pluggable } from '@folio/stripes/core'; + +// This must return a function to render a link button + +const propTypes = { + disabled: PropTypes.bool, + id: PropTypes.string, + input: PropTypes.shape({ + name: PropTypes.string, + value: PropTypes.string, + }), + onResourceSelected: PropTypes.func, + resource: PropTypes.object, +}; + +const OrganizationLookup = ({ disabled, id, input: { name, value }, onResourceSelected, resource }) => { + let triggerButton = useRef(null); + + const renderOrganizationLinkButton = (v) => ( + { + triggerButton = pluggableRenderProps.buttonRef; + + const organizationName = resource?.name; + const buttonProps = { + 'aria-haspopup': 'true', + 'buttonRef': triggerButton, + 'buttonStyle': v ? 'default' : 'primary', + 'disabled': disabled, + 'id': `${id}-find-organizations-btn`, + 'marginBottom0': true, + 'name': name, + 'onClick': pluggableRenderProps.onClick, + }; + + if (value) { + return ( + } + triggerRef={triggerButton} + > + {({ ariaIds }) => ( + + )} + + ); + } + + return ( + + ); + }} + type="find-organization" + > + + + ); + + const renderOrganizations = () => ( +
+ + + } + value={resource.name ?? } + /> + + +
+ ); + + const renderEmpty = () => ( +
+ + + + + + + + +
+ ); + + return ( + + + + + + )} + id={id} + roundedBorder + > + {value ? renderOrganizations() : renderEmpty()} + + ); +}; + +OrganizationLookup.propTypes = propTypes; + +export default OrganizationLookup; diff --git a/index.js b/index.js index 0526f094..16e6e831 100644 --- a/index.js +++ b/index.js @@ -11,8 +11,18 @@ import { Organizations as Organization } from './src/Organizations'; import { ContactsContainer } from './src/contacts'; import { InterfaceContainer } from './src/interfaces'; import Settings from './src/Settings'; +import setUpRegistry from './setUpRegistry'; class Organizations extends Component { + static eventHandler(event, _s, data) { + if (event === 'LOAD_STRIPES_REGISTRY') { + // Data should contain Registry singleton: + setUpRegistry(data); + } + + return null; + } + static propTypes = { stripes: PropTypes.shape({ connect: PropTypes.func.isRequired, diff --git a/package.json b/package.json index 477315e1..89289ad5 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,10 @@ "stripes": { "actsAs": [ "app", + "handler", "settings" ], + "handlerName": "eventHandler", "displayName": "ui-organizations.meta.title", "moduleName": "Organizations", "route": "/organizations", @@ -274,7 +276,8 @@ "react-final-form": "^6.5.1", "react-final-form-arrays": "^3.1.1", "react-tether": "^1.0.1", - "redux-form": "^8.3.0" + "redux-form": "^8.3.0", + "@folio/stripes-erm-components": "^6.0.0" }, "peerDependencies": { "@folio/stripes": "^7.0.0", diff --git a/setUpRegistry.js b/setUpRegistry.js new file mode 100644 index 00000000..ab413598 --- /dev/null +++ b/setUpRegistry.js @@ -0,0 +1,19 @@ +import { InternalContactsArrayDisplay } from '@folio/stripes-erm-components'; +import OrganizationLookup from './OrganizationLookup'; + +const setUpRegistry = (registry) => { + // Organization Resource + const organizationReg = registry.registerResource('organization'); + + organizationReg.setViewResources('/organizations/organizations'); + organizationReg.setViewResource(organization => `/organizations/organizations/${organization.id}`); + + organizationReg.setRenderFunction('internalContacts', record => { + return ; + }); + + // Lookup plugin + organizationReg.setLookupComponent(OrganizationLookup); +}; + +export default setUpRegistry; diff --git a/translations/ui-organizations/en_US.json b/translations/ui-organizations/en_US.json index 08f02b42..2f188023 100644 --- a/translations/ui-organizations/en_US.json +++ b/translations/ui-organizations/en_US.json @@ -356,5 +356,11 @@ "permission.creds.manage": "Organizations: Interface usernames and passwords: view, edit, create, delete", "permission.acqUnits.assign": "Organizations: Assign acquisition units to new organization", "permission.acqUnits.manage": "Organizations: Manage acquisition units", - "permission.settings": "Settings (Organizations): Can view and edit settings" -} \ No newline at end of file + "permission.settings": "Settings (Organizations): Can view and edit settings", + "relatedOrganization.linkOrganization": "Link organization", + "relatedOrganization.noPlugin": "No \"find-organization\" plugin is installed", + "relatedOrganization.replaceOrganization": "Replace organization", + "relatedOrganization.replaceOrganizationSpecific": "Replace organization {organizationName}", + "relatedOrganization.noneLinked": "No organization linked", + "relatedOrganization.linkToStart": "Link an organization to get started" +} From bd9f3b2d55f0401d0e8a937ac19700c326e40c14 Mon Sep 17 00:00:00 2001 From: Peter Date: Mon, 21 Mar 2022 15:04:42 +0100 Subject: [PATCH 2/3] ERM-1958: add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6aeeaad..18f39330 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Add record metadata widget to contact person. Refs UIORGS-305. * Display linked agreements on an organization record. Refs UIORGS-306. * Can not delete integration from organization. Refs UIORGS-307. +* Add filter integration for ui-dashboard. Refs ERM-1958. ## [3.1.0](https://github.com/folio-org/ui-organizations/tree/v3.1.0) (2022-03-04) [Full Changelog](https://github.com/folio-org/ui-organizations/compare/v3.0.1...v3.1.0) From 6fb39747ed45c94163787237eaa7c412f664f6fb Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Thu, 24 Mar 2022 10:33:35 +0000 Subject: [PATCH 3/3] fix: Registry Fixes to registry code, allow for a renderOrganiztions prop to customise card output --- OrganizationLookup.js | 25 ++++++++++++++++++++++--- package.json | 3 +-- setUpRegistry.js | 9 ++------- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/OrganizationLookup.js b/OrganizationLookup.js index 96954b69..233b5817 100644 --- a/OrganizationLookup.js +++ b/OrganizationLookup.js @@ -29,7 +29,14 @@ const propTypes = { resource: PropTypes.object, }; -const OrganizationLookup = ({ disabled, id, input: { name, value }, onResourceSelected, resource }) => { +const OrganizationLookup = ({ + disabled, + id, + input: { name, value }, + onResourceSelected, + renderOrganizations, + resource +}) => { let triggerButton = useRef(null); const renderOrganizationLinkButton = (v) => ( @@ -84,7 +91,7 @@ const OrganizationLookup = ({ disabled, id, input: { name, value }, onResourceSe ); - const renderOrganizations = () => ( + const defaultRenderOrganizations = () => (
@@ -110,6 +117,18 @@ const OrganizationLookup = ({ disabled, id, input: { name, value }, onResourceSe
); + const renderFunction = () => { + if (value) { + if (renderOrganizations) { + return renderOrganizations(resource); + } + + return defaultRenderOrganizations(); + } + + return renderEmpty(); + }; + return ( - {value ? renderOrganizations() : renderEmpty()} + {renderFunction()} ); }; diff --git a/package.json b/package.json index 1bcc0c41..1d9ce30b 100644 --- a/package.json +++ b/package.json @@ -270,8 +270,7 @@ "react-final-form": "^6.5.1", "react-final-form-arrays": "^3.1.1", "react-tether": "^1.0.1", - "redux-form": "^8.3.0", - "@folio/stripes-erm-components": "^6.0.0" + "redux-form": "^8.3.0" }, "peerDependencies": { "@folio/stripes": "^7.0.0", diff --git a/setUpRegistry.js b/setUpRegistry.js index ab413598..6b746cf5 100644 --- a/setUpRegistry.js +++ b/setUpRegistry.js @@ -1,16 +1,11 @@ -import { InternalContactsArrayDisplay } from '@folio/stripes-erm-components'; import OrganizationLookup from './OrganizationLookup'; const setUpRegistry = (registry) => { // Organization Resource const organizationReg = registry.registerResource('organization'); - organizationReg.setViewResources('/organizations/organizations'); - organizationReg.setViewResource(organization => `/organizations/organizations/${organization.id}`); - - organizationReg.setRenderFunction('internalContacts', record => { - return ; - }); + organizationReg.setViewResources('/organizations'); + organizationReg.setViewResource(organization => `/organizations/view/${organization.id}`); // Lookup plugin organizationReg.setLookupComponent(OrganizationLookup);