From 402661dd830f4a3b7a4acf7d437e4aa6151b6ded Mon Sep 17 00:00:00 2001 From: scottybollinger Date: Wed, 3 Feb 2021 16:05:29 -0600 Subject: [PATCH] Remove unused duplicate code --- .../content_sources/source_logic.test.ts | 48 +------------------ .../views/content_sources/source_logic.ts | 41 ---------------- 2 files changed, 1 insertion(+), 88 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_logic.test.ts index a0efbfe4aca1d..ebff9e06998c5 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_logic.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_logic.test.ts @@ -17,11 +17,7 @@ jest.mock('../../app_logic', () => ({ AppLogic: { values: { isOrganization: true } }, })); -import { - fullContentSources, - sourceConfigData, - contentItems, -} from '../../__mocks__/content_sources.mock'; +import { fullContentSources, contentItems } from '../../__mocks__/content_sources.mock'; import { meta } from '../../__mocks__/meta.mock'; import { DEFAULT_META } from '../../../shared/constants'; @@ -45,7 +41,6 @@ describe('SourceLogic', () => { const defaultValues = { contentSource: {}, contentItems: [], - sourceConfigData: {}, dataLoading: true, sectionLoading: true, buttonLoading: false, @@ -87,13 +82,6 @@ describe('SourceLogic', () => { expect(setSuccessMessage).toHaveBeenCalled(); }); - it('setSourceConfigData', () => { - SourceLogic.actions.setSourceConfigData(sourceConfigData); - - expect(SourceLogic.values.sourceConfigData).toEqual(sourceConfigData); - expect(SourceLogic.values.dataLoading).toEqual(false); - }); - it('setSearchResults', () => { SourceLogic.actions.setSearchResults(searchServerResponse); @@ -401,40 +389,6 @@ describe('SourceLogic', () => { }); }); - describe('getSourceConfigData', () => { - const serviceType = 'github'; - - it('calls API and sets values', async () => { - AppLogic.values.isOrganization = true; - - const setSourceConfigDataSpy = jest.spyOn(SourceLogic.actions, 'setSourceConfigData'); - const promise = Promise.resolve(contentSource); - http.get.mockReturnValue(promise); - SourceLogic.actions.getSourceConfigData(serviceType); - - expect(http.get).toHaveBeenCalledWith( - `/api/workplace_search/org/settings/connectors/${serviceType}` - ); - await promise; - expect(setSourceConfigDataSpy).toHaveBeenCalled(); - }); - - it('handles error', async () => { - const error = { - response: { - error: 'this is an error', - status: 400, - }, - }; - const promise = Promise.reject(error); - http.get.mockReturnValue(promise); - SourceLogic.actions.getSourceConfigData(serviceType); - await expectedAsyncError(promise); - - expect(flashAPIErrors).toHaveBeenCalledWith(error); - }); - }); - it('resetSourceState', () => { SourceLogic.actions.resetSourceState(); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_logic.ts index d8698242a0c88..a7c0eb32a7dde 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_logic.ts @@ -26,7 +26,6 @@ import { ContentSourceFullData, Meta, DocumentSummaryItem, SourceContentItem } f export interface SourceActions { onInitializeSource(contentSource: ContentSourceFullData): ContentSourceFullData; onUpdateSourceName(name: string): string; - setSourceConfigData(sourceConfigData: SourceConfigData): SourceConfigData; setSearchResults(searchResultsResponse: SearchResultsResponse): SearchResultsResponse; initializeFederatedSummary(sourceId: string): { sourceId: string }; onUpdateSummary(summary: DocumentSummaryItem[]): DocumentSummaryItem[]; @@ -40,28 +39,9 @@ export interface SourceActions { resetSourceState(): void; removeContentSource(sourceId: string): { sourceId: string }; initializeSource(sourceId: string): { sourceId: string }; - getSourceConfigData(serviceType: string): { serviceType: string }; setButtonNotLoading(): void; } -interface SourceConfigData { - serviceType: string; - name: string; - configured: boolean; - categories: string[]; - needsPermissions?: boolean; - privateSourcesEnabled: boolean; - configuredFields: { - publicKey: string; - privateKey: string; - consumerKey: string; - baseUrl?: string; - clientId?: string; - clientSecret?: string; - }; - accountContextOnly?: boolean; -} - interface SourceValues { contentSource: ContentSourceFullData; dataLoading: boolean; @@ -70,7 +50,6 @@ interface SourceValues { contentItems: SourceContentItem[]; contentMeta: Meta; contentFilterValue: string; - sourceConfigData: SourceConfigData; } interface SearchResultsResponse { @@ -83,7 +62,6 @@ export const SourceLogic = kea>({ actions: { onInitializeSource: (contentSource: ContentSourceFullData) => contentSource, onUpdateSourceName: (name: string) => name, - setSourceConfigData: (sourceConfigData: SourceConfigData) => sourceConfigData, onUpdateSummary: (summary: object[]) => summary, setSearchResults: (searchResultsResponse: SearchResultsResponse) => searchResultsResponse, setContentFilterValue: (contentFilterValue: string) => contentFilterValue, @@ -95,7 +73,6 @@ export const SourceLogic = kea>({ removeContentSource: (sourceId: string) => ({ sourceId, }), - getSourceConfigData: (serviceType: string) => ({ serviceType }), resetSourceState: () => true, setButtonNotLoading: () => false, }, @@ -114,17 +91,10 @@ export const SourceLogic = kea>({ }), }, ], - sourceConfigData: [ - {} as SourceConfigData, - { - setSourceConfigData: (_, sourceConfigData) => sourceConfigData, - }, - ], dataLoading: [ true, { onInitializeSource: () => false, - setSourceConfigData: () => false, resetSourceState: () => false, }, ], @@ -132,7 +102,6 @@ export const SourceLogic = kea>({ false, { setButtonNotLoading: () => false, - setSourceConfigData: () => false, resetSourceState: () => false, removeContentSource: () => true, }, @@ -258,16 +227,6 @@ export const SourceLogic = kea>({ actions.setButtonNotLoading(); } }, - getSourceConfigData: async ({ serviceType }) => { - const route = `/api/workplace_search/org/settings/connectors/${serviceType}`; - - try { - const response = await HttpLogic.values.http.get(route); - actions.setSourceConfigData(response); - } catch (e) { - flashAPIErrors(e); - } - }, onUpdateSourceName: (name: string) => { setSuccessMessage( i18n.translate(