DebugTab.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <div class="tab-content">
  3. <div
  4. class="sticky top-0 z-10 grid cols-auto items-center justify-center px-6 py-2 bg-gray-100 border-b border-tint-200 text-xs"
  5. >
  6. <nav class="grid cols-auto items-center gapx-6 gapy-2">
  7. <CheckboxField
  8. label="Dumps"
  9. v-model="visibleTypes.dump"
  10. name="show_dumps"
  11. :disabled="!dumps.length"
  12. />
  13. <CheckboxField
  14. label="Glows"
  15. v-model="visibleTypes.glow"
  16. name="show_glows"
  17. :disabled="!glows.length"
  18. />
  19. <CheckboxField
  20. label="Logs"
  21. v-model="visibleTypes.log"
  22. name="show_logs"
  23. :disabled="!logs.length"
  24. />
  25. <CheckboxField
  26. label="Queries"
  27. v-model="visibleTypes.query"
  28. name="show_queries"
  29. :disabled="!queries.length"
  30. />
  31. <button
  32. v-if="hasFilteredVisibleTypes"
  33. @click="resetVisibleTypes"
  34. class="link-dimmed no-underline absolute left-full ml-6 hidden | sm:block"
  35. >
  36. Reset&nbsp;filters
  37. </button>
  38. </nav>
  39. </div>
  40. <div class="layout-col">
  41. <DebugEvent
  42. v-for="event in visibleTimelineEvents"
  43. :key="event.microtime"
  44. v-bind="{ event }"
  45. ></DebugEvent>
  46. </div>
  47. <p
  48. v-if="visibleTimelineEvents.length === 0"
  49. class="absolute inset-0 grid place-center alert-empty"
  50. >
  51. No debug data available.
  52. </p>
  53. </div>
  54. </template>
  55. <script>
  56. import Event from '../DebugTimeline/Event';
  57. import DebugEvent from '../DebugTimeline/DebugEvent.vue';
  58. import CheckboxField from '../Shared/CheckboxField';
  59. import _ from 'lodash';
  60. export default {
  61. inject: ['report'],
  62. components: { CheckboxField, DebugEvent },
  63. props: ['query', 'dump', 'log', 'glow'],
  64. data() {
  65. return {
  66. visibleTypes: {
  67. query: this.query !== undefined ? this.query : true,
  68. dump: this.dump !== undefined ? this.dump : true,
  69. log: this.log !== undefined ? this.log : true,
  70. glow: this.glow !== undefined ? this.glow : true,
  71. },
  72. };
  73. },
  74. computed: {
  75. queries() {
  76. return this.report.context.queries || [];
  77. },
  78. dumps() {
  79. return this.report.context.dumps;
  80. },
  81. logs() {
  82. return this.report.context.logs || [];
  83. },
  84. glows() {
  85. return this.report.glows;
  86. },
  87. timelineEvents() {
  88. return _.sortBy(
  89. [
  90. ...this.queries.map(query => Event.forQuery(query)),
  91. ...this.dumps.map(dump => Event.forDump(dump)),
  92. ...this.logs.map(log => Event.forLog(log)),
  93. ...this.glows.map(glow => Event.forGlow(glow)),
  94. ],
  95. e => e.microtime,
  96. );
  97. },
  98. visibleTimelineEvents() {
  99. return this.timelineEvents.filter(e => {
  100. return this.visibleTypes[e.type];
  101. });
  102. },
  103. hasFilteredVisibleTypes() {
  104. let visibleCount = Object.values(this.visibleTypes).filter(type => type).length;
  105. let totalCount = Object.values(this.visibleTypes).length;
  106. return visibleCount !== totalCount;
  107. },
  108. },
  109. methods: {
  110. resetVisibleTypes() {
  111. this.visibleTypes = _.mapValues(this.visibleTypes, () => true);
  112. },
  113. },
  114. };
  115. </script>