Skip to content

Commit

Permalink
chore: get rid of che-server APIs: /user and /profile; hide the Accou…
Browse files Browse the repository at this point in the history
…nt page.
  • Loading branch information
akurinnoy committed Oct 26, 2022
1 parent eeac13d commit 8a292d7
Show file tree
Hide file tree
Showing 26 changed files with 383 additions and 587 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,13 @@ describe('About Menu', () => {

const productCli = 'crwctl';
const email = 'johndoe@example.com';
const name = 'John Doe';
const store = createStore(productCli, name, email);
const user = {
id: 'test-id',
name: name,
email: email,
links: [],
};
const username = 'John Doe';
const store = createStore(productCli, username, email);
const branding = selectBranding(store.getState());
const userProfile = selectUserProfile(store.getState());

const component = (
<Provider store={store}>
<AboutMenu branding={branding} user={user} userProfile={userProfile} />
<AboutMenu branding={branding} username={username} />
</Provider>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import { BrandingData } from '../../../../services/bootstrap/branding.constant';

type Props = {
branding: BrandingData;
user: che.User | undefined;
userProfile: api.che.user.Profile | undefined;
username: string;
};
type State = {
isLauncherOpen: boolean;
Expand All @@ -40,26 +39,6 @@ export class AboutMenu extends React.PureComponent<Props, State> {
};
}

private getUsername(): string {
const { userProfile, user } = this.props;

let username = '';

if (userProfile && userProfile.attributes) {
if (userProfile.attributes.firstName) {
username += userProfile.attributes.firstName;
}
if (userProfile.attributes.lastName) {
username += ' ' + userProfile.attributes.lastName;
}
}
if (!username && user && user.name) {
username += user.name;
}

return username;
}

private buildLauncherItems(): React.ReactNode[] {
const branding = this.props.branding;
const items: React.ReactElement[] = [];
Expand Down Expand Up @@ -109,9 +88,9 @@ export class AboutMenu extends React.PureComponent<Props, State> {
}

public render(): React.ReactElement {
const { username } = this.props;
const { isLauncherOpen, isModalOpen } = this.state;

const username = this.getUsername();
const { logoFile, name, productVersion } = this.props.branding;

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,14 @@ describe('User Menu', () => {
global.open = jest.fn();

const email = 'johndoe@example.com';
const name = 'John Doe';
const store = createStore(name, email);
const username = 'John Doe';
const store = createStore(username, email);
const history = createHashHistory();
const user = {
id: 'test-id',
name: name,
email: email,
links: [],
};
const branding = selectBranding(store.getState());
const userProfile = selectUserProfile(store.getState());

const component = (
<Provider store={store}>
<UserMenu
branding={branding}
history={history}
user={user}
userProfile={userProfile}
logout={mockLogout}
/>
<UserMenu branding={branding} history={history} username={username} logout={mockLogout} />
</Provider>
);

Expand All @@ -79,17 +66,17 @@ describe('User Menu', () => {
it('should open the dropdown', () => {
render(component);

const menuButton = screen.getByRole('button', { name });
const menuButton = screen.getByRole('button', { name: username });
fireEvent.click(menuButton);

const items = screen.getAllByRole('menuitem');
expect(items.length).toEqual(3);
expect(items.length).toEqual(2);
});

it('should fire the logout event', () => {
render(component);

const menuButton = screen.getByRole('button', { name });
const menuButton = screen.getByRole('button', { name: username });
fireEvent.click(menuButton);

const logoutItem = screen.getByRole('menuitem', { name: /logout/i });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import { BrandingData } from '../../../../services/bootstrap/branding.constant';
type Props = MappedProps & {
branding: BrandingData;
history: History;
user: che.User | undefined;
userProfile: api.che.user.Profile | undefined;
username: string;
logout: () => void;
};
type State = {
Expand Down Expand Up @@ -54,35 +53,16 @@ export class UserMenu extends React.PureComponent<Props, State> {
});
}

private getUsername(): string {
const { userProfile, user } = this.props;

let username = '';

if (userProfile && userProfile.attributes) {
if (userProfile.attributes.firstName) {
username += userProfile.attributes.firstName;
}
if (userProfile.attributes.lastName) {
username += ' ' + userProfile.attributes.lastName;
}
}
if (!username && user && user.name) {
username += user.name;
}

return username;
}

private buildUserDropdownItems(): Array<React.ReactElement> {
return [
<DropdownItem
key="user-account"
component="button"
onClick={() => this.props.history.push(ROUTE.USER_ACCOUNT)}
>
Account
</DropdownItem>,
// temporary hidden, https://github.com/eclipse/che/issues/21595
// <DropdownItem
// key="user-account"
// component="button"
// onClick={() => this.props.history.push(ROUTE.USER_ACCOUNT)}
// >
// Account
// </DropdownItem>,
<DropdownItem
key="user-preferences"
component="button"
Expand All @@ -97,7 +77,7 @@ export class UserMenu extends React.PureComponent<Props, State> {
}

private buildUserToggleButton(): React.ReactElement {
const username = this.getUsername();
const username = this.props.username;
return (
<DropdownToggle onToggle={isOpen => this.onUsernameButtonToggle(isOpen)}>
{username}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ exports[`Page header tools should correctly render the component 1`] = `
onKeyDown={[Function]}
type="button"
>
<span
className="pf-c-dropdown__toggle-text"
>
John Doe
</span>
<span
className="pf-c-dropdown__toggle-icon"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,10 @@ describe('Page header tools', () => {
const name = 'John Doe';
const store = createStore(productCli, name, email);
const history = createHashHistory();
const user = {
id: 'test-id',
name: name,
email: email,
links: [],
};

const component = (
<Provider store={store}>
<HeaderTools history={history} user={user} logout={mockLogout} />
<HeaderTools history={history} logout={mockLogout} />
</Provider>
);

Expand Down
17 changes: 6 additions & 11 deletions packages/dashboard-frontend/src/Layout/Header/Tools/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { selectApplications } from '../../../store/ClusterInfo/selectors';

type Props = MappedProps & {
history: History;
user: che.User | undefined;
logout: () => void;
};
export class HeaderTools extends React.PureComponent<Props> {
Expand All @@ -40,29 +39,25 @@ export class HeaderTools extends React.PureComponent<Props> {

public render(): React.ReactElement {
const { applications, userProfile } = this.props;
const userEmail = userProfile.email || '';
const imageUrl = userEmail ? gravatarUrl(userEmail, { default: 'retro' }) : '';
const isUserAuthenticated = !!userEmail;

const { email, username } = userProfile;
const imageUrl = email ? gravatarUrl(email, { default: 'retro' }) : '';
const isUserAuthenticated = !!email;

return (
<>
<PageHeaderTools>
<PageHeaderToolsGroup>
{applications.length !== 0 && <ApplicationsMenu applications={applications} />}
<PageHeaderToolsItem>
<AboutMenu
branding={this.props.branding}
user={this.props.user}
userProfile={this.props.userProfile}
/>
<AboutMenu branding={this.props.branding} username={username} />
</PageHeaderToolsItem>
{isUserAuthenticated && (
<PageHeaderToolsItem>
<UserMenu
branding={this.props.branding}
history={this.props.history}
user={this.props.user}
userProfile={this.props.userProfile}
username={username}
logout={() => this.props.logout()}
/>
</PageHeaderToolsItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ describe('Page header', () => {
const mockToggleNav = jest.fn();
const mockChangeTheme = jest.fn();

const user = {
email: 'johndoe@example.com',
name: 'John Doe',
} as che.User;
const logoUrl = 'branding/logo';
const isHeaderVisible = true;
const history = createHashHistory();
Expand All @@ -45,7 +41,6 @@ describe('Page header', () => {
history={history}
isVisible={isHeaderVisible}
logoUrl={logoUrl}
user={user}
logout={mockLogout}
toggleNav={mockToggleNav}
changeTheme={mockChangeTheme}
Expand Down
13 changes: 3 additions & 10 deletions packages/dashboard-frontend/src/Layout/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,16 @@
* Red Hat, Inc. - initial API and implementation
*/

import { Brand, PageHeader } from '@patternfly/react-core';
import { History } from 'history';
import React from 'react';
import { Brand, PageHeader } from '@patternfly/react-core';
import { User } from 'che';

import HeaderTools from './Tools';
import { ThemeVariant } from '../themeVariant';
import HeaderTools from './Tools';

type Props = {
history: History;
isVisible: boolean;
logoUrl: string;
user: User | undefined;
logout: () => void;
toggleNav: () => void;
changeTheme: (theme: ThemeVariant) => void;
Expand Down Expand Up @@ -65,11 +62,7 @@ export default class Header extends React.PureComponent<Props, State> {
showNavToggle={true}
onNavToggle={() => this.toggleNav()}
headerTools={
<HeaderTools
history={this.props.history}
user={this.props.user}
logout={() => this.props.logout()}
/>
<HeaderTools history={this.props.history} logout={() => this.props.logout()} />
}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ describe('PreloadIssuesAlert component', () => {
})
.withInfrastructureNamespace([], false, 'expected error 3')
.withPlugins([], false, 'expected error 4')
.withUser({} as che.User, 'expected error 5')
.withUserProfile({}, 'expected error 6')
.withUserProfile(
{
email: 'user1@che',
username: 'user1',
},
'expected error 6',
)
.withWorkspacesSettings({} as che.WorkspaceSettings, false, 'expected error 7')
.build();
renderComponent(store);
Expand All @@ -59,9 +64,6 @@ describe('PreloadIssuesAlert component', () => {
const pluginsAlert = screen.queryByRole('heading', { name: /expected error 4/i });
expect(pluginsAlert).toBeTruthy();

const userInfoAlert = screen.queryByRole('heading', { name: /expected error 5/i });
expect(userInfoAlert).toBeTruthy();

const userProfileAlert = screen.queryByRole('heading', { name: /expected error 6/i });
expect(userProfileAlert).toBeTruthy();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { selectInfrastructureNamespacesError } from '../../store/InfrastructureN
import { selectUserProfileError } from '../../store/UserProfile/selectors';
import { selectWorkspacesSettingsError } from '../../store/Workspaces/Settings/selectors';
import { selectWorkspacesError } from '../../store/Workspaces/selectors';
import { selectUserError } from '../../store/User/selectors';
import { AlertVariant } from '@patternfly/react-core';
import { lazyInject } from '../../inversify.config';
import { AppAlerts } from '../../services/alerts/appAlerts';
Expand Down Expand Up @@ -53,14 +52,6 @@ export class PreloadIssuesAlert extends React.PureComponent<Props> {
});
});
}
// user info error
if (this.props.userError) {
this.appAlerts.showAlert({
key: 'user-error',
title: this.props.userError,
variant: AlertVariant.danger,
});
}
// plugins error
if (this.props.pluginsError) {
this.appAlerts.showAlert({
Expand Down Expand Up @@ -117,7 +108,6 @@ export class PreloadIssuesAlert extends React.PureComponent<Props> {
}

const mapStateToProps = (state: AppState) => ({
userError: selectUserError(state),
registriesErrors: selectRegistriesErrors(state),
pluginsError: selectPluginsError(state),
dwDefaultEditorError: selectDwDefaultEditorError(state),
Expand Down
Loading

0 comments on commit 8a292d7

Please sign in to comment.