ZmenuInstantDownload.tsx 2.28 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 19
import { gql, useQuery } from '@apollo/client';
import { Pick2 } from 'ts-multipick';
20

21
import { parseFeatureId } from '../browserHelper';
22 23 24 25

import { InstantDownloadTranscript } from 'src/shared/components/instant-download';
import { CircleLoader } from 'src/shared/components/loader/Loader';

26
import { FullTranscript } from 'src/shared/types/thoas/transcript';
27 28 29 30 31 32 33

import styles from './Zmenu.scss';

type Props = {
  id: string;
};

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
const TRANSCRIPT_QUERY = gql`
  query Transcript($genomeId: String!, $transcriptId: String!) {
    transcript(byId: { genome_id: $genomeId, stable_id: $transcriptId }) {
      metadata {
        biotype {
          value
        }
      }
      gene {
        stable_id
      }
    }
  }
`;

type Transcript = Pick2<FullTranscript, 'metadata', 'biotype'> &
  Pick2<FullTranscript, 'gene', 'stable_id'>;

52
const ZmenuInstantDownload = (props: Props) => {
53 54 55 56 57 58 59 60 61 62
  const { genomeId, objectId: transcriptId } = parseFeatureId(props.id);

  const { data, loading } = useQuery<{
    transcript: Transcript;
  }>(TRANSCRIPT_QUERY, {
    variables: {
      genomeId,
      transcriptId
    }
  });
63

64
  if (loading) {
65 66 67 68 69 70 71
    return (
      <div className={styles.zmenuInstantDowloadLoading}>
        <CircleLoader />
      </div>
    );
  }

72
  if (!data) {
73 74 75
    return null;
  }

76
  const payload = {
77 78
    transcript: {
      id: transcriptId,
79
      biotype: data.transcript.metadata.biotype.value
80 81
    },
    gene: {
82
      id: data.transcript.gene.stable_id
83 84
    }
  };
85 86 87 88 89 90 91 92

  return (
    <InstantDownloadTranscript
      genomeId={genomeId}
      {...payload}
      layout="vertical"
    />
  );
93 94 95
};

export default ZmenuInstantDownload;