Skip to content

Commit

Permalink
Merge pull request #4491 from broadinstitute/local-no-analyst-ui
Browse files Browse the repository at this point in the history
Local no analyst UI
  • Loading branch information
hanars authored Nov 21, 2024
2 parents 40151b8 + bc0af5d commit 4155a0f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
18 changes: 15 additions & 3 deletions ui/pages/DataManagement/components/Users.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { Icon, Button } from 'semantic-ui-react'
import Cookies from 'js-cookie'
import { getHijakEnabled } from 'redux/selectors'
import { getHijakEnabled, getUser } from 'redux/selectors'
import DataTable from 'shared/components/table/DataTable'
import DataLoader from 'shared/components/DataLoader'
import { getAllUsers, getAllUsersLoading } from '../selectors'
Expand Down Expand Up @@ -34,6 +34,9 @@ const COLUMNS = [
hasFieldColumn('isActive', 'Active?'),
]

const LOCAL_COLUMNS = [...COLUMNS]
LOCAL_COLUMNS.splice(-5, 2)

const hijakLogIn = (e, { value }) => {
const hijackFormData = new FormData()
hijackFormData.append('user_pk', value.id)
Expand All @@ -55,17 +58,24 @@ const HIJAK_COLUMNS = [
{ name: 'id', format: val => <Button content="Log In" value={val} onClick={hijakLogIn} /> },
]

const getColumns = (hijak, { isAnalyst }) => {
if (hijak) {
return HIJAK_COLUMNS
}
return isAnalyst ? COLUMNS : LOCAL_COLUMNS
}

const getUserFilterVal = ({ email, displayName }) => `${email}-${displayName}`

const Users = React.memo(({ users, loading, load, hijak }) => (
const Users = React.memo(({ users, currentUser, loading, load, hijak }) => (
<DataLoader load={load} content loading={false}>
<DataTable
striped
idField="username"
defaultSortColumn="email"
loading={loading}
data={users}
columns={hijak ? HIJAK_COLUMNS : COLUMNS}
columns={getColumns(hijak, currentUser)}
getRowFilterVal={getUserFilterVal}
downloadFileName="users"
downloadAlign="1em"
Expand All @@ -78,12 +88,14 @@ Users.propTypes = {
loading: PropTypes.bool,
load: PropTypes.func,
hijak: PropTypes.bool,
currentUser: PropTypes.object,
}

const mapStateToProps = state => ({
users: getAllUsers(state),
loading: getAllUsersLoading(state),
hijak: getHijakEnabled(state),
currentUser: getUser(state),
})

const mapDispatchToProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ EditBulkForm.propTypes = {

const FAMILY_ID_EXPORT_DATA = FAMILY_BULK_EDIT_EXPORT_DATA.slice(0, 1)
const FAMILY_EXPORT_DATA = FAMILY_BULK_EDIT_EXPORT_DATA.slice(1)
const FAMILY_CORE_EXPORT_DATA = FAMILY_BULK_EDIT_EXPORT_DATA.slice(1, 5)

const FamiliesBulkForm = React.memo(props => (
const FamiliesBulkForm = React.memo(({ user, ...props }) => (
<EditBulkForm
name="families"
actionDescription="bulk-add or edit families"
Expand All @@ -85,19 +86,27 @@ const FamiliesBulkForm = React.memo(props => (
</div>
}
requiredFields={FAMILY_ID_EXPORT_DATA}
optionalFields={FAMILY_EXPORT_DATA}
optionalFields={user.isAnalyst ? FAMILY_EXPORT_DATA : FAMILY_CORE_EXPORT_DATA}
uploadFormats={FILE_FORMATS}
getRawData={getProjectAnalysisGroupFamiliesByGuid}
templateLinkContent="current families"
{...props}
/>
))

FamiliesBulkForm.propTypes = {
user: PropTypes.object,
}

const mapFamiliesStateToProps = state => ({
user: getUser(state),
})

const mapFamiliesDispatchToProps = {
onSubmit: updateFamilies,
}

export const EditFamiliesBulkForm = connect(null, mapFamiliesDispatchToProps)(FamiliesBulkForm)
export const EditFamiliesBulkForm = connect(mapFamiliesStateToProps, mapFamiliesDispatchToProps)(FamiliesBulkForm)

const INDIVIDUAL_BULK_UPDATE_EXPORT_DATA = [...INDIVIDUAL_CORE_EXPORT_DATA, ...INDIVIDUAL_INTERNAL_EXPORT_DATA]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@ import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'

import { getUser } from 'redux/selectors'
import DataLoader from 'shared/components/DataLoader'
import EditRecordsForm from 'shared/components/form/EditRecordsForm'
import { FAMILY_FIELD_ID, INDIVIDUAL_FIELD_ID } from 'shared/utils/constants'
import { INDIVIDUAL_FIELDS } from '../../constants'
import { loadIndividuals, updateIndividuals } from '../../reducers'
import { getProjectAnalysisGroupIndividualsByGuid, getIndivdualsLoading } from '../../selectors'

const EditIndividualsForm = React.memo(({ load, loading, ...props }) => (
const INDIVIDUAL_CORE_FIELDS = INDIVIDUAL_FIELDS.slice(0, -1)

const EditIndividualsForm = React.memo(({ load, loading, user, ...props }) => (
<DataLoader load={load} content={props.records} loading={loading}>
<EditRecordsForm
idField="individualGuid"
entityKey="individuals"
defaultSortColumn={FAMILY_FIELD_ID}
filterColumn={INDIVIDUAL_FIELD_ID}
columns={INDIVIDUAL_FIELDS}
columns={user.isAnalyst ? INDIVIDUAL_FIELDS : INDIVIDUAL_CORE_FIELDS}
{...props}
/>
</DataLoader>
Expand All @@ -28,11 +31,13 @@ EditIndividualsForm.propTypes = {
modalName: PropTypes.string,
load: PropTypes.func,
loading: PropTypes.bool,
user: PropTypes.object,
}

const mapStateToProps = (state, ownProps) => ({
loading: getIndivdualsLoading(state),
records: getProjectAnalysisGroupIndividualsByGuid(state, ownProps),
user: getUser(state),
})

const mapDispatchToProps = {
Expand Down

0 comments on commit 4155a0f

Please sign in to comment.