feat(catalog): add placeholder for identity API implementation

This commit is contained in:
Nikita Nek Dudnik
2020-06-16 11:05:17 +02:00
parent 806790ea89
commit 3b19d7f37a
8 changed files with 55 additions and 3 deletions
+4
View File
@@ -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,
@@ -40,7 +40,7 @@ export type IdentityApi = {
// TODO: getProfile(): Promise<Profile> - We want this to be async when added, but needs more work.
};
export const identifyApiRef = createApiRef<IdentityApi>({
export const identityApiRef = createApiRef<IdentityApi>({
id: 'core.identity',
description: 'Provides access to the identity of the signed in user',
});
@@ -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.');
}
}
@@ -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';
@@ -26,3 +26,4 @@ export * from './ConfigApi';
export * from './ErrorApi';
export * from './OAuthRequestApi';
export * from './StorageApi';
export * from './IdentityApi';
+4
View File
@@ -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(),
@@ -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';
+2 -2
View File
@@ -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(() => {