-
-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/issue actions revisited (#1160)
* replacing issue actions with more simple ones and based on role * fixing no defined task variable * simplifying main bounty actions on the issue page for admin and users
- Loading branch information
Showing
21 changed files
with
700 additions
and
160 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
frontend/src/components/design-library/molecules/action-buttons/action-buttons.stories.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,87 @@ | ||
import React, { Component } from 'react'; | ||
import AddIcon from '@material-ui/icons/Add'; | ||
import EditIcon from '@material-ui/icons/Edit'; | ||
import DeleteIcon from '@material-ui/icons/Delete'; | ||
import CancelIcon from '@material-ui/icons/Cancel'; | ||
import SaveIcon from '@material-ui/icons/Save'; | ||
import ActionButtons from './action-buttons'; | ||
import { Dialog } from '@material-ui/core'; | ||
|
||
export default { | ||
title: 'Design Library/Molecules/ActionButtons', | ||
component: ActionButtons, | ||
}; | ||
|
||
const Template = (args) => <ActionButtons {...args} />; | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = { | ||
primary: [ | ||
{ | ||
key: 'create', | ||
onClick: () => {}, | ||
label: 'Create', | ||
disabled: false, | ||
icon: <AddIcon fontSize='small' />, | ||
component: <Dialog open={false}>create</Dialog>, | ||
}, | ||
], | ||
secondary: [ | ||
{ | ||
key: 'cancel', | ||
onClick: () => {}, | ||
label: 'Cancel', | ||
disabled: false, | ||
icon: <CancelIcon fontSize='small' />, | ||
component: <Dialog open={false}>cancel</Dialog>, | ||
}, | ||
], | ||
}; | ||
|
||
export const WithManyActions = Template.bind({}); | ||
WithManyActions.args = { | ||
primary: [ | ||
{ | ||
key: 'create 2', | ||
onClick: () => {}, | ||
label: 'Create', | ||
disabled: false, | ||
icon: <AddIcon fontSize='small' />, | ||
component: <Dialog open={false}>create 2</Dialog>, | ||
}, | ||
{ | ||
key: 'edit', | ||
onClick: () => {}, | ||
label: 'Edit', | ||
disabled: false, | ||
icon: <EditIcon fontSize='small' />, | ||
component: <Dialog open={false}>edit</Dialog>, | ||
}, | ||
{ | ||
key: 'delete', | ||
onClick: () => {}, | ||
label: 'Delete', | ||
disabled: false, | ||
icon: <DeleteIcon fontSize='small' />, | ||
component: <Dialog open={false}>delete</Dialog>, | ||
}, | ||
], | ||
secondary: [ | ||
{ | ||
key: 'cancel secondary', | ||
onClick: () => {}, | ||
label: 'Cancel', | ||
disabled: false, | ||
icon: <CancelIcon fontSize='small' />, | ||
component: <Dialog open={false}>cancel secondary</Dialog>, | ||
}, | ||
{ | ||
key: 'save secondary', | ||
onClick: () => {}, | ||
label: 'Save', | ||
disabled: false, | ||
icon: <SaveIcon fontSize='small' />, | ||
component: <Dialog open={false}>save secondary</Dialog>, | ||
}, | ||
], | ||
}; |
66 changes: 66 additions & 0 deletions
66
frontend/src/components/design-library/molecules/action-buttons/action-buttons.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,66 @@ | ||
import React from 'react'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { Button } from '@material-ui/core'; | ||
|
||
|
||
interface ActionButtonsProps { | ||
primary: any[]; | ||
secondary: any[]; | ||
} | ||
|
||
const ActionButtons: React.FC<ActionButtonsProps> = ({ primary, secondary }) => { | ||
const [ currentKey, setCurrentKey ] = React.useState(''); | ||
|
||
const actionClick = (key:string, onClick: any) => { | ||
setCurrentKey(key); | ||
onClick?.(); | ||
} | ||
|
||
return ( | ||
<div> | ||
{primary?.map((action, index) => ( | ||
<> | ||
<div style={{ marginTop: 30, marginBottom: 10 }}> | ||
<Button | ||
onClick={() => actionClick(action.key, action.onClick)} | ||
color='primary' | ||
fullWidth | ||
size='large' | ||
variant='contained' | ||
disabled={action.disabled} | ||
endIcon={action.icon} | ||
> | ||
<span style={{ display: 'inline-block', marginRight: 10 }}> | ||
<FormattedMessage id={action.label} /> | ||
</span> | ||
</Button> | ||
</div> | ||
{action.component && React.cloneElement(action.component, { open: action.key === currentKey, onClose: () => setCurrentKey('') })} | ||
</> | ||
))} | ||
<div style={{ display: 'flex', justifyContent: 'space-evenly' }}> | ||
{secondary?.map((action, index) => ( | ||
<> | ||
<Button | ||
onClick={() => actionClick(action.key, action.onClick)} | ||
size='small' | ||
color='secondary' | ||
variant='contained' | ||
disabled={action.disabled} | ||
fullWidth | ||
style={{ marginRight: 5 }} | ||
endIcon={action.icon} | ||
> | ||
<span style={{ display: 'inline-block', marginRight: 10 }}> | ||
{action.label} | ||
</span> | ||
</Button> | ||
{action.component && React.cloneElement(action.component, { open: action.key === currentKey, onClose: () => setCurrentKey('') })} | ||
</> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ActionButtons; |
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
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
61 changes: 61 additions & 0 deletions
61
frontend/src/components/design-library/organisms/issue-actions/issue-actions.stories.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,61 @@ | ||
import React from 'react'; | ||
import IssueActions from './issue-actions'; | ||
|
||
const roles = { | ||
admin: { | ||
primary: [ | ||
{ | ||
onClick: () => {}, | ||
label: 'Pay contributor', | ||
disabled: false, | ||
icon: null, | ||
}, | ||
], | ||
secondary: [ | ||
{ | ||
onClick: () => {}, | ||
label: 'Make a payment', | ||
disabled: false, | ||
icon: null, | ||
}, | ||
], | ||
}, | ||
user: { | ||
primary: [ | ||
{ | ||
onClick: () => {}, | ||
label: 'Create', | ||
disabled: false, | ||
icon: null, | ||
}, | ||
], | ||
secondary: [ | ||
{ | ||
onClick: () => {}, | ||
label: 'Cancel', | ||
disabled: false, | ||
icon: null, | ||
}, | ||
], | ||
}, | ||
} | ||
|
||
export default { | ||
title: 'Design Library/Organisms/IssueActions', | ||
component: IssueActions, | ||
}; | ||
|
||
const Template = (args) => <IssueActions {...args} />; | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = { | ||
role: 'admin', | ||
roles, | ||
|
||
}; | ||
|
||
export const User = Template.bind({}); | ||
User.args = { | ||
role: 'user', | ||
roles, | ||
} |
22 changes: 22 additions & 0 deletions
22
frontend/src/components/design-library/organisms/issue-actions/issue-actions.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 React from 'react'; | ||
import ActionButtons from '../../molecules/action-buttons/action-buttons'; | ||
|
||
interface IssueActionsProps { | ||
role: string; | ||
roles: any; | ||
children?: React.ReactNode; | ||
} | ||
|
||
const IssueActions = ({ | ||
role, | ||
roles, | ||
}:IssueActionsProps) => { | ||
return ( | ||
<ActionButtons | ||
primary={roles[role].primary} | ||
secondary={roles[role].secondary} | ||
/> | ||
); | ||
}; | ||
|
||
export default IssueActions; |
Oops, something went wrong.