Skip to content

Commit

Permalink
Fix [Project settings] Fix members tab display logic (#2073)
Browse files Browse the repository at this point in the history
  • Loading branch information
illia-prokopchuk authored and ilan7empest committed Dec 4, 2023
1 parent 9e5c5f3 commit ed36032
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/api/projects-iguazio-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ const projectsIguazioApi = {
return iguazioHttpClient.post('/async_transactions', data)
},
getScrubbedUsers: config => iguazioHttpClient.get('/scrubbed_users', config),
getScrubbedUserGroups: config => iguazioHttpClient.get('/scrubbed_user_groups', config)
getScrubbedUserGroups: config => iguazioHttpClient.get('/scrubbed_user_groups', config),
getActiveUser: () => iguazioHttpClient.get('/self')
}

export default projectsIguazioApi
26 changes: 23 additions & 3 deletions src/components/ProjectSettings/ProjectSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ import ContentMenu from '../../elements/ContentMenu/ContentMenu'
import { setNotification } from '../../reducers/notificationReducer'
import projectsIguazioApi from '../../api/projects-iguazio-api'
import { PROJECTS_SETTINGS_MEMBERS_TAB, PROJECTS_SETTINGS_SECRETS_TAB } from '../../constants'
import { COMPLETED_STATE, generateMembers, page, tabs, validTabs } from './projectSettings.util'
import {
COMPLETED_STATE,
generateMembers,
isProjectMembersTabShown,
page,
tabs,
validTabs
} from './projectSettings.util'
import { isProjectValid } from '../../utils/handleRedirect'
import {
initialMembersState,
Expand All @@ -53,6 +60,10 @@ const ProjectSettings = ({ frontendSpec, projectStore }) => {
() => frontendSpec?.feature_flags?.project_membership === 'enabled',
[frontendSpec]
)
const projectMembersTabIsShown = useMemo(
() => isProjectMembersTabShown(projectMembershipIsEnabled, membersState),
[membersState, projectMembershipIsEnabled]
)

const fetchProjectIdAndOwner = useCallback(() => {
return projectsIguazioApi
Expand Down Expand Up @@ -108,6 +119,14 @@ const ProjectSettings = ({ frontendSpec, projectStore }) => {
setProjectMembersIsShown(false)
})
}
const fetchActiveUser = () => {
projectsIguazioApi.getActiveUser().then(response => {
membersDispatch({
type: membersActions.SET_ACTIVE_USER,
payload: response.data.data
})
})
}
const fetchProjectOwnerVisibility = project => {
projectsIguazioApi
.getProjectOwnerVisibility(project)
Expand All @@ -124,6 +143,7 @@ const ProjectSettings = ({ frontendSpec, projectStore }) => {
fetchProjectOwnerVisibility(params.projectName)
fetchProjectIdAndOwner()
.then(projectId => {
fetchActiveUser()
fetchProjectMembersVisibility(params.projectName)

return fetchProjectMembers(projectId)
Expand Down Expand Up @@ -215,9 +235,9 @@ const ProjectSettings = ({ frontendSpec, projectStore }) => {
activeTab={params.pageTab}
location={location}
screen={page}
tabs={tabs(projectMembershipIsEnabled)}
tabs={tabs(projectMembersTabIsShown)}
/>
{params.pageTab === PROJECTS_SETTINGS_MEMBERS_TAB && projectMembershipIsEnabled ? (
{params.pageTab === PROJECTS_SETTINGS_MEMBERS_TAB && projectMembersTabIsShown ? (
<ProjectSettingsMembers
changeMembersCallback={changeMembersCallback}
loading={membersState.loading}
Expand Down
14 changes: 14 additions & 0 deletions src/components/ProjectSettings/projectSettings.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,17 @@ export const generateMembers = (membersResponse, membersDispatch) => {
payload: members
})
}

export const isProjectMembersTabShown = (
projectMembershipIsEnabled,
{ activeUser, members, projectInfo }
) => {
if (!projectMembershipIsEnabled) {
return false
}

const userIsAdmin = members.some(member => member.role === 'Admin' && member.id === activeUser.id)
const userIsOwner = activeUser.id === projectInfo.owner.id

return userIsOwner || userIsAdmin
}
8 changes: 8 additions & 0 deletions src/elements/MembersPopUp/membersReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ such restriction.
import { groupBy } from 'lodash'

/*
* - activeUser : logged in user data
* - projectInfo : additional information about the project such as ID and Owner of the project
* (data is received from iguazio API).
* - projectAuthorizationRoles: the list of modification roles (Admin, Editor, Viewer). Each of them contains the list
Expand All @@ -34,6 +35,7 @@ import { groupBy } from 'lodash'
* - groupedVisibleMembers : grouped members list by their role, which is used to generate the request body.
* */
export const initialMembersState = {
activeUser: {},
projectInfo: {
id: '',
owner: {
Expand All @@ -57,6 +59,7 @@ export const membersActions = {
GET_PROJECT_USERS_DATA_BEGIN: 'GET_PROJECT_USERS_DATA_BEGIN',
GET_PROJECT_USERS_DATA_END: 'GET_PROJECT_USERS_DATA_END',
RESET_MEMBERS_STATE: 'RESET_MEMBERS_STATE',
SET_ACTIVE_USER: 'SET_ACTIVE_USER',
SET_MEMBERS: 'SET_MEMBERS',
SET_MEMBERS_ORIGINAL: 'SET_MEMBERS_ORIGINAL',
SET_PROJECT_AUTHORIZATION_ROLES: 'SET_PROJECT_AUTHORIZATION_ROLES',
Expand All @@ -81,6 +84,11 @@ export const membersReducer = (state, { type, payload }) => {
...state,
loading: false
}
case membersActions.SET_ACTIVE_USER:
return {
...state,
activeUser: payload
}
case membersActions.SET_MEMBERS:
return {
...state,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@import '~igz-controls/scss/colors';
@import '~igz-controls/scss/mixins';
@import '../../scss/main.scss';

.settings {
@import '../../scss/main.scss';
&__artifact-path,
&__goals,
&__description,
Expand Down
10 changes: 3 additions & 7 deletions src/elements/ProjectSettingsMembers/ProjectSettingsMembers.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ const ProjectSettingsMembers = ({
projectMembersIsShown,
setNotification
}) => {
const totalMembersInProject =
membersState.users.length + membersState.userGroups.length
const totalMembersInProject = membersState.users.length + membersState.userGroups.length
return (
<div className="settings__card">
{loading ? (
Expand All @@ -48,11 +47,8 @@ const ProjectSettingsMembers = ({
<span className="settings__members-summary_icon">
<Users />
</span>
<span className="settings__members-summary_amount">
{totalMembersInProject}
</span>
member{totalMembersInProject !== 1 ? 's have' : ' has'} access to
this project
<span className="settings__members-summary_amount">{totalMembersInProject}</span>
{totalMembersInProject !== 1 ? 'members have' : 'member has'} access to this project
</div>
{projectMembersIsShown && (
<MembersPopUp
Expand Down

0 comments on commit ed36032

Please sign in to comment.