|
34 | 34 | let currentPage = $state(0); |
35 | 35 | let totalObservations = shapValues.length; |
36 | 36 | let totalPages = Math.ceil(totalObservations / maxDisplayedValues); |
| 37 | + let filterText = $state(""); |
| 38 | + let dropdownOpen = $state(false); |
37 | 39 |
|
38 | 40 | console.log('DeepDiveManager: 1/3 command in file'); |
39 | 41 | let pagedObservations = $derived( |
|
60 | 62 | currentPage -= 1; |
61 | 63 | } |
62 | 64 | } |
| 65 | + function handleInputFocus() { |
| 66 | + dropdownOpen = true; |
| 67 | + } |
| 68 | + function handleInputBlur(event: FocusEvent) { |
| 69 | + // Delay closing to allow click selection |
| 70 | + setTimeout(() => { dropdownOpen = false; }, 100); |
| 71 | + } |
| 72 | + function handleObservationClick(idx: number) { |
| 73 | + selectedObservationIndex = idx; |
| 74 | + dropdownOpen = false; |
| 75 | + } |
63 | 76 |
|
64 | 77 | $effect(() => { |
65 | 78 | console.log('Selected observation index:', selectedObservationIndex); |
|
74 | 87 | console.log('Current page:', currentPage); |
75 | 88 | console.log('Total pages:', totalPages); |
76 | 89 | }); |
| 90 | +
|
| 91 | + let allObservations = $derived( |
| 92 | + Array.from({length: totalObservations}, (_, idx) => ({ |
| 93 | + name: `Observation ${idx + 1}`, |
| 94 | + index: idx |
| 95 | + })) |
| 96 | + ); |
| 97 | +
|
| 98 | + let filteredObservations = $derived( |
| 99 | + allObservations.filter(obs => |
| 100 | + obs.name.toLowerCase().includes(filterText.toLowerCase()) || |
| 101 | + obs.index.toString().includes(filterText) |
| 102 | + ).slice(0, maxDisplayedValues) |
| 103 | + ); |
77 | 104 | </script> |
78 | 105 |
|
79 | 106 | <div> |
80 | | -<div class="observation-dropdown"> |
81 | | - <label for="observation-select">Select Observation:</label> |
82 | | - <select id="observation-select" bind:value={selectedObservationIndex}> |
83 | | - {#each pagedObservations as obs} |
84 | | - <option value={obs.index}>{obs.name}</option> |
85 | | - {/each} |
86 | | - </select> |
87 | | - <button on:click={prevPage} disabled={currentPage === 0}>Prev</button> |
88 | | - <button on:click={nextPage} disabled={currentPage === totalPages - 1}>Next</button> |
| 107 | +<div class="observation-dropdown" style="position:relative;max-width:300px;"> |
| 108 | + <label for="observation-filter">Filter Observations:</label> |
| 109 | + <input id="observation-filter" type="text" bind:value={filterText} placeholder="Type to filter..." |
| 110 | + on:focus={handleInputFocus} on:blur={handleInputBlur} autocomplete="off" /> |
| 111 | + {#if dropdownOpen} |
| 112 | + <ul class="dropdown-list" style="position:absolute;z-index:10;top:40px;left:0;width:100%;background:white;border:1px solid #ccc;max-height:200px;overflow-y:auto;padding:0;margin:0;list-style:none;"> |
| 113 | + {#each filteredObservations as obs} |
| 114 | + <li style="padding:8px;cursor:pointer;" on:mousedown={() => handleObservationClick(obs.index)}>{obs.name}</li> |
| 115 | + {/each} |
| 116 | + {#if filteredObservations.length === 0} |
| 117 | + <li style="padding:8px;color:#888;">No matches</li> |
| 118 | + {/if} |
| 119 | + </ul> |
| 120 | + {/if} |
| 121 | + <div style="margin-top:8px;"> |
| 122 | + <button on:click={prevPage} disabled={currentPage === 0}>Prev</button> |
| 123 | + <button on:click={nextPage} disabled={currentPage === totalPages - 1}>Next</button> |
| 124 | + </div> |
89 | 125 | </div> |
90 | 126 | <DeepDiveChart |
91 | 127 | shapValues={shapValues} |
|
0 commit comments