|
159 | 159 | /** |
160 | 160 | * @param {number} uid |
161 | 161 | * @param {number} fid |
| 162 | + * @param {string} type |
162 | 163 | */ |
163 | | - function deleteUtilityItem(uid, fid) { |
164 | | - const found = innerUtilities.find((_, index) => index === uid); |
165 | | - if (!found) return; |
| 164 | + function deleteUtilityItem(uid, fid, type) { |
| 165 | + const foundUtility = innerUtilities.find((_, index) => index === uid); |
| 166 | + const foundItem = foundUtility?.items?.find((_, index) => index === fid); |
| 167 | + if (!foundUtility || !foundItem) return; |
| 168 | +
|
| 169 | + if (type === 'function') { |
| 170 | + foundItem.function_name = null; |
| 171 | + foundItem.function_display_name = null; |
| 172 | + } else if (type === 'template') { |
| 173 | + foundItem.template_name = null; |
| 174 | + foundItem.template_display_name = null; |
| 175 | + } |
| 176 | +
|
| 177 | + if (foundItem.function_name == null && foundItem.template_name == null) { |
| 178 | + foundUtility.items = foundUtility.items.filter((_, index) => index !== fid); |
| 179 | + } |
166 | 180 |
|
167 | | - found.items = found.items?.filter((_, index) => index !== fid) || []; |
168 | 181 | innerRefresh(innerUtilities); |
169 | 182 | handleAgentChange(); |
170 | 183 | } |
|
330 | 343 | {/if} |
331 | 344 | {#each utility.items as item, fid (fid)} |
332 | 345 | <div class="utility-content"> |
333 | | - <div class="utility-list-item"> |
334 | | - <div class="utility-label line-align-center"> |
335 | | - {'Function'} |
336 | | - </div> |
337 | | - <div class="utility-value"> |
338 | | - <div class="utility-input line-align-center"> |
339 | | - <Input |
340 | | - type="text" |
341 | | - value={item.function_display_name} |
342 | | - disabled |
343 | | - /> |
| 346 | + {#if item.function_name} |
| 347 | + <div class="utility-list-item"> |
| 348 | + <div class="utility-label line-align-center"> |
| 349 | + {'Function'} |
344 | 350 | </div> |
345 | | - <div class="utility-delete line-align-center"> |
346 | | - <i |
347 | | - class="bx bxs-no-entry text-danger clickable" |
348 | | - role="link" |
349 | | - tabindex="0" |
350 | | - on:keydown={() => {}} |
351 | | - on:click={() => deleteUtilityItem(uid, fid)} |
352 | | - /> |
| 351 | + <div class="utility-value"> |
| 352 | + <div class="utility-input line-align-center"> |
| 353 | + <Input |
| 354 | + type="text" |
| 355 | + value={item.function_display_name} |
| 356 | + disabled |
| 357 | + /> |
| 358 | + </div> |
| 359 | + <div class="utility-delete line-align-center"> |
| 360 | + <i |
| 361 | + class="bx bxs-no-entry text-danger clickable" |
| 362 | + role="link" |
| 363 | + tabindex="0" |
| 364 | + on:keydown={() => {}} |
| 365 | + on:click={() => deleteUtilityItem(uid, fid, 'function')} |
| 366 | + /> |
| 367 | + </div> |
353 | 368 | </div> |
354 | 369 | </div> |
355 | | - </div> |
| 370 | + {/if} |
356 | 371 | {#if item.template_name} |
357 | | - <div class="utility-list-item"> |
358 | | - <div class="utility-label line-align-center"> |
359 | | - {'Template'} |
360 | | - </div> |
361 | | - <div class="utility-value"> |
362 | | - <div class="utility-input line-align-center"> |
363 | | - <Input |
364 | | - type="text" |
365 | | - value={item.template_display_name} |
366 | | - disabled |
367 | | - /> |
| 372 | + <div class="utility-list-item"> |
| 373 | + <div class="utility-label line-align-center"> |
| 374 | + {'Template'} |
| 375 | + </div> |
| 376 | + <div class="utility-value"> |
| 377 | + <div class="utility-input line-align-center"> |
| 378 | + <Input |
| 379 | + type="text" |
| 380 | + value={item.template_display_name} |
| 381 | + disabled |
| 382 | + /> |
| 383 | + </div> |
| 384 | + <div class="utility-delete line-align-center"> |
| 385 | + <i |
| 386 | + class="bx bxs-no-entry text-danger clickable" |
| 387 | + role="link" |
| 388 | + tabindex="0" |
| 389 | + on:keydown={() => {}} |
| 390 | + on:click={() => deleteUtilityItem(uid, fid, 'template')} |
| 391 | + /> |
| 392 | + </div> |
368 | 393 | </div> |
369 | | - <div class="utility-delete line-align-center"></div> |
370 | 394 | </div> |
371 | | - </div> |
372 | 395 | {/if} |
373 | 396 | <div class="utility-list-item"> |
374 | 397 | <div class="utility-label line-align-center"> |
|
0 commit comments