Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
le0pard committed Aug 6, 2023
1 parent e99bfda commit 51a17a8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
51 changes: 25 additions & 26 deletions src/common/components/configurationView/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useCallback } from 'react'
import classnames from 'classnames'
import { useDispatch, useSelector } from 'react-redux'
import hljs from 'highlight.js/lib/core'
Expand Down Expand Up @@ -75,6 +75,21 @@ const formatValue = (value) => {
return `${result.value}${result.unit}`
}

const renderCodeInlineCss = (codeHighlightStyle) => {
return Object.keys(codeHighlightStyle).map((className) => {
const content = codeHighlightStyle[className]
const body = Object.keys(content)
.map((key) => `${key}: ${content[key]};`)
.join('')

return `.${className} { ${body} }`
})
}

const renderHightlightedCode = (code, isAlterSystem) => {
return hljs.highlight(code, { language: isAlterSystem ? 'sql' : 'ini' }).value
}

const ConfigurationView = () => {
const dispatch = useDispatch()

Expand Down Expand Up @@ -107,12 +122,13 @@ const ConfigurationView = () => {
// app theme
const theme = useSelector(selectThemeSettings)
// tab click state
const handleClickTab = (tab) => dispatch(openConfigTab(tab))

const warningInfo = () => warningInfoMessagesVal.join('\n')
const handleClickTab = useCallback((tab) => dispatch(openConfigTab(tab)), [dispatch])

const isAlterSystem = TAB_ALTER_SYSTEM === tabState

const warningInfo = () =>
warningInfoMessagesVal.map((item) => `${isAlterSystem ? '--' : '#'} ${item}`).join('\n')

const hardwareConfiguration = () =>
[
['DB Version', dbVersion],
Expand All @@ -138,8 +154,6 @@ const ConfigurationView = () => {
const getParallelSettings = () => parallelSettingsVal.map((item) => [item.key, item.value])

const postgresqlConfig = () => {
const isRenderAlterSystem = TAB_ALTER_SYSTEM === tabState

const configData = [
['max_connections', maxConnectionsVal],
['shared_buffers', formatValue(sharedBuffersVal)],
Expand All @@ -158,9 +172,7 @@ const ConfigurationView = () => {
return configData
.filter((item) => !!item[1])
.map((item) =>
isRenderAlterSystem
? `ALTER SYSTEM SET\n ${item[0]} = '${item[1]}';`
: `${item[0]} = ${item[1]}`
isAlterSystem ? `ALTER SYSTEM SET\n ${item[0]} = '${item[1]}';` : `${item[0]} = ${item[1]}`
)
.join('\n')
}
Expand Down Expand Up @@ -197,21 +209,6 @@ const ConfigurationView = () => {
)
}

const renderInlineCss = (codeHighlightStyle) => {
return Object.keys(codeHighlightStyle).map((className) => {
const content = codeHighlightStyle[className]
const body = Object.keys(content)
.map((key) => `${key}: ${content[key]};`)
.join('')

return `.${className} { ${body} }`
})
}

const renderHightlightedCode = (code) => {
return hljs.highlight(code, { language: isAlterSystem ? 'sql' : 'ini' }).value
}

const renderConfigResult = () => {
const generatedConfigRes = generateConfig()

Expand All @@ -231,7 +228,9 @@ const ConfigurationView = () => {
<pre style={{ display: 'block', overflowX: 'auto', padding: '0.5rem' }}>
<code
style={{ whiteSpace: 'pre' }}
dangerouslySetInnerHTML={{ __html: renderHightlightedCode(generatedConfigRes) }}
dangerouslySetInnerHTML={{
__html: renderHightlightedCode(generatedConfigRes, isAlterSystem)
}}
/>
</pre>
<div className="configuration-view-copy-wrapper">
Expand All @@ -251,7 +250,7 @@ const ConfigurationView = () => {
<div>
{renderTabs()}
{renderConfigResult()}
<style>{renderInlineCss(codeHighlightStyle)}</style>
<style>{renderCodeInlineCss(codeHighlightStyle)}</style>
</div>
)
}
Expand Down
4 changes: 2 additions & 2 deletions src/features/configuration/configurationSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,10 @@ export const selectWarningInfoMessages = createSelector(
[selectTotalMemoryInBytes],
(totalMemory) => {
if (totalMemory < 256 * SIZE_UNIT_MAP['MB']) {
return ['# WARNING', '# this tool not being optimal', '# for low memory systems']
return ['WARNING', 'this tool not being optimal', 'for low memory systems']
}
if (totalMemory > 100 * SIZE_UNIT_MAP['GB']) {
return ['# WARNING', '# this tool not being optimal', '# for very high memory systems']
return ['WARNING', 'this tool not being optimal', 'for very high memory systems']
}
return []
}
Expand Down

0 comments on commit 51a17a8

Please sign in to comment.