SharedWorkflowState.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template>
  2. <ui-card>
  3. <div class="flex items-center mb-4">
  4. <div class="flex-1 text-overflow mr-4">
  5. <p class="w-full mr-2 text-overflow">{{ data.state.name }}</p>
  6. <p
  7. class="w-full mr-2 text-gray-600 leading-tight text-overflow"
  8. :title="`Started at: ${formatDate(
  9. data.state.startedTimestamp,
  10. 'DD MMM, hh:mm A'
  11. )}`"
  12. >
  13. {{ formatDate(data.state.startedTimestamp, 'relative') }}
  14. </p>
  15. </div>
  16. <ui-button
  17. v-if="data.state.tabId"
  18. icon
  19. class="mr-2"
  20. title="Open tab"
  21. @click="openTab"
  22. >
  23. <v-remixicon name="riExternalLinkLine" />
  24. </ui-button>
  25. <ui-button variant="accent" @click="stopWorkflow">
  26. <v-remixicon name="riStopLine" class="mr-2 -ml-1" />
  27. <span>Stop</span>
  28. </ui-button>
  29. </div>
  30. <div class="divide-y bg-box-transparent divide-y px-4 rounded-lg">
  31. <div
  32. v-for="block in getBlock()"
  33. :key="block.name"
  34. class="flex items-center py-2"
  35. >
  36. <v-remixicon :name="block.icon" />
  37. <p class="flex-1 ml-2 mr-4">{{ block.name }}</p>
  38. <ui-spinner color="text-accnet" size="20" />
  39. </div>
  40. </div>
  41. </ui-card>
  42. </template>
  43. <script setup>
  44. import browser from 'webextension-polyfill';
  45. import { sendMessage } from '@/utils/message';
  46. import { tasks } from '@/utils/shared';
  47. import dayjs from '@/lib/dayjs';
  48. const props = defineProps({
  49. data: {
  50. type: Object,
  51. default: () => ({}),
  52. },
  53. });
  54. function getBlock() {
  55. if (!props.data.state.currentBlock) return [];
  56. if (Array.isArray(props.data.state.currentBlock)) {
  57. return props.data.state.currentBlock.map((item) => {
  58. if (tasks[item.name]) return tasks[item.name];
  59. return item;
  60. });
  61. }
  62. return [tasks[props.data.state.currentBlock.name]];
  63. }
  64. function formatDate(date, format) {
  65. if (format === 'relative') return dayjs(date).fromNow();
  66. return dayjs(date).format(format);
  67. }
  68. function openTab() {
  69. browser.tabs.update(props.data.state.tabId, { active: true });
  70. }
  71. function stopWorkflow() {
  72. sendMessage(
  73. props.data.isCollection ? 'collection:stop' : 'workflow:stop',
  74. props.data.id,
  75. 'background'
  76. );
  77. }
  78. </script>