BrowserBar.tsx 6.02 KB
Newer Older
1
import React, { FunctionComponent, Fragment, useState, useEffect } from 'react';
2
import { connect } from 'react-redux';
3
4

import { browserInfoConfig } from '../browserConfig';
5
6
import { TrackType } from '../track-panel/trackPanelConfig';

7
8
import {
  toggleBrowserNav,
9
  toggleGenomeSelector,
10
11
  selectBrowserTab,
  toggleDrawer
12
} from '../browserActions';
13
import { ChrLocation } from '../browserState';
14
15
16
import {
  getBrowserNavOpened,
  getChrLocation,
17
  getBrowserActivated,
18
  getDefaultChrLocation,
19
  getGenomeSelectorActive,
20
  getDrawerOpened,
21
  getSelectedBrowserTab,
22
23
  getObjectInfo,
  getTrackPanelModalOpened
24
} from '../browserSelectors';
25
26
import { RootState } from 'src/rootReducer';

Imran Salam's avatar
Imran Salam committed
27
import BrowserReset from '../browser-reset/BrowserReset';
28
import BrowserGenomeSelector from '../browser-genome-selector/BrowserGenomeSelector';
29
import BrowserTabs from '../browser-tabs/BrowserTabs';
30
31

import styles from './BrowserBar.scss';
32

33
type StateProps = {
34
  browserActivated: boolean;
35
  browserNavOpened: boolean;
36
  chrLocation: ChrLocation;
37
  defaultChrLocation: ChrLocation;
38
  drawerOpened: boolean;
39
  genomeSelectorActive: boolean;
40
  objectInfo: any;
41
  selectedBrowserTab: TrackType;
42
  trackPanelModalOpened: boolean;
43
44
45
};

type DispatchProps = {
46
  selectBrowserTab: (selectedBrowserTab: TrackType) => void;
47
  toggleBrowserNav: () => void;
48
  toggleDrawer: (drawerOpened: boolean) => void;
49
  toggleGenomeSelector: (genomeSelectorActive: boolean) => void;
50
51
};

Imran Salam's avatar
Imran Salam committed
52
type OwnProps = {
53
  dispatchBrowserLocation: (chrLocation: ChrLocation) => void;
Imran Salam's avatar
Imran Salam committed
54
};
55
56
57

type BrowserBarProps = StateProps & DispatchProps & OwnProps;

Imran Salam's avatar
Imran Salam committed
58
59
60
61
export const BrowserBar: FunctionComponent<BrowserBarProps> = (
  props: BrowserBarProps
) => {
  const { navigator, reset } = browserInfoConfig;
62
  const { objectInfo } = props;
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
  const [showBrowserInfo, toggleShowBrowserInfo] = useState(true);

  const changeBrowserInfoToggle = () => {
    const [, chrStart, chrEnd] = props.defaultChrLocation;

    if (
      props.genomeSelectorActive === true ||
      (chrStart === 0 && chrEnd === 0)
    ) {
      toggleShowBrowserInfo(false);
    } else {
      toggleShowBrowserInfo(true);
    }
  };

  useEffect(() => {
    changeBrowserInfoToggle();
  }, [props.defaultChrLocation]);

  useEffect(() => {
    changeBrowserInfoToggle();
  }, [props.genomeSelectorActive]);
85

86
87
88
89
90
91
92
93
94
95
96
  const getBrowserInfoClasses = () => {
    let classNames = styles.browserInfo;

    if (props.drawerOpened === true) {
      classNames += ` ${styles.browserInfoGreyed}`;
    }

    return classNames;
  };

  const getBrowserNavIcon = () => {
97
    if (props.drawerOpened === true) {
98
      return navigator.icon.grey;
99
100
    } else if (props.browserNavOpened === true) {
      return navigator.icon.selected;
101
102
103
104
105
    } else {
      return navigator.icon.default;
    }
  };

106
107
108
109
110
111
112
113
  const toggleNavigator = () => {
    if (props.drawerOpened === true) {
      return;
    }

    props.toggleBrowserNav();
  };

Imran Salam's avatar
Imran Salam committed
114
115
  return (
    <div className={styles.browserBar}>
116
      <div className={getBrowserInfoClasses()}>
Imran Salam's avatar
Imran Salam committed
117
        <dl className={styles.browserInfoLeft}>
118
          <BrowserReset
119
            dispatchBrowserLocation={props.dispatchBrowserLocation}
120
121
            chrLocation={props.chrLocation}
            defaultChrLocation={props.defaultChrLocation}
122
123
            details={reset}
            drawerOpened={props.drawerOpened}
124
          />
125
          {showBrowserInfo ? (
126
127
128
            <Fragment>
              <dd className={styles.geneSymbol}>
                <label>Gene</label>
129
                <span className={styles.value}>{objectInfo.obj_symbol}</span>
130
131
132
              </dd>
              <dd>
                <label>Stable ID</label>
133
                <span className={styles.value}>{objectInfo.stable_id}</span>
134
135
136
              </dd>
              <dd className="show-for-large">
                <label>Spliced mRNA length</label>
137
138
139
                <span className={styles.value}>
                  {objectInfo.spliced_length}
                </span>
140
141
                <label>bp</label>
              </dd>
142
              <dd className={`show-for-large ${styles.nonLabelValue}`}>
143
                {objectInfo.bio_type}
144
145
              </dd>
              <dd className={`show-for-large ${styles.nonLabelValue}`}>
146
                {objectInfo.strand} strand
147
              </dd>
148
            </Fragment>
149
          ) : null}
Imran Salam's avatar
Imran Salam committed
150
151
        </dl>
        <dl className={styles.browserInfoRight}>
152
153
          <BrowserGenomeSelector
            browserActivated={props.browserActivated}
154
            dispatchBrowserLocation={props.dispatchBrowserLocation}
155
            defaultChrLocation={props.defaultChrLocation}
156
            drawerOpened={props.drawerOpened}
157
158
            genomeSelectorActive={props.genomeSelectorActive}
            toggleGenomeSelector={props.toggleGenomeSelector}
159
          />
160
161
          {props.genomeSelectorActive ? null : (
            <dd className={styles.navigator}>
162
              <button title={navigator.description} onClick={toggleNavigator}>
163
                <img src={getBrowserNavIcon()} alt={navigator.description} />
164
165
166
              </button>
            </dd>
          )}
167
168
        </dl>
      </div>
169
170
171
172
173
      <BrowserTabs
        drawerOpened={props.drawerOpened}
        genomeSelectorActive={props.genomeSelectorActive}
        selectBrowserTab={props.selectBrowserTab}
        selectedBrowserTab={props.selectedBrowserTab}
174
        toggleDrawer={props.toggleDrawer}
175
        trackPanelModalOpened={props.trackPanelModalOpened}
176
      />
Imran Salam's avatar
Imran Salam committed
177
178
179
    </div>
  );
};
180

181
const mapStateToProps = (state: RootState): StateProps => ({
182
  browserActivated: getBrowserActivated(state),
183
  browserNavOpened: getBrowserNavOpened(state),
184
  chrLocation: getChrLocation(state),
185
  defaultChrLocation: getDefaultChrLocation(state),
186
  drawerOpened: getDrawerOpened(state),
187
  genomeSelectorActive: getGenomeSelectorActive(state),
188
  objectInfo: getObjectInfo(state),
189
190
  selectedBrowserTab: getSelectedBrowserTab(state),
  trackPanelModalOpened: getTrackPanelModalOpened(state)
191
192
193
});

const mapDispatchToProps: DispatchProps = {
194
  selectBrowserTab,
195
  toggleBrowserNav,
196
  toggleDrawer,
197
  toggleGenomeSelector
198
199
200
201
202
203
};

export default connect(
  mapStateToProps,
  mapDispatchToProps
)(BrowserBar);