ZmenuAppLinks.tsx 2.07 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/**
 * See the NOTICE file distributed with this work for additional information
 * regarding copyright ownership.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

17
import React from 'react';
18
import { useSelector } from 'react-redux';
19 20

import * as urlFor from 'src/shared/helpers/urlHelper';
21 22
import { parseFeatureId } from 'src/content/app/browser/browserHelper';
import { buildFocusIdForUrl } from 'src/shared/state/ens-object/ensObjectHelpers';
23

24
import { getBrowserActiveGenomeId } from '../browserSelectors';
25 26

import { ToggleButton as ToolboxToggleButton } from 'src/shared/components/toolbox';
27
import ViewInApp, { UrlObj } from 'src/shared/components/view-in-app/ViewInApp';
28 29 30 31 32 33 34 35

import styles from './Zmenu.scss';

type Props = {
  featureId: string;
};

const ZmenuAppLinks = (props: Props) => {
36 37
  const genomeId = useSelector(getBrowserActiveGenomeId);

38
  const parsedFeatureId = parseFeatureId(props.featureId);
39

40
  if (parsedFeatureId.type !== 'gene') {
41 42 43
    return null;
  }

44 45
  const featureIdForUrl = buildFocusIdForUrl(parsedFeatureId);

46
  const getBrowserLink = () =>
47
    urlFor.browser({ genomeId, focus: featureIdForUrl });
48

49 50
  const links: UrlObj = {
    genomeBrowser: {
51 52
      url: getBrowserLink(),
      replaceState: true
53 54 55 56 57 58 59 60
    },
    entityViewer: {
      url: urlFor.entityViewer({
        genomeId,
        entityId: featureIdForUrl
      })
    }
  };
61

62 63 64 65
  return (
    <div className={styles.zmenuAppLinks}>
      <ToolboxToggleButton
        className={styles.zmenuToggleFooter}
66
        label="Download"
67
      />
68
      <ViewInApp links={links} />
69 70 71 72
    </div>
  );
};

73
export default ZmenuAppLinks;