SharedWorkflowState.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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
  26. variant="accent"
  27. :disabled="!!data.state.parentState"
  28. @click="stopWorkflow"
  29. >
  30. <v-remixicon name="riStopLine" class="mr-2 -ml-1" />
  31. <span>{{ t('common.stop') }}</span>
  32. </ui-button>
  33. </div>
  34. <div class="divide-y bg-box-transparent divide-y px-4 rounded-lg">
  35. <div
  36. v-for="block in getBlock()"
  37. :key="block.name"
  38. class="flex items-center py-2"
  39. >
  40. <v-remixicon :name="block.icon" />
  41. <p class="flex-1 ml-2 mr-4 text-overflow">{{ block.name }}</p>
  42. <ui-spinner color="text-accent" size="20" />
  43. </div>
  44. </div>
  45. <div
  46. v-if="data.state.parentState"
  47. class="py-2 px-4 bg-yellow-200 rounded-lg mt-2 text-sm"
  48. >
  49. {{ t('workflow.state.executeBy', { name: data.state.parentState.name }) }}
  50. </div>
  51. </ui-card>
  52. </template>
  53. <script setup>
  54. import browser from 'webextension-polyfill';
  55. import { useI18n } from 'vue-i18n';
  56. import { sendMessage } from '@/utils/message';
  57. import { tasks } from '@/utils/shared';
  58. import dayjs from '@/lib/dayjs';
  59. const props = defineProps({
  60. data: {
  61. type: Object,
  62. default: () => ({}),
  63. },
  64. });
  65. const { t } = useI18n();
  66. function getBlock() {
  67. if (!props.data.state.currentBlock) return [];
  68. if (Array.isArray(props.data.state.currentBlock)) {
  69. return props.data.state.currentBlock.map((item) => {
  70. if (tasks[item.name])
  71. return {
  72. ...tasks[item.name],
  73. name: t(`workflow.blocks.${item.name}.name`),
  74. };
  75. return item;
  76. });
  77. }
  78. return [tasks[props.data.state.currentBlock.name]];
  79. }
  80. function formatDate(date, format) {
  81. if (format === 'relative') return dayjs(date).fromNow();
  82. return dayjs(date).format(format);
  83. }
  84. function openTab() {
  85. browser.tabs.update(props.data.state.tabId, { active: true });
  86. }
  87. function stopWorkflow() {
  88. sendMessage(
  89. props.data.isCollection ? 'collection:stop' : 'workflow:stop',
  90. props.data.id,
  91. 'background'
  92. );
  93. }
  94. </script>