-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add nav items and icons to org selector #16353
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Copyright (c) 2023 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 classNames from "classnames"; | ||
import { FunctionComponent } from "react"; | ||
import { consistentClassname } from "./consistent-classname"; | ||
import "./styles.css"; | ||
|
||
const SIZE_CLASSES = { | ||
small: "w-6 h-6", | ||
medium: "w-10 h-10", | ||
}; | ||
|
||
const TEXT_SIZE_CLASSES = { | ||
small: "text-sm", | ||
medium: "text-xl", | ||
}; | ||
|
||
type Props = { | ||
id: string; | ||
name: string; | ||
size?: keyof typeof SIZE_CLASSES; | ||
className?: string; | ||
}; | ||
export const OrgIcon: FunctionComponent<Props> = ({ id, name, size = "medium", className }) => { | ||
const logoBGClass = consistentClassname(id); | ||
const initials = getOrgInitials(name); | ||
const sizeClasses = SIZE_CLASSES[size]; | ||
const textClass = TEXT_SIZE_CLASSES[size]; | ||
|
||
return ( | ||
<div | ||
className={classNames("rounded-full flex items-center justify-center", sizeClasses, logoBGClass, className)} | ||
> | ||
<span className={`text-white font-semibold ${textClass}`}>{initials}</span> | ||
</div> | ||
); | ||
}; | ||
|
||
function getOrgInitials(name: string) { | ||
// If for some reason there is no name, default to G for Gitpod | ||
return (name || "G").charAt(0).toLocaleUpperCase(); | ||
} |
54 changes: 54 additions & 0 deletions
54
components/dashboard/src/components/org-icon/consistent-classname.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Copyright (c) 2023 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 { BG_CLASSES, consistentClassname } from "./consistent-classname"; | ||
|
||
describe("consistentClassname()", () => { | ||
test("empty string", () => { | ||
const id = ""; | ||
const cn = consistentClassname(id); | ||
|
||
expect(cn).toEqual(BG_CLASSES[0]); | ||
}); | ||
|
||
test("max value", () => { | ||
const id = "ffffffffffffffffffffffffffffffff"; | ||
const cn = consistentClassname(id); | ||
|
||
expect(cn).toEqual(BG_CLASSES[BG_CLASSES.length - 1]); | ||
}); | ||
|
||
test("with an id value", () => { | ||
const id = "c5895528-23ac-4ebd-9d8b-464228d5755f"; | ||
const cn = consistentClassname(id); | ||
|
||
expect(BG_CLASSES).toContain(cn); | ||
}); | ||
|
||
test("with an id value without hyphens", () => { | ||
const id = "c589552823ac4ebd9d8b464228d5755f"; | ||
const cn = consistentClassname(id); | ||
|
||
expect(BG_CLASSES).toContain(cn); | ||
}); | ||
|
||
test("with a shorter id value", () => { | ||
const id = "c5895528"; | ||
const cn = consistentClassname(id); | ||
|
||
expect(BG_CLASSES).toContain(cn); | ||
}); | ||
|
||
test("returns the same classname for the same value", () => { | ||
const id = "c5895528-23ac-4ebd-9d8b-464228d5755f"; | ||
const cn1 = consistentClassname(id); | ||
const cn2 = consistentClassname(id); | ||
|
||
expect(cn1).toEqual(cn2); | ||
expect(BG_CLASSES).toContain(cn1); | ||
expect(BG_CLASSES).toContain(cn2); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
components/dashboard/src/components/org-icon/consistent-classname.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Copyright (c) 2023 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. | ||
*/ | ||
|
||
// Represents the max value our base16 guid can be, 32 "f"s | ||
const GUID_MAX = "".padEnd(32, "f"); | ||
gtsiolis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export const BG_CLASSES = [ | ||
"bg-gradient-1", | ||
"bg-gradient-2", | ||
"bg-gradient-3", | ||
"bg-gradient-4", | ||
"bg-gradient-5", | ||
"bg-gradient-6", | ||
"bg-gradient-7", | ||
"bg-gradient-8", | ||
"bg-gradient-9", | ||
]; | ||
|
||
export const consistentClassname = (id: string) => { | ||
// Turn id into a 32 char. guid, pad with "0" if it's not 32 chars already | ||
const guid = id.replaceAll("-", "").substring(0, 32).padEnd(32, "0"); | ||
|
||
// Map guid into a 0,1 range by dividing by the max guid | ||
var quotient = parseInt(guid, 16) / parseInt(GUID_MAX, 16); | ||
var idx = Math.floor(quotient * (BG_CLASSES.length - 1)); | ||
|
||
return BG_CLASSES[idx]; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright (c) 2023 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. | ||
*/ | ||
|
||
|
||
@layer components { | ||
.bg-gradient-1 { | ||
background: linear-gradient(45deg, theme('colors.orange.500') 25%, theme('colors.orange.300') 75%); | ||
} | ||
.bg-gradient-2 { | ||
background: linear-gradient(45deg, theme('colors.orange.500') 25%, theme('colors.pink.800') 75%); | ||
} | ||
.bg-gradient-3 { | ||
background: linear-gradient(45deg, theme('colors.orange.500') 25%, theme('colors.red.500') 75%); | ||
} | ||
.bg-gradient-4 { | ||
background: linear-gradient(45deg, theme('colors.orange.500') 25%, theme('colors.green.700') 75%); | ||
} | ||
.bg-gradient-5 { | ||
background: linear-gradient(45deg, theme('colors.orange.500') 25%, theme('colors.yellow.300') 75%); | ||
} | ||
.bg-gradient-6 { | ||
background: linear-gradient(45deg, theme('colors.orange.500') 25%, theme('colors.indigo.700') 75%); | ||
} | ||
.bg-gradient-7 { | ||
background: linear-gradient(45deg, theme('colors.orange.500') 25%, theme('colors.teal.500') 75%); | ||
} | ||
.bg-gradient-8 { | ||
background: linear-gradient(45deg, theme('colors.orange.500') 25%, theme('colors.sky.900') 75%); | ||
} | ||
.bg-gradient-9 { | ||
background: linear-gradient(45deg, theme('colors.orange.500') 25%, theme('colors.rose.300') 75%); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
components/dashboard/src/data/billing-mode/user-billing-mode-query.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Copyright (c) 2023 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 { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { getGitpodService } from "../../service/service"; | ||
import { useCurrentUser } from "../../user-context"; | ||
|
||
type UserBillingModeQueryResult = BillingMode; | ||
|
||
export const useUserBillingMode = () => { | ||
const user = useCurrentUser(); | ||
|
||
return useQuery<UserBillingModeQueryResult>({ | ||
queryKey: getUserBillingModeQueryKey(user?.id ?? ""), | ||
queryFn: async () => { | ||
if (!user) { | ||
throw new Error("No current user, cannot load billing mode"); | ||
} | ||
return await getGitpodService().server.getBillingModeForUser(); | ||
}, | ||
enabled: !!user, | ||
}); | ||
}; | ||
|
||
export const getUserBillingModeQueryKey = (userId: string) => ["billing-mode", { userId }]; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: Thanks for caring about the dark theme colors! 🌔