feat(ui/admin): remember showRoles toggle selection

pull/5944/head
Pavel Zavora 2022-06-16 13:49:48 +02:00
parent 4665be92d5
commit f3f3c9bb45
4 changed files with 24 additions and 9 deletions

View File

@ -484,3 +484,7 @@ export const changeSelectedDBs = (selectedDBs /* : string[] */) => ({
export const changeShowUsers = () => ({ export const changeShowUsers = () => ({
type: 'INFLUXDB_CHANGE_SHOW_USERS', type: 'INFLUXDB_CHANGE_SHOW_USERS',
}) })
export const changeShowRoles = () => ({
type: 'INFLUXDB_CHANGE_SHOW_ROLES',
})

View File

@ -5,6 +5,7 @@ import {Source, NotificationAction} from 'src/types'
import {UserRole, User, Database} from 'src/types/influxAdmin' import {UserRole, User, Database} from 'src/types/influxAdmin'
import {notify as notifyAction} from 'src/shared/actions/notifications' import {notify as notifyAction} from 'src/shared/actions/notifications'
import { import {
changeShowRoles,
createUserAsync, createUserAsync,
filterUsers as filterUsersAction, filterUsers as filterUsersAction,
} from 'src/admin/actions/influxdb' } from 'src/admin/actions/influxdb'
@ -47,17 +48,19 @@ const validateUser = (
} }
const mapStateToProps = ({ const mapStateToProps = ({
adminInfluxDB: {databases, users, roles, selectedDBs}, adminInfluxDB: {databases, users, roles, selectedDBs, showRoles},
}) => ({ }) => ({
databases, databases,
users, users,
roles, roles,
selectedDBs, selectedDBs,
showRoles,
}) })
const mapDispatchToProps = { const mapDispatchToProps = {
filterUsers: filterUsersAction, filterUsers: filterUsersAction,
createUser: createUserAsync, createUser: createUserAsync,
toggleShowRoles: changeShowRoles,
notify: notifyAction, notify: notifyAction,
} }
@ -69,6 +72,7 @@ interface ConnectedProps {
users: User[] users: User[]
roles: UserRole[] roles: UserRole[]
selectedDBs: string[] selectedDBs: string[]
showRoles: boolean
} }
type ReduxDispatchProps = ResolveThunks<typeof mapDispatchToProps> type ReduxDispatchProps = ResolveThunks<typeof mapDispatchToProps>
@ -81,9 +85,11 @@ const UsersPage = ({
users, users,
roles, roles,
selectedDBs, selectedDBs,
showRoles,
notify, notify,
createUser, createUser,
filterUsers, filterUsers,
toggleShowRoles,
}: Props) => { }: Props) => {
const [isEnterprise, usersPage] = useMemo( const [isEnterprise, usersPage] = useMemo(
() => [ () => [
@ -118,13 +124,6 @@ const UsersPage = ({
filterUsers(debouncedFilterText) filterUsers(debouncedFilterText)
}, [debouncedFilterText]) }, [debouncedFilterText])
// hide role
const [showRoles, setShowRoles] = useState(true)
const changeHideRoles = useCallback(() => setShowRoles(!showRoles), [
showRoles,
setShowRoles,
])
const [createVisible, setCreateVisible] = useState(false) const [createVisible, setCreateVisible] = useState(false)
const createNew = useCallback( const createNew = useCallback(
async (user: {name: string; password: string}) => { async (user: {name: string; password: string}) => {
@ -170,7 +169,7 @@ const UsersPage = ({
<div className="hide-roles-toggle"> <div className="hide-roles-toggle">
<SlideToggle <SlideToggle
active={showRoles} active={showRoles}
onChange={changeHideRoles} onChange={toggleShowRoles}
size={ComponentSize.ExtraSmall} size={ComponentSize.ExtraSmall}
/> />
Show Roles Show Roles

View File

@ -48,6 +48,7 @@ const initialState = {
databases: [], databases: [],
selectedDBs: ['*'], selectedDBs: ['*'],
showUsers: true, showUsers: true,
showRoles: true,
} }
const adminInfluxDB = (state = initialState, action) => { const adminInfluxDB = (state = initialState, action) => {
@ -372,6 +373,9 @@ const adminInfluxDB = (state = initialState, action) => {
case 'INFLUXDB_CHANGE_SHOW_USERS': { case 'INFLUXDB_CHANGE_SHOW_USERS': {
return {...state, showUsers: !state.showUsers} return {...state, showUsers: !state.showUsers}
} }
case 'INFLUXDB_CHANGE_SHOW_ROLES': {
return {...state, showRoles: !state.showRoles}
}
} }
return state return state

View File

@ -22,6 +22,7 @@ import {
loadDatabases, loadDatabases,
changeSelectedDBs, changeSelectedDBs,
changeShowUsers, changeShowUsers,
changeShowRoles,
} from 'src/admin/actions/influxdb' } from 'src/admin/actions/influxdb'
import {NEW_DEFAULT_DATABASE, NEW_EMPTY_RP} from 'src/admin/constants' import {NEW_DEFAULT_DATABASE, NEW_EMPTY_RP} from 'src/admin/constants'
@ -546,5 +547,12 @@ describe('Admin.InfluxDB.Reducers', () => {
expect(showUsers).toEqual(!prev) expect(showUsers).toEqual(!prev)
}) })
}) })
it('can change showRoles flag', () => {
const vals = [undefined, true, false]
vals.forEach(prev => {
const {showRoles} = reducer({showRoles: prev}, changeShowRoles())
expect(showRoles).toEqual(!prev)
})
})
}) })
}) })