summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/odlux/apps/helpApp/src/components/helpStatus.tsx
blob: 813fffd19df0ae34cc84b1501b3559f8ad8f86a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import * as React from 'react';

import { withStyles, WithStyles, createStyles, Theme } from '@material-ui/core/styles';
import { faExclamationTriangle } from '@fortawesome/free-solid-svg-icons';  // select app icon

import connect, { Connect } from '../../../../framework/src/flux/connect';
import { IApplicationStoreState } from '../../../../framework/src/store/applicationStore';

import Typography from '@material-ui/core/Typography';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faQuestionCircle } from '@fortawesome/free-solid-svg-icons';
import { withRouter, RouteComponentProps } from 'react-router';

const styles = (theme: Theme) => createStyles({
  icon: {
    marginLeft: 8,
    marginRight: 8
  },
  disabled: {
    color: theme.palette.grey[400]
  },
  link: {
    cursor: "pointer",
    '&:hover': {
      textDecoration: "underline"
    }
  }
});

const mapProps = (state: IApplicationStoreState) => ({
  appId: state.framework.applicationState.appId,
  toc: state.help.toc
});


type HelpStatusComponentProps = & RouteComponentProps & WithStyles<typeof styles> & Connect<typeof mapProps>;

class HelpStatusComponent extends React.Component<HelpStatusComponentProps> {
  render() {
    const { classes, history, toc, appId } = this.props;
    const rootNode = toc && toc.find(t => t.id === "sdnr");
    const helpNode = appId
      ? rootNode && rootNode.nodes && rootNode.nodes.find(n => n.id === appId || n.id === appId+"App")
      : rootNode;
    return helpNode
      ? (
        <Typography variant="body1" color="inherit" className={classes.link} onClick={(event) => { event.stopPropagation(); history.push(`/help/${helpNode.uri}`) }} >
          <FontAwesomeIcon className={classes.icon} icon={faQuestionCircle} />
          Help
        </Typography>
      )
      : (
        <Typography variant="body1" className={classes.disabled}>
          <FontAwesomeIcon className={classes.icon} icon={faQuestionCircle} />
          Help
        </Typography>
      );
  };

}

export const HelpStatus = withRouter(withStyles(styles)(connect(mapProps)(HelpStatusComponent)));
export default HelpStatus;