Skip to content

Commit

Permalink
linters
Browse files Browse the repository at this point in the history
  • Loading branch information
himdel committed Oct 28, 2024
1 parent ee4f7b2 commit 6382747
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 67 deletions.
12 changes: 6 additions & 6 deletions src/components/pulp-about-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ const Value = ({ children }: { children: ReactNode }) => (
interface IProps {
isOpen: boolean;
onClose: () => void;
userName: string;
username: string;
}

interface IApplicationInfo {
pulp_core_version?: string;
}

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

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

// FIXME
const user = { username: userName, id: null, groups: [] };
const user = { username, id: null, groups: [] };

return (
<AboutModal
Expand Down Expand Up @@ -115,10 +115,10 @@ export const PulpAboutModal = ({ isOpen, onClose, userName }: IProps) => {
? formatPath(Paths.core.user.detail, { user_id: user.id })
: null
}
title={userName}
title={username}
>
{userName}
{user?.username && user.username !== userName ? (
{username}
{user?.username && user.username !== username ? (
<> ({user.username})</>
) : null}
</MaybeLink>
Expand Down
128 changes: 67 additions & 61 deletions src/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,12 @@ import { StandaloneMenu } from './menu';
import { Paths, formatPath } from './paths';
import { useUserContext } from './user-context';

export const StandaloneLayout = ({ children }: { children: ReactNode }) => {
const [aboutModalVisible, setAboutModalVisible] = useState<boolean>(false);
const { getUsername, clearCredentials } = useUserContext();

const userName = getUsername();
let aboutModal = null;
let docsDropdownItems = [];
let userDropdownItems = [];

if (userName) {
userDropdownItems = [
<DropdownItem isDisabled key='username'>
<Trans>Username: {userName}</Trans>
</DropdownItem>,
<DropdownSeparator key='separator' />,
<DropdownItem
key='profile'
component={
<Link to={formatPath(Paths.core.user.profile)}>{t`My profile`}</Link>
}
/>,

<DropdownItem
key='logout'
aria-label={'logout'}
onClick={() => clearCredentials()}
>
{t`Logout`}
</DropdownItem>,
];

docsDropdownItems = [
const DocsDropdown = ({ showAbout }: { showAbout: () => void }) => (
<StatefulDropdown
ariaLabel={t`Docs dropdown`}
data-cy='docs-dropdown'
defaultText={<QuestionCircleIcon />}
items={[
<DropdownItem
key='documentation'
component={
Expand All @@ -72,19 +46,56 @@ export const StandaloneLayout = ({ children }: { children: ReactNode }) => {
>{t`Documentation`}</ExternalLink>
}
/>,
<DropdownItem key='about' onClick={() => setAboutModalVisible(true)}>
<DropdownItem key='about' onClick={() => showAbout()}>
{t`About`}
</DropdownItem>,
].filter(Boolean);
]}
toggleType='icon'
/>
);

aboutModal = (
<PulpAboutModal
isOpen={aboutModalVisible}
onClose={() => setAboutModalVisible(false)}
userName={userName}
/>
);
}
const UserDropdown = ({
username,
clearCredentials,
}: {
username?: string;
clearCredentials: () => void;
}) =>
username ? (
<StatefulDropdown
ariaLabel={t`User dropdown`}
data-cy='user-dropdown'
defaultText={username}
items={[
<DropdownItem isDisabled key='username'>
<Trans>Username: {username}</Trans>
</DropdownItem>,
<DropdownSeparator key='separator' />,
<DropdownItem
key='profile'
component={
<Link
to={formatPath(Paths.core.user.profile)}
>{t`My profile`}</Link>
}
/>,
<DropdownItem
key='logout'
aria-label={'logout'}
onClick={() => clearCredentials()}
>
{t`Logout`}
</DropdownItem>,
]}
toggleType='dropdown'
/>
) : null;

export const StandaloneLayout = ({ children }: { children: ReactNode }) => {
const [aboutModalVisible, setAboutModalVisible] = useState<boolean>(false);
const { getUsername, clearCredentials } = useUserContext();

const username = getUsername();

const Header = (
<Masthead>
Expand All @@ -103,33 +114,22 @@ export const StandaloneLayout = ({ children }: { children: ReactNode }) => {
padding: '9px 0 0 4px',
}}
>
Pulp UI
{APPLICATION_NAME}
</span>
</MastheadBrand>
</MastheadMain>
<MastheadContent>
<span style={{ flexGrow: 1 }} />
<DarkmodeSwitcher />
<LanguageSwitcher />
{credentials ? (
<StatefulDropdown
ariaLabel={t`Docs dropdown`}
data-cy='docs-dropdown'
defaultText={<QuestionCircleIcon />}
items={docsDropdownItems}
toggleType='icon'
<DocsDropdown showAbout={() => setAboutModalVisible(true)} />
{username ? (
<UserDropdown
clearCredentials={clearCredentials}
username={username}
/>
) : null}
{!credentials ? (
<LoginLink />
) : (
<StatefulDropdown
ariaLabel={t`User dropdown`}
data-cy='user-dropdown'
defaultText={userName}
items={userDropdownItems}
toggleType='dropdown'
/>
<LoginLink />
)}
</MastheadContent>
</Masthead>
Expand All @@ -146,7 +146,13 @@ export const StandaloneLayout = ({ children }: { children: ReactNode }) => {
return (
<Page isManagedSidebar header={Header} sidebar={Sidebar}>
{children}
{aboutModalVisible && aboutModal}
{aboutModalVisible ? (
<PulpAboutModal
isOpen
onClose={() => setAboutModalVisible(false)}
username={username}
/>
) : null}
</Page>
);
};

0 comments on commit 6382747

Please sign in to comment.