From ede1477c41c8777867dd9489f001815778e2df06 Mon Sep 17 00:00:00 2001 From: Rishi Diwan Date: Thu, 2 Nov 2023 15:58:06 +0530 Subject: [PATCH] Removed the analytics service --- src/actions.ts | 29 ------- src/components/AnalyticsServices.tsx | 81 ------------------ src/components/ConfigTabContainer.tsx | 2 - src/components/ServiceEditForm.tsx | 2 - .../__tests__/AnalyticsServices-test.tsx | 84 ------------------- .../__tests__/ConfigTabContainer-test.tsx | 5 -- src/interfaces.ts | 6 -- src/reducers/analyticsServices.ts | 8 -- src/reducers/index.ts | 4 - 9 files changed, 221 deletions(-) delete mode 100644 src/components/AnalyticsServices.tsx delete mode 100644 src/components/__tests__/AnalyticsServices-test.tsx delete mode 100644 src/reducers/analyticsServices.ts diff --git a/src/actions.ts b/src/actions.ts index 20d4cd81a..09f6c9df0 100644 --- a/src/actions.ts +++ b/src/actions.ts @@ -11,7 +11,6 @@ import { PatronAuthServicesData, SitewideSettingsData, MetadataServicesData, - AnalyticsServicesData, SearchServicesData, DiscoveryServicesData, LibraryRegistrationsData, @@ -87,9 +86,6 @@ export default class ActionCreator extends BaseActionCreator { static readonly METADATA_SERVICES = "METADATA_SERVICES"; static readonly EDIT_METADATA_SERVICE = "EDIT_METADATA_SERVICE"; static readonly DELETE_METADATA_SERVICE = "DELETE_METADATA_SERVICE"; - static readonly ANALYTICS_SERVICES = "ANALYTICS_SERVICES"; - static readonly EDIT_ANALYTICS_SERVICE = "EDIT_ANALYTICS_SERVICE"; - static readonly DELETE_ANALYTICS_SERVICE = "DELETE_ANALYTICS_SERVICE"; static readonly SEARCH_SERVICES = "SEARCH_SERVICES"; static readonly EDIT_SEARCH_SERVICE = "EDIT_SEARCH_SERVICE"; static readonly DELETE_SEARCH_SERVICE = "DELETE_SEARCH_SERVICE"; @@ -602,31 +598,6 @@ export default class ActionCreator extends BaseActionCreator { ).bind(this); } - fetchAnalyticsServices() { - const url = "/admin/analytics_services"; - return this.fetchJSON( - ActionCreator.ANALYTICS_SERVICES, - url - ).bind(this); - } - - editAnalyticsService(data: FormData) { - const url = "/admin/analytics_services"; - return this.postForm(ActionCreator.EDIT_ANALYTICS_SERVICE, url, data).bind( - this - ); - } - - deleteAnalyticsService(identifier: string | number) { - const url = "/admin/analytics_service/" + identifier; - return this.postForm( - ActionCreator.DELETE_ANALYTICS_SERVICE, - url, - null, - "DELETE" - ).bind(this); - } - fetchSearchServices() { const url = "/admin/search_services"; return this.fetchJSON( diff --git a/src/components/AnalyticsServices.tsx b/src/components/AnalyticsServices.tsx deleted file mode 100644 index f37413a2f..000000000 --- a/src/components/AnalyticsServices.tsx +++ /dev/null @@ -1,81 +0,0 @@ -import EditableConfigList, { - EditableConfigListStateProps, - EditableConfigListDispatchProps, - EditableConfigListOwnProps, -} from "./EditableConfigList"; -import { connect } from "react-redux"; -import ActionCreator from "../actions"; -import { AnalyticsServicesData, AnalyticsServiceData } from "../interfaces"; -import ServiceEditForm from "./ServiceEditForm"; -import NeighborhoodAnalyticsForm from "./NeighborhoodAnalyticsForm"; - -/** Right panel for analytics services on the system configuration page. - Shows a list of current analytics services and allows creating a new - service or editing or deleting an existing service. */ -export class AnalyticsServices extends EditableConfigList< - AnalyticsServicesData, - AnalyticsServiceData -> { - EditForm = ServiceEditForm; - ExtraFormSection = NeighborhoodAnalyticsForm; - extraFormKey = "location_source"; - listDataKey = "analytics_services"; - itemTypeName = "analytics service"; - urlBase = "/admin/web/config/analytics/"; - identifierKey = "id"; - labelKey = "protocol"; - - label(item): string { - for (const protocol of this.props.data.protocols) { - if (protocol.name === item.protocol) { - return protocol.label; - } - } - return item.protocol; - } -} - -function mapStateToProps(state, ownProps) { - const data = Object.assign( - {}, - (state.editor.analyticsServices && state.editor.analyticsServices.data) || - {} - ); - if (state.editor.libraries && state.editor.libraries.data) { - data.allLibraries = state.editor.libraries.data.libraries; - } - // fetchError = an error involving loading the list of analytics services; formError = an error upon submission of the - // create/edit form. - return { - data: data, - responseBody: - state.editor.analyticsServices && - state.editor.analyticsServices.successMessage, - fetchError: state.editor.analyticsServices.fetchError, - formError: state.editor.analyticsServices.formError, - isFetching: - state.editor.analyticsServices.isFetching || - state.editor.analyticsServices.isEditing, - }; -} - -function mapDispatchToProps(dispatch, ownProps) { - const actions = new ActionCreator(null, ownProps.csrfToken); - return { - fetchData: () => dispatch(actions.fetchAnalyticsServices()), - editItem: (data: FormData) => dispatch(actions.editAnalyticsService(data)), - deleteItem: (identifier: string | number) => - dispatch(actions.deleteAnalyticsService(identifier)), - }; -} - -const ConnectedAnalyticsServices = connect< - EditableConfigListStateProps, - EditableConfigListDispatchProps, - EditableConfigListOwnProps ->( - mapStateToProps, - mapDispatchToProps -)(AnalyticsServices); - -export default ConnectedAnalyticsServices; diff --git a/src/components/ConfigTabContainer.tsx b/src/components/ConfigTabContainer.tsx index 2cfbec0d0..edc25304b 100644 --- a/src/components/ConfigTabContainer.tsx +++ b/src/components/ConfigTabContainer.tsx @@ -7,7 +7,6 @@ import PatronAuthServices from "./PatronAuthServices"; import SitewideAnnouncements from "./SitewideAnnouncements"; import SitewideSettings from "./SitewideSettings"; import MetadataServices from "./MetadataServices"; -import AnalyticsServices from "./AnalyticsServices"; import SearchServices from "./SearchServices"; import CatalogServices from "./CatalogServices"; import DiscoveryServices from "./DiscoveryServices"; @@ -47,7 +46,6 @@ export default class ConfigTabContainer extends TabContainer< patronAuth: PatronAuthServices, sitewideSettings: SitewideSettings, metadata: MetadataServices, - analytics: AnalyticsServices, search: SearchServices, catalogServices: CatalogServices, discovery: DiscoveryServices, diff --git a/src/components/ServiceEditForm.tsx b/src/components/ServiceEditForm.tsx index 29ab34a26..fdf81fdee 100644 --- a/src/components/ServiceEditForm.tsx +++ b/src/components/ServiceEditForm.tsx @@ -35,7 +35,6 @@ export interface ServiceEditFormState { libraries: LibraryWithSettingsData[]; expandedLibraries: string[]; selectedLibrary: string | null; - analyticsOption?: string | null; } /** Form for editing service configuration based on protocol information from the server. @@ -61,7 +60,6 @@ export default class ServiceEditForm< libraries: (this.props.item && this.props.item.libraries) || [], expandedLibraries: [], selectedLibrary: null, - analyticsOption: null, }; this.handleProtocolChange = this.handleProtocolChange.bind(this); this.handleParentChange = this.handleParentChange.bind(this); diff --git a/src/components/__tests__/AnalyticsServices-test.tsx b/src/components/__tests__/AnalyticsServices-test.tsx deleted file mode 100644 index ec888afd7..000000000 --- a/src/components/__tests__/AnalyticsServices-test.tsx +++ /dev/null @@ -1,84 +0,0 @@ -import { expect } from "chai"; -import { stub } from "sinon"; - -import * as React from "react"; -import { mount } from "enzyme"; - -import { AnalyticsServices } from "../AnalyticsServices"; -import NeighborhoodAnalyticsForm from "../NeighborhoodAnalyticsForm"; - -describe("AnalyticsServices", () => { - let wrapper; - let fetchData; - let editItem; - const data = { - analytics_services: [ - { - id: 2, - protocol: "test protocol", - settings: { - test_setting: "test setting", - }, - }, - ], - protocols: [ - { - name: "test protocol", - label: "test protocol label", - sitewide: false, - settings: [], - }, - ], - allLibraries: [ - { - short_name: "nypl", - }, - ], - }; - - const pause = () => { - return new Promise((resolve) => setTimeout(resolve, 0)); - }; - - beforeEach(() => { - fetchData = stub(); - editItem = stub().returns( - new Promise((resolve) => resolve()) - ); - - wrapper = mount( - - ); - }); - - it("shows analytics service list", () => { - const service = wrapper.find("li"); - expect(service.length).to.equal(1); - expect(service.at(0).text()).to.contain("test protocol label"); - const editLink = service.at(0).find("a").at(0); - expect(editLink.props().href).to.equal( - "/admin/web/config/analytics/edit/2" - ); - }); - - it("shows neighborhood analytics panel", () => { - let neighborhoodForm = wrapper.find(NeighborhoodAnalyticsForm); - expect(neighborhoodForm.length).to.equal(0); - const setting = { key: "location_source", options: [] }; - const protocols = [{ ...data.protocols[0], ...{ settings: [setting] } }]; - wrapper.setProps({ - editOrCreate: "create", - data: { ...data, ...{ protocols } }, - }); - wrapper.setState({ protocol: "test protocol" }); - neighborhoodForm = wrapper.find(NeighborhoodAnalyticsForm); - expect(neighborhoodForm.length).to.equal(1); - expect(neighborhoodForm.prop("setting")).to.equal(setting); - }); -}); diff --git a/src/components/__tests__/ConfigTabContainer-test.tsx b/src/components/__tests__/ConfigTabContainer-test.tsx index aeaaefad9..77f461ca6 100644 --- a/src/components/__tests__/ConfigTabContainer-test.tsx +++ b/src/components/__tests__/ConfigTabContainer-test.tsx @@ -12,7 +12,6 @@ import IndividualAdmins from "../IndividualAdmins"; import PatronAuthServices from "../PatronAuthServices"; import SitewideSettings from "../SitewideSettings"; import MetadataServices from "../MetadataServices"; -import AnalyticsServices from "../AnalyticsServices"; import SearchServices from "../SearchServices"; import CatalogServices from "../CatalogServices"; import DiscoveryServices from "../DiscoveryServices"; @@ -69,7 +68,6 @@ describe("ConfigTabContainer", () => { PatronAuthServices, SitewideSettings, MetadataServices, - AnalyticsServices, SearchServices, CatalogServices, DiscoveryServices, @@ -116,7 +114,6 @@ describe("ConfigTabContainer", () => { const linkTexts = links.map((link) => link.text()); expect(linkTexts).to.contain("Libraries"); expect(linkTexts).to.contain("Admins"); - expect(linkTexts).not.to.contain("Analytics"); expect(linkTexts).not.to.contain("Collections"); expect(linkTexts).not.to.contain("Patron Authentication"); expect(linkTexts).not.to.contain("Sitewide Settings"); @@ -141,7 +138,6 @@ describe("ConfigTabContainer", () => { SearchServices, CatalogServices, DiscoveryServices, - AnalyticsServices, SitewideAnnouncements, ]; for (const componentClass of hiddenComponentClasses) { @@ -193,7 +189,6 @@ describe("ConfigTabContainer", () => { SearchServices, CatalogServices, DiscoveryServices, - AnalyticsServices, SitewideAnnouncements, ]; for (const componentClass of hiddenComponentClasses) { diff --git a/src/interfaces.ts b/src/interfaces.ts index 759c152d8..3c30e4e25 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -369,12 +369,6 @@ export interface MetadataServicesData extends ServicesData { metadata_services: MetadataServiceData[]; } -export interface AnalyticsServiceData extends ServiceData {} - -export interface AnalyticsServicesData extends ServicesData { - analytics_services: AnalyticsServiceData[]; -} - export interface SearchServiceData extends ServiceData {} export interface SearchServicesData extends ServicesData { diff --git a/src/reducers/analyticsServices.ts b/src/reducers/analyticsServices.ts deleted file mode 100644 index d8797bc63..000000000 --- a/src/reducers/analyticsServices.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { AnalyticsServicesData } from "../interfaces"; -import ActionCreator from "../actions"; -import createFetchEditReducer from "./createFetchEditReducer"; - -export default createFetchEditReducer( - ActionCreator.ANALYTICS_SERVICES, - ActionCreator.EDIT_ANALYTICS_SERVICE -); diff --git a/src/reducers/index.ts b/src/reducers/index.ts index 6457a006b..a4d1b3402 100644 --- a/src/reducers/index.ts +++ b/src/reducers/index.ts @@ -15,7 +15,6 @@ import patronAuthServices from "./patronAuthServices"; import sitewideAnnouncements from "./sitewideAnnouncements"; import sitewideSettings from "./sitewideSettings"; import metadataServices from "./metadataServices"; -import analyticsServices from "./analyticsServices"; import searchServices from "./searchServices"; import catalogServices from "./catalogServices"; import discoveryServices from "./discoveryServices"; @@ -51,7 +50,6 @@ import { SitewideAnnouncementsData, SitewideSettingsData, MetadataServicesData, - AnalyticsServicesData, SearchServicesData, CatalogServicesData, DiscoveryServicesData, @@ -84,7 +82,6 @@ export interface State { sitewideAnnouncements: FetchEditState; sitewideSettings: FetchEditState; metadataServices: FetchEditState; - analyticsServices: FetchEditState; searchServices: FetchEditState; catalogServices: FetchEditState; discoveryServices: FetchEditState; @@ -126,7 +123,6 @@ export default combineReducers({ sitewideAnnouncements, sitewideSettings, metadataServices, - analyticsServices, searchServices, catalogServices, discoveryServices,