BrowserBar.tsx 6.28 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
  getObjectInfo,
23
24
  getTrackPanelModalOpened,
  getTrackPanelOpened
25
} from '../browserSelectors';
Andrey Azov's avatar
Andrey Azov committed
26
import { RootState } from 'src/store';
27

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

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

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

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

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

type BrowserBarProps = StateProps & DispatchProps & OwnProps;

Imran Salam's avatar
Imran Salam committed
60
61
62
63
export const BrowserBar: FunctionComponent<BrowserBarProps> = (
  props: BrowserBarProps
) => {
  const { navigator, reset } = browserInfoConfig;
64
  const { objectInfo } = props;
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
  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]);
87

88
89
90
  const getBrowserInfoClasses = () => {
    let classNames = styles.browserInfo;

91
92
93
94
    if (props.trackPanelOpened === false) {
      classNames += ` ${styles.browserInfoExpanded}`;
    }

95
96
97
98
99
100
101
102
    if (props.drawerOpened === true) {
      classNames += ` ${styles.browserInfoGreyed}`;
    }

    return classNames;
  };

  const getBrowserNavIcon = () => {
103
    if (props.drawerOpened === true) {
104
      return navigator.icon.grey;
105
106
    } else if (props.browserNavOpened === true) {
      return navigator.icon.selected;
107
108
109
110
111
    } else {
      return navigator.icon.default;
    }
  };

112
113
114
115
116
117
118
119
  const toggleNavigator = () => {
    if (props.drawerOpened === true) {
      return;
    }

    props.toggleBrowserNav();
  };

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

189
const mapStateToProps = (state: RootState): StateProps => ({
190
  browserActivated: getBrowserActivated(state),
191
  browserNavOpened: getBrowserNavOpened(state),
192
  chrLocation: getChrLocation(state),
193
  defaultChrLocation: getDefaultChrLocation(state),
194
  drawerOpened: getDrawerOpened(state),
195
  genomeSelectorActive: getGenomeSelectorActive(state),
196
  objectInfo: getObjectInfo(state),
197
  selectedBrowserTab: getSelectedBrowserTab(state),
198
199
  trackPanelModalOpened: getTrackPanelModalOpened(state),
  trackPanelOpened: getTrackPanelOpened(state)
200
201
202
});

const mapDispatchToProps: DispatchProps = {
203
  selectBrowserTab,
204
  toggleBrowserNav,
205
  toggleDrawer,
206
  toggleGenomeSelector
207
208
209
210
211
212
};

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