From 14c0a579a509137cbe6a0a0b3a8fbbef2d5d1630 Mon Sep 17 00:00:00 2001 From: Kiss Miklos Date: Fri, 10 Jun 2022 15:25:39 +0200 Subject: [PATCH 1/8] add UserSettingsIdentityCard Signed-off-by: Kiss Miklos --- .../General/UserSettingsGeneral.tsx | 4 ++ .../General/UserSettingsIdentityCard.tsx | 51 +++++++++++++++++++ .../src/components/useUserProfileInfo.ts | 1 + 3 files changed, 56 insertions(+) create mode 100644 plugins/user-settings/src/components/General/UserSettingsIdentityCard.tsx diff --git a/plugins/user-settings/src/components/General/UserSettingsGeneral.tsx b/plugins/user-settings/src/components/General/UserSettingsGeneral.tsx index 6705997d1c..db7fdd7be6 100644 --- a/plugins/user-settings/src/components/General/UserSettingsGeneral.tsx +++ b/plugins/user-settings/src/components/General/UserSettingsGeneral.tsx @@ -17,6 +17,7 @@ import { Grid } from '@material-ui/core'; import React from 'react'; import { UserSettingsProfileCard } from './UserSettingsProfileCard'; import { UserSettingsAppearanceCard } from './UserSettingsAppearanceCard'; +import { UserSettingsIdentityCard } from './UserSettingsIdentityCard'; export const UserSettingsGeneral = () => { return ( @@ -27,6 +28,9 @@ export const UserSettingsGeneral = () => { + + + ); }; diff --git a/plugins/user-settings/src/components/General/UserSettingsIdentityCard.tsx b/plugins/user-settings/src/components/General/UserSettingsIdentityCard.tsx new file mode 100644 index 0000000000..b656c6b861 --- /dev/null +++ b/plugins/user-settings/src/components/General/UserSettingsIdentityCard.tsx @@ -0,0 +1,51 @@ +/* + * Copyright 2022 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. + */ +import { InfoCard } from '@backstage/core-components'; +import { Grid, Typography } from '@material-ui/core'; +import React from 'react'; +import { useUserProfile } from '../useUserProfileInfo'; +import Chip from '@material-ui/core/Chip'; + +export const UserSettingsIdentityCard = () => { + const { backstageIdentity } = useUserProfile(); + + return ( + + + + + + + User Entity:{' '} + + + + Ownership Entities:{' '} + {backstageIdentity?.ownershipEntityRefs.map(it => ( + + ))} + + + + + + + ); +}; diff --git a/plugins/user-settings/src/components/useUserProfileInfo.ts b/plugins/user-settings/src/components/useUserProfileInfo.ts index f893520cd2..c168fc12b4 100644 --- a/plugins/user-settings/src/components/useUserProfileInfo.ts +++ b/plugins/user-settings/src/components/useUserProfileInfo.ts @@ -53,6 +53,7 @@ export const useUserProfile = () => { return { profile: value!.profile, + backstageIdentity: value!.identity, displayName: value!.profile.displayName ?? value!.identity.userEntityRef, loading, }; From 9d2d6a0ceae21b39bb4c810d366b16df346b302a Mon Sep 17 00:00:00 2001 From: Kiss Miklos Date: Fri, 10 Jun 2022 15:30:00 +0200 Subject: [PATCH 2/8] add changeset to plugin-user-settings Signed-off-by: Kiss Miklos --- .changeset/early-hats-rest.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/early-hats-rest.md diff --git a/.changeset/early-hats-rest.md b/.changeset/early-hats-rest.md new file mode 100644 index 0000000000..6eab693200 --- /dev/null +++ b/.changeset/early-hats-rest.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-user-settings': patch +--- + +Add UserSettingsIdentityCard to show the result of the identityApi.getBackstageIdentity() call to help debug ownership issues. From 3ff65242b84b1c012239c049905d34d4c9beb12e Mon Sep 17 00:00:00 2001 From: Kiss Miklos Date: Fri, 10 Jun 2022 15:50:47 +0200 Subject: [PATCH 3/8] add api-report.md Signed-off-by: Kiss Miklos --- plugins/user-settings/api-report.md | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/plugins/user-settings/api-report.md b/plugins/user-settings/api-report.md index 136b23bd71..db98f54a90 100644 --- a/plugins/user-settings/api-report.md +++ b/plugins/user-settings/api-report.md @@ -7,6 +7,7 @@ import { ApiRef } from '@backstage/core-plugin-api'; import { BackstagePlugin } from '@backstage/core-plugin-api'; +import { BackstageUserIdentity } from '@backstage/core-plugin-api'; import { IconComponent } from '@backstage/core-plugin-api'; import { ProfileInfo } from '@backstage/core-plugin-api'; import { PropsWithChildren } from 'react'; @@ -129,9 +130,17 @@ export const UserSettingsThemeToggle: () => JSX.Element; // Warning: (ae-missing-release-tag) "useUserProfile" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export const useUserProfile: () => { - profile: ProfileInfo; - displayName: string; - loading: boolean; -}; +export const useUserProfile: () => + | { + profile: ProfileInfo; + displayName: string; + backstageIdentity: undefined; + loading: boolean; + } + | { + profile: ProfileInfo; + backstageIdentity: BackstageUserIdentity; + displayName: string; + loading: false; + }; ``` From f6dfc61d2707c85621c0b8a1ecf1dcc918279606 Mon Sep 17 00:00:00 2001 From: Kiss Miklos Date: Mon, 13 Jun 2022 10:00:22 +0200 Subject: [PATCH 4/8] add test Signed-off-by: Kiss Miklos --- .../General/UserSettingsIdentityCard.test.tsx | 53 +++++++++++++++++++ .../General/UserSettingsIdentityCard.tsx | 3 +- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 plugins/user-settings/src/components/General/UserSettingsIdentityCard.test.tsx diff --git a/plugins/user-settings/src/components/General/UserSettingsIdentityCard.test.tsx b/plugins/user-settings/src/components/General/UserSettingsIdentityCard.test.tsx new file mode 100644 index 0000000000..19c3eb2182 --- /dev/null +++ b/plugins/user-settings/src/components/General/UserSettingsIdentityCard.test.tsx @@ -0,0 +1,53 @@ +/* + * Copyright 2022 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. + */ + +import { + renderWithEffects, + wrapInTestApp, + TestApiRegistry, +} from '@backstage/test-utils'; +import { screen } from '@testing-library/react'; +import React from 'react'; +import { UserSettingsIdentityCard } from './UserSettingsIdentityCard'; +import { ApiProvider } from '@backstage/core-app-api'; +import { identityApiRef } from '@backstage/core-plugin-api'; + +const apiRegistry = TestApiRegistry.from([ + identityApiRef, + { + getProfileInfo: jest.fn(async () => ({})), + getBackstageIdentity: jest.fn(async () => ({ + type: 'user' as const, + userEntityRef: 'foo:bar/foobar', + ownershipEntityRefs: ['test-ownership'], + })), + }, +]); + +describe('', () => { + it('displays an identity card', async () => { + await renderWithEffects( + wrapInTestApp( + + + , + ), + ); + + expect(screen.getByText('test-ownership')).toBeInTheDocument(); + expect(screen.getByText('foo:bar/foobar')).toBeInTheDocument(); + }); +}); diff --git a/plugins/user-settings/src/components/General/UserSettingsIdentityCard.tsx b/plugins/user-settings/src/components/General/UserSettingsIdentityCard.tsx index b656c6b861..908cda1423 100644 --- a/plugins/user-settings/src/components/General/UserSettingsIdentityCard.tsx +++ b/plugins/user-settings/src/components/General/UserSettingsIdentityCard.tsx @@ -14,10 +14,11 @@ * limitations under the License. */ import { InfoCard } from '@backstage/core-components'; -import { Grid, Typography } from '@material-ui/core'; import React from 'react'; import { useUserProfile } from '../useUserProfileInfo'; import Chip from '@material-ui/core/Chip'; +import Grid from '@material-ui/core/Grid'; +import Typography from '@material-ui/core/Typography'; export const UserSettingsIdentityCard = () => { const { backstageIdentity } = useUserProfile(); From 6955d948a7dfb14507659589b58ce98dfc9a2ad7 Mon Sep 17 00:00:00 2001 From: Kiss Miklos Date: Mon, 13 Jun 2022 10:13:53 +0200 Subject: [PATCH 5/8] export the componenet from the plugin Signed-off-by: Kiss Miklos --- plugins/user-settings/src/components/General/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/user-settings/src/components/General/index.ts b/plugins/user-settings/src/components/General/index.ts index 80a9c75d89..ff4d1210c4 100644 --- a/plugins/user-settings/src/components/General/index.ts +++ b/plugins/user-settings/src/components/General/index.ts @@ -21,3 +21,4 @@ export { UserSettingsSignInAvatar } from './UserSettingsSignInAvatar'; export { UserSettingsAppearanceCard } from './UserSettingsAppearanceCard'; export { UserSettingsThemeToggle } from './UserSettingsThemeToggle'; export { UserSettingsPinToggle } from './UserSettingsPinToggle'; +export { UserSettingsIdentityCard } from './UserSettingsIdentityCard'; From f9a5c9a7c85ec16abb32cab2ef770abb23b33308 Mon Sep 17 00:00:00 2001 From: Kiss Miklos Date: Mon, 13 Jun 2022 10:22:58 +0200 Subject: [PATCH 6/8] update api-report Signed-off-by: Kiss Miklos --- plugins/user-settings/api-report.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/user-settings/api-report.md b/plugins/user-settings/api-report.md index db98f54a90..9db9f5f91b 100644 --- a/plugins/user-settings/api-report.md +++ b/plugins/user-settings/api-report.md @@ -71,6 +71,11 @@ export const UserSettingsFeatureFlags: () => JSX.Element; // @public (undocumented) export const UserSettingsGeneral: () => JSX.Element; +// Warning: (ae-missing-release-tag) "UserSettingsIdentityCard" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export const UserSettingsIdentityCard: () => JSX.Element; + // Warning: (ae-missing-release-tag) "UserSettingsMenu" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) From ae2adaff8ed07156633bfcb74b2b423a3d50d5b7 Mon Sep 17 00:00:00 2001 From: Kiss Miklos Date: Mon, 13 Jun 2022 11:37:17 +0200 Subject: [PATCH 7/8] make changeset more clear Signed-off-by: Kiss Miklos --- .changeset/early-hats-rest.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/early-hats-rest.md b/.changeset/early-hats-rest.md index 6eab693200..dfe685ea77 100644 --- a/.changeset/early-hats-rest.md +++ b/.changeset/early-hats-rest.md @@ -2,4 +2,4 @@ '@backstage/plugin-user-settings': patch --- -Add UserSettingsIdentityCard to show the result of the identityApi.getBackstageIdentity() call to help debug ownership issues. +Added new `` to show the result of the `identityApi.getBackstageIdentity()` call to help debug ownership issues. The new card has been added to the user settings page. From d5962d1cc6d53be0970fb5bcea014e4633cabaf9 Mon Sep 17 00:00:00 2001 From: Kiss Miklos Date: Mon, 13 Jun 2022 11:37:37 +0200 Subject: [PATCH 8/8] update api-report.md Signed-off-by: Kiss Miklos --- plugins/user-settings/api-report.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/user-settings/api-report.md b/plugins/user-settings/api-report.md index 9db9f5f91b..a38b37846a 100644 --- a/plugins/user-settings/api-report.md +++ b/plugins/user-settings/api-report.md @@ -139,8 +139,8 @@ export const useUserProfile: () => | { profile: ProfileInfo; displayName: string; - backstageIdentity: undefined; loading: boolean; + backstageIdentity?: undefined; } | { profile: ProfileInfo;