Skip to content

Commit 1748b55

Browse files
SSA implemented with TS
1 parent 400c162 commit 1748b55

File tree

6 files changed

+272
-217
lines changed

6 files changed

+272
-217
lines changed

admin-ui/plugins/auth-server/components/JsonViewer/JsonViewer.js

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React, { useMemo, memo } from 'react'
2+
import { JsonView, allExpanded, darkStyles, defaultStyles } from 'react-json-view-lite'
3+
import 'react-json-view-lite/dist/index.css'
4+
import './JsonViewer.css'
5+
import customColors from '@/customColors'
6+
7+
interface JsonViewerProps {
8+
data: Record<string, unknown> | unknown[]
9+
theme?: 'light' | 'dark'
10+
expanded?: boolean
11+
style?: React.CSSProperties
12+
className?: string
13+
}
14+
15+
const JsonViewer: React.FC<JsonViewerProps> = ({
16+
data,
17+
theme = 'light',
18+
expanded = true,
19+
style = {},
20+
className = '',
21+
}) => {
22+
const styles = useMemo(() => (theme === 'dark' ? darkStyles : defaultStyles), [theme])
23+
const shouldExpand = useMemo(() => (expanded ? allExpanded : undefined), [expanded])
24+
25+
const containerStyle = useMemo(
26+
() => ({
27+
padding: '1rem',
28+
borderRadius: '4px',
29+
backgroundColor: theme === 'dark' ? customColors.black : customColors.white,
30+
...style,
31+
}),
32+
[theme, style],
33+
)
34+
35+
return (
36+
<div className={`json-viewer ${className}`} style={containerStyle}>
37+
<JsonView data={data} style={styles} shouldExpandNode={shouldExpand} />
38+
</div>
39+
)
40+
}
41+
42+
JsonViewer.displayName = 'JsonViewer'
43+
44+
export default memo(JsonViewer)

admin-ui/plugins/auth-server/components/JsonViewer/JsonViewerDialog.js renamed to admin-ui/plugins/auth-server/components/JsonViewer/JsonViewerDialog.tsx

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
import React from 'react'
1+
import React, { memo } from 'react'
22
import { Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap'
33
import { useTranslation } from 'react-i18next'
44
import JsonViewer from './JsonViewer'
5-
import PropTypes from 'prop-types'
65
import customColors from '@/customColors'
76
import GluuFormFooter from 'Routes/Apps/Gluu/GluuFormFooter'
87

9-
const JsonViewerDialog = ({
8+
interface JsonViewerDialogProps {
9+
isOpen: boolean
10+
toggle: () => void
11+
data: Record<string, unknown> | unknown[]
12+
title?: string
13+
theme?: 'light' | 'dark'
14+
expanded?: boolean
15+
}
16+
17+
const JsonViewerDialog: React.FC<JsonViewerDialogProps> = ({
1018
isOpen,
1119
toggle,
1220
data,
@@ -15,12 +23,14 @@ const JsonViewerDialog = ({
1523
expanded = true,
1624
}) => {
1725
const { t } = useTranslation()
26+
1827
return (
1928
<Modal isOpen={isOpen} toggle={toggle} size="lg" className="modal-outline-primary">
2029
<ModalHeader toggle={toggle}>
2130
<i
2231
style={{ color: customColors.logo }}
2332
className="fa fa-2x fa-code fa-fw modal-icon mb-3"
33+
aria-hidden="true"
2434
/>
2535
{title}
2636
</ModalHeader>
@@ -35,21 +45,14 @@ const JsonViewerDialog = ({
3545
showApply={false}
3646
disableBack={false}
3747
className="w-100"
38-
backButtonLabel={t('actions.close')}
48+
backButtonLabel={t('actions.cancel')}
3949
backIconClass="fa fa-times-circle"
4050
/>
4151
</ModalFooter>
4252
</Modal>
4353
)
4454
}
4555

46-
JsonViewerDialog.propTypes = {
47-
isOpen: PropTypes.bool.isRequired,
48-
toggle: PropTypes.func.isRequired,
49-
data: PropTypes.object.isRequired,
50-
title: PropTypes.string,
51-
theme: PropTypes.string,
52-
expanded: PropTypes.bool,
53-
}
56+
JsonViewerDialog.displayName = 'JsonViewerDialog'
5457

55-
export default JsonViewerDialog
58+
export default memo(JsonViewerDialog)

0 commit comments

Comments
 (0)