-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Groups): now we can create new group via UI [#634]
- Loading branch information
1 parent
3a1fb71
commit 99766cf
Showing
15 changed files
with
472 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/ui/src/ui/pages/groups/CreateGroupModal/CreateGroupModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Button from '../../../components/Button/Button'; | ||
import React, {useCallback} from 'react'; | ||
import {useDispatch} from 'react-redux'; | ||
import {openGroupEditorModal} from '../../../store/actions/groups'; | ||
import {isIdmAclAvailable} from '../../../config'; | ||
|
||
export const ShowCreateGroupModalButton: React.FC = () => { | ||
const dispatch = useDispatch(); | ||
const onClick = useCallback(() => { | ||
dispatch(openGroupEditorModal()); | ||
}, []); | ||
|
||
if (isIdmAclAvailable()) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Button view="action" onClick={onClick}> | ||
Create new | ||
</Button> | ||
); | ||
}; |
58 changes: 58 additions & 0 deletions
58
packages/ui/src/ui/pages/groups/DeleteGroupModal/DeleteUserModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React, {useCallback} from 'react'; | ||
import {useDispatch, useSelector} from 'react-redux'; | ||
import {RootState} from '../../../store/reducers'; | ||
import {Text} from '@gravity-ui/uikit'; | ||
import {closeGroupDeleteModal, deleteGroup, fetchGroups} from '../../../store/actions/groups'; | ||
import {YTDFDialog, makeErrorFields} from '../../../components/Dialog'; | ||
import {YTError} from '../../../types'; | ||
|
||
export const DeleteGroupModal: React.FC = () => { | ||
const dispatch = useDispatch(); | ||
const [error, setError] = React.useState<YTError | undefined>(undefined); | ||
const groupNameToDelete = useSelector( | ||
(state: RootState) => state.groups.deleteGroup.groupNameToDelete, | ||
); | ||
|
||
const onClose = useCallback(() => { | ||
dispatch(closeGroupDeleteModal()); | ||
}, [dispatch]); | ||
|
||
const onAdd = useCallback(async () => { | ||
try { | ||
setError(undefined); | ||
|
||
await deleteGroup({groupName: groupNameToDelete}); | ||
|
||
onClose(); | ||
|
||
// we don't need to wait for the end of the action | ||
dispatch(fetchGroups()); | ||
} catch (error) { | ||
setError(error as YTError); | ||
} | ||
}, [dispatch, groupNameToDelete, onClose]); | ||
|
||
return ( | ||
<YTDFDialog | ||
visible={Boolean(groupNameToDelete)} | ||
headerProps={{title: `Delete group ${groupNameToDelete}`}} | ||
pristineSubmittable={true} | ||
onClose={onClose} | ||
onAdd={onAdd} | ||
fields={[ | ||
{ | ||
name: 'groupname', | ||
type: 'block', | ||
extras: { | ||
children: ( | ||
<Text> | ||
Are you sure you want to delete "{groupNameToDelete}"? | ||
</Text> | ||
), | ||
}, | ||
}, | ||
...makeErrorFields([error]), | ||
]} | ||
/> | ||
); | ||
}; |
44 changes: 44 additions & 0 deletions
44
packages/ui/src/ui/pages/groups/GroupActions/GroupActions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from 'react'; | ||
|
||
import {useDispatch} from 'react-redux'; | ||
|
||
import ClickableAttributesButton from '../../../components/AttributesButton/ClickableAttributesButton'; | ||
|
||
import Icon from '../../../components/Icon/Icon'; | ||
import Button from '../../../components/Button/Button'; | ||
|
||
import {openGroupEditorModal, showGroupDeleteModal} from '../../../store/actions/groups'; | ||
import {isIdmAclAvailable} from '../../../config'; | ||
|
||
type GroupActionsProps = { | ||
className?: string; | ||
groupname: string; | ||
}; | ||
|
||
export function GroupActions({className, groupname}: GroupActionsProps) { | ||
const dispatch = useDispatch(); | ||
|
||
const onEdit = React.useCallback(() => { | ||
dispatch(openGroupEditorModal(groupname)); | ||
}, [groupname]); | ||
|
||
const onRemove = React.useCallback(() => { | ||
dispatch(showGroupDeleteModal(groupname)); | ||
}, [groupname]); | ||
|
||
const allowDelete = !isIdmAclAvailable(); | ||
|
||
return ( | ||
<div className={className}> | ||
<ClickableAttributesButton title={groupname} path={`//sys/groups/${groupname}`} /> | ||
<Button view="flat-secondary" size="m" onClick={onEdit}> | ||
<Icon awesome="pencil-alt" /> | ||
</Button> | ||
{allowDelete && ( | ||
<Button view="flat-secondary" size="m" onClick={onRemove}> | ||
<Icon awesome="trash-bin" /> | ||
</Button> | ||
)} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/ui/src/ui/pages/groups/GroupsPageFilters/GroupsPageFilters.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.