EditWorkflowParameters.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <div
  3. class="overflow-auto scroll"
  4. style="max-height: calc(100vh - 15rem); min-height: 200px"
  5. >
  6. <p
  7. v-if="state.parameters.length === 0"
  8. class="my-4 text-center text-gray-600 dark:text-gray-200"
  9. >
  10. No parameters
  11. </p>
  12. <table v-else class="w-full">
  13. <thead>
  14. <tr class="text-sm text-left">
  15. <th>Name</th>
  16. <th>Type</th>
  17. <th>Placeholder</th>
  18. <th>Default Value</th>
  19. <th></th>
  20. </tr>
  21. </thead>
  22. <tbody>
  23. <template v-for="(param, index) in state.parameters" :key="index">
  24. <tr class="align-top">
  25. <td>
  26. <ui-input
  27. :model-value="param.name"
  28. placeholder="Parameter name"
  29. @change="updateParam(index, $event)"
  30. />
  31. </td>
  32. <td>
  33. <ui-select
  34. :model-value="param.type"
  35. @change="updateParamType(index, $event)"
  36. >
  37. <option
  38. v-for="type in paramTypes"
  39. :key="type.id"
  40. :value="type.id"
  41. >
  42. {{ type.name }}
  43. </option>
  44. </ui-select>
  45. </td>
  46. <td>
  47. <ui-input v-model="param.placeholder" placeholder="A parameter" />
  48. </td>
  49. <td>
  50. <component
  51. :is="paramTypes[param.type].valueComp"
  52. v-if="paramTypes[param.type].valueComp"
  53. v-model="param.defaultValue"
  54. :param-data="param"
  55. max-width="250px"
  56. />
  57. <ui-input
  58. v-else
  59. v-model="param.defaultValue"
  60. :type="param.type === 'number' ? 'number' : 'text'"
  61. placeholder="NULL"
  62. />
  63. </td>
  64. <td>
  65. <ui-button icon @click="state.parameters.splice(index, 1)">
  66. <v-remixicon name="riDeleteBin7Line" />
  67. </ui-button>
  68. </td>
  69. </tr>
  70. <tr v-if="paramTypes[param.type].options">
  71. <td colspan="999" style="padding-top: 0">
  72. <ui-expand
  73. hide-header-icon
  74. header-class="flex items-center focus:ring-0 w-full"
  75. >
  76. <template #header="{ show }">
  77. <v-remixicon
  78. :rotate="show ? 270 : 180"
  79. name="riArrowLeftSLine"
  80. class="mr-2 transition-transform -ml-1"
  81. />
  82. <span>Options</span>
  83. </template>
  84. <div class="pl-[28px] mt-2 mb-4">
  85. <component
  86. :is="paramTypes[param.type].options"
  87. v-model="param.data"
  88. />
  89. </div>
  90. </ui-expand>
  91. </td>
  92. </tr>
  93. </template>
  94. </tbody>
  95. </table>
  96. </div>
  97. <ui-button variant="accent" class="mt-4" @click="addParameter">
  98. Add parameter
  99. </ui-button>
  100. </template>
  101. <script setup>
  102. import { reactive, watch } from 'vue';
  103. import cloneDeep from 'lodash.clonedeep';
  104. import { workflowParameters } from '@business';
  105. const props = defineProps({
  106. data: {
  107. type: Array,
  108. default: () => [],
  109. },
  110. });
  111. const emit = defineEmits(['update']);
  112. const paramTypes = {
  113. string: {
  114. id: 'string',
  115. name: 'Input (string)',
  116. },
  117. number: {
  118. id: 'number',
  119. name: 'Input (number)',
  120. },
  121. ...workflowParameters,
  122. };
  123. const state = reactive({
  124. parameters: cloneDeep(props.data || []),
  125. });
  126. function addParameter() {
  127. state.parameters.push({
  128. data: {},
  129. name: 'param',
  130. type: 'string',
  131. defaultValue: '',
  132. placeholder: 'Text',
  133. });
  134. }
  135. function updateParam(index, value) {
  136. state.parameters[index].name = value.replace(/\s/g, '_');
  137. }
  138. function updateParamType(index, type) {
  139. const param = state.parameters[index];
  140. param.type = type;
  141. param.data = paramTypes[type].data || {};
  142. }
  143. watch(
  144. () => state.parameters,
  145. (parameters) => {
  146. emit('update', parameters);
  147. },
  148. { deep: true }
  149. );
  150. </script>
  151. <style scoped>
  152. table th,
  153. table td {
  154. @apply p-1 font-normal;
  155. }
  156. </style>