WorkflowRunning.vue 2.2 KB

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