- Notifications
You must be signed in to change notification settings - Fork926
feat: add license settings UI#7210
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
22 commits Select commitHold shift + click to select a range
d1e0377
wip: license page
rodrimaia16e0a5c
WIP
rodrimaia432456f
WIP
rodrimaiaa26bdc1
wip
rodrimaia496f535
wip
rodrimaiabcb5d9a
wip
rodrimaia7adf2f1
wip
rodrimaia8ece196
wip
rodrimaia3774944
wip
rodrimaia5b782ce
Apply suggestions from code review
rodrimaiaeaba405
wip: ui improvements
rodrimaia1d107d8
Merge branch 'main' into add_license_settings
rodrimaiaee583e1
wip: extract components
rodrimaia21a610e
wip: stories
rodrimaiafba262c
wip: stories
rodrimaia0922b5b
fixes from PR reviews
rodrimaia6ab9d3e
fix stories
rodrimaia8d55d98
fix empty license page
rodrimaia832f599
fix copy
rodrimaiac3a1141
fix
rodrimaia16a8445
wip
rodrimaia0322172
add golang test
rodrimaiaFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletionsenterprise/coderd/license/license.go
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 |
---|---|---|
@@ -52,6 +52,13 @@ func Entitlements( | ||
return entitlements, xerrors.Errorf("query active user count: %w", err) | ||
} | ||
// always shows active user count regardless of license | ||
rodrimaia marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
entitlements.Features[codersdk.FeatureUserLimit] = codersdk.Feature{ | ||
Entitlement: codersdk.EntitlementNotEntitled, | ||
Enabled: enablements[codersdk.FeatureUserLimit], | ||
Actual: &activeUserCount, | ||
} | ||
allFeatures := false | ||
// Here we loop through licenses to detect enabled features. | ||
9 changes: 9 additions & 0 deletionsenterprise/coderd/license/license_test.go
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
2 changes: 2 additions & 0 deletionssite/package.json
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
13 changes: 13 additions & 0 deletionssite/src/AppRouter.tsx
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
31 changes: 31 additions & 0 deletionssite/src/api/api.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 |
---|---|---|
@@ -965,6 +965,37 @@ export const getWorkspaceBuildParameters = async ( | ||
) | ||
return response.data | ||
} | ||
type Claims = { | ||
license_expires?: jwt.NumericDate | ||
account_type?: string | ||
account_id?: string | ||
trial: boolean | ||
all_features: boolean | ||
version: number | ||
features: Record<string, number> | ||
require_telemetry?: boolean | ||
} | ||
export type GetLicensesResponse = Omit<TypesGen.License, "claims"> & { | ||
claims: Claims | ||
expires_at: string | ||
} | ||
rodrimaia marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
export const getLicenses = async (): Promise<GetLicensesResponse[]> => { | ||
const response = await axios.get(`/api/v2/licenses`) | ||
return response.data | ||
} | ||
export const createLicense = async ( | ||
data: TypesGen.AddLicenseRequest, | ||
): Promise<TypesGen.AddLicenseRequest> => { | ||
const response = await axios.post(`/api/v2/licenses`, data) | ||
return response.data | ||
} | ||
export const removeLicense = async (licenseId: number): Promise<void> => { | ||
await axios.delete(`/api/v2/licenses/${licenseId}`) | ||
} | ||
rodrimaia marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
export class MissingBuildParameters extends Error { | ||
parameters: TypesGen.TemplateVersionParameter[] = [] | ||
7 changes: 7 additions & 0 deletionssite/src/components/DeploySettingsLayout/Sidebar.tsx
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
178 changes: 178 additions & 0 deletionssite/src/components/FileUpload/FileUpload.tsx
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,178 @@ | ||
import { makeStyles } from "@material-ui/core/styles" | ||
import { Stack } from "components/Stack/Stack" | ||
import { FC, DragEvent, useRef, ReactNode } from "react" | ||
import UploadIcon from "@material-ui/icons/CloudUploadOutlined" | ||
import { useClickable } from "hooks/useClickable" | ||
import CircularProgress from "@material-ui/core/CircularProgress" | ||
import { combineClasses } from "utils/combineClasses" | ||
import IconButton from "@material-ui/core/IconButton" | ||
import RemoveIcon from "@material-ui/icons/DeleteOutline" | ||
import FileIcon from "@material-ui/icons/FolderOutlined" | ||
const useFileDrop = ( | ||
callback: (file: File) => void, | ||
fileTypeRequired?: string, | ||
): { | ||
onDragOver: (e: DragEvent<HTMLDivElement>) => void | ||
onDrop: (e: DragEvent<HTMLDivElement>) => void | ||
} => { | ||
const onDragOver = (e: DragEvent<HTMLDivElement>) => { | ||
e.preventDefault() | ||
} | ||
const onDrop = (e: DragEvent<HTMLDivElement>) => { | ||
e.preventDefault() | ||
const file = e.dataTransfer.files[0] | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- file can be undefined | ||
if (!file) { | ||
return | ||
} | ||
if (fileTypeRequired && file.type !== fileTypeRequired) { | ||
return | ||
} | ||
callback(file) | ||
} | ||
return { | ||
onDragOver, | ||
onDrop, | ||
} | ||
} | ||
export interface FileUploadProps { | ||
isUploading: boolean | ||
onUpload: (file: File) => void | ||
onRemove?: () => void | ||
file?: File | ||
removeLabel: string | ||
title: string | ||
description?: ReactNode | ||
extension?: string | ||
fileTypeRequired?: string | ||
} | ||
export const FileUpload: FC<FileUploadProps> = ({ | ||
isUploading, | ||
onUpload, | ||
onRemove, | ||
file, | ||
removeLabel, | ||
title, | ||
description, | ||
extension, | ||
fileTypeRequired, | ||
}) => { | ||
const styles = useStyles() | ||
const inputRef = useRef<HTMLInputElement>(null) | ||
const tarDrop = useFileDrop(onUpload, fileTypeRequired) | ||
const clickable = useClickable(() => { | ||
if (inputRef.current) { | ||
inputRef.current.click() | ||
} | ||
}) | ||
if (!isUploading && file) { | ||
return ( | ||
<Stack | ||
className={styles.file} | ||
direction="row" | ||
justifyContent="space-between" | ||
alignItems="center" | ||
> | ||
<Stack direction="row" alignItems="center"> | ||
<FileIcon /> | ||
<span>{file.name}</span> | ||
</Stack> | ||
<IconButton title={removeLabel} size="small" onClick={onRemove}> | ||
<RemoveIcon /> | ||
</IconButton> | ||
</Stack> | ||
) | ||
} | ||
return ( | ||
<> | ||
<div | ||
className={combineClasses({ | ||
[styles.root]: true, | ||
[styles.disabled]: isUploading, | ||
})} | ||
{...clickable} | ||
{...tarDrop} | ||
> | ||
<Stack alignItems="center" spacing={1}> | ||
{isUploading ? ( | ||
<CircularProgress size={32} /> | ||
) : ( | ||
<UploadIcon className={styles.icon} /> | ||
)} | ||
<Stack alignItems="center" spacing={0.5}> | ||
<span className={styles.title}>{title}</span> | ||
<span className={styles.description}>{description}</span> | ||
</Stack> | ||
</Stack> | ||
</div> | ||
<input | ||
type="file" | ||
ref={inputRef} | ||
className={styles.input} | ||
accept={extension} | ||
onChange={(event) => { | ||
const file = event.currentTarget.files?.[0] | ||
if (file) { | ||
onUpload(file) | ||
} | ||
}} | ||
/> | ||
</> | ||
) | ||
} | ||
const useStyles = makeStyles((theme) => ({ | ||
root: { | ||
display: "flex", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
borderRadius: theme.shape.borderRadius, | ||
border: `2px dashed ${theme.palette.divider}`, | ||
padding: theme.spacing(6), | ||
cursor: "pointer", | ||
"&:hover": { | ||
backgroundColor: theme.palette.background.paper, | ||
}, | ||
}, | ||
disabled: { | ||
pointerEvents: "none", | ||
opacity: 0.75, | ||
}, | ||
icon: { | ||
fontSize: theme.spacing(8), | ||
}, | ||
title: { | ||
fontSize: theme.spacing(2), | ||
}, | ||
description: { | ||
color: theme.palette.text.secondary, | ||
textAlign: "center", | ||
maxWidth: theme.spacing(50), | ||
}, | ||
input: { | ||
display: "none", | ||
}, | ||
file: { | ||
borderRadius: theme.shape.borderRadius, | ||
border: `1px solid ${theme.palette.divider}`, | ||
padding: theme.spacing(2), | ||
background: theme.palette.background.paper, | ||
}, | ||
})) |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
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.