Skip to content

Commit ab059be

Browse files
committed
Fix: Remove section delete button if sectionEditable=true
1 parent 5fbb128 commit ab059be

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

ui_components/src/lib/components/SurveyConfigurator.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
<SectionComponent bind:config={config.sections[index]}
6060
editable={editable}
6161
sectionTypeEditable={sectionTypeEditable}
62+
sectionEditable={sectionEditable}
6263
bind:this={_sectionComponents[index]}
6364
sectionIndex={index}
6465
onMoveRequest={handleMoveRequest}

ui_components/src/lib/components/input/SectionComponent.svelte

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<script lang="ts" module>
2-
import DOMPurify from "dompurify";
2+
import DOMPurify from "dompurify";
33
import type {SectionConfig} from "../../interfaces.ts";
44
5-
export function getDefaultSectionConfig(): SectionConfig{
5+
export function getDefaultSectionConfig(): SectionConfig {
66
return {
77
title: "New section",
88
description: "Section description",
@@ -30,16 +30,18 @@
3030
editable = false,
3131
viewerMode = false,
3232
sectionTypeEditable = true,
33-
displaySectionType=true,
33+
sectionEditable = true,
34+
displaySectionType = true,
3435
sectionIndex = -1,
3536
onMoveRequest = null,
36-
onDeleteSectionRequest = ()=>{},
37+
onDeleteSectionRequest = () => {
38+
},
3739
} = $props();
3840
3941
//Insert missing keys
4042
let defultConfig = getDefaultSectionConfig()
41-
for(let key in defultConfig){
42-
if(!(key in config)){
43+
for (let key in defultConfig) {
44+
if (!(key in config)) {
4345
config[key] = defultConfig[key];
4446
}
4547
}
@@ -49,9 +51,9 @@
4951
let fieldComponents = $derived(_fieldComponents.filter(Boolean));
5052
5153
52-
let fieldValues = $state(value !== null && value !== undefined ? value :[]);
53-
$effect(()=>{
54-
value = _.cloneDeep(fieldValues);
54+
let fieldValues = $state(value !== null && value !== undefined ? value : []);
55+
$effect(() => {
56+
value = _.cloneDeep(fieldValues);
5557
});
5658
5759
let textVal = $state();
@@ -61,20 +63,20 @@
6163
console.log("Validating section");
6264
let sectionValid = true;
6365
for (let i = 0; i < fieldComponents.length; i++) {
64-
if(!fieldComponents[i].validate()){
66+
if (!fieldComponents[i].validate()) {
6567
sectionValid = false;
6668
}
6769
}
6870
6971
return sectionValid;
7072
}
7173
72-
export function getValue(){
74+
export function getValue() {
7375
let fieldValues = []
7476
for (let i = 0; i < fieldComponents.length; i++) {
7577
fieldValues.push(fieldComponents[i].getValue());
7678
}
77-
return { name: config.title, fields: fieldValues};
79+
return {name: config.title, fields: fieldValues};
7880
}
7981
8082
@@ -91,8 +93,8 @@
9193
}
9294
9395
94-
function handleMoveRequest(srcSectionIndex, srcFieldIndex, destSectionIndex, destFieldIndex){
95-
if(onMoveRequest){
96+
function handleMoveRequest(srcSectionIndex, srcFieldIndex, destSectionIndex, destFieldIndex) {
97+
if (onMoveRequest) {
9698
onMoveRequest(srcSectionIndex, srcFieldIndex, destSectionIndex, destFieldIndex);
9799
}
98100
}
@@ -116,11 +118,11 @@
116118
<div style="display: flex; justify-content: space-between; gap: 1em">
117119
<div style="flex: 1">
118120
<h2>
119-
{#if editable}
120-
<EditableText bind:value={config.title}/>
121-
{:else}
122-
{config.title}
123-
{/if}
121+
{#if editable}
122+
<EditableText bind:value={config.title}/>
123+
{:else}
124+
{config.title}
125+
{/if}
124126
</h2>
125127
</div>
126128
<div class="text-end">
@@ -154,7 +156,7 @@
154156
</div>
155157

156158

157-
{#each config.fields, index (index)}
159+
{#each config.fields, index(index)}
158160
<div class="mb-3">
159161
<InputComponent
160162
bind:config={config.fields[index]}
@@ -172,13 +174,15 @@
172174
{/each}
173175

174176
{#if editable}
175-
176177
<div class="d-flex justify-content-between">
177178
<button class="btn btn-primary" onclick={addField}><i class="bx bx-plus"></i> Add field</button>
178179
<div></div>
179-
<button class="btn btn-danger" onclick={() => {onDeleteSectionRequest()}}><i class="bx bxs-trash"></i> Delete section</button>
180+
{#if sectionEditable}
181+
<button class="btn btn-danger" onclick={() => {onDeleteSectionRequest()}}><i
182+
class="bx bxs-trash"></i> Delete section
183+
</button>
184+
{/if}
180185
</div>
181-
182186
{/if}
183187
</div>
184188
</div>

0 commit comments

Comments
 (0)