-
-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(console,phrases): add test sample code editor (#5475)
* feat(console,phrases): add test sample code editor add test sample code editor * fix(console): remove unused styles remove unused styles * refactor(console): refactor the components structure erfactor the components structure * refactor(console): clean up the root component clean up the root component
- Loading branch information
Showing
35 changed files
with
564 additions
and
294 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 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 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 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
35 changes: 35 additions & 0 deletions
35
packages/console/src/pages/JwtClaims/MonacoCodeEditor/use-editor-height.ts
This file contains 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 { useRef, useState, useLayoutEffect } from 'react'; | ||
|
||
// Recalculate the height of the editor when the container size changes | ||
// This is to avoid the code editor's height shaking when the content is updated. | ||
// @see {@link https://github.com/react-monaco-editor/react-monaco-editor/issues/391} | ||
const useEditorHeight = () => { | ||
const containerRef = useRef<HTMLDivElement>(null); | ||
|
||
const [editorHeight, setEditorHeight] = useState<number | string>('100%'); | ||
const safeArea = 16; | ||
|
||
useLayoutEffect(() => { | ||
const handleResize = () => { | ||
if (containerRef.current) { | ||
setEditorHeight(containerRef.current.clientHeight - safeArea); | ||
} | ||
}; | ||
|
||
handleResize(); | ||
|
||
const resizeObserver = new ResizeObserver(handleResize); | ||
|
||
if (containerRef.current) { | ||
resizeObserver.observe(containerRef.current); | ||
} | ||
|
||
return () => { | ||
resizeObserver.disconnect(); | ||
}; | ||
}, []); | ||
|
||
return { containerRef, editorHeight }; | ||
}; | ||
|
||
export default useEditorHeight; |
129 changes: 0 additions & 129 deletions
129
packages/console/src/pages/JwtClaims/RightPanel/index.tsx
This file was deleted.
Oops, something went wrong.
This file contains 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,41 @@ | ||
/* Code Editor for the custom JWT claims script. */ | ||
import { useMemo } from 'react'; | ||
import { useFormContext } from 'react-hook-form'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import Card from '@/ds-components/Card'; | ||
|
||
import MonacoCodeEditor, { type Model } from './MonacoCodeEditor'; | ||
import { userJwtFile, machineToMachineJwtFile, JwtTokenType } from './config'; | ||
import * as styles from './index.module.scss'; | ||
import { type JwtClaimsFormType } from './type'; | ||
|
||
const titlePhrases = Object.freeze({ | ||
[JwtTokenType.UserAccessToken]: 'user_jwt', | ||
[JwtTokenType.MachineToMachineAccessToken]: 'machine_to_machine_jwt', | ||
}); | ||
|
||
function ScriptPanel() { | ||
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); | ||
|
||
const { watch } = useFormContext<JwtClaimsFormType>(); | ||
const tokenType = watch('tokenType'); | ||
|
||
// TODO: API integration, read/write the custom claims code value | ||
const activeModel = useMemo<Model>(() => { | ||
return tokenType === JwtTokenType.UserAccessToken ? userJwtFile : machineToMachineJwtFile; | ||
}, [tokenType]); | ||
|
||
return ( | ||
<Card className={styles.codePanel}> | ||
<div className={styles.cardTitle}> | ||
{t('jwt_claims.code_editor_title', { | ||
token: t(`jwt_claims.${titlePhrases[tokenType]}`), | ||
})} | ||
</div> | ||
<MonacoCodeEditor className={styles.flexGrow} models={[activeModel]} /> | ||
</Card> | ||
); | ||
} | ||
|
||
export default ScriptPanel; |
File renamed without changes.
This file contains 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
Oops, something went wrong.