|
| 1 | +<script lang="ts" setup> |
| 2 | +import { computed } from "vue"; |
| 3 | +import { GraphTypes } from "~/src/shared/types"; |
| 4 | +import { IconSvg } from "~/src/shared/ui"; |
| 5 | +
|
| 6 | +const emit = defineEmits(['onMetricChange', 'onFullscreen', 'onThresholdChange', 'onPercentChange']) |
| 7 | +
|
| 8 | +type Props = { |
| 9 | + data: Object; |
| 10 | + isFullscreen: boolean; |
| 11 | + metric: GraphTypes; |
| 12 | + threshold: number; |
| 13 | + percent: number; |
| 14 | +}; |
| 15 | +
|
| 16 | +const props = defineProps<Props>(); |
| 17 | +
|
| 18 | +const fetchToolbar = async function () { |
| 19 | + return await props.data.then(response => response.toolbar); |
| 20 | +}; |
| 21 | +
|
| 22 | +const toolbar = await fetchToolbar(); |
| 23 | +
|
| 24 | +const percentLabel = computed(() => |
| 25 | + props.metric === GraphTypes.CALLS ? "Min calls" : "Percent" |
| 26 | +); |
| 27 | +</script> |
| 28 | + |
| 29 | +<template> |
| 30 | + <div class="call-graph__toolbar-wrapper"> |
| 31 | + <div class="call-graph__toolbar"> |
| 32 | + <button title="Full screen" @click="emit('onFullscreen')"> |
| 33 | + <IconSvg name="fullscreen" class="call-graph__toolbar-icon"/> |
| 34 | + </button> |
| 35 | + <button |
| 36 | + v-for="button in toolbar" |
| 37 | + class="call-graph__toolbar-action" |
| 38 | + :class="{ |
| 39 | + 'call-graph__toolbar-action--active': metric === button.metric, |
| 40 | + }" |
| 41 | + :title="button.description" |
| 42 | + @click="emit('onMetricChange', button.metric)" |
| 43 | + > |
| 44 | + {{ button.label }} |
| 45 | + </button> |
| 46 | + </div> |
| 47 | + |
| 48 | + <div class="call-graph__toolbar call-graph__toolbar--right"> |
| 49 | + <label |
| 50 | + v-if="metric !== GraphTypes.CALLS" |
| 51 | + class="call-graph__toolbar-input-wr" |
| 52 | + > |
| 53 | + Threshold |
| 54 | + |
| 55 | + <input |
| 56 | + class="call-graph__toolbar-input" |
| 57 | + type="number" |
| 58 | + :value="threshold" |
| 59 | + :min="0" |
| 60 | + :max="10" |
| 61 | + :step="0.1" |
| 62 | + @input="emit('onThresholdChange', $event.target.value)" |
| 63 | + /> |
| 64 | + </label> |
| 65 | + |
| 66 | + <label class="call-graph__toolbar-input-wr"> |
| 67 | + {{ percentLabel }} |
| 68 | + |
| 69 | + <input |
| 70 | + class="call-graph__toolbar-input" |
| 71 | + type="number" |
| 72 | + :value="percent" |
| 73 | + :min="metric === GraphTypes.CALLS ? 1 : 0" |
| 74 | + :max="metric === GraphTypes.CALLS ? 1000 : 100" |
| 75 | + :step="metric === GraphTypes.CALLS ? 10 : 5" |
| 76 | + @input="emit('onPercentChange', $event.target.value)" |
| 77 | + /> |
| 78 | + </label> |
| 79 | + </div> |
| 80 | + </div> |
| 81 | +</template> |
| 82 | + |
| 83 | +<style lang="scss" scoped> |
| 84 | +.call-graph--fullscreen { |
| 85 | + @apply rounded-none mt-0 top-0 left-0 fixed w-full h-full bg-gray-800 z-[99999]; |
| 86 | +} |
| 87 | +
|
| 88 | +.call-graph__toolbar { |
| 89 | + @apply absolute top-5 left-5 flex bg-gray-200 p-2 rounded gap-x-5 shadow-lg; |
| 90 | +} |
| 91 | +
|
| 92 | +.call-graph__toolbar--right { |
| 93 | + @apply right-5 left-auto py-1; |
| 94 | +} |
| 95 | +
|
| 96 | +.call-graph__toolbar-icon { |
| 97 | + @apply w-4 h-4 fill-blue-500; |
| 98 | +} |
| 99 | +
|
| 100 | +.call-graph__toolbar-action { |
| 101 | + @apply text-xs uppercase text-gray-600; |
| 102 | +} |
| 103 | +
|
| 104 | +.call-graph__toolbar-action--active { |
| 105 | + @apply font-bold; |
| 106 | +} |
| 107 | +
|
| 108 | +.call-graph__toolbar-input-wr { |
| 109 | + @apply text-xs uppercase text-gray-600; |
| 110 | +} |
| 111 | +
|
| 112 | +.call-graph__toolbar-input { |
| 113 | + @apply border-gray-600 text-gray-600 w-10 font-bold text-right bg-gray-300 ml-1 py-1 rounded; |
| 114 | +} |
| 115 | +</style> |
0 commit comments