Skip to content
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

New style permissions #899

Merged
merged 48 commits into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
9b77227
OrgView: provide the app width
bpierre Jul 29, 2019
a9b55a1
Permissions: add permissionsByRole()
bpierre Jul 29, 2019
677c524
Add usePermissions() and usePermissionsPerRole()
bpierre Jul 29, 2019
38d15fd
LocalIdentityBadge: coding style
bpierre Jul 29, 2019
e529371
Permissions new style - initial version
bpierre Jul 29, 2019
d73ce4b
Permissions: manage role + filter by action
bpierre Aug 5, 2019
d6aedb3
Fix syntax
bpierre Aug 5, 2019
4471abb
Permissions: remove dead code since we don't have the entity view any…
sohkai Aug 18, 2019
6394c73
Permissions: prefer 'appAddress' over 'proxyAddress' and remove redun…
sohkai Aug 18, 2019
969cad9
Permissions: fix lint
sohkai Aug 18, 2019
ba6ef62
Merge branch 'newstyle' into newstyle-permissions
sohkai Aug 18, 2019
f132e23
OrgView: add proptypes
sohkai Aug 18, 2019
26cc9bc
useAppWidth: refactor into its own hook inside apps/
sohkai Aug 18, 2019
8c514fc
Permissions: remove more assumptions about selecting by entity
sohkai Aug 18, 2019
5310385
Permissions: clarify how scroll to top works
sohkai Aug 18, 2019
013958b
Permissions: update to new Button API
sohkai Aug 18, 2019
e8b98b9
Permissions: remove unused components
sohkai Aug 18, 2019
424968e
AppCard: use Tag and adjust styles
sohkai Aug 18, 2019
0021a2d
Permissions: search by app name and role name
sohkai Aug 18, 2019
e70826b
Permissions: align entity type dropdown with other apps
sohkai Aug 18, 2019
054b5e7
Permissions: small AppPermissions tweaks and fixes
sohkai Aug 18, 2019
123e90c
Permissions: don't add extra left padding to permissions table if no …
sohkai Aug 18, 2019
6af5797
Permissions: avoid showing permissions table heading in smaller layouts
sohkai Aug 18, 2019
d09c1b1
Permissions: update assign and manage panels to new DropDown
sohkai Aug 18, 2019
2491f84
Permissions: add empty filtered state
sohkai Aug 18, 2019
878ea11
Permissions: prefer 'appAddress' over 'proxyAddress' when referring t…
sohkai Aug 18, 2019
e957fe1
Permissions: remove more dead code
sohkai Aug 18, 2019
bc71a61
Permissions: update Tag API to prefer 'label' prop over children
sohkai Aug 18, 2019
5393bc9
Permissions: update text styles
sohkai Aug 18, 2019
8c5c0c7
Permissions: add PermissionsIdentityBadge to handle any and burned en…
sohkai Aug 18, 2019
6db3923
cosmetic: alphabetize definitions in prop-types
sohkai Aug 18, 2019
8a605f0
AppCard: remove custom CSS on Tag
bpierre Aug 20, 2019
f15c5e2
Permissions header: fix text wrap / overflow
bpierre Aug 20, 2019
efd370c
Move AppCard to its own component
bpierre Aug 20, 2019
6d7ac94
Permissions search: debounce updates
bpierre Aug 20, 2019
e8736c1
PermissionsIdentityBadge: extend LocalIdentityBadge proptypes
bpierre Aug 21, 2019
53d1de8
Memoize PermissionsView
bpierre Aug 21, 2019
16796f0
Move the tabs state one level up to keep it between screens
bpierre Aug 21, 2019
25365b0
Routing: add a local path for apps
bpierre Aug 21, 2019
60b9314
Permissions: use a local path
bpierre Aug 21, 2019
88435a4
Merge branch 'newstyle' into newstyle-permissions
bpierre Aug 21, 2019
93a63e8
Remove direct window.location.hash manipulations
bpierre Aug 21, 2019
9cff7b6
Missing hook dependency
bpierre Aug 21, 2019
c23294a
Remove one more window.location.hash
bpierre Aug 21, 2019
1f84578
Merge branch 'newstyle' into newstyle-permissions
bpierre Aug 21, 2019
ddc5835
ESLint
bpierre Aug 21, 2019
294d46a
ESLint
bpierre Aug 21, 2019
a320208
Routing: remove spurious trailing slashes on navigation
sohkai Aug 21, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"eth-provider": "^0.2.0",
"file-saver": "^2.0.1",
"history": "^4.9.0",
"lodash.debounce": "^4.0.8",
"lodash.memoize": "^4.1.2",
"lodash.throttle": "^4.1.1",
"lodash.uniqby": "^4.7.0",
Expand Down
22 changes: 15 additions & 7 deletions src/Wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ class Wrapper extends React.PureComponent {
}
}

openApp = (instanceId, params) => {
openApp = (instanceId, { params, localPath } = {}) => {
if (this.props.autoClosingPanel) {
// this.handleMenuPanelClose()
}

const { historyPush, locator } = this.props
historyPush(getAppPath({ dao: locator.dao, instanceId, params }))
historyPush(getAppPath({ dao: locator.dao, instanceId, params, localPath }))
}

handleAppIFrameRef = appIFrame => {
Expand Down Expand Up @@ -166,7 +166,12 @@ class Wrapper extends React.PureComponent {
}
// params need to be a string
handleParamsRequest = params => {
this.openApp(this.props.locator.instanceId, params)
this.openApp(this.props.locator.instanceId, { params })
}

// Update the local path of the current instance
handlePathRequest = localPath => {
this.openApp(this.props.locator.instanceId, { localPath })
}

getAppInstancesGroups = memoize(apps =>
Expand Down Expand Up @@ -285,7 +290,10 @@ class Wrapper extends React.PureComponent {
daoLoading={daoStatus === DAO_STATUS_LOADING}
instanceId={locator.instanceId}
>
{this.renderApp(locator.instanceId, locator.params)}
{this.renderApp(locator.instanceId, {
params: locator.params,
localPath: locator.localPath,
})}
</AppLoader>

<SignerPanel
Expand Down Expand Up @@ -322,7 +330,7 @@ class Wrapper extends React.PureComponent {
</div>
)
}
renderApp(instanceId, params) {
renderApp(instanceId, { params, localPath }) {
const {
account,
apps,
Expand Down Expand Up @@ -359,9 +367,9 @@ class Wrapper extends React.PureComponent {
apps={apps}
appsLoading={appsLoading}
permissionsLoading={permissionsLoading}
params={params}
localPath={localPath}
onMessage={this.handleAppMessage}
onParamsRequest={this.handleParamsRequest}
onPathRequest={this.handlePathRequest}
wrapper={wrapper}
/>
)
Expand Down
100 changes: 0 additions & 100 deletions src/apps/Permissions/AppCard.js

This file was deleted.

170 changes: 43 additions & 127 deletions src/apps/Permissions/AppPermissions.js
Original file line number Diff line number Diff line change
@@ -1,140 +1,56 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Button, Table, TableRow, Text, Viewport } from '@aragon/ui'
import LocalIdentityBadge from '../../components/IdentityBadge/LocalIdentityBadge'
import { TableHeader, TableCell, FirstTableCell, LastTableCell } from './Table'
import { PermissionsConsumer } from '../../contexts/PermissionsContext'
import { AppType, EthereumAddressType } from '../../prop-types'
import Section from './Section'
import { BackButton, Bar, textStyle } from '@aragon/ui'
import { AppType } from '../../prop-types'
import { usePermissionsByRole } from '../../contexts/PermissionsContext'
import EmptyBlock from './EmptyBlock'
import AppInstanceLabel from '../../components/AppInstanceLabel'
import EntityPermissions from './EntityPermissions'
import AppRoles from './AppRoles'
import PermissionsView from './PermissionsView'

class AppPermissions extends React.PureComponent {
static propTypes = {
address: EthereumAddressType.isRequired,
app: AppType, // may not be available if still loading
loading: PropTypes.bool.isRequired,
onManageRole: PropTypes.func.isRequired,
}
render() {
const { app, loading, address, onManageRole } = this.props
return (
<PermissionsConsumer>
{({ revokePermission, getAppPermissions }) => {
const appPermissions = getAppPermissions(app)
return (
<React.Fragment>
<AppRoles
app={app}
loading={loading}
onManageRole={onManageRole}
/>
<Section title="Permissions set on this app">
{loading || appPermissions.length === 0 ? (
<EmptyBlock>
{loading
? 'Loading app permissions…'
: 'No permissions set.'}
</EmptyBlock>
) : (
<Viewport>
{({ below }) => (
<Table
noSideBorders={below('medium')}
header={
<TableRow>
<TableHeader
title="Action"
style={{ width: '20%' }}
/>
<TableHeader title="Allowed for" />
<TableHeader />
</TableRow>
}
>
{appPermissions.map(({ role, entity }, i) => (
<Row
key={i}
role={role}
entity={entity}
proxyAddress={address}
onRevoke={revokePermission}
/>
))}
</Table>
)}
</Viewport>
)}
</Section>
<EntityPermissions
title="Permissions granted to this app"
noPermissionsLabel="No permissions granted."
address={address}
loading={loading}
onRevoke={revokePermission}
/>
</React.Fragment>
)
}}
</PermissionsConsumer>
)
}
}
function AppPermissions({ app, loading, onBack, onManageRole }) {
const permissions = usePermissionsByRole()

class Row extends React.Component {
static propTypes = {
entity: PropTypes.object.isRequired,
onRevoke: PropTypes.func.isRequired,
proxyAddress: EthereumAddressType.isRequired,
role: PropTypes.object.isRequired,
if (loading) {
return <EmptyBlock>Loading permissions…</EmptyBlock>
}

handleRevoke = () => {
const { onRevoke, role, entity, proxyAddress } = this.props
onRevoke({
proxyAddress,
roleBytes: role.bytes,
entityAddress: entity.address,
})
}
renderEntity() {
const { entity } = this.props
if (!entity) {
return 'Unknown'
}
if (entity.type === 'app') {
return <AppInstanceLabel app={entity.app} proxyAddress={entity.address} />
}
const appPermissions = permissions.filter(
permission =>
permission.app && permission.app.proxyAddress === app.proxyAddress
)

return (
<LocalIdentityBadge
entity={entity.type === 'any' ? 'Any account' : entity.address}
/>
)
if (appPermissions.length === 0) {
return <EmptyBlock>No permissions found.</EmptyBlock>
}
render() {
const { role } = this.props
return (
<TableRow>
<FirstTableCell>
<Text weight="bold">{role ? role.name : 'Unknown'}</Text>
</FirstTableCell>
<TableCell>{this.renderEntity()}</TableCell>
<LastTableCell align="right">
<Button
mode="outline"
emphasis="negative"
compact
onClick={this.handleRevoke}

return (
<React.Fragment>
<Bar>
<BackButton onClick={onBack} />
</Bar>
<PermissionsView
heading={
<span
css={`
${textStyle('body2')}
font-weight: 600;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? Shouldn't body2 take care of the correct font-weight?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The designs had them at a different font-weight than the default (400).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then my suggestion would be to revisit the designs so that these are in sync, it seems a bit arbitrary that this body2 text has a different font-weight
cc @dizzypaty

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we need to add some variants I think (e.g. body2-bold).

`}
>
Revoke
</Button>
</LastTableCell>
</TableRow>
)
}
Available permissions
</span>
}
onManageRole={onManageRole}
permissions={appPermissions}
showApps={false}
/>
</React.Fragment>
)
}

AppPermissions.propTypes = {
app: AppType, // may not be available if still loading
loading: PropTypes.bool.isRequired,
onManageRole: PropTypes.func.isRequired,
onBack: PropTypes.func.isRequired,
}

export default AppPermissions
Loading