Skip to content

Commit 6382747

Browse files
committed
linters
1 parent ee4f7b2 commit 6382747

2 files changed

Lines changed: 73 additions & 67 deletions

File tree

src/components/pulp-about-modal.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ const Value = ({ children }: { children: ReactNode }) => (
2626
interface IProps {
2727
isOpen: boolean;
2828
onClose: () => void;
29-
userName: string;
29+
username: string;
3030
}
3131

3232
interface IApplicationInfo {
3333
pulp_core_version?: string;
3434
}
3535

36-
export const PulpAboutModal = ({ isOpen, onClose, userName }: IProps) => {
36+
export const PulpAboutModal = ({ isOpen, onClose, username }: IProps) => {
3737
const [applicationInfo, setApplicationInfo] = useState<IApplicationInfo>({});
3838

3939
useEffect(() => {
@@ -54,7 +54,7 @@ export const PulpAboutModal = ({ isOpen, onClose, userName }: IProps) => {
5454
const ui_extra = config.EXTRA_VERSION;
5555

5656
// FIXME
57-
const user = { username: userName, id: null, groups: [] };
57+
const user = { username, id: null, groups: [] };
5858

5959
return (
6060
<AboutModal
@@ -115,10 +115,10 @@ export const PulpAboutModal = ({ isOpen, onClose, userName }: IProps) => {
115115
? formatPath(Paths.core.user.detail, { user_id: user.id })
116116
: null
117117
}
118-
title={userName}
118+
title={username}
119119
>
120-
{userName}
121-
{user?.username && user.username !== userName ? (
120+
{username}
121+
{user?.username && user.username !== username ? (
122122
<> ({user.username})</>
123123
) : null}
124124
</MaybeLink>

src/layout.tsx

Lines changed: 67 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -31,38 +31,12 @@ import { StandaloneMenu } from './menu';
3131
import { Paths, formatPath } from './paths';
3232
import { useUserContext } from './user-context';
3333

34-
export const StandaloneLayout = ({ children }: { children: ReactNode }) => {
35-
const [aboutModalVisible, setAboutModalVisible] = useState<boolean>(false);
36-
const { getUsername, clearCredentials } = useUserContext();
37-
38-
const userName = getUsername();
39-
let aboutModal = null;
40-
let docsDropdownItems = [];
41-
let userDropdownItems = [];
42-
43-
if (userName) {
44-
userDropdownItems = [
45-
<DropdownItem isDisabled key='username'>
46-
<Trans>Username: {userName}</Trans>
47-
</DropdownItem>,
48-
<DropdownSeparator key='separator' />,
49-
<DropdownItem
50-
key='profile'
51-
component={
52-
<Link to={formatPath(Paths.core.user.profile)}>{t`My profile`}</Link>
53-
}
54-
/>,
55-
56-
<DropdownItem
57-
key='logout'
58-
aria-label={'logout'}
59-
onClick={() => clearCredentials()}
60-
>
61-
{t`Logout`}
62-
</DropdownItem>,
63-
];
64-
65-
docsDropdownItems = [
34+
const DocsDropdown = ({ showAbout }: { showAbout: () => void }) => (
35+
<StatefulDropdown
36+
ariaLabel={t`Docs dropdown`}
37+
data-cy='docs-dropdown'
38+
defaultText={<QuestionCircleIcon />}
39+
items={[
6640
<DropdownItem
6741
key='documentation'
6842
component={
@@ -72,19 +46,56 @@ export const StandaloneLayout = ({ children }: { children: ReactNode }) => {
7246
>{t`Documentation`}</ExternalLink>
7347
}
7448
/>,
75-
<DropdownItem key='about' onClick={() => setAboutModalVisible(true)}>
49+
<DropdownItem key='about' onClick={() => showAbout()}>
7650
{t`About`}
7751
</DropdownItem>,
78-
].filter(Boolean);
52+
]}
53+
toggleType='icon'
54+
/>
55+
);
7956

80-
aboutModal = (
81-
<PulpAboutModal
82-
isOpen={aboutModalVisible}
83-
onClose={() => setAboutModalVisible(false)}
84-
userName={userName}
85-
/>
86-
);
87-
}
57+
const UserDropdown = ({
58+
username,
59+
clearCredentials,
60+
}: {
61+
username?: string;
62+
clearCredentials: () => void;
63+
}) =>
64+
username ? (
65+
<StatefulDropdown
66+
ariaLabel={t`User dropdown`}
67+
data-cy='user-dropdown'
68+
defaultText={username}
69+
items={[
70+
<DropdownItem isDisabled key='username'>
71+
<Trans>Username: {username}</Trans>
72+
</DropdownItem>,
73+
<DropdownSeparator key='separator' />,
74+
<DropdownItem
75+
key='profile'
76+
component={
77+
<Link
78+
to={formatPath(Paths.core.user.profile)}
79+
>{t`My profile`}</Link>
80+
}
81+
/>,
82+
<DropdownItem
83+
key='logout'
84+
aria-label={'logout'}
85+
onClick={() => clearCredentials()}
86+
>
87+
{t`Logout`}
88+
</DropdownItem>,
89+
]}
90+
toggleType='dropdown'
91+
/>
92+
) : null;
93+
94+
export const StandaloneLayout = ({ children }: { children: ReactNode }) => {
95+
const [aboutModalVisible, setAboutModalVisible] = useState<boolean>(false);
96+
const { getUsername, clearCredentials } = useUserContext();
97+
98+
const username = getUsername();
8899

89100
const Header = (
90101
<Masthead>
@@ -103,33 +114,22 @@ export const StandaloneLayout = ({ children }: { children: ReactNode }) => {
103114
padding: '9px 0 0 4px',
104115
}}
105116
>
106-
Pulp UI
117+
{APPLICATION_NAME}
107118
</span>
108119
</MastheadBrand>
109120
</MastheadMain>
110121
<MastheadContent>
111122
<span style={{ flexGrow: 1 }} />
112123
<DarkmodeSwitcher />
113124
<LanguageSwitcher />
114-
{credentials ? (
115-
<StatefulDropdown
116-
ariaLabel={t`Docs dropdown`}
117-
data-cy='docs-dropdown'
118-
defaultText={<QuestionCircleIcon />}
119-
items={docsDropdownItems}
120-
toggleType='icon'
125+
<DocsDropdown showAbout={() => setAboutModalVisible(true)} />
126+
{username ? (
127+
<UserDropdown
128+
clearCredentials={clearCredentials}
129+
username={username}
121130
/>
122-
) : null}
123-
{!credentials ? (
124-
<LoginLink />
125131
) : (
126-
<StatefulDropdown
127-
ariaLabel={t`User dropdown`}
128-
data-cy='user-dropdown'
129-
defaultText={userName}
130-
items={userDropdownItems}
131-
toggleType='dropdown'
132-
/>
132+
<LoginLink />
133133
)}
134134
</MastheadContent>
135135
</Masthead>
@@ -146,7 +146,13 @@ export const StandaloneLayout = ({ children }: { children: ReactNode }) => {
146146
return (
147147
<Page isManagedSidebar header={Header} sidebar={Sidebar}>
148148
{children}
149-
{aboutModalVisible && aboutModal}
149+
{aboutModalVisible ? (
150+
<PulpAboutModal
151+
isOpen
152+
onClose={() => setAboutModalVisible(false)}
153+
username={username}
154+
/>
155+
) : null}
150156
</Page>
151157
);
152158
};

0 commit comments

Comments
 (0)