diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ed7a0b57..5527ed88b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## Changelog -### December 14, 2021 +### December 16, 2021 #### Updated @@ -8,6 +8,7 @@ - Updated node-sass and sass-loader dependency versions to reduce the number of high risk vulnerabilities. - Removed Analytics tab from System Configuration for librarians and library managers, and added Admins tab. - Relabeled "library manager" role to "administrator", and "librarian" role to "user". +- Removed redundant requests to retrieve libraries when opening the system configuration screen. ### v0.5.5 diff --git a/src/components/EditableConfigList.tsx b/src/components/EditableConfigList.tsx index 16b195f36..94239f050 100644 --- a/src/components/EditableConfigList.tsx +++ b/src/components/EditableConfigList.tsx @@ -115,8 +115,10 @@ export abstract class GenericEditableConfigList< } UNSAFE_componentWillMount() { - if (this.props.fetchData) { - this.props.fetchData(); + const { fetchData, isFetching } = this.props; + + if (fetchData && !isFetching) { + fetchData(); } } diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 62447b4b3..c604b016b 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -17,6 +17,7 @@ import * as palaceLogoUrl from "../images/PalaceCollectionManagerLogo.svg"; import title from "../utils/title"; export interface HeaderStateProps { + isFetchingLibraries?: boolean; libraries?: LibraryData[]; } @@ -203,8 +204,10 @@ export class Header extends React.Component { } UNSAFE_componentWillMount() { - if (this.props.fetchLibraries) { - this.props.fetchLibraries(); + const { fetchLibraries, isFetchingLibraries } = this.props; + + if (fetchLibraries && !isFetchingLibraries) { + fetchLibraries(); } } @@ -297,10 +300,8 @@ export class Header extends React.Component { function mapStateToProps(state, ownProps) { return { - libraries: - state.editor.libraries && - state.editor.libraries.data && - state.editor.libraries.data.libraries, + isFetchingLibraries: state.editor.libraries?.isFetching, + libraries: state.editor.libraries?.data?.libraries, }; } diff --git a/src/components/__tests__/EditableConfigList-test.tsx b/src/components/__tests__/EditableConfigList-test.tsx index 3b56f61a7..a9b84f6a5 100644 --- a/src/components/__tests__/EditableConfigList-test.tsx +++ b/src/components/__tests__/EditableConfigList-test.tsx @@ -478,6 +478,26 @@ describe("EditableConfigList", () => { expect(editItem.callCount).to.equal(1); }); + it("does not fetch data on mount if a fetch is already in progress", () => { + // Expect one pre-existing call to fetchData from the component mounted in beforeEach()... + expect(fetchData.callCount).to.equal(1); + + wrapper = shallow( + , + { context: { admin: systemAdmin } } + ); + + // ...but no more! + expect(fetchData.callCount).to.equal(1); + }); + it("fetches data again on save", async () => { wrapper.setProps({ editOrCreate: "create" }); const form = wrapper.find(ThingEditForm); diff --git a/src/components/__tests__/Header-test.tsx b/src/components/__tests__/Header-test.tsx index 813f0bf8e..adec342be 100644 --- a/src/components/__tests__/Header-test.tsx +++ b/src/components/__tests__/Header-test.tsx @@ -230,6 +230,19 @@ describe("Header", () => { expect(fetchLibraries.callCount).to.equal(1); }); + it("does not fetch libraries on mount if a fetch is already in progress", () => { + const fetchLibraries = stub(); + + wrapper = shallow( +
, + { + context: { admin: libraryManager }, + } + ); + + expect(fetchLibraries.callCount).to.equal(0); + }); + it("changes library", async () => { const libraries = [ { short_name: "nypl", name: "NYPL" },