|
| 1 | +<template> |
| 2 | + <ToolTippy :isInteractive="true" @trigger="onTrigger"> |
| 3 | + <span class="text-no-wrap"> |
| 4 | + {{ middleTrim(theGene, 6, 6) }} |
| 5 | + </span> |
| 6 | + <template #tooltipContent> |
| 7 | + <div @click.stop> |
| 8 | + <span>{{ theGene }}</span> |
| 9 | + </div> |
| 10 | + </template> |
| 11 | + </ToolTippy> |
| 12 | +</template> |
| 13 | + |
| 14 | +<script setup> |
| 15 | +import { computed, ref } from 'vue' |
| 16 | +import router from '@/router' |
| 17 | +import { useFetchData } from '@/composables/fetchData' |
| 18 | +import { PAGE_NAMES, URLS } from '@/constants' |
| 19 | +import { middleTrim } from '@/util/util' |
| 20 | +import { useAppStore } from '@/stores/AppStore' |
| 21 | +
|
| 22 | +const { data, errorMessage, fetchData } = useFetchData() |
| 23 | +const appStore = useAppStore() |
| 24 | +
|
| 25 | +const genePage = PAGE_NAMES.GENE |
| 26 | +
|
| 27 | +const props = defineProps({ |
| 28 | + trait: Object, |
| 29 | +}) |
| 30 | +
|
| 31 | +const theGene = computed(() => props?.trait?.gene?.symbol) |
| 32 | +
|
| 33 | +const geneLink = ref(null) |
| 34 | +const geneText = ref(`Checking ${theGene.value}, please wait ...`) |
| 35 | +const geneLinkText = computed(() => { |
| 36 | + return geneText.value |
| 37 | +}) |
| 38 | +const geneChecked = ref(false) |
| 39 | +
|
| 40 | +const onTrigger = async () => { |
| 41 | + if(!geneChecked.value) { |
| 42 | + const url = encodeURI(`${URLS.PORTAL_GENE_CHECK}?q=${theGene.value}`) |
| 43 | + if(await fetchData(url, 'gene check', appStore.currentPageName)) { |
| 44 | + geneChecked.value = true |
| 45 | + if(data?.value?.count > 0) { |
| 46 | + const u = encodeURI(`${URLS.PORTAL_GENE_PAGE}?gene=${theGene.value}`) |
| 47 | + geneLink.value = u |
| 48 | + geneText.value = `View ${ theGene.value } in CMDKP portal` |
| 49 | + } else { |
| 50 | + geneText.value = `Unknown gene: ${ theGene.value }` |
| 51 | + } |
| 52 | + } else { |
| 53 | + console.error(`Error checking gene: ${ theGene.value } on portal:`, errorMessage) |
| 54 | + } |
| 55 | + } |
| 56 | +} |
| 57 | +
|
| 58 | +const onClick = () => { |
| 59 | + router.push({ name: genePage, query: { gene: theGene.value } }) |
| 60 | +} |
| 61 | +</script> |
| 62 | +
|
| 63 | +<style scoped> |
| 64 | +</style> |
0 commit comments