EditWorkflowParameters.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. <div class="text-sm grid grid-cols-12 space-x-2">
  14. <div class="col-span-3" style="padding-left: 28px">Name</div>
  15. <div class="col-span-2">Type</div>
  16. <div class="col-span-3">Placeholder</div>
  17. <div class="col-span-4">Default Value</div>
  18. </div>
  19. <draggable
  20. v-model="state.parameters"
  21. tag="div"
  22. item-key="id"
  23. handle=".handle"
  24. >
  25. <template #item="{ element: param, index }">
  26. <div class="mb-4">
  27. <div class="grid grid-cols-12 space-x-2">
  28. <div class="col-span-3 flex items-center">
  29. <v-remixicon name="mdiDrag" class="handle mr-2 cursor-move" />
  30. <ui-input
  31. :model-value="param.name"
  32. placeholder="Parameter name"
  33. @change="updateParam(index, $event)"
  34. />
  35. </div>
  36. <div class="col-span-2">
  37. <ui-select
  38. :model-value="param.type"
  39. @change="updateParamType(index, $event)"
  40. >
  41. <option
  42. v-for="type in paramTypesArr"
  43. :key="type.id"
  44. :value="type.id"
  45. >
  46. {{ type.name }}
  47. </option>
  48. </ui-select>
  49. </div>
  50. <div class="col-span-3">
  51. <ui-input
  52. v-model="param.placeholder"
  53. placeholder="A parameter"
  54. />
  55. </div>
  56. <div class="col-span-4 flex items-center">
  57. <component
  58. :is="paramTypes[param.type].valueComp"
  59. v-if="paramTypes[param.type].valueComp"
  60. v-model="param.defaultValue"
  61. :param-data="param"
  62. :editor="true"
  63. class="flex-1"
  64. style="max-width: 232px"
  65. />
  66. <ui-input
  67. v-else
  68. v-model="param.defaultValue"
  69. :type="param.type === 'number' ? 'number' : 'text'"
  70. placeholder="NULL"
  71. />
  72. <ui-button
  73. icon
  74. class="ml-2"
  75. @click="state.parameters.splice(index, 1)"
  76. >
  77. <v-remixicon name="riDeleteBin7Line" />
  78. </ui-button>
  79. </div>
  80. </div>
  81. <div class="w-full">
  82. <ui-expand
  83. hide-header-icon
  84. header-class="flex items-center focus:ring-0 w-full"
  85. >
  86. <template #header="{ show }">
  87. <v-remixicon
  88. :rotate="show ? 270 : 180"
  89. name="riArrowLeftSLine"
  90. class="mr-2 transition-transform -ml-1"
  91. />
  92. <span>Options</span>
  93. </template>
  94. <div class="pl-[28px] mt-2 mb-4">
  95. <ui-textarea
  96. v-model="param.description"
  97. placeholder="Description"
  98. title="Description"
  99. class="mb-2"
  100. style="max-width: 400px"
  101. />
  102. <component
  103. :is="paramTypes[param.type].options"
  104. v-if="paramTypes[param.type].options"
  105. v-model="param.data"
  106. :default-value="paramTypes[param.type].data"
  107. />
  108. </div>
  109. </ui-expand>
  110. </div>
  111. </div>
  112. </template>
  113. </draggable>
  114. </table>
  115. </div>
  116. <ui-button variant="accent" class="mt-4" @click="addParameter">
  117. Add parameter
  118. </ui-button>
  119. </template>
  120. <script setup>
  121. import { reactive, watch } from 'vue';
  122. import { nanoid } from 'nanoid/non-secure';
  123. import cloneDeep from 'lodash.clonedeep';
  124. import workflowParameters from '@business/parameters';
  125. import Draggable from 'vuedraggable';
  126. import ParameterInputValue from './Parameter/ParameterInputValue.vue';
  127. import ParameterInputOptions from './Parameter/ParameterInputOptions.vue';
  128. const props = defineProps({
  129. data: {
  130. type: Array,
  131. default: () => [],
  132. },
  133. });
  134. const emit = defineEmits(['update']);
  135. const customParameters = workflowParameters();
  136. const paramTypes = {
  137. string: {
  138. id: 'string',
  139. name: 'Input (string)',
  140. options: ParameterInputOptions,
  141. valueComp: ParameterInputValue,
  142. data: {
  143. masks: [],
  144. useMask: false,
  145. unmaskValue: false,
  146. },
  147. },
  148. number: {
  149. id: 'number',
  150. name: 'Input (number)',
  151. },
  152. ...customParameters,
  153. };
  154. const paramTypesArr = Object.values(paramTypes).filter((item) => item.id);
  155. const state = reactive({
  156. parameters: cloneDeep(props.data || []).map((item) => {
  157. item.id = nanoid(4);
  158. return item;
  159. }),
  160. });
  161. function addParameter() {
  162. state.parameters.push({
  163. name: 'param',
  164. type: 'string',
  165. description: '',
  166. defaultValue: '',
  167. placeholder: 'Text',
  168. data: paramTypes.string.data,
  169. });
  170. }
  171. function updateParam(index, value) {
  172. state.parameters[index].name = value.replace(/\s/g, '_');
  173. }
  174. function updateParamType(index, type) {
  175. const param = state.parameters[index];
  176. param.type = type;
  177. param.data = paramTypes[type].data || {};
  178. }
  179. watch(
  180. () => state.parameters,
  181. (parameters) => {
  182. emit('update', parameters);
  183. },
  184. { deep: true }
  185. );
  186. </script>
  187. <style scoped>
  188. table th,
  189. table td {
  190. @apply p-1 font-normal;
  191. }
  192. </style>