11import {
22 readToolboxVoteSnapshot ,
33 reorderToolboxVoteRows ,
4+ updateToolboxVoteMetadata ,
45} from "../src/engine/api/toolbox-votes-api-client.js" ;
56
67const status = document . querySelector ( "[data-toolbox-votes-status]" ) ;
@@ -14,11 +15,22 @@ const sortHeaders = Array.from(document.querySelectorAll("[data-toolbox-votes-so
1415const widthLayout = document . querySelector ( "[data-toolbox-votes-layout]" ) ;
1516const widthToggle = document . querySelector ( "[data-toolbox-votes-width-toggle]" ) ;
1617const widthStatus = document . querySelector ( "[data-toolbox-votes-width-status]" ) ;
18+ const groupEdit = document . querySelector ( "[data-toolbox-votes-group-edit]" ) ;
19+ const pathEdit = document . querySelector ( "[data-toolbox-votes-path-edit]" ) ;
20+ const statusEdit = document . querySelector ( "[data-toolbox-votes-status-edit]" ) ;
21+ const metadataSave = document . querySelector ( "[data-toolbox-votes-metadata-save]" ) ;
1722const sortButtonLabels = new Map ( sortButtons . map ( ( button ) => [
1823 button . dataset . toolboxVotesSort ,
1924 button . textContent . trim ( ) ,
2025] ) ) ;
2126
27+ const RELEASE_CHANNEL_OPTIONS = Object . freeze ( [
28+ [ "planned" , "Planned" ] ,
29+ [ "wireframe" , "Wireframe" ] ,
30+ [ "beta" , "Beta" ] ,
31+ [ "complete" , "Complete" ] ,
32+ ] ) ;
33+
2234const SORT_TYPES = Object . freeze ( {
2335 down : "number" ,
2436 downPercent : "number" ,
@@ -143,6 +155,58 @@ function setSelectedDetails(voteRow) {
143155 if ( selectedPath ) {
144156 selectedPath . textContent = voteRow ?. path || "None" ;
145157 }
158+ setMetadataEditor ( voteRow ) ;
159+ }
160+
161+ function option ( value , label = value ) {
162+ const node = document . createElement ( "option" ) ;
163+ node . value = value ;
164+ node . textContent = label ;
165+ return node ;
166+ }
167+
168+ function populateGroupOptions ( rows ) {
169+ if ( ! groupEdit ) {
170+ return ;
171+ }
172+ const selectedValue = groupEdit . value ;
173+ const groups = [ ...new Set ( rows . map ( ( row ) => row . group ) . filter ( Boolean ) ) ] . sort ( ( left , right ) => left . localeCompare ( right ) ) ;
174+ groupEdit . replaceChildren ( ...groups . map ( ( group ) => option ( group ) ) ) ;
175+ if ( groups . includes ( selectedValue ) ) {
176+ groupEdit . value = selectedValue ;
177+ }
178+ }
179+
180+ function populateStatusOptions ( ) {
181+ if ( ! statusEdit || statusEdit . childElementCount ) {
182+ return ;
183+ }
184+ statusEdit . replaceChildren ( ...RELEASE_CHANNEL_OPTIONS . map ( ( [ value , label ] ) => option ( value , label ) ) ) ;
185+ }
186+
187+ function setMetadataEditor ( voteRow ) {
188+ populateStatusOptions ( ) ;
189+ const disabled = ! voteRow ;
190+ [ groupEdit , pathEdit , statusEdit , metadataSave ] . forEach ( ( control ) => {
191+ if ( control ) {
192+ control . disabled = disabled ;
193+ }
194+ } ) ;
195+ if ( ! voteRow ) {
196+ if ( groupEdit ) groupEdit . value = "" ;
197+ if ( pathEdit ) pathEdit . value = "" ;
198+ if ( statusEdit ) statusEdit . value = "planned" ;
199+ return ;
200+ }
201+ if ( groupEdit ) {
202+ groupEdit . value = voteRow . group || "" ;
203+ }
204+ if ( pathEdit ) {
205+ pathEdit . value = voteRow . path || "" ;
206+ }
207+ if ( statusEdit ) {
208+ statusEdit . value = voteRow . releaseChannel || "planned" ;
209+ }
146210}
147211
148212function selectRow ( toolId ) {
@@ -216,6 +280,7 @@ function renderRows(rows) {
216280 return ;
217281 }
218282 snapshotRows = rows ;
283+ populateGroupOptions ( snapshotRows ) ;
219284 updateSortHeaders ( ) ;
220285 updateDragStatus ( ) ;
221286 const displayRows = sortedRows ( ) ;
@@ -320,4 +385,23 @@ widthToggle?.addEventListener("click", () => {
320385 }
321386} ) ;
322387
388+ metadataSave ?. addEventListener ( "click" , ( ) => {
389+ if ( ! selectedToolId ) {
390+ setStatus ( "Select a Toolbox row before updating metadata." ) ;
391+ return ;
392+ }
393+ try {
394+ const snapshot = updateToolboxVoteMetadata ( selectedToolId , {
395+ group : groupEdit ?. value || "" ,
396+ path : pathEdit ?. value || "" ,
397+ releaseChannel : statusEdit ?. value || "planned" ,
398+ } ) ;
399+ renderSnapshot ( snapshot , "Toolbox metadata updated. Reload Toolbox Build Path to see the SSoT values." ) ;
400+ selectRow ( selectedToolId ) ;
401+ } catch ( error ) {
402+ const message = error instanceof Error ? error . message : String ( error || "Toolbox metadata update unavailable." ) ;
403+ setStatus ( `Toolbox metadata could not be updated. ${ message } ` ) ;
404+ }
405+ } ) ;
406+
323407renderToolboxVotes ( ) ;
0 commit comments