Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 4 additions & 23 deletions rdmo/core/assets/js/utils/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { set, unset, toNumber, isNaN } from 'lodash'
import { set, unset } from 'lodash'

const updateConfig = (config, path, value) => {
const newConfig = {...config}
Expand All @@ -17,28 +17,9 @@ const getConfigFromLocalStorage = (prefix) => {

return Object.entries(ls)
.filter(([lsPath,]) => lsPath.startsWith(prefix))
.map(([lsPath, lsValue]) => {
if (lsPath.startsWith(prefix)) {
const path = lsPath.replace(`${prefix}.`, '')

// check if it is literal 'true' or 'false'
if (lsValue === 'true') {
return [path, true]
} else if (lsValue === 'false') {
return [path, false]
}

// check if the value is number or a string
const numberValue = toNumber(lsValue)
if (isNaN(numberValue)) {
return [path, lsValue]
} else {
return [path, numberValue]
}
} else {
return null
}
})
.map(([lsPath, lsValue]) => (
lsPath.startsWith(prefix) ? [lsPath.replace(`${prefix}.`, ''), lsValue] : null
))
}

const setConfigInLocalStorage = (prefix, path, value) => {
Expand Down
22 changes: 13 additions & 9 deletions rdmo/management/assets/js/components/common/Checkboxes.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import React from 'react'
import PropTypes from 'prop-types'

const Checkbox = ({ label, value, onChange }) => (
<span className="checkbox">
<label>
<input type="checkbox" checked={value} onChange={() => onChange(!value)} />
{ label }
</label>
</span>
)
const Checkbox = ({ label, value, onChange }) => {
const checked = [true, 'true'].includes(value) // values are stored as string in the local storage

return (
<span className="checkbox">
<label>
<input type="checkbox" checked={checked} onChange={() => onChange(!checked)} />
{ label }
</label>
</span>
)
}

Checkbox.propTypes = {
label: PropTypes.oneOfType([PropTypes.object, PropTypes.string]).isRequired,
value: PropTypes.bool.isRequired,
value: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]).isRequired,
onChange: PropTypes.func.isRequired
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const ProjectFilters = ({ catalogs, config, configActions, isManager, projectsAc
setEndDate
} = useDatePicker()

const showFilters = get(config, 'showFilters', false)
const showFilters = [true, 'true'].includes(get(config, 'showFilters', false))
const toggleFilters = () => configActions.updateConfig('showFilters', !showFilters)

const resetAllFilters = () => {
Expand Down