From 3b19d7f37abcce4233ea18d17e9e0c23b50df65e Mon Sep 17 00:00:00 2001 From: Nikita Nek Dudnik Date: Tue, 16 Jun 2020 11:05:17 +0200 Subject: [PATCH] feat(catalog): add placeholder for identity API implementation --- packages/app/src/apis.ts | 4 +++ .../src/apis/definitions/IdentityApi.ts | 2 +- .../implementations/IdentityApi/Identity.ts | 25 +++++++++++++++++++ .../apis/implementations/IdentityApi/index.ts | 16 ++++++++++++ .../src/apis/implementations/index.ts | 1 + packages/storybook/.storybook/apis.js | 4 +++ .../CatalogPage/CatalogPage.test.tsx | 2 ++ plugins/catalog/src/hooks/useEntities.ts | 4 +-- 8 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 packages/core-api/src/apis/implementations/IdentityApi/Identity.ts create mode 100644 packages/core-api/src/apis/implementations/IdentityApi/index.ts diff --git a/packages/app/src/apis.ts b/packages/app/src/apis.ts index 9bfc618216..a6d9987819 100644 --- a/packages/app/src/apis.ts +++ b/packages/app/src/apis.ts @@ -32,6 +32,8 @@ import { githubAuthApiRef, storageApiRef, WebStorage, + identityApiRef, + MockIdentity, } from '@backstage/core'; import { @@ -52,6 +54,8 @@ export const apis = (config: ConfigApi) => { const builder = ApiRegistry.builder(); + builder.add(identityApiRef, new MockIdentity()); + const alertApi = builder.add(alertApiRef, new AlertApiForwarder()); const errorApi = builder.add( errorApiRef, diff --git a/packages/core-api/src/apis/definitions/IdentityApi.ts b/packages/core-api/src/apis/definitions/IdentityApi.ts index bbfab0ef35..4c9ccfdbf6 100644 --- a/packages/core-api/src/apis/definitions/IdentityApi.ts +++ b/packages/core-api/src/apis/definitions/IdentityApi.ts @@ -40,7 +40,7 @@ export type IdentityApi = { // TODO: getProfile(): Promise - We want this to be async when added, but needs more work. }; -export const identifyApiRef = createApiRef({ +export const identityApiRef = createApiRef({ id: 'core.identity', description: 'Provides access to the identity of the signed in user', }); diff --git a/packages/core-api/src/apis/implementations/IdentityApi/Identity.ts b/packages/core-api/src/apis/implementations/IdentityApi/Identity.ts new file mode 100644 index 0000000000..6f2035d1b8 --- /dev/null +++ b/packages/core-api/src/apis/implementations/IdentityApi/Identity.ts @@ -0,0 +1,25 @@ +/* + * Copyright 2020 Spotify AB + * + * 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. + */ +import { IdentityApi } from '../..'; + +export class MockIdentity implements IdentityApi { + getUserId(): string { + return ''; + } + getIdToken(): string | undefined { + throw new Error('Method not implemented.'); + } +} diff --git a/packages/core-api/src/apis/implementations/IdentityApi/index.ts b/packages/core-api/src/apis/implementations/IdentityApi/index.ts new file mode 100644 index 0000000000..1e57036685 --- /dev/null +++ b/packages/core-api/src/apis/implementations/IdentityApi/index.ts @@ -0,0 +1,16 @@ +/* + * Copyright 2020 Spotify AB + * + * 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 './Identity'; diff --git a/packages/core-api/src/apis/implementations/index.ts b/packages/core-api/src/apis/implementations/index.ts index e6d23fee21..885082ce09 100644 --- a/packages/core-api/src/apis/implementations/index.ts +++ b/packages/core-api/src/apis/implementations/index.ts @@ -26,3 +26,4 @@ export * from './ConfigApi'; export * from './ErrorApi'; export * from './OAuthRequestApi'; export * from './StorageApi'; +export * from './IdentityApi'; diff --git a/packages/storybook/.storybook/apis.js b/packages/storybook/.storybook/apis.js index d3150400cf..9dc1e2bad2 100644 --- a/packages/storybook/.storybook/apis.js +++ b/packages/storybook/.storybook/apis.js @@ -11,6 +11,8 @@ import { ErrorAlerter, GoogleAuth, GithubAuth, + identityApiRef, + MockIdentity, } from '@backstage/core'; const builder = ApiRegistry.builder(); @@ -19,6 +21,8 @@ const alertApi = builder.add(alertApiRef, new AlertApiForwarder()); builder.add(errorApiRef, new ErrorAlerter(alertApi, new ErrorApiForwarder())); +builder.add(identityApiRef, new MockIdentity()); + const oauthRequestApi = builder.add( oauthRequestApiRef, new OAuthRequestManager(), diff --git a/plugins/catalog/src/components/CatalogPage/CatalogPage.test.tsx b/plugins/catalog/src/components/CatalogPage/CatalogPage.test.tsx index 2e1989323c..4cd0cae7af 100644 --- a/plugins/catalog/src/components/CatalogPage/CatalogPage.test.tsx +++ b/plugins/catalog/src/components/CatalogPage/CatalogPage.test.tsx @@ -20,6 +20,8 @@ import { errorApiRef, storageApiRef, WebStorage, + IdentityApi, + identityApiRef, } from '@backstage/core'; import { MockErrorApi, wrapInTestApp } from '@backstage/test-utils'; import { render } from '@testing-library/react'; diff --git a/plugins/catalog/src/hooks/useEntities.ts b/plugins/catalog/src/hooks/useEntities.ts index e23ec72910..1530be6f7c 100644 --- a/plugins/catalog/src/hooks/useEntities.ts +++ b/plugins/catalog/src/hooks/useEntities.ts @@ -15,7 +15,7 @@ */ import { useState, useMemo } from 'react'; import { EntityFilterType, entityFilters } from '../data/filters'; -import { useApi, identifyApiRef } from '@backstage/core'; +import { useApi, identityApiRef } from '@backstage/core'; import { catalogApiRef } from '..'; import { useStarredEntities } from './useStarredEntites'; import { Entity } from '@backstage/catalog-model'; @@ -43,7 +43,7 @@ export const useEntities = (): UseEntities => { async () => catalogApi.getEntities(), ); - const indentityApi = useApi(identifyApiRef); + const indentityApi = useApi(identityApiRef); const userId = indentityApi.getUserId(); const entitiesByFilter = useMemo(() => {