All files / web/src/components/nodes/trigger TriggerConfigForm.vue

0% Statements 0/133
100% Branches 1/1
100% Functions 1/1
0% Lines 0/133

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
<script setup lang="ts">
import { ref, computed, watch } from 'vue'
import type { NodeType } from '@/types/generated/NodeType'
 
interface Props {
  modelValue: any
  nodeType: NodeType
}
 
const props = defineProps<Props>()
const emit = defineEmits<{
  'update:modelValue': [value: any]
}>()
 
// Local configuration state
const localConfig = ref({
  // Webhook configuration
  path: props.modelValue?.path || '',
  method: props.modelValue?.method || 'POST',
  auth: props.modelValue?.auth || null,
 
  // Schedule configuration
  cron: props.modelValue?.cron || '0 0 * * * *',
  timezone: props.modelValue?.timezone || 'UTC',
  payload: props.modelValue?.payload || null,
})
 
// Preset cron expressions (6-field format: sec min hour day month weekday)
const cronPresets = [
  { label: 'Every minute', value: '0 * * * * *' },
  { label: 'Every hour', value: '0 0 * * * *' },
  { label: 'Midnight daily', value: '0 0 0 * * *' },
  { label: 'Daily at 9 AM', value: '0 0 9 * * *' },
  { label: 'Every Sunday', value: '0 0 0 * * 0' },
  { label: 'First day of month', value: '0 0 0 1 * *' },
  { label: 'Custom', value: '' },
]
 
// Common timezones
const timezones = [
  'UTC',
  'America/New_York',
  'America/Los_Angeles',
  'Europe/London',
  'Europe/Paris',
  'Asia/Shanghai',
  'Asia/Tokyo',
  'Australia/Sydney',
]
 
// HTTP method options
const httpMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH']
 
// Currently selected preset
const selectedPreset = ref('')
 
// Watch config changes and emit updates
watch(
  localConfig,
  (newConfig) => {
    emit('update:modelValue', newConfig)
  },
  { deep: true }
)
 
// Update cron expression when selecting a preset
const selectPreset = (preset: string) => {
  selectedPreset.value = preset
  if (preset) {
    localConfig.value.cron = preset
  }
}
 
// Determine which configuration sections to display
const isManualTrigger = computed(() => props.nodeType === 'ManualTrigger')
const isWebhookTrigger = computed(() => props.nodeType === 'WebhookTrigger')
const isScheduleTrigger = computed(() => props.nodeType === 'ScheduleTrigger')
</script>
 
<template>
  <div class="trigger-config">
    <!-- Manual Trigger configuration -->
    <div v-if="isManualTrigger" class="config-section">
      <div class="info-message">
        This node starts the workflow manually. No configuration required.
      </div>
    </div>
 
    <!-- Webhook Trigger configuration -->
    <div v-if="isWebhookTrigger" class="config-section">
      <div class="form-group">
        <label class="form-label">Webhook Path</label>
        <el-input
          v-model="localConfig.path"
          placeholder="/api/webhook/my-webhook"
          clearable
        />
        <span class="form-hint">URL path that triggers this workflow</span>
      </div>
 
      <div class="form-group">
        <label class="form-label">HTTP Method</label>
        <el-select v-model="localConfig.method" placeholder="Select HTTP method">
          <el-option
            v-for="method in httpMethods"
            :key="method"
            :label="method"
            :value="method"
          />
        </el-select>
      </div>
    </div>
 
    <!-- Schedule Trigger configuration -->
    <div v-if="isScheduleTrigger" class="config-section">
      <div class="form-group">
        <label class="form-label">Preset Schedule</label>
        <el-select
          v-model="selectedPreset"
          placeholder="Choose a preset"
          @change="selectPreset"
        >
          <el-option
            v-for="preset in cronPresets"
            :key="preset.value"
            :label="preset.label"
            :value="preset.value"
          />
        </el-select>
      </div>
 
      <div class="form-group">
        <label class="form-label">Cron Expression</label>
        <el-input
          v-model="localConfig.cron"
          placeholder="0 0 * * * *"
          clearable
        >
          <template #prepend>
            <span>Cron</span>
          </template>
        </el-input>
        <span class="form-hint">
          Format: sec min hour day month weekday (e.g. 0 0 * * * * for hourly)
        </span>
      </div>
 
      <div class="form-group form-group--compact">
        <label class="form-label">Timezone</label>
        <el-select
          v-model="localConfig.timezone"
          placeholder="Select timezone"
          filterable
          class="timezone-select"
        >
          <el-option
            v-for="tz in timezones"
            :key="tz"
            :label="tz"
            :value="tz"
          />
        </el-select>
        <span class="form-hint">Schedule runs in this timezone</span>
      </div>
 
      <div class="form-group">
        <label class="form-label">Trigger Payload (optional)</label>
        <el-input
          v-model="localConfig.payload"
          type="textarea"
          :rows="4"
          placeholder='{"key": "value"}'
        />
        <span class="form-hint">JSON payload passed to the workflow when triggered</span>
      </div>
    </div>
  </div>
</template>
 
<style lang="scss" scoped>
.trigger-config {
  padding: var(--rf-spacing-md);
}
 
.config-section {
  display: flex;
  flex-direction: column;
  gap: var(--rf-spacing-lg);
}
 
.info-message {
  padding: var(--rf-spacing-lg);
  background-color: var(--rf-color-bg-secondary);
  border-radius: var(--rf-radius-base);
  color: var(--rf-color-text-regular);
  font-size: var(--rf-font-size-base);
}
 
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--rf-spacing-xs);
}
 
.form-group--compact {
  max-width: 340px;
}
 
.timezone-select {
  width: 100%;
}
 
.form-label {
  font-size: var(--rf-font-size-sm);
  font-weight: var(--rf-font-weight-medium);
  color: var(--rf-color-text-primary);
}
 
.form-hint {
  font-size: var(--rf-font-size-xs);
  color: var(--rf-color-text-secondary);
  margin-top: calc(var(--rf-spacing-xs) * -0.5);
}
</style>