EditWorkflowParameters.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. :editor="true"
  56. max-width="250px"
  57. />
  58. <ui-input
  59. v-else
  60. v-model="param.defaultValue"
  61. :type="param.type === 'number' ? 'number' : 'text'"
  62. placeholder="NULL"
  63. />
  64. </td>
  65. <td>
  66. <ui-button icon @click="state.parameters.splice(index, 1)">
  67. <v-remixicon name="riDeleteBin7Line" />
  68. </ui-button>
  69. </td>
  70. </tr>
  71. <tr v-if="paramTypes[param.type].options">
  72. <td colspan="999" style="padding-top: 0">
  73. <ui-expand
  74. hide-header-icon
  75. header-class="flex items-center focus:ring-0 w-full"
  76. >
  77. <template #header="{ show }">
  78. <v-remixicon
  79. :rotate="show ? 270 : 180"
  80. name="riArrowLeftSLine"
  81. class="mr-2 transition-transform -ml-1"
  82. />
  83. <span>Options</span>
  84. </template>
  85. <div class="pl-[28px] mt-2 mb-4">
  86. <component
  87. :is="paramTypes[param.type].options"
  88. v-model="param.data"
  89. />
  90. </div>
  91. </ui-expand>
  92. </td>
  93. </tr>
  94. </template>
  95. </tbody>
  96. </table>
  97. </div>
  98. <ui-button variant="accent" class="mt-4" @click="addParameter">
  99. Add parameter
  100. </ui-button>
  101. </template>
  102. <script setup>
  103. import { reactive, watch } from 'vue';
  104. import cloneDeep from 'lodash.clonedeep';
  105. import * as workflowParameters from '@business/parameters';
  106. const props = defineProps({
  107. data: {
  108. type: Array,
  109. default: () => [],
  110. },
  111. });
  112. const emit = defineEmits(['update']);
  113. const paramTypes = {
  114. string: {
  115. id: 'string',
  116. name: 'Input (string)',
  117. },
  118. number: {
  119. id: 'number',
  120. name: 'Input (number)',
  121. },
  122. ...workflowParameters,
  123. };
  124. const state = reactive({
  125. parameters: cloneDeep(props.data || []),
  126. });
  127. function addParameter() {
  128. state.parameters.push({
  129. data: {},
  130. name: 'param',
  131. type: 'string',
  132. defaultValue: '',
  133. placeholder: 'Text',
  134. });
  135. }
  136. function updateParam(index, value) {
  137. state.parameters[index].name = value.replace(/\s/g, '_');
  138. }
  139. function updateParamType(index, type) {
  140. const param = state.parameters[index];
  141. param.type = type;
  142. param.data = paramTypes[type].data || {};
  143. }
  144. watch(
  145. () => state.parameters,
  146. (parameters) => {
  147. emit('update', parameters);
  148. },
  149. { deep: true }
  150. );
  151. </script>
  152. <style scoped>
  153. table th,
  154. table td {
  155. @apply p-1 font-normal;
  156. }
  157. </style>