-
-
Notifications
You must be signed in to change notification settings - Fork 772
CDN config UI v1 #10019
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
Draft
Tymek
wants to merge
7
commits into
main
Choose a base branch
from
cdn-config-ui
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
CDN config UI v1 #10019
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* How to generate OpenAPI client | ||
* | ||
* For now we only use generated types (src/openapi/models). | ||
* Run `yarn gen:api` to generate the client. | ||
* We may use methods (src/openapi/apis) for new features in the future. | ||
*/ | ||
module.exports = { | ||
unleashApi: { | ||
output: { | ||
mode: 'tags', | ||
workspace: 'src/openapi', | ||
target: 'apis', | ||
schemas: 'models', | ||
client: 'swr', | ||
clean: true, | ||
// mock: true, | ||
override: { | ||
mutator: { | ||
path: './fetcher.ts', | ||
name: 'fetcher', | ||
}, | ||
header: () => [ | ||
'Generated by Orval', | ||
'Do not edit manually.', | ||
'See `gen:api` script in package.json', | ||
], | ||
}, | ||
}, | ||
input: { | ||
target: | ||
process.env.UNLEASH_OPENAPI_URL || | ||
'http://localhost:4242/docs/openapi.json', | ||
}, | ||
hooks: { | ||
afterAllFilesWrite: './scripts/clean_orval_generated.sh', | ||
}, | ||
}, | ||
}; |
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
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
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 |
---|---|---|
|
@@ -19,6 +19,8 @@ import { | |
CREATE_CLIENT_API_TOKEN, | ||
CREATE_FRONTEND_API_TOKEN, | ||
} from '@server/types/permissions'; | ||
import { Box } from '@mui/material'; | ||
import { ApiTokenDocs } from '../ApiTokenDocs/ApiTokenDocs.tsx'; | ||
|
||
export const ApiTokenPage = () => { | ||
const { tokens, loading, refetch } = useApiTokens(); | ||
|
@@ -96,6 +98,11 @@ export const ApiTokenPage = () => { | |
/> | ||
} | ||
> | ||
{rows.length > 0 ? ( | ||
<Box sx={{ mb: 4 }}> | ||
<ApiTokenDocs /> | ||
</Box> | ||
) : null} | ||
Comment on lines
+101
to
+105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This refactoring makes sense but I'd do it as a different PR |
||
<ApiTokenTable | ||
loading={loading} | ||
headerGroups={headerGroups} | ||
|
83 changes: 83 additions & 0 deletions
83
frontend/src/component/admin/cdn/ApiTokenDocs/ApiTokenDocs.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,83 @@ | ||
import { Alert, Box, IconButton, styled, Tooltip } from '@mui/material'; | ||
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; | ||
import CopyIcon from '@mui/icons-material/FileCopy'; | ||
import copy from 'copy-to-clipboard'; | ||
import useToast from 'hooks/useToast'; | ||
|
||
const GridContainer = styled('div')(({ theme }) => ({ | ||
display: 'grid', | ||
gridTemplateColumns: 'auto auto 1fr', | ||
gridAutoRows: 'min-content', | ||
alignItems: 'center', | ||
gap: theme.spacing(1), | ||
marginTop: theme.spacing(1.5), | ||
})); | ||
const GridItem = Box; | ||
|
||
export const ApiTokenDocs = () => { | ||
const { uiConfig } = useUiConfig(); | ||
const { setToastData } = useToast(); | ||
|
||
const onCopyToClipboard = (url: string) => () => { | ||
copy(url); | ||
setToastData({ | ||
type: 'success', | ||
text: 'Copied to clipboard', | ||
}); | ||
}; | ||
|
||
const clientApiUrl = `${uiConfig.unleashUrl}/api/`; | ||
const frontendApiUrl = `${uiConfig.unleashUrl}/api/frontend/`; | ||
|
||
return ( | ||
<Alert severity='info'> | ||
<p> | ||
Read the{' '} | ||
<a | ||
href='https://docs.getunleash.io/reference/sdks' | ||
target='_blank' | ||
rel='noreferrer' | ||
> | ||
SDK overview | ||
</a>{' '} | ||
to connect Unleash to your application. Please note it can take | ||
up to <strong>1 minute</strong> before a new API key is | ||
activated. | ||
</p> | ||
<GridContainer> | ||
<GridItem> | ||
<strong>CLIENT API URL: </strong> | ||
</GridItem> | ||
<GridItem> | ||
<pre style={{ display: 'inline' }}>{clientApiUrl}</pre> | ||
</GridItem> | ||
<GridItem> | ||
<Tooltip title='Copy URL' arrow> | ||
<IconButton | ||
onClick={onCopyToClipboard(clientApiUrl)} | ||
size='small' | ||
> | ||
<CopyIcon /> | ||
</IconButton> | ||
</Tooltip> | ||
</GridItem> | ||
<GridItem> | ||
<strong>FRONTEND API URL: </strong> | ||
</GridItem> | ||
<GridItem> | ||
<pre style={{ display: 'inline' }}>{frontendApiUrl}</pre> | ||
</GridItem> | ||
<GridItem> | ||
<Tooltip title='Copy URL' arrow> | ||
<IconButton | ||
onClick={onCopyToClipboard(frontendApiUrl)} | ||
size='small' | ||
> | ||
<CopyIcon /> | ||
</IconButton> | ||
</Tooltip> | ||
</GridItem> | ||
</GridContainer> | ||
</Alert> | ||
); | ||
}; |
44 changes: 44 additions & 0 deletions
44
frontend/src/component/admin/cdn/ApiTokenForm/ApiTokenForm.styles.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,44 @@ | ||
import { Box, Button, styled } from '@mui/material'; | ||
import Input from '../../../common/Input/Input.tsx'; | ||
import GeneralSelect from '../../../common/GeneralSelect/GeneralSelect.tsx'; | ||
|
||
export const StyledContainer = styled('div')(() => ({ | ||
maxWidth: '400px', | ||
})); | ||
|
||
export const StyledForm = styled('form')(() => ({ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
height: '100%', | ||
})); | ||
|
||
export const StyledInput = styled(Input)(({ theme }) => ({ | ||
width: '100%', | ||
marginBottom: theme.spacing(2), | ||
})); | ||
|
||
export const StyledSelectInput = styled(GeneralSelect)(({ theme }) => ({ | ||
marginBottom: theme.spacing(2), | ||
minWidth: '400px', | ||
[theme.breakpoints.down('sm')]: { | ||
minWidth: '379px', | ||
}, | ||
})); | ||
|
||
export const StyledInputDescription = styled('p')(({ theme }) => ({ | ||
marginBottom: theme.spacing(1), | ||
})); | ||
|
||
export const StyledInputLabel = styled('label')(({ theme }) => ({ | ||
marginBottom: theme.spacing(1), | ||
})); | ||
|
||
export const CancelButton = styled(Button)(({ theme }) => ({ | ||
marginLeft: theme.spacing(3), | ||
})); | ||
|
||
export const StyledBox = styled(Box)({ | ||
marginTop: 'auto', | ||
display: 'flex', | ||
justifyContent: 'flex-end', | ||
}); |
49 changes: 49 additions & 0 deletions
49
frontend/src/component/admin/cdn/ApiTokenForm/ApiTokenForm.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,49 @@ | ||
import { Alert, Link } from '@mui/material'; | ||
import type React from 'react'; | ||
import type { ReactNode } from 'react'; | ||
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; | ||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; | ||
import { CancelButton, StyledBox, StyledForm } from './ApiTokenForm.styles'; | ||
|
||
interface IApiTokenFormProps { | ||
handleSubmit: (e: any) => void; | ||
handleCancel: () => void; | ||
mode: 'Create' | 'Edit'; | ||
actions?: ReactNode; | ||
children?: React.ReactNode; | ||
} | ||
|
||
const ApiTokenForm: React.FC<IApiTokenFormProps> = ({ | ||
children, | ||
actions, | ||
handleSubmit, | ||
handleCancel, | ||
}) => { | ||
const { uiConfig } = useUiConfig(); | ||
|
||
const isUnleashCloud = Boolean(uiConfig?.flags?.UNLEASH_CLOUD); | ||
|
||
return ( | ||
<StyledForm onSubmit={handleSubmit}> | ||
<ConditionallyRender | ||
condition={isUnleashCloud} | ||
show={ | ||
<Alert severity='info' sx={{ mb: 4 }}> | ||
Please be aware of our{' '} | ||
<Link href='https://www.getunleash.io/fair-use-policy'> | ||
fair use policy | ||
</Link> | ||
. | ||
</Alert> | ||
} | ||
/> | ||
{children} | ||
<StyledBox> | ||
{actions} | ||
<CancelButton onClick={handleCancel}>Cancel</CancelButton> | ||
</StyledBox> | ||
</StyledForm> | ||
); | ||
}; | ||
|
||
export default ApiTokenForm; |
35 changes: 35 additions & 0 deletions
35
frontend/src/component/admin/cdn/ApiTokenForm/TokenInfo/TokenInfo.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,35 @@ | ||
import type React from 'react'; | ||
import { StyledInput, StyledInputDescription } from '../ApiTokenForm.styles'; | ||
import type { ApiTokenFormErrorType } from '../../useCdnTokenForm.ts'; | ||
|
||
interface ITokenInfoProps { | ||
tokenName: string; | ||
setTokenName: React.Dispatch<React.SetStateAction<string>>; | ||
|
||
errors: { [key: string]: string }; | ||
clearErrors: (error?: ApiTokenFormErrorType) => void; | ||
} | ||
export const TokenInfo = ({ | ||
tokenName, | ||
setTokenName, | ||
errors, | ||
clearErrors, | ||
}: ITokenInfoProps) => { | ||
return ( | ||
<> | ||
<StyledInputDescription> | ||
What would you like to call this token? | ||
</StyledInputDescription> | ||
<StyledInput | ||
value={tokenName} | ||
name='tokenName' | ||
onChange={(e) => setTokenName(e.target.value)} | ||
label='Token name' | ||
error={errors.tokenName !== undefined} | ||
errorText={errors.tokenName} | ||
onFocus={() => clearErrors('tokenName')} | ||
autoFocus | ||
/> | ||
</> | ||
); | ||
}; |
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,22 @@ | ||
import { PermissionGuard } from 'component/common/PermissionGuard/PermissionGuard'; | ||
import { ADMIN } from '@server/types/permissions'; | ||
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; | ||
import { CdnTokenPage } from './CdnTokenPage/CdnTokenPage.tsx'; | ||
|
||
export const CdnAdmin = () => ( | ||
<div> | ||
<PermissionGuard permissions={[ADMIN]}> | ||
<CdnPage /> | ||
</PermissionGuard> | ||
</div> | ||
); | ||
|
||
const CdnPage = () => { | ||
const { loading } = useUiConfig(); | ||
|
||
if (loading) { | ||
return null; | ||
} | ||
|
||
return <CdnTokenPage />; | ||
}; |
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.
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.
I feel this should be a separate PR fixing orval config.