|
51 | 51 | function handleReorder(reorderedItems: { item: any; originalIndex: number }[]) { |
52 | 52 | console.log('handleReorder', property.name, reorderedItems); |
53 | 53 | const full = [...data[property.name]]; |
| 54 | + // Capture the current filteredItems mapping before any potential state changes |
| 55 | + const indexMap = filteredItems.map((f: any) => f.originalIndex); |
54 | 56 | reorderedItems.forEach(({ item }, pos) => { |
55 | | - const originalIndex = filteredItems[pos].originalIndex; |
| 57 | + const originalIndex = indexMap[pos]; |
56 | 58 | full[originalIndex] = item; |
57 | 59 | }); |
58 | 60 | data[property.name] = full; |
|
152 | 154 | <div class="h-16 flex w-full items-center justify-between space-x-3 p-0 text-xl font-medium"> |
153 | 155 | {initCap(property.name)} |
154 | 156 | </div> |
155 | | -{#if findItemInDefinition?.crud == null || findItemInDefinition.crud.includes('c')} |
| 157 | +{#if findItemInDefinition?.crud == null || findItemInDefinition?.crud?.includes('c')} |
156 | 158 | <div class="relative w-full overflow-visible"> |
157 | 159 | <!-- <div class="mx-4 mb-4 flex flex-wrap justify-end gap-2"> --> |
158 | 160 | <button |
|
193 | 195 | items={filteredItems} |
194 | 196 | onReorder={handleReorder} |
195 | 197 | class="space-y-2" |
196 | | - dragDisabled={!(findItemInDefinition?.crud == null || findItemInDefinition.crud.includes('s'))} |
| 198 | + dragDisabled={!(findItemInDefinition?.crud == null || findItemInDefinition?.crud?.includes('s'))} |
197 | 199 | > |
198 | 200 | {#snippet children({ item: itemWrapper }: { item: any })} |
199 | 201 | <!-- svelte-ignore a11y_click_events_have_key_events --> |
200 | 202 | <div class="rounded-box bg-base-100 flex items-center space-x-3 px-4 py-2"> |
201 | | - {#if findItemInDefinition?.crud == null || findItemInDefinition.crud.includes('s')} |
| 203 | + {#if findItemInDefinition?.crud == null || findItemInDefinition?.crud?.includes('s')} |
202 | 204 | <Grip class="h-6 w-6 text-base-content/30 cursor-grab flex-shrink-0" /> |
203 | 205 | {/if} |
204 | 206 | <!-- Show the first 3 fields --> |
|
235 | 237 | > |
236 | 238 | <SearchIcon class="h-6 w-6" /></button |
237 | 239 | > |
238 | | - {#if findItemInDefinition?.crud == null || findItemInDefinition.crud.includes('d')} |
| 240 | + {#if findItemInDefinition?.crud == null || findItemInDefinition?.crud?.includes('d')} |
239 | 241 | <button |
240 | 242 | class="btn btn-ghost btn-sm" |
241 | 243 | onclick={() => { |
|
0 commit comments