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 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 | 420x 1x 1x 164x 1x 2x 1x 1x 4x 4x 4x 11x 4x 1x 4x 1x 4x 4x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 1x 1x 13x 1x 288x 288x 288x 288x 288x 44x 43x 38x 288x 288x 288x 288x 7x 3x 2x 2x 2x 2x 2x 288x 288x 288x 288x 288x 2x 164x 148x 144x 288x 51x 288x 288x 104x 2x 2x 2x 2x 288x 288x 288x 140x 288x 52x 288x 14x 288x 102x 288x 289x 201x 198x 288x 1x 2x 2x 1x 1x 288x 191x 353x | <template>
<BaseFormSidebar
:is-open="isOpen"
:dirty="dirty"
storage-key="entity-form-sidebar"
:title="sidebarTitle"
panel-width="1400px"
:loading="loading"
:submit-disabled="formData.fields.length === 0 || hasUnnamedFields"
:submit-label="mode === 'create' ? 'Create Entity' : 'Update Entity'"
:submit-icon="mode === 'create' ? 'fa-solid fa-plus' : 'fa-solid fa-save'"
:submit-button-class="mode === 'create' ? 'btn-success' : 'btn-primary'"
@close="handleClose"
@submit="handleSubmit"
>
<template v-if="mode === 'view'" #footer>
<button type="button" class="btn btn-secondary" @click="handleClose">
<font-awesome-icon icon="fa-solid fa-times" class="me-1" />
{{ t('common.close') }}
</button>
</template>
<!-- Language Selector -->
<EditingLanguageSelector
:model-value="currentLanguage"
:languages="enabledLanguages"
class="mb-3"
@update:model-value="$emit('update:currentLanguage', $event)"
/>
<form @submit.prevent="handleSubmit">
<ul class="nav nav-tabs mb-3" role="tablist">
<li class="nav-item" role="presentation">
<button
type="button"
class="nav-link"
:class="{ active: activeTab === 'details' }"
@click="activeTab = 'details'"
>
{{ t('entity.details') }}
</button>
</li>
<li class="nav-item" role="presentation">
<button
type="button"
class="nav-link"
:class="{ active: activeTab === 'schema' }"
@click="activeTab = 'schema'"
>
{{ t('entity.fields') }}
</button>
</li>
<li class="nav-item" role="presentation">
<button
type="button"
class="nav-link"
:class="{ active: activeTab === 'forms' }"
@click="activeTab = 'forms'"
>
{{ t('entity.forms') }}
</button>
</li>
<li class="nav-item" role="presentation">
<button
type="button"
class="nav-link"
:class="{ active: activeTab === 'emails' }"
data-testid="entity-tab-emails"
@click="activeTab = 'emails'"
>
{{ t('entity.emails') }}
</button>
</li>
</ul>
<div class="tab-content" :class="{ 'view-only': mode === 'view' }" :inert="mode === 'view'">
<div
class="tab-pane"
:class="{ active: activeTab === 'details', show: activeTab === 'details' }"
>
<div class="mb-3">
<MultilingualInput
:model-value="formData.name"
:label="t('entity.entityName')"
:placeholder="t('entity.placeholderName')"
:default-language="defaultLanguage"
:enabled-languages="enabledLanguages"
:current-language="currentLanguage"
:show-language-selector="false"
required
@update:model-value="$emit('update:formData', { ...formData, name: $event })"
/>
<div v-if="nameError" class="text-danger small mt-1">
{{ nameError }}
</div>
</div>
<div class="mb-3">
<MultilingualTextarea
:model-value="formData.description ?? ''"
:label="t('entity.description')"
:placeholder="t('entity.placeholderDescription')"
:default-language="defaultLanguage"
:enabled-languages="enabledLanguages"
:current-language="currentLanguage"
:show-language-selector="false"
:max-newlines="4"
@update:model-value="$emit('update:formData', { ...formData, description: $event })"
/>
</div>
<div class="mb-3">
<label id="visibility-label" class="form-label">{{ t('entity.visibility') }}</label>
<div ref="visibilityDropdownRef" class="visibility-dropdown">
<button
id="visibility"
type="button"
class="form-select text-start"
aria-haspopup="listbox"
:aria-expanded="isVisibilityDropdownOpen"
aria-labelledby="visibility-label"
@click="isVisibilityDropdownOpen = !isVisibilityDropdownOpen"
>
{{ visibilityLabel(formData.visibility) }}
</button>
<div v-if="isVisibilityDropdownOpen" class="visibility-dropdown-menu" role="listbox">
<button
type="button"
role="option"
data-value="flow-members"
class="visibility-dropdown-option"
:class="{ selected: formData.visibility === 'flow-members' }"
:aria-selected="formData.visibility === 'flow-members'"
:disabled="formData.visibility === 'public' && !canDisablePublic"
@click="selectVisibility('flow-members')"
>
<div class="option-label">{{ t('entity.visibilityFlowMembers') }}</div>
<div
v-if="formData.visibility === 'public' && !canDisablePublic"
class="option-description text-danger"
>
{{ cannotDisablePublicMessage }}
</div>
<div v-else class="option-description">
{{ t('entity.visibilityFlowMembersDescription') }}
</div>
</button>
<button
type="button"
role="option"
data-value="restricted"
class="visibility-dropdown-option"
:class="{ selected: formData.visibility === 'restricted' }"
:aria-selected="formData.visibility === 'restricted'"
:disabled="formData.visibility === 'public' && !canDisablePublic"
@click="selectVisibility('restricted')"
>
<div class="option-label">{{ t('entity.visibilityRestricted') }}</div>
<div
v-if="formData.visibility === 'public' && !canDisablePublic"
class="option-description text-danger"
>
{{ cannotDisablePublicMessage }}
</div>
<div v-else class="option-description">
{{ t('entity.visibilityRestrictedDescription') }}
</div>
</button>
<button
type="button"
role="option"
data-value="public"
class="visibility-dropdown-option"
:class="{ selected: formData.visibility === 'public' }"
:aria-selected="formData.visibility === 'public'"
:disabled="formData.visibility !== 'public' && !canEnablePublic"
@click="selectVisibility('public')"
>
<div class="option-label">{{ t('entity.visibilityPublic') }}</div>
<div
v-if="formData.visibility !== 'public' && !canEnablePublic"
class="option-description text-danger"
>
{{ t('entity.visibilityCannotEnablePublic') }}
</div>
<div v-else class="option-description">
{{ t('entity.visibilityPublicDescription') }}
</div>
</button>
</div>
</div>
<div
v-if="showRestrictedRolesHint"
class="form-text"
data-testid="restricted-roles-hint"
>
{{ t('entity.visibilityRestrictedRolesHint') }}
</div>
</div>
<div class="mb-3 form-check form-switch">
<input
id="comments-enabled"
class="form-check-input"
type="checkbox"
role="switch"
:checked="formData.commentsEnabled ?? false"
@change="
$emit('update:formData', {
...formData,
commentsEnabled: ($event.target as HTMLInputElement).checked
})
"
/>
<label class="form-check-label" for="comments-enabled">{{
t('entity.commentsEnabled')
}}</label>
<div class="form-text">
{{
isPublicEntity
? t('entity.commentsEnabledHelpPublic')
: t('entity.commentsEnabledHelp')
}}
</div>
</div>
<CommentBlocksList
v-if="mode === 'edit' && entityId && formData.commentsEnabled"
:entity-id="entityId"
/>
<div class="row mb-3">
<div class="col-md-6">
<label class="form-label">{{ t('entity.pictureOptional') }}</label>
<ImageField
:model-value="formData.picture"
:field="{ name: 'picture', type: 'image', fieldId: 'entity-picture' }"
:is-editing="mode !== 'view'"
:entity-id="entityId"
@update:model-value="$emit('update:formData', { ...formData, picture: $event })"
/>
</div>
<div class="col-md-6">
<label class="form-label">{{ t('entity.iconOptional') }}</label>
<ImageField
:model-value="formData.icon"
:field="{ name: 'icon', type: 'image', fieldId: 'entity-icon' }"
:is-editing="mode !== 'view'"
:entity-id="entityId"
@update:model-value="$emit('update:formData', { ...formData, icon: $event })"
/>
</div>
</div>
</div>
<div
class="tab-pane"
:class="{ active: activeTab === 'schema', show: activeTab === 'schema' }"
>
<div class="mb-3">
<SchemaBuilder
:model-value="formData.fields"
:default-language="defaultLanguage"
:enabled-languages="enabledLanguages"
:current-language="currentLanguage"
:has-items="hasItems"
:forms="formData.forms ?? []"
:email-templates="formData.emailTemplates ?? []"
:is-public-entity="isPublicEntity"
:field-errors="fieldErrors"
@update:model-value="$emit('update:formData', { ...formData, fields: $event })"
@workflow-state-removed="handleWorkflowStateRemoved"
/>
</div>
</div>
<div
class="tab-pane"
:class="{ active: activeTab === 'forms', show: activeTab === 'forms' }"
>
<div class="mb-3">
<FormBuilder
:model-value="formData.forms ?? []"
:entity-fields="formData.fields"
:default-language="defaultLanguage"
:enabled-languages="enabledLanguages"
:current-language="currentLanguage"
@update:model-value="$emit('update:formData', { ...formData, forms: $event })"
/>
</div>
</div>
<div
class="tab-pane"
:class="{ active: activeTab === 'emails', show: activeTab === 'emails' }"
>
<div class="mb-3">
<EmailTemplatesEditor
:model-value="formData.emailTemplates ?? []"
:entity-fields="formData.fields"
:default-language="defaultLanguage"
:enabled-languages="enabledLanguages"
:current-language="currentLanguage"
:used-template-ids="templatesInUse"
:entity-id="mode === 'edit' ? entityId : undefined"
@update:model-value="
$emit('update:formData', { ...formData, emailTemplates: $event })
"
/>
</div>
</div>
</div>
<div v-if="error" class="alert alert-danger" role="alert">
{{ error }}
</div>
</form>
<!-- Danger Zone (edit mode only, and only if at least one action is permitted) -->
<DangerZone v-if="showDangerZone">
<DangerZoneAction
v-if="canClearItems"
:action-label="t('item.clearAll')"
:warning-text="t('item.clearAllWarning')"
@action="$emit('clearAll')"
/>
<hr v-if="canClearItems && canDeleteEntity" class="my-3" />
<DangerZoneAction
v-if="canDeleteEntity"
:action-label="t('entity.deleteEntity')"
:warning-text="t('entity.dangerZoneWarning')"
@action="$emit('delete')"
/>
</DangerZone>
</BaseFormSidebar>
</template>
<script setup lang="ts">
// @implements UC-I18N-002.1, UC-I18N-010.1, UC-COMMENT-001.1, UC-COMMENT-007.1, UC-WORKFLOW-010.1
import { useUnsavedChanges } from '@/composables/useUnsavedChanges'
import { ref, computed, onMounted, onBeforeUnmount } from 'vue'
import BaseFormSidebar from '@/components/BaseFormSidebar.vue'
import DangerZone from '@/components/DangerZone.vue'
import DangerZoneAction from '@/components/DangerZoneAction.vue'
import ImageField from '@/components/ImageField.vue'
import CommentBlocksList from '@/components/CommentBlocksList.vue'
import SchemaBuilder from '@/components/SchemaBuilder.vue'
import FormBuilder from '@/components/FormBuilder.vue'
import EmailTemplatesEditor from '@/components/EmailTemplatesEditor.vue'
import MultilingualInput from '@/components/MultilingualInput.vue'
import MultilingualTextarea from '@/components/MultilingualTextarea.vue'
import { useUILanguage } from '@/composables/useUILanguage'
import { usePermissions } from '@/composables/usePermissions'
import { useEntitiesStore } from '@/stores/entities'
import type { WorkflowStateMigration } from '@/stores/entities'
import EditingLanguageSelector from './EditingLanguageSelector.vue'
import type { VisibilityLevel } from '@/utils/constants'
import type { EmailTemplate } from '@/schemas/entity-schema'
import { usedTemplateIds } from '@/utils/emailTemplates'
const { t } = useUILanguage()
const { hasPermission } = usePermissions()
const entitiesStore = useEntitiesStore()
const activeTab = ref<'details' | 'schema' | 'forms' | 'emails'>('details')
const props = defineProps<{
isOpen: boolean
mode: 'create' | 'edit' | 'view'
formData: {
name: string | Record<string, string>
description?: string | Record<string, string>
visibility: VisibilityLevel
commentsEnabled?: boolean
fields: any[]
forms?: any[]
emailTemplates?: EmailTemplate[]
picture?: string
icon?: string
workflowStateMigrations?: WorkflowStateMigration[]
}
entityId?: string
defaultLanguage: string
enabledLanguages: string[]
currentLanguage: string
loading: boolean
error: string
nameError?: string
fieldErrors?: Record<string, string>
hasItems?: boolean
linksInfo?: {
sameUserFlowsCount: number
otherUserFlowsCount: number
totalFlowsCount: number
} | null
}>()
// A field is considered unnamed when it has no name in any language.
function isFieldNamed(field: any): boolean {
if (!field.name) return false
if (typeof field.name === 'string') return field.name.trim().length > 0
return Object.values(field.name as Record<string, string>).some((v) => v && v.trim().length > 0)
}
const hasUnnamedFields = computed(() => props.formData.fields.some((f) => !isFieldNamed(f)))
const isPublicEntity = computed(() => props.formData.visibility === 'public')
// Templates an Email action sends can't be deleted (the API would reject the entity)
const templatesInUse = computed(() => usedTemplateIds(props.formData.fields))
// Whether the current fields would be rejected by the backend if this entity
// were public: a `user` field, or an `entity_ref` field targeting a non-public entity.
const hasFieldsBlockingPublic = computed(() =>
props.formData.fields.some((field) => {
if (field.type === 'user') return true
Eif (field.type === 'entity_ref') {
const targetId = field.reference?.entityId
Iif (!targetId) return false
const target = entitiesStore.entities.find((e) => e.id === targetId)
return !target || target.visibility !== 'public'
}
return false
})
)
const canEnablePublic = computed(() => !hasFieldsBlockingPublic.value)
const canDisablePublic = computed(() => (props.linksInfo?.otherUserFlowsCount ?? 0) === 0)
const visibilityDropdownRef = ref<HTMLElement | null>(null)
const isVisibilityDropdownOpen = ref(false)
const cannotDisablePublicMessage = computed(() =>
t('entity.visibilityCannotDisablePublic').replace(
'{count}',
String(props.linksInfo?.otherUserFlowsCount ?? 0)
)
)
function visibilityLabel(visibility: VisibilityLevel): string {
if (visibility === 'public') return t('entity.visibilityPublic')
if (visibility === 'restricted') return t('entity.visibilityRestricted')
return t('entity.visibilityFlowMembers')
}
// Roles are only created when the entity becomes restricted (UC-RBAC-008.1) —
// not when an already restricted entity is merely edited.
const savedEntity = computed(() =>
entitiesStore.entities.find((entity) => entity.id === props.entityId)
)
const savedVisibility = computed(() => savedEntity.value?.visibility)
const showRestrictedRolesHint = computed(
() =>
props.mode !== 'view' &&
props.formData.visibility === 'restricted' &&
(props.mode === 'create' || savedVisibility.value !== 'restricted')
)
function selectVisibility(visibility: VisibilityLevel) {
Iif (
visibility !== 'public' &&
props.formData.visibility === 'public' &&
!canDisablePublic.value
) {
return
}
Iif (visibility === 'public' && props.formData.visibility !== 'public' && !canEnablePublic.value) {
return
}
emit('update:formData', { ...props.formData, visibility })
isVisibilityDropdownOpen.value = false
}
function onVisibilityClickOutside(event: MouseEvent) {
if (!visibilityDropdownRef.value) return
const target = event.target as Node | null
if (target && !visibilityDropdownRef.value.contains(target)) {
isVisibilityDropdownOpen.value = false
}
}
onMounted(() => {
document.addEventListener('mousedown', onVisibilityClickOutside)
})
onBeforeUnmount(() => {
document.removeEventListener('mousedown', onVisibilityClickOutside)
})
const canDeleteEntity = computed(
() => !!props.entityId && hasPermission(`entities-${props.entityId}:delete`, savedEntity.value)
)
const canClearItems = computed(
() =>
!!props.entityId && hasPermission(`entities-${props.entityId}:items:delete`, savedEntity.value)
)
const showDangerZone = computed(
() => props.mode === 'edit' && (canDeleteEntity.value || canClearItems.value)
)
const sidebarTitle = computed(() => {
if (props.mode === 'create') return t('entity.createNew')
if (props.mode === 'view') return t('entity.inspectEntity')
return t('entity.editEntity')
})
const emit = defineEmits<{
'update:formData': [value: any]
'update:currentLanguage': [value: string]
close: []
submit: []
delete: []
clearAll: []
}>()
function handleClose() {
emit('close')
}
function handleWorkflowStateRemoved(payload: WorkflowStateMigration) {
const existing = props.formData.workflowStateMigrations ?? []
emit('update:formData', {
...props.formData,
workflowStateMigrations: [
...existing.filter(
(m) => !(m.fieldId === payload.fieldId && m.removedStateId === payload.removedStateId)
),
payload
]
})
}
function handleSubmit() {
emit('submit')
}
// Closing, or leaving the page, asks before dropping the changes (BaseFormSidebar)
const { dirty } = useUnsavedChanges(
() => props.formData,
() => props.isOpen && props.mode !== 'view'
)
</script>
<style scoped>
/* Override global tab-content padding inside sidebar to avoid unwanted left offset */
:deep(.tab-content) {
padding-left: 0;
}
/* Inspection mode: content is inert (non-interactive); dim it to signal read-only */
.tab-content.view-only {
opacity: 0.75;
}
.visibility-dropdown {
position: relative;
}
.visibility-dropdown-menu {
position: absolute;
z-index: 30;
left: 0;
right: 0;
margin-top: 0.25rem;
border: 1px solid var(--bw-border);
border-radius: 0.5rem;
background: var(--bw-surface);
box-shadow: 0 10px 24px rgba(12, 19, 31, 0.25);
overflow: hidden;
}
.visibility-dropdown-option {
display: block;
width: 100%;
text-align: left;
border: 0;
background: transparent;
color: var(--bw-text);
padding: 0.5rem 0.6rem;
}
.visibility-dropdown-option:not(:last-child) {
border-bottom: 1px solid var(--bw-border);
}
.visibility-dropdown-option:hover:not(:disabled),
.visibility-dropdown-option.selected {
background: var(--bw-surface-muted);
}
.visibility-dropdown-option:disabled {
cursor: not-allowed;
color: var(--bw-text-muted);
}
.option-label {
font-weight: 500;
}
.option-description {
font-size: 0.8rem;
margin-top: 0.15rem;
color: var(--bw-text-muted);
}
</style>
|