|
12 | 12 | siteStatus,
|
13 | 13 | siteResults,
|
14 | 14 | } from "../../stores/response";
|
15 |
| - import TableItemComponent from "./TableItemComponent.svelte"; |
16 | 15 | import { lensOptions } from "../../stores/options";
|
17 | 16 | import type { HeaderData } from "../../types/options";
|
18 | 17 | import InfoButtonComponent from "../buttons/InfoButtonComponent.wc.svelte";
|
|
114 | 113 | }
|
115 | 114 | };
|
116 | 115 |
|
| 116 | + /** |
| 117 | + * adds and removes tableRows from the datarequestsStore whenever a checkbox is checked or unchecked |
| 118 | + */ |
| 119 | + const updateStoreOnCheck = (tableRow: (string | number)[]): void => { |
| 120 | + const siteId = tableRow[0] as string; |
| 121 | + const isChecked = $datarequestsStore.includes(siteId); |
| 122 | +
|
| 123 | + if (!isChecked) { |
| 124 | + datarequestsStore.update((store: string[]) => { |
| 125 | + return [...store, siteId]; |
| 126 | + }); |
| 127 | + } else { |
| 128 | + datarequestsStore.update((store: string[]) => { |
| 129 | + return store.filter((site: string) => site !== siteId); |
| 130 | + }); |
| 131 | + } |
| 132 | + }; |
| 133 | +
|
117 | 134 | /**
|
118 | 135 | * Configuration options for the result table.
|
119 | 136 | */
|
|
179 | 196 |
|
180 | 197 | const pageSizeOptions: number[] = Array.from(
|
181 | 198 | new Set([10, 25, 50, pageSize]),
|
182 |
| - ).sort(); |
| 199 | + ).sort((a, b) => a - b); |
183 | 200 | let currentPageSize = $state(pageSize);
|
184 | 201 | </script>
|
185 | 202 |
|
|
220 | 237 | </tr>
|
221 | 238 | </thead>
|
222 | 239 | <tbody part="lens-result-table-table-body">
|
223 |
| - <!-- eslint-disable-next-line svelte/require-each-key --> |
224 |
| - {#each visibleRows as tableRow} |
225 |
| - <TableItemComponent {tableRow} /> |
| 240 | + {#each visibleRows as tableRow (tableRow[0])} |
| 241 | + <tr part="lens-result-table-item-body-row"> |
| 242 | + <td |
| 243 | + part="lens-result-table-item-body-cell lens-result-table-item-body-cell-checkbox" |
| 244 | + ><input |
| 245 | + part="lens-result-table-item-body-checkbox" |
| 246 | + type="checkbox" |
| 247 | + checked={$datarequestsStore.includes( |
| 248 | + tableRow[0] as string, |
| 249 | + )} |
| 250 | + onchange={() => updateStoreOnCheck(tableRow)} |
| 251 | + /></td |
| 252 | + > |
| 253 | + {#each tableRow as data, index (index)} |
| 254 | + <td part="lens-result-table-item-body-cell">{data}</td> |
| 255 | + {/each} |
| 256 | + </tr> |
226 | 257 | {/each}
|
| 258 | + <!-- Invisible rows for spacing --> |
| 259 | + {#if visibleRows.length < currentPageSize} |
| 260 | + {#each Array(currentPageSize - visibleRows.length).keys() as i (i)} |
| 261 | + <tr part="lens-result-table-item-body-row"> |
| 262 | + {#each Array(headerData.length + 1).keys() as j (j)} |
| 263 | + <td part="lens-result-table-item-body-cell"></td> |
| 264 | + {/each} |
| 265 | + </tr> |
| 266 | + {/each} |
| 267 | + {/if} |
227 | 268 | </tbody>
|
228 | 269 | </table>
|
229 | 270 | <slot name="lens-result-above-pagination" />
|
|
323 | 364 | [part~="lens-result-table-pagination-switcher"] {
|
324 | 365 | margin-left: 20px;
|
325 | 366 | }
|
| 367 | +
|
| 368 | + [part~="lens-result-table-item-body-row"] { |
| 369 | + border-bottom: solid 1px var(--light-gray); |
| 370 | + height: 2em; |
| 371 | + } |
326 | 372 | </style>
|
0 commit comments