Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UBP] Pagination and UI fixes #11481

Merged
merged 1 commit into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion components/dashboard/src/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,17 @@ export default function Menu() {
link: `/t/${team.slug}/members`,
},
];
if (showUsageBasedUI) {
teamSettingsList.push({
title: "Usage",
link: `/t/${team.slug}/usage`,
});
}
if (currentUserInTeam?.role === "owner") {
teamSettingsList.push({
title: "Settings",
link: `/t/${team.slug}/settings`,
alternatives: getTeamSettingsMenu({ team, showPaymentUI, showUsageBasedUI }).flatMap((e) => e.link),
alternatives: getTeamSettingsMenu({ team, showPaymentUI }).flatMap((e) => e.link),
});
}

Expand Down
16 changes: 13 additions & 3 deletions components/dashboard/src/components/Arrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@
* See License-AGPL.txt in the project root for license information.
*/

function Arrow(props: { up: boolean; customBorderClasses?: string }) {
function Arrow(props: { direction: string; customBorderClasses?: string }) {
const { direction, customBorderClasses } = props;

// Using any because of known TS bug with bracket notation:
// https://github.com/microsoft/TypeScript/issues/10530
const directionMap: any = {
up: "-135deg",
down: "45deg",
left: "135deg",
right: "315deg",
};
return (
<span
className={
"mx-2 " +
(props.customBorderClasses ||
(customBorderClasses ||
"border-gray-400 dark:border-gray-500 group-hover:border-gray-600 dark:group-hover:border-gray-400")
}
style={{
Expand All @@ -18,7 +28,7 @@ function Arrow(props: { up: boolean; customBorderClasses?: string }) {
padding: 3,
borderWidth: "0 2px 2px 0",
display: "inline-block",
transform: `rotate(${props.up ? "-135deg" : "45deg"})`,
transform: `rotate(${directionMap[direction]})`,
}}
></span>
);
Expand Down
2 changes: 1 addition & 1 deletion components/dashboard/src/components/DropDown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function DropDown(props: DropDownProps) {
>
{props.prefix}
{current}
<Arrow up={false} customBorderClasses={props.renderAsLink ? asLinkArrowBorder : undefined} />
<Arrow direction={"down"} customBorderClasses={props.renderAsLink ? asLinkArrowBorder : undefined} />
</span>
</ContextMenu>
);
Expand Down
50 changes: 50 additions & 0 deletions components/dashboard/src/components/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License-AGPL.txt in the project root for license information.
*/

import Arrow from "./Arrow";

function Pagination(props: { numberOfPages: number; currentPage: number; setCurrentPage: any }) {
const { numberOfPages, currentPage, setCurrentPage } = props;
const availablePageNumbers = [...Array(numberOfPages + 1).keys()].slice(1);

const nextPage = () => {
if (currentPage !== numberOfPages) setCurrentPage(currentPage + 1);
};
const prevPage = () => {
if (currentPage !== 1) setCurrentPage(currentPage - 1);
};

return (
<nav className="mt-16">
<ul className="flex justify-center space-x-4">
<li className="text-gray-400 cursor-pointer">
<span onClick={prevPage}>
<Arrow direction={"left"} />
Previous
</span>
</li>
{availablePageNumbers.map((pn) => (
<li
key={pn}
className={`text-gray-500 cursor-pointer w-8 text-center rounded-md ${
currentPage === pn ? "bg-gray-200" : ""
} `}
>
<span onClick={() => setCurrentPage(pn)}>{pn}</span>
</li>
))}
<li className="text-gray-400 cursor-pointer">
<span onClick={nextPage}>
Next
<Arrow direction={"right"} />
</span>
</li>
</ul>
</nav>
);
}

export default Pagination;
1 change: 1 addition & 0 deletions components/dashboard/src/images/credits.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion components/dashboard/src/start/StartWorkspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps,
>
<button className="secondary">
More Actions...
<Arrow up={false} />
<Arrow direction={"down"} />
</button>
</ContextMenu>
<button
Expand Down
4 changes: 2 additions & 2 deletions components/dashboard/src/teams/TeamBilling.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function TeamBilling() {
const team = getCurrentTeam(location, teams);
const [members, setMembers] = useState<TeamMemberInfo[]>([]);
const [teamSubscription, setTeamSubscription] = useState<TeamSubscription2 | undefined>();
const { showPaymentUI, showUsageBasedUI, currency, setCurrency } = useContext(PaymentContext);
const { showPaymentUI, currency, setCurrency } = useContext(PaymentContext);
const [pendingTeamPlan, setPendingTeamPlan] = useState<PendingPlan | undefined>();
const [pollTeamSubscriptionTimeout, setPollTeamSubscriptionTimeout] = useState<NodeJS.Timeout | undefined>();

Expand Down Expand Up @@ -140,7 +140,7 @@ export default function TeamBilling() {

return (
<PageWithSubMenu
subMenu={getTeamSettingsMenu({ team, showPaymentUI, showUsageBasedUI })}
subMenu={getTeamSettingsMenu({ team, showPaymentUI })}
title="Billing"
subtitle="Manage team billing and plans."
>
Expand Down
16 changes: 4 additions & 12 deletions components/dashboard/src/teams/TeamSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { getGitpodService, gitpodHostUrl } from "../service/service";
import { UserContext } from "../user-context";
import { getCurrentTeam, TeamsContext } from "./teams-context";

export function getTeamSettingsMenu(params: { team?: Team; showPaymentUI?: boolean; showUsageBasedUI?: boolean }) {
const { team, showPaymentUI, showUsageBasedUI } = params;
export function getTeamSettingsMenu(params: { team?: Team; showPaymentUI?: boolean }) {
const { team, showPaymentUI } = params;
return [
{
title: "General",
Expand All @@ -30,14 +30,6 @@ export function getTeamSettingsMenu(params: { team?: Team; showPaymentUI?: boole
},
]
: []),
...(showUsageBasedUI
? [
{
title: "Usage",
link: [`/t/${team?.slug}/usage`],
},
]
: []),
];
}

Expand All @@ -49,7 +41,7 @@ export default function TeamSettings() {
const { user } = useContext(UserContext);
const location = useLocation();
const team = getCurrentTeam(location, teams);
const { showPaymentUI, showUsageBasedUI } = useContext(PaymentContext);
const { showPaymentUI } = useContext(PaymentContext);

const close = () => setModal(false);

Expand All @@ -76,7 +68,7 @@ export default function TeamSettings() {
return (
<>
<PageWithSubMenu
subMenu={getTeamSettingsMenu({ team, showPaymentUI, showUsageBasedUI })}
subMenu={getTeamSettingsMenu({ team, showPaymentUI })}
title="Settings"
subtitle="Manage general team settings."
>
Expand Down
Loading