-
Notifications
You must be signed in to change notification settings - Fork 10
Topcoder Admin App - Roles Management Update #1056
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,20 +9,22 @@ import { | |
useMemo, | ||
useRef, | ||
} from 'react' | ||
import ReactSelect, { components, SingleValue } from 'react-select' | ||
import { components, SingleValue } from 'react-select' | ||
import CreatableReactSelect from 'react-select/creatable' | ||
import classNames from 'classnames' | ||
|
||
import { IconOutline, InputWrapper, LoadingSpinner } from '~/libs/ui' | ||
|
||
import { SelectOption } from '../../models' | ||
import ReactSelect from '../common/ReactSelectExport' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The import path for |
||
|
||
import styles from './FieldSingleSelect.module.scss' | ||
|
||
interface Props { | ||
label?: string | ||
className?: string | ||
placeholder?: string | ||
readonly value?: SelectOption | ||
readonly value?: SelectOption | null | ||
readonly onChange?: (event: SelectOption) => void | ||
readonly disabled?: boolean | ||
readonly dirty?: boolean | ||
|
@@ -32,6 +34,10 @@ interface Props { | |
readonly onBlur?: (event: FocusEvent<HTMLInputElement>) => void | ||
readonly options: SelectOption[] | ||
readonly isLoading?: boolean | ||
readonly classNameWrapper?: string | ||
readonly onSearchChange?: (value: string) => void | ||
readonly creatable?: boolean | ||
readonly createLabel?: (inputValue: string) => string | ||
} | ||
|
||
// eslint-disable-next-line react/function-component-definition | ||
|
@@ -60,6 +66,10 @@ export const FieldSingleSelect: FC<Props> = (props: Props) => { | |
[], | ||
) | ||
|
||
const Input = useMemo(() => ( | ||
props.creatable ? CreatableReactSelect : ReactSelect | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider renaming the |
||
), [props.creatable]) | ||
|
||
return ( | ||
<InputWrapper | ||
{...props} | ||
|
@@ -72,7 +82,7 @@ export const FieldSingleSelect: FC<Props> = (props: Props) => { | |
hideInlineErrors={props.hideInlineErrors} | ||
ref={wrapRef as MutableRefObject<HTMLDivElement>} | ||
> | ||
<ReactSelect | ||
<Input | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The component |
||
components={asyncSelectComponents} | ||
className={classNames(props.className, styles.select)} | ||
placeholder={props.placeholder ?? 'Enter'} | ||
|
@@ -88,9 +98,13 @@ export const FieldSingleSelect: FC<Props> = (props: Props) => { | |
} | ||
}} | ||
value={props.value} | ||
defaultValue={props.value} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
isDisabled={props.disabled || props.isLoading} | ||
onBlur={props.onBlur} | ||
options={props.options} | ||
onInputChange={props.onSearchChange} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
createOptionPosition='first' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
formatCreateLabel={props.createLabel} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
/> | ||
{props.isLoading && ( | ||
<div className={styles.blockActionLoading}> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,17 @@ export const RoleMembersFilters: FC<Props> = props => { | |
inputControl={register('userHandle')} | ||
disabled={props.isLoading} | ||
/> | ||
<InputText | ||
type='text' | ||
name='email' | ||
label='Email' | ||
placeholder='Enter' | ||
tabIndex={0} | ||
onChange={_.noop} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
classNameWrapper={styles.field} | ||
inputControl={register('email')} | ||
disabled={props.isLoading} | ||
/> | ||
</div> | ||
|
||
<div className={styles.blockBottom}> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
/** | ||
* Role members table. | ||
*/ | ||
import { FC, useContext, useEffect, useMemo } from 'react' | ||
import { FC, useMemo } from 'react' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
import _ from 'lodash' | ||
import classNames from 'classnames' | ||
|
||
import { useWindowSize, WindowSize } from '~/libs/shared' | ||
import { Button, InputCheckbox, Table, TableColumn } from '~/libs/ui' | ||
|
||
import { AdminAppContext } from '../../contexts' | ||
import { useTableFilterLocal, useTableFilterLocalProps } from '../../hooks' | ||
import { AdminAppContextType, RoleMemberInfo } from '../../models' | ||
import { RoleMemberInfo } from '../../models' | ||
import { MobileTableColumn } from '../../models/MobileTableColumn.model' | ||
import { Pagination } from '../common/Pagination' | ||
import { TableMobile } from '../common/TableMobile' | ||
|
@@ -28,8 +27,6 @@ interface Props { | |
} | ||
|
||
export const RoleMembersTable: FC<Props> = (props: Props) => { | ||
const { loadUser, usersMapping, cancelLoadUser }: AdminAppContextType | ||
= useContext(AdminAppContext) | ||
const { | ||
page, | ||
setPage, | ||
|
@@ -51,27 +48,6 @@ export const RoleMembersTable: FC<Props> = (props: Props) => { | |
unselectAll, | ||
}: useTableSelectionProps<string> = useTableSelection<string>(datasIds) | ||
|
||
useEffect(() => { | ||
// clear queue of currently loading user handles | ||
cancelLoadUser() | ||
// load user handles for members visible on the current page | ||
_.forEach(results, result => { | ||
loadUser(result.id) | ||
}) | ||
|
||
return () => { | ||
// clear queue of currently loading user handles after exit ui | ||
cancelLoadUser() | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [results]) | ||
|
||
useEffect(() => { | ||
_.forEach(results, result => { | ||
result.handle = usersMapping[result.id] | ||
}) | ||
}, [usersMapping, results]) | ||
|
||
const columns = useMemo<TableColumn<RoleMemberInfo>[]>( | ||
() => [ | ||
{ | ||
|
@@ -108,20 +84,12 @@ export const RoleMembersTable: FC<Props> = (props: Props) => { | |
{ | ||
label: 'Handle', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
propertyName: 'handle', | ||
renderer: (data: RoleMemberInfo) => { | ||
if (!data.id) { | ||
return <></> | ||
} | ||
|
||
return ( | ||
<> | ||
{!usersMapping[data.id] | ||
? 'loading...' | ||
: usersMapping[data.id]} | ||
</> | ||
) | ||
}, | ||
type: 'element', | ||
type: 'text', | ||
}, | ||
{ | ||
label: 'Email', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The addition of the 'Email' column with |
||
propertyName: 'email', | ||
type: 'text', | ||
}, | ||
{ | ||
className: styles.blockColumnAction, | ||
|
@@ -145,7 +113,6 @@ export const RoleMembersTable: FC<Props> = (props: Props) => { | |
[ | ||
isSelectAll, | ||
selectedDatas, | ||
usersMapping, | ||
props.isRemoving, | ||
props.isRemovingBool, | ||
props.doRemoveRoleMember, | ||
|
@@ -171,12 +138,30 @@ export const RoleMembersTable: FC<Props> = (props: Props) => { | |
), | ||
type: 'element', | ||
}, | ||
], [ | ||
{ | ||
...columns[3], | ||
className: '', | ||
label: `${columns[3].label as string} label`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The label concatenation with 'label' seems redundant. Consider revising the label assignment to avoid potential confusion. |
||
mobileType: 'label', | ||
renderer: () => ( | ||
<div> | ||
{columns[3].label as string} | ||
: | ||
</div> | ||
), | ||
type: 'element', | ||
}, | ||
{ | ||
...columns[3], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of |
||
mobileType: 'last-value', | ||
}, | ||
], | ||
[ | ||
{ | ||
...columns[3], | ||
...columns[4], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The spread operator is changed from |
||
className: classNames( | ||
columns[3].className, | ||
columns[4].className, | ||
styles.blockRightColumn, | ||
), | ||
colSpan: 2, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import statement for
ReactSelect
has been split into two separate imports. Consider consolidating them into a single import statement for better readability and to reduce redundancy.