From 6fc77d4fa7fcc79a0f759e84d06575e87ee1aa5a Mon Sep 17 00:00:00 2001 From: Chris Hellen Date: Tue, 14 May 2024 09:16:32 -0500 Subject: [PATCH 1/4] Implemented TitleManager component --- src/BursarExportPlugin.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/BursarExportPlugin.tsx b/src/BursarExportPlugin.tsx index 7056106..a919e2b 100644 --- a/src/BursarExportPlugin.tsx +++ b/src/BursarExportPlugin.tsx @@ -1,8 +1,8 @@ import { Button, LoadingPane, Pane, PaneFooter } from '@folio/stripes/components'; -import { useStripes } from '@folio/stripes/core'; +import { useStripes, TitleManager } from '@folio/stripes/core'; import { FormApi } from 'final-form'; import React, { useCallback, useRef } from 'react'; -import { FormattedMessage } from 'react-intl'; +import { FormattedMessage, useIntl } from 'react-intl'; import { formValuesToDto, schedulingToDto } from './api/dto/to'; import { useAutomaticSchedulerMutation, useManualSchedulerMutation } from './api/mutators'; import ConfigurationForm from './components/ConfigurationForm'; @@ -71,6 +71,8 @@ export default function BursarExportPlugin() { } return ( + <> + + ); } From 17820871aa05753a53e397330fcb80f4d6318cf2 Mon Sep 17 00:00:00 2001 From: Chris Hellen Date: Wed, 15 May 2024 14:07:54 -0500 Subject: [PATCH 2/4] Implemeneted TitleManager component in TSX syntax. Updated packages. Fixed lint errors. --- package.json | 3 +- src/BursarExportPlugin.tsx | 33 ++++++++-------- src/components/TitleManager/TitleManager.tsx | 40 ++++++++++++++++++++ translations/ui-plugin-bursar-export/en.json | 1 + 4 files changed, 60 insertions(+), 17 deletions(-) create mode 100644 src/components/TitleManager/TitleManager.tsx diff --git a/package.json b/package.json index 1591fa3..1b663cf 100644 --- a/package.json +++ b/package.json @@ -105,7 +105,8 @@ "react-final-form": "^6.3.0", "react-final-form-arrays": "^3.1.0", "react-final-form-listeners": "^1.0.2", - "react-router-prop-types": "^1.0.4" + "react-router-prop-types": "^1.0.4", + "react-titled": "^2.0.0" }, "peerDependencies": { "@folio/stripes": "^9.0.0", diff --git a/src/BursarExportPlugin.tsx b/src/BursarExportPlugin.tsx index a919e2b..c94907e 100644 --- a/src/BursarExportPlugin.tsx +++ b/src/BursarExportPlugin.tsx @@ -1,5 +1,5 @@ import { Button, LoadingPane, Pane, PaneFooter } from '@folio/stripes/components'; -import { useStripes, TitleManager } from '@folio/stripes/core'; +import { useStripes } from '@folio/stripes/core'; import { FormApi } from 'final-form'; import React, { useCallback, useRef } from 'react'; import { FormattedMessage, useIntl } from 'react-intl'; @@ -9,8 +9,10 @@ import ConfigurationForm from './components/ConfigurationForm'; import { FORM_ID } from './constants'; import useInitialValues from './hooks/useInitialValues'; import { FormValues } from './types'; +import TitleManager from './components/TitleManager/TitleManager'; export default function BursarExportPlugin() { + const intl = useIntl(); const stripes = useStripes(); const initialValues = useInitialValues(); @@ -71,20 +73,19 @@ export default function BursarExportPlugin() { } return ( - <> - - } - > - - - + + } + > + + + ); } diff --git a/src/components/TitleManager/TitleManager.tsx b/src/components/TitleManager/TitleManager.tsx new file mode 100644 index 0000000..13dc6c2 --- /dev/null +++ b/src/components/TitleManager/TitleManager.tsx @@ -0,0 +1,40 @@ +import React from 'react'; +import { Titled } from 'react-titled'; + +interface TitleManagerProps { + children: React.ReactNode; + prefix?: string; + page?: string; + record?: string; +} + +class TitleManager extends React.Component { + static defaultProps: Partial = { prefix: '' }; + + renderTitle = (currentTitle: string | undefined) => { + const { prefix = '', page, record } = this.props; + + if (typeof currentTitle !== 'string') return ''; + + const tokens = currentTitle.split(' - '); + + if (tokens.length === 2) { + tokens[1] = ''; + } + + if (page) tokens[0] = page; + if (record) tokens[1] = record; + + return prefix + tokens.filter(t => t).join(' - '); + }; + + render() { + return ( + + {this.props.children} + + ); + } +} + +export default TitleManager; diff --git a/translations/ui-plugin-bursar-export/en.json b/translations/ui-plugin-bursar-export/en.json index c0a6f86..7534707 100644 --- a/translations/ui-plugin-bursar-export/en.json +++ b/translations/ui-plugin-bursar-export/en.json @@ -1,5 +1,6 @@ { "meta.title": "Transfer configuration", + "meta.settingsTitle": "Users settings - Transfer criteria", "bursarExports.paneTitle": "Transfer configuration", From 899f3b2226a116e32a179d77a3dfcefa76cee7e3 Mon Sep 17 00:00:00 2001 From: Chris Hellen Date: Wed, 15 May 2024 19:11:39 -0500 Subject: [PATCH 3/4] Added TitleManager mock to Jest testing. Deleted unneeded TSX implementation. --- package.json | 3 +- src/BursarExportPlugin.tsx | 5 +-- src/components/TitleManager/TitleManager.tsx | 40 -------------------- test/__mocks__/stripes-core.mock.ts | 1 + 4 files changed, 4 insertions(+), 45 deletions(-) delete mode 100644 src/components/TitleManager/TitleManager.tsx diff --git a/package.json b/package.json index 1b663cf..1591fa3 100644 --- a/package.json +++ b/package.json @@ -105,8 +105,7 @@ "react-final-form": "^6.3.0", "react-final-form-arrays": "^3.1.0", "react-final-form-listeners": "^1.0.2", - "react-router-prop-types": "^1.0.4", - "react-titled": "^2.0.0" + "react-router-prop-types": "^1.0.4" }, "peerDependencies": { "@folio/stripes": "^9.0.0", diff --git a/src/BursarExportPlugin.tsx b/src/BursarExportPlugin.tsx index c94907e..a20fbc4 100644 --- a/src/BursarExportPlugin.tsx +++ b/src/BursarExportPlugin.tsx @@ -1,5 +1,5 @@ import { Button, LoadingPane, Pane, PaneFooter } from '@folio/stripes/components'; -import { useStripes } from '@folio/stripes/core'; +import { useStripes, TitleManager } from '@folio/stripes/core'; import { FormApi } from 'final-form'; import React, { useCallback, useRef } from 'react'; import { FormattedMessage, useIntl } from 'react-intl'; @@ -9,7 +9,6 @@ import ConfigurationForm from './components/ConfigurationForm'; import { FORM_ID } from './constants'; import useInitialValues from './hooks/useInitialValues'; import { FormValues } from './types'; -import TitleManager from './components/TitleManager/TitleManager'; export default function BursarExportPlugin() { const intl = useIntl(); @@ -73,7 +72,7 @@ export default function BursarExportPlugin() { } return ( - + { - static defaultProps: Partial = { prefix: '' }; - - renderTitle = (currentTitle: string | undefined) => { - const { prefix = '', page, record } = this.props; - - if (typeof currentTitle !== 'string') return ''; - - const tokens = currentTitle.split(' - '); - - if (tokens.length === 2) { - tokens[1] = ''; - } - - if (page) tokens[0] = page; - if (record) tokens[1] = record; - - return prefix + tokens.filter(t => t).join(' - '); - }; - - render() { - return ( - - {this.props.children} - - ); - } -} - -export default TitleManager; diff --git a/test/__mocks__/stripes-core.mock.ts b/test/__mocks__/stripes-core.mock.ts index 3ea74ab..b567861 100644 --- a/test/__mocks__/stripes-core.mock.ts +++ b/test/__mocks__/stripes-core.mock.ts @@ -19,6 +19,7 @@ jest.mock('@folio/stripes/core', () => { } }), Pluggable: jest.fn(({ children }) => [children]), + TitleManager: jest.fn(({ children }) => children), useOkapiKy: jest.fn(), useStripes: jest.fn(() => STRIPES), }; From c73fc863750b7feee1a84f7878c4ff6db9b92b7d Mon Sep 17 00:00:00 2001 From: Chris Hellen Date: Thu, 16 May 2024 13:53:34 -0500 Subject: [PATCH 4/4] Updated settings title translation id --- src/BursarExportPlugin.tsx | 2 +- translations/ui-plugin-bursar-export/en.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BursarExportPlugin.tsx b/src/BursarExportPlugin.tsx index a20fbc4..ed47791 100644 --- a/src/BursarExportPlugin.tsx +++ b/src/BursarExportPlugin.tsx @@ -72,7 +72,7 @@ export default function BursarExportPlugin() { } return ( - +