catalog-react: moved DefaultStarredEntitiesApi implementation to catalog plugin

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-02-18 17:42:18 +01:00
parent 03ec06bf7f
commit c077b432b8
25 changed files with 77 additions and 29 deletions
@@ -22,11 +22,13 @@ import {
configApiRef,
storageApiRef,
} from '@backstage/core-plugin-api';
import { CatalogTableRow } from '@backstage/plugin-catalog';
import {
CatalogTableRow,
DefaultStarredEntitiesApi,
} from '@backstage/plugin-catalog';
import {
CatalogApi,
catalogApiRef,
DefaultStarredEntitiesApi,
entityRouteRef,
starredEntitiesApiRef,
} from '@backstage/plugin-catalog-react';
-10
View File
@@ -24,7 +24,6 @@ import { default as React_2 } from 'react';
import { ReactNode } from 'react';
import { RouteRef } from '@backstage/core-plugin-api';
import { ScmIntegrationRegistry } from '@backstage/integration';
import { StorageApi } from '@backstage/core-plugin-api';
import { StyleRules } from '@material-ui/core/styles/withStyles';
import { SystemEntity } from '@backstage/catalog-model';
import { TableColumn } from '@backstage/core-components';
@@ -138,15 +137,6 @@ export type DefaultEntityFilters = {
text?: EntityTextFilter;
};
// @public
export class DefaultStarredEntitiesApi implements StarredEntitiesApi {
constructor(opts: { storageApi: StorageApi });
// (undocumented)
starredEntitie$(): Observable<Set<string>>;
// (undocumented)
toggleStarred(entityRef: string): Promise<void>;
}
// @public (undocumented)
export type EntityFilter = {
getCatalogFilters?: () => Record<
@@ -14,6 +14,5 @@
* limitations under the License.
*/
export { DefaultStarredEntitiesApi } from './DefaultStarredEntitiesApi';
export { starredEntitiesApiRef } from './StarredEntitiesApi';
export type { StarredEntitiesApi } from './StarredEntitiesApi';
@@ -23,13 +23,14 @@ import {
identityApiRef,
storageApiRef,
} from '@backstage/core-plugin-api';
import { DefaultStarredEntitiesApi } from '@backstage/plugin-catalog';
import { MockStorageApi, TestApiProvider } from '@backstage/test-utils';
import { act, renderHook } from '@testing-library/react-hooks';
import qs from 'qs';
import React, { PropsWithChildren } from 'react';
import { MemoryRouter } from 'react-router';
import { catalogApiRef } from '../api';
import { DefaultStarredEntitiesApi, starredEntitiesApiRef } from '../apis';
import { starredEntitiesApiRef } from '../apis';
import { EntityKindPicker, UserListPicker } from '../components';
import { EntityKindFilter, EntityTypeFilter, UserListFilter } from '../filters';
import { UserListFilterKind } from '../types';
@@ -16,10 +16,11 @@
import { Entity } from '@backstage/catalog-model';
import { StorageApi } from '@backstage/core-plugin-api';
import { DefaultStarredEntitiesApi } from '@backstage/plugin-catalog';
import { MockStorageApi, TestApiProvider } from '@backstage/test-utils';
import { act, renderHook } from '@testing-library/react-hooks';
import React, { PropsWithChildren } from 'react';
import { DefaultStarredEntitiesApi, starredEntitiesApiRef } from '../apis';
import { starredEntitiesApiRef } from '../apis';
import { useStarredEntities } from './useStarredEntities';
describe('useStarredEntities', () => {
+12
View File
@@ -13,10 +13,13 @@ import { ExternalRouteRef } from '@backstage/core-plugin-api';
import { IconComponent } from '@backstage/core-plugin-api';
import { IndexableDocument } from '@backstage/search-common';
import { InfoCardVariants } from '@backstage/core-components';
import { Observable } from '@backstage/types';
import { Overrides } from '@material-ui/core/styles/overrides';
import { default as React_2 } from 'react';
import { ReactNode } from 'react';
import { RouteRef } from '@backstage/core-plugin-api';
import { StarredEntitiesApi } from '@backstage/plugin-catalog-react';
import { StorageApi } from '@backstage/core-plugin-api';
import { StyleRules } from '@material-ui/core/styles/withStyles';
import { TableColumn } from '@backstage/core-components';
import { TableProps } from '@backstage/core-components';
@@ -170,6 +173,15 @@ export interface DefaultCatalogPageProps {
initiallySelectedFilter?: UserListFilterKind;
}
// @public
export class DefaultStarredEntitiesApi implements StarredEntitiesApi {
constructor(opts: { storageApi: StorageApi });
// (undocumented)
starredEntitie$(): Observable<Set<string>>;
// (undocumented)
toggleStarred(entityRef: string): Promise<void>;
}
// @public (undocumented)
export interface DependencyOfComponentsCardProps {
// (undocumented)
+3 -1
View File
@@ -44,6 +44,7 @@
"@backstage/plugin-catalog-react": "^0.7.0",
"@backstage/search-common": "^0.2.4",
"@backstage/theme": "^0.2.15",
"@backstage/types": "^0.1.2",
"@material-ui/core": "^4.12.2",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.57",
@@ -51,7 +52,8 @@
"lodash": "^4.17.21",
"react-helmet": "6.1.0",
"react-router": "6.0.0-beta.0",
"react-use": "^17.2.4"
"react-use": "^17.2.4",
"zen-observable": "^0.8.15"
},
"peerDependencies": {
"@types/react": "^16.13.1 || ^17.0.0",
@@ -15,10 +15,10 @@
*/
import { StorageApi } from '@backstage/core-plugin-api';
import { StarredEntitiesApi } from '@backstage/plugin-catalog-react';
import { Observable } from '@backstage/types';
import ObservableImpl from 'zen-observable';
import { performMigrationToTheNewBucket } from './migration';
import { StarredEntitiesApi } from './StarredEntitiesApi';
/**
* Default implementation of the StarredEntitiesApi that is backed by the StorageApi.
@@ -0,0 +1,17 @@
/*
* Copyright 2021 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { DefaultStarredEntitiesApi } from './DefaultStarredEntitiesApi';
+17
View File
@@ -0,0 +1,17 @@
/*
* Copyright 2021 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './StarredEntitiesApi';
@@ -29,7 +29,6 @@ import {
} from '@backstage/core-plugin-api';
import {
catalogApiRef,
DefaultStarredEntitiesApi,
entityRouteRef,
starredEntitiesApiRef,
} from '@backstage/plugin-catalog-react';
@@ -43,6 +42,7 @@ import {
import DashboardIcon from '@material-ui/icons/Dashboard';
import { fireEvent, screen } from '@testing-library/react';
import React from 'react';
import { DefaultStarredEntitiesApi } from '../../apis';
import { createComponentRouteRef } from '../../routes';
import { CatalogTableRow } from '../CatalogTable';
import { DefaultCatalogPage } from './DefaultCatalogPage';
@@ -22,7 +22,6 @@ import {
import { ApiProvider } from '@backstage/core-app-api';
import {
entityRouteRef,
DefaultStarredEntitiesApi,
MockEntityListContextProvider,
starredEntitiesApiRef,
UserListFilter,
@@ -34,6 +33,7 @@ import {
} from '@backstage/test-utils';
import { act, fireEvent } from '@testing-library/react';
import * as React from 'react';
import { DefaultStarredEntitiesApi } from '../../apis';
import { CatalogTable } from './CatalogTable';
const entities: Entity[] = [
@@ -21,7 +21,6 @@ import { AlertApi, alertApiRef } from '@backstage/core-plugin-api';
import {
AsyncEntityProvider,
catalogApiRef,
DefaultStarredEntitiesApi,
EntityProvider,
entityRouteRef,
starredEntitiesApiRef,
@@ -36,6 +35,7 @@ import {
import { act, fireEvent } from '@testing-library/react';
import React from 'react';
import { Route, Routes } from 'react-router';
import { DefaultStarredEntitiesApi } from '../../apis';
import { EntityLayout } from './EntityLayout';
const mockEntity = {
+2
View File
@@ -20,6 +20,8 @@
* @packageDocumentation
*/
export * from './apis';
export * from './components/AboutCard';
export * from './components/CatalogKindHeader';
export * from './components/CatalogSearchResultListItem';
+1 -1
View File
@@ -19,7 +19,6 @@ import { Entity } from '@backstage/catalog-model';
import {
catalogApiRef,
catalogRouteRef,
DefaultStarredEntitiesApi,
entityRouteRef,
starredEntitiesApiRef,
} from '@backstage/plugin-catalog-react';
@@ -33,6 +32,7 @@ import {
fetchApiRef,
storageApiRef,
} from '@backstage/core-plugin-api';
import { DefaultStarredEntitiesApi } from './apis';
import { AboutCardProps } from './components/AboutCard';
import { DefaultCatalogPageProps } from './components/CatalogPage';
import { DependencyOfComponentsCardProps } from './components/DependencyOfComponentsCard';
@@ -21,8 +21,8 @@ import {
import {
starredEntitiesApiRef,
entityRouteRef,
DefaultStarredEntitiesApi,
} from '@backstage/plugin-catalog-react';
import { DefaultStarredEntitiesApi } from '@backstage/plugin-catalog';
import React from 'react';
import { Content } from './Content';
@@ -23,8 +23,8 @@ import {
import {
starredEntitiesApiRef,
entityRouteRef,
DefaultStarredEntitiesApi,
} from '@backstage/plugin-catalog-react';
import { DefaultStarredEntitiesApi } from '@backstage/plugin-catalog';
import { Grid } from '@material-ui/core';
import React, { ComponentType } from 'react';
@@ -26,8 +26,8 @@ import { Content, Page, InfoCard } from '@backstage/core-components';
import {
starredEntitiesApiRef,
entityRouteRef,
DefaultStarredEntitiesApi
} from '@backstage/plugin-catalog-react';
import { DefaultStarredEntitiesApi } from '@backstage/plugin-catalog';
import {
HomePageSearchBar,
SearchContextProvider,
@@ -153,4 +153,3 @@ export const DefaultTemplate = () => {
</SearchContextProvider>
);
};
+4 -2
View File
@@ -20,7 +20,6 @@ import { scmIntegrationsApiRef } from '@backstage/integration-react';
import {
catalogApiRef,
starredEntitiesApiRef,
DefaultStarredEntitiesApi,
} from '@backstage/plugin-catalog-react';
import React from 'react';
import { scaffolderApiRef, ScaffolderClient } from '../src';
@@ -30,7 +29,10 @@ import {
fetchApiRef,
storageApiRef,
} from '@backstage/core-plugin-api';
import { CatalogEntityPage } from '@backstage/plugin-catalog';
import {
CatalogEntityPage,
DefaultStarredEntitiesApi,
} from '@backstage/plugin-catalog';
createDevApp()
.addPage({
@@ -20,10 +20,10 @@ import {
configApiRef,
storageApiRef,
} from '@backstage/core-plugin-api';
import { DefaultStarredEntitiesApi } from '@backstage/plugin-catalog';
import {
CatalogApi,
catalogApiRef,
DefaultStarredEntitiesApi,
starredEntitiesApiRef,
} from '@backstage/plugin-catalog-react';
import {