Restore original casing for kind, namespace and name in DefaultTechDocsCollator
Signed-off-by: Oliver Sand <oliver.sand@sda-se.com>
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
---
|
||||
'@backstage/plugin-techdocs': patch
|
||||
'@backstage/plugin-techdocs-backend': patch
|
||||
---
|
||||
|
||||
Restore original casing for `kind`, `namespace` and `name` in `DefaultTechDocsCollator`.
|
||||
@@ -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,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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) || '',
|
||||
|
||||
@@ -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('<TechDocsPage />', () => {
|
||||
await singleResult;
|
||||
expect(querySpy).toBeCalledWith({
|
||||
filters: {
|
||||
kind: 'testable',
|
||||
kind: 'Testable',
|
||||
name: 'test',
|
||||
namespace: 'testspace',
|
||||
},
|
||||
@@ -108,7 +108,7 @@ describe('<TechDocsPage />', () => {
|
||||
await waitFor(() =>
|
||||
expect(querySpy).toBeCalledWith({
|
||||
filters: {
|
||||
kind: 'testable',
|
||||
kind: 'Testable',
|
||||
name: 'test',
|
||||
namespace: 'testspace',
|
||||
},
|
||||
@@ -120,23 +120,3 @@ describe('<TechDocsPage />', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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 (
|
||||
<SearchContextProvider initialState={initialState}>
|
||||
|
||||
Reference in New Issue
Block a user