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 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | <script setup lang="ts"> import { Plus, Search, CircleCheck, CircleClose, Delete, Edit } from '@element-plus/icons-vue' import HeaderBar from '../components/shared/HeaderBar.vue' import PageLayout from '../components/shared/PageLayout.vue' import EmptyState from '../components/shared/EmptyState.vue' import SearchInfo from '../components/shared/SearchInfo.vue' import { ElButton, ElTable, ElTableColumn, ElInput, ElMessageBox, ElMessage, } from 'element-plus' import { onMounted, reactive, computed } from 'vue' import { useSecretsList } from '../composables/secrets/useSecretsList' import { useSecretOperations } from '../composables/secrets/useSecretOperations' import type { Secret } from '@/types/generated/Secret' import { SUCCESS_MESSAGES, ERROR_MESSAGES, VALIDATION_MESSAGES, CONFIRM_MESSAGES } from '@/constants' const { isLoading, searchQuery, filteredSecrets, loadSecrets } = useSecretsList() const { createSecret, updateSecret, deleteSecret } = useSecretOperations() interface EditState { mode: 'idle' | 'creating' | 'editing' targetKey?: string newRow?: { key: string value: string description: string isNew: boolean } editData: Record< string, { value: string description: string } > } const editState = reactive<EditState>({ mode: 'idle', editData: {}, }) const tableData = computed(() => { if (editState.mode === 'creating' && editState.newRow) { return [editState.newRow, ...filteredSecrets.value] } return filteredSecrets.value }) onMounted(() => { loadSecrets() }) function handleAddSecret() { editState.mode = 'creating' editState.newRow = { key: '', value: '', description: '', isNew: true } } function handleEditSecret(row: Secret) { editState.mode = 'editing' editState.targetKey = row.key editState.editData[row.key] = { value: '', // Security: require re-entry of secret value description: row.description || '', } } function cancelEdit() { if (editState.mode === 'editing' && editState.targetKey) { delete editState.editData[editState.targetKey] } editState.mode = 'idle' editState.targetKey = undefined editState.newRow = undefined } async function saveNewSecret() { if (!editState.newRow?.key || !editState.newRow?.value) { ElMessage.error(ERROR_MESSAGES.REQUIRED_FIELD_MISSING) return } try { const formattedKey = editState.newRow.key.toUpperCase().replace(/[^A-Z0-9]/g, '_') await createSecret(formattedKey, editState.newRow.value, editState.newRow.description) ElMessage.success(SUCCESS_MESSAGES.SECRET_CREATED) cancelEdit() await loadSecrets() searchQuery.value = '' // Clear search to ensure new secret is visible } catch (error: any) { ElMessage.error(ERROR_MESSAGES.FAILED_TO_CREATE('secret') + ': ' + (error.message || error)) } } async function saveEditedSecret(key: string) { const data = editState.editData[key] if (!data?.value) { ElMessage.error(VALIDATION_MESSAGES.REQUIRED_FIELD('secret value')) return } try { await updateSecret(key, data.value, data.description) ElMessage.success(SUCCESS_MESSAGES.SECRET_UPDATED) delete editState.editData[key] editState.mode = 'idle' editState.targetKey = undefined await loadSecrets() } catch (error: any) { ElMessage.error(ERROR_MESSAGES.FAILED_TO_UPDATE('secret') + ': ' + (error.message || error)) } } async function handleDeleteSecret(row: Secret) { try { await ElMessageBox.confirm( CONFIRM_MESSAGES.DELETE_SECRET, 'Delete Confirmation', { confirmButtonText: 'Confirm', cancelButtonText: 'Cancel', type: 'warning', }, ) await deleteSecret(row.key) ElMessage.success(SUCCESS_MESSAGES.SECRET_DELETED) await loadSecrets() } catch (error: any) { // Filter out user-initiated dialog cancellation const errorMessage = error?.message || error if (errorMessage !== 'cancel' && errorMessage !== 'close' && error !== 'cancel') { ElMessage.error(ERROR_MESSAGES.FAILED_TO_DELETE('secret') + ': ' + errorMessage) } } } function isEditing(row: any): boolean { return editState.mode === 'editing' && editState.targetKey === row.key } function formatDate(timestamp: number | undefined): string { if (!timestamp) return 'Never' const now = Date.now() const diff = now - timestamp if (diff < 0 || Math.abs(diff) < 1000) return 'Just now' const days = Math.floor(diff / (1000 * 60 * 60 * 24)) const hours = Math.floor(diff / (1000 * 60 * 60)) const minutes = Math.floor(diff / (1000 * 60)) if (minutes < 1) return 'Just now' if (minutes < 60) return `${minutes} minute${minutes > 1 ? 's' : ''} ago` if (hours < 24) return `${hours} hour${hours > 1 ? 's' : ''} ago` if (days === 0) return 'Today' if (days === 1) return 'Yesterday' if (days < 7) return `${days} days ago` if (days < 30) return `${Math.floor(days / 7)} weeks ago` return `${Math.floor(days / 30)} months ago` } // Format key on blur to prevent cursor jumping during typing function formatKeyOnBlur() { if (editState.newRow) { editState.newRow.key = editState.newRow.key.toUpperCase().replace(/[^A-Z0-9_]/g, '_') } } // Helper to get edit value safely function getEditValue(key: string): string { return editState.editData[key]?.value || '' } // Helper to set edit value function setEditValue(key: string, value: string) { if (editState.editData[key]) { editState.editData[key].value = value } } // Helper to get edit description safely function getEditDescription(key: string): string { return editState.editData[key]?.description || '' } // Helper to set edit description function setEditDescription(key: string, description: string) { if (editState.editData[key]) { editState.editData[key].description = description } } </script> <template> <PageLayout variant="default"> <HeaderBar title="Secrets Management"> <template #actions> <ElInput v-model="searchQuery" placeholder="Search secrets..." :prefix-icon="Search" clearable class="search-input" /> <ElButton type="primary" :icon="Plus" @click="handleAddSecret" :disabled="editState.mode === 'creating'" > New Secret </ElButton> </template> </HeaderBar> <SearchInfo :count="filteredSecrets.length" :search-query="searchQuery" item-name="secret" @clear="searchQuery = ''" /> <div v-if="tableData.length > 0 || editState.mode === 'creating'" class="table-section"> <ElTable :data="tableData" :loading="isLoading" :row-key="(row) => (row.isNew ? '__new__' : row.key)" stripe style="width: 100%" class="secrets-table" > <ElTableColumn prop="key" label="Key" min-width="200"> <template #default="{ row }"> <ElInput v-if="row.isNew" v-model="editState.newRow!.key" placeholder="SECRET_KEY" @blur="formatKeyOnBlur" /> <span v-else class="secret-key">{{ row.key }}</span> </template> </ElTableColumn> <ElTableColumn label="Value" min-width="250"> <template #default="{ row }"> <ElInput v-if="row.isNew" v-model="editState.newRow!.value" placeholder="Enter secret value" type="password" show-password /> <ElInput v-else-if="isEditing(row)" :model-value="getEditValue(row.key)" @update:model-value="(val) => setEditValue(row.key, val)" placeholder="Enter new value" type="password" show-password /> <span v-else class="masked-value">••••••••</span> </template> </ElTableColumn> <ElTableColumn prop="description" label="Description" min-width="250"> <template #default="{ row }"> <ElInput v-if="row.isNew" v-model="editState.newRow!.description" placeholder="Optional description" /> <ElInput v-else-if="isEditing(row)" :model-value="getEditDescription(row.key)" @update:model-value="(val) => setEditDescription(row.key, val)" placeholder="Optional description" /> <span v-else class="secret-description"> {{ row.description || 'No description' }} </span> </template> </ElTableColumn> <ElTableColumn prop="updated_at" label="Last Updated" width="150"> <template #default="{ row }"> <span v-if="!row.isNew" class="update-time">{{ formatDate(row.updated_at) }}</span> </template> </ElTableColumn> <ElTableColumn label="Actions" width="150" fixed="right"> <template #default="{ row }"> <div v-if="row.isNew" class="action-buttons"> <ElButton :icon="CircleCheck" circle size="small" type="primary" @click="saveNewSecret" /> <ElButton :icon="CircleClose" circle size="small" @click="cancelEdit" /> </div> <div v-else-if="isEditing(row)" class="action-buttons"> <ElButton :icon="CircleCheck" circle size="small" type="primary" @click="saveEditedSecret(row.key)" /> <ElButton :icon="CircleClose" circle size="small" @click="cancelEdit" /> </div> <div v-else class="action-buttons"> <ElButton :icon="Edit" circle size="small" @click="handleEditSecret(row)" :disabled="editState.mode !== 'idle'" /> <ElButton :icon="Delete" circle size="small" type="danger" @click="handleDeleteSecret(row)" :disabled="editState.mode !== 'idle'" /> </div> </template> </ElTableColumn> </ElTable> </div> <EmptyState v-if="filteredSecrets.length === 0 && editState.mode !== 'creating'" :search-query="searchQuery" :is-loading="isLoading" item-name="secret" create-text="Create your first" @action="handleAddSecret" @clear-search="searchQuery = ''" /> </PageLayout> </template> <style lang="scss" scoped> .search-input { width: var(--rf-size-xl); } .table-section { background: var(--rf-color-bg-container); border-radius: var(--rf-radius-base); padding: var(--rf-spacing-lg); box-shadow: var(--rf-shadow-sm); margin-top: var(--rf-spacing-xl); margin-bottom: var(--rf-spacing-xl); } .secrets-table { :deep(.el-table__header) { font-weight: var(--rf-font-weight-semibold); } .secret-key { font-family: 'Monaco', 'Courier New', monospace; font-weight: var(--rf-font-weight-medium); color: var(--rf-color-primary); } .masked-value { font-family: 'Monaco', 'Courier New', monospace; color: var(--rf-color-text-secondary); letter-spacing: var(--rf-letter-spacing-wide); } .secret-description { color: var(--rf-color-text-regular); } .update-time { color: var(--rf-color-text-secondary); font-size: var(--rf-font-size-sm); } .action-buttons { display: flex; gap: var(--rf-spacing-sm); } } </style> |