Skip to content

Commit

Permalink
feat(auth-ui): toggle intro submit data button text per authz
Browse files Browse the repository at this point in the history
  • Loading branch information
vpsx committed Oct 11, 2019
1 parent 513210f commit 5e1d0e6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/Index/page.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import MediaQuery from 'react-responsive';
import Introduction from '../components/Introduction';
import { ReduxIndexButtonBar, ReduxIndexBarChart, ReduxIndexCounts } from './reduxer';
import { ReduxIndexButtonBar, ReduxIndexBarChart, ReduxIndexCounts, ReduxIntroduction } from './reduxer';
import dictIcons from '../img/icons';
import { components } from '../params';
import getProjectNodeCounts from './utils';
Expand All @@ -24,7 +23,7 @@ class IndexPageComponent extends React.Component {
<div className='index-page'>
<div className='index-page__top'>
<div className='index-page__introduction'>
<Introduction data={components.index.introduction} dictIcons={dictIcons} />
<ReduxIntroduction data={components.index.introduction} dictIcons={dictIcons} />
<MediaQuery query={`(max-width: ${breakpoints.tablet}px)`}>
<ReduxIndexCounts />
</MediaQuery>
Expand Down
9 changes: 9 additions & 0 deletions src/Index/reduxer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { setActive } from '../Layout/reduxer';
import IndexBarChart from '../components/charts/IndexBarChart/.';
import IndexCounts from '../components/cards/IndexCounts/.';
import IndexButtonBar from '../components/IndexButtonBar';
import Introduction from '../components/Introduction';
import { components } from '../params';

export const ReduxIndexBarChart = (() => {
Expand Down Expand Up @@ -61,3 +62,11 @@ export const ReduxIndexButtonBar = (() => {

return connect(mapStateToProps, mapDispatchToProps)(IndexButtonBar);
})();

export const ReduxIntroduction = (() => {
const mapStateToProps = state => ({
userAuthMapping: state.userAuthMapping,
});

return connect(mapStateToProps)(Introduction);
})();
24 changes: 23 additions & 1 deletion src/components/Introduction.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,32 @@ import PropTypes from 'prop-types';
import React, { Component } from 'react';
import IconicLink from './buttons/IconicLink';
import './Introduction.less';
import { useArboristUI } from '../configs';

class Introduction extends Component {
static propTypes = {
data: PropTypes.object.isRequired,
dictIcons: PropTypes.object.isRequired,
};

userHasCreateForAnyProject = () => {
const actionHasCreate = x => { return (x["method"] === "create") }
//array of arrays of { service: x, method: y }
var actionArrays = Object.values(this.props.userAuthMapping)
var hasCreate = actionArrays.some(x => { return x.some(actionHasCreate) })
return hasCreate
}

render() {
var buttonText = 'Submit Data'
if (useArboristUI) {
if (this.userHasCreateForAnyProject()) {
buttonText = 'Submit/Browse Data'
} else {
buttonText = 'Browse Data'
}
}

return (
<div className='introduction'>
<div className='h1-typo introduction__title'>{this.props.data.heading}</div>
Expand All @@ -20,11 +38,15 @@ class Introduction extends Component {
className='introduction__icon'
icon='upload'
iconColor='#'
caption='Submit Data'
caption={buttonText}
/>
</div>
);
}
}

Introduction.propTypes = {
userAuthMapping: PropTypes.object.isRequired,
};

export default Introduction;

0 comments on commit 5e1d0e6

Please sign in to comment.