From 106a5dc3ad6efc9ecf212f9b5dd3cee080aba463 Mon Sep 17 00:00:00 2001 From: Oliver Sand Date: Wed, 27 Oct 2021 14:29:26 +0200 Subject: [PATCH] Restore original casing for `kind`, `namespace` and `name` in `DefaultTechDocsCollator` Signed-off-by: Oliver Sand --- .changeset/techdocs-poor-paws-rest.md | 6 ++++ .../search/DefaultTechDocsCollator.test.ts | 4 +++ .../src/search/DefaultTechDocsCollator.ts | 4 ++- .../reader/components/TechDocsSearch.test.tsx | 34 ++++-------------- .../src/reader/components/TechDocsSearch.tsx | 36 +++++-------------- 5 files changed, 28 insertions(+), 56 deletions(-) create mode 100644 .changeset/techdocs-poor-paws-rest.md diff --git a/.changeset/techdocs-poor-paws-rest.md b/.changeset/techdocs-poor-paws-rest.md new file mode 100644 index 0000000000..71e00f18ba --- /dev/null +++ b/.changeset/techdocs-poor-paws-rest.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-techdocs': patch +'@backstage/plugin-techdocs-backend': patch +--- + +Restore original casing for `kind`, `namespace` and `name` in `DefaultTechDocsCollator`. diff --git a/plugins/techdocs-backend/src/search/DefaultTechDocsCollator.test.ts b/plugins/techdocs-backend/src/search/DefaultTechDocsCollator.test.ts index 29c74a119c..21be228636 100644 --- a/plugins/techdocs-backend/src/search/DefaultTechDocsCollator.test.ts +++ b/plugins/techdocs-backend/src/search/DefaultTechDocsCollator.test.ts @@ -138,6 +138,8 @@ describe('DefaultTechDocsCollator with legacyPathCasing configuration', () => { componentType: entity!.spec!.type, lifecycle: entity!.spec!.lifecycle, owner: '', + kind: entity.kind, + name: entity.metadata.name, }); }); }); @@ -183,6 +185,8 @@ describe('DefaultTechDocsCollator', () => { componentType: entity!.spec!.type, lifecycle: entity!.spec!.lifecycle, owner: '', + kind: entity.kind, + name: entity.metadata.name, }); }); }); diff --git a/plugins/techdocs-backend/src/search/DefaultTechDocsCollator.ts b/plugins/techdocs-backend/src/search/DefaultTechDocsCollator.ts index c0a96b7862..121ef6e46d 100644 --- a/plugins/techdocs-backend/src/search/DefaultTechDocsCollator.ts +++ b/plugins/techdocs-backend/src/search/DefaultTechDocsCollator.ts @@ -130,7 +130,9 @@ export class DefaultTechDocsCollator implements DocumentCollator { path: doc.location, }), path: doc.location, - ...entityInfo, + kind: entity.kind, + namespace: entity.metadata.namespace || 'default', + name: entity.metadata.name, entityTitle: entity.metadata.title, componentType: entity.spec?.type?.toString() || 'other', lifecycle: (entity.spec?.lifecycle as string) || '', diff --git a/plugins/techdocs/src/reader/components/TechDocsSearch.test.tsx b/plugins/techdocs/src/reader/components/TechDocsSearch.test.tsx index c6f017e92d..602a94e758 100644 --- a/plugins/techdocs/src/reader/components/TechDocsSearch.test.tsx +++ b/plugins/techdocs/src/reader/components/TechDocsSearch.test.tsx @@ -13,8 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import React from 'react'; -import { buildInitialFilters, TechDocsSearch } from './TechDocsSearch'; +import { ApiProvider, ApiRegistry } from '@backstage/core-app-api'; +import { searchApiRef } from '@backstage/plugin-search'; +import { wrapInTestApp } from '@backstage/test-utils'; import { act, fireEvent, @@ -22,9 +23,8 @@ import { waitFor, within, } from '@testing-library/react'; -import { wrapInTestApp } from '@backstage/test-utils'; -import { ApiProvider, ApiRegistry } from '@backstage/core-app-api'; -import { searchApiRef } from '@backstage/plugin-search'; +import React from 'react'; +import { TechDocsSearch } from './TechDocsSearch'; const entityId = { name: 'test', @@ -89,7 +89,7 @@ describe('', () => { await singleResult; expect(querySpy).toBeCalledWith({ filters: { - kind: 'testable', + kind: 'Testable', name: 'test', namespace: 'testspace', }, @@ -108,7 +108,7 @@ describe('', () => { await waitFor(() => expect(querySpy).toBeCalledWith({ filters: { - kind: 'testable', + kind: 'Testable', name: 'test', namespace: 'testspace', }, @@ -120,23 +120,3 @@ describe('', () => { }); }); }); - -describe('buildInitialFilters', () => { - const filterEnt = { - name: 'Test', - kind: 'TestKind', - namespace: 'TeStNaMeSpAcE', - }; - it('should use filters as is when legacy path', () => { - const filters = buildInitialFilters(true, filterEnt); - expect(filters).toStrictEqual(filterEnt); - }); - it('should lowercase all filters for new approach', () => { - const filters = buildInitialFilters(false, filterEnt); - expect(filters).toStrictEqual({ - name: 'test', - kind: 'testkind', - namespace: 'testnamespace', - }); - }); -}); diff --git a/plugins/techdocs/src/reader/components/TechDocsSearch.tsx b/plugins/techdocs/src/reader/components/TechDocsSearch.tsx index 64229e6620..5bc1947ed6 100644 --- a/plugins/techdocs/src/reader/components/TechDocsSearch.tsx +++ b/plugins/techdocs/src/reader/components/TechDocsSearch.tsx @@ -14,7 +14,8 @@ * limitations under the License. */ -import React, { ChangeEvent, useEffect, useState } from 'react'; +import { EntityName } from '@backstage/catalog-model'; +import { SearchContextProvider, useSearch } from '@backstage/plugin-search'; import { CircularProgress, Grid, @@ -22,21 +23,15 @@ import { InputAdornment, TextField, } from '@material-ui/core'; -import Autocomplete from '@material-ui/lab/Autocomplete'; -import { SearchContextProvider, useSearch } from '@backstage/plugin-search'; -import { DocsResultListItem } from '../../components/DocsResultListItem'; import SearchIcon from '@material-ui/icons/Search'; -import { useDebounce } from 'react-use'; +import Autocomplete from '@material-ui/lab/Autocomplete'; +import React, { ChangeEvent, useEffect, useState } from 'react'; import { useNavigate } from 'react-router'; -import { configApiRef, useApi } from '@backstage/core-plugin-api'; +import { useDebounce } from 'react-use'; +import { DocsResultListItem } from '../../components/DocsResultListItem'; -type EntityId = { - name: string; - namespace: string; - kind: string; -}; type TechDocsSearchProps = { - entityId: EntityId; + entityId: EntityName; debounceTime?: number; }; @@ -54,17 +49,6 @@ type TechDocsSearchResult = { document: TechDocsDoc; }; -export const buildInitialFilters = ( - legacyPaths: boolean, - entityId: EntityId, -) => { - return legacyPaths - ? entityId - : Object.entries(entityId).reduce((acc, [key, value]) => { - return { ...acc, [key]: value?.toLocaleLowerCase('en-US') }; - }, {}); -}; - const TechDocsSearchBar = ({ entityId, debounceTime = 150, @@ -176,15 +160,11 @@ const TechDocsSearchBar = ({ }; export const TechDocsSearch = (props: TechDocsSearchProps) => { - const configApi = useApi(configApiRef); - const legacyPaths = configApi.getOptionalBoolean( - 'techdocs.legacyUseCaseSensitiveTripletPaths', - ); const initialState = { term: '', types: ['techdocs'], pageCursor: '', - filters: buildInitialFilters(legacyPaths || false, props.entityId), + filters: props.entityId, }; return (