@@ -13,9 +13,11 @@ import createBlock from "roamjs-components/writes/createBlock";
1313import deleteBlock from "roamjs-components/writes/deleteBlock" ;
1414import type { RoamBasicNode } from "roamjs-components/types" ;
1515import NumberPanel from "roamjs-components/components/ConfigPanels/NumberPanel" ;
16+ import TextPanel from "roamjs-components/components/ConfigPanels/TextPanel" ;
1617import {
1718 LeftSidebarPersonalSectionConfig ,
1819 getLeftSidebarPersonalSectionConfig ,
20+ PersonalSectionChild ,
1921} from "~/utils/getLeftSidebarSettings" ;
2022import { extractRef , getSubTree } from "roamjs-components/util" ;
2123import getTextByBlockUid from "roamjs-components/queries/getTextByBlockUid" ;
@@ -56,6 +58,9 @@ const SectionItem = memo(
5658 new Set ( ) ,
5759 ) ;
5860 const isExpanded = expandedChildLists . has ( section . uid ) ;
61+ const [ childSettingsUid , setChildSettingsUid ] = useState < string | null > (
62+ null ,
63+ ) ;
5964 const toggleChildrenList = useCallback ( ( sectionUid : string ) => {
6065 setExpandedChildLists ( ( prev ) => {
6166 const next = new Set ( prev ) ;
@@ -168,6 +173,7 @@ const SectionItem = memo(
168173 text : childName ,
169174 uid : newChild ,
170175 children : [ ] ,
176+ alias : { value : "" } ,
171177 } ,
172178 ] ,
173179 } ;
@@ -189,7 +195,7 @@ const SectionItem = memo(
189195 const removeChild = useCallback (
190196 async (
191197 section : LeftSidebarPersonalSectionConfig ,
192- child : RoamBasicNode ,
198+ child : PersonalSectionChild ,
193199 ) => {
194200 try {
195201 await deleteBlock ( child . uid ) ;
@@ -369,43 +375,114 @@ const SectionItem = memo(
369375
370376 { ( section . children || [ ] ) . length > 0 && (
371377 < div className = "space-y-1" >
372- { ( section . children || [ ] ) . map ( ( child , index ) => (
373- < div
374- key = { child . uid }
375- className = "group flex items-center justify-between rounded bg-gray-50 p-2 hover:bg-gray-100"
376- >
377- < div className = "mr-2 min-w-0 flex-1 truncate" >
378- { child . text }
378+ { ( section . children || [ ] ) . map ( ( child , index ) => {
379+ const childAlias = child . alias ?. value ;
380+ const isSettingsOpen = childSettingsUid === child . uid ;
381+ return (
382+ < div key = { child . uid } >
383+ < div className = "group flex items-center justify-between rounded bg-gray-50 p-2 hover:bg-gray-100" >
384+ < div
385+ className = "mr-2 min-w-0 flex-1 truncate"
386+ title = { child . text }
387+ >
388+ { childAlias ? (
389+ < span >
390+ < span className = "font-medium" >
391+ { childAlias }
392+ </ span >
393+ < span className = "ml-2 text-xs text-gray-400" >
394+ ({ child . text } )
395+ </ span >
396+ </ span >
397+ ) : (
398+ child . text
399+ ) }
400+ </ div >
401+ < ButtonGroup minimal className = "flex-shrink-0" >
402+ < Button
403+ icon = "settings"
404+ small
405+ onClick = { ( ) => setChildSettingsUid ( child . uid ) }
406+ title = "Child Settings"
407+ className = "opacity-0 transition-opacity group-hover:opacity-100"
408+ />
409+ < Button
410+ icon = "arrow-up"
411+ small
412+ disabled = { index === 0 }
413+ onClick = { ( ) => moveChild ( section , index , "up" ) }
414+ title = "Move child up"
415+ className = "opacity-0 transition-opacity group-hover:opacity-100"
416+ />
417+ < Button
418+ icon = "arrow-down"
419+ small
420+ disabled = {
421+ index === ( section . children || [ ] ) . length - 1
422+ }
423+ onClick = { ( ) => moveChild ( section , index , "down" ) }
424+ title = "Move child down"
425+ className = "opacity-0 transition-opacity group-hover:opacity-100"
426+ />
427+ < Button
428+ icon = "trash"
429+ small
430+ intent = "danger"
431+ onClick = { ( ) => void removeChild ( section , child ) }
432+ title = "Remove child"
433+ />
434+ </ ButtonGroup >
435+ </ div >
436+ < Dialog
437+ isOpen = { isSettingsOpen }
438+ onClose = { ( ) => {
439+ setChildSettingsUid ( null ) ;
440+ refreshAndNotify ( ) ;
441+ } }
442+ title = { `Settings for "${ child . text } "` }
443+ style = { { width : "400px" } }
444+ >
445+ < div className = "p-4" >
446+ < TextPanel
447+ title = "Alias"
448+ description = "Display name for this item"
449+ order = { 0 }
450+ uid = { child . alias ?. uid }
451+ parentUid = { child . uid }
452+ defaultValue = ""
453+ options = { {
454+ onChange : (
455+ event : React . ChangeEvent < HTMLInputElement > ,
456+ ) => {
457+ const nextValue = event . target . value ;
458+ setSections ( ( prev ) =>
459+ prev . map ( ( s ) =>
460+ s . uid === section . uid
461+ ? {
462+ ...s ,
463+ children : s . children ?. map ( ( c ) =>
464+ c . uid === child . uid
465+ ? {
466+ ...c ,
467+ alias : {
468+ ...c . alias ,
469+ value : nextValue ,
470+ } ,
471+ }
472+ : c ,
473+ ) ,
474+ }
475+ : s ,
476+ ) ,
477+ ) ;
478+ } ,
479+ } }
480+ />
481+ </ div >
482+ </ Dialog >
379483 </ div >
380- < ButtonGroup minimal className = "flex-shrink-0" >
381- < Button
382- icon = "arrow-up"
383- small
384- disabled = { index === 0 }
385- onClick = { ( ) => moveChild ( section , index , "up" ) }
386- title = "Move child up"
387- className = "opacity-0 transition-opacity group-hover:opacity-100"
388- />
389- < Button
390- icon = "arrow-down"
391- small
392- disabled = {
393- index === ( section . children || [ ] ) . length - 1
394- }
395- onClick = { ( ) => moveChild ( section , index , "down" ) }
396- title = "Move child down"
397- className = "opacity-0 transition-opacity group-hover:opacity-100"
398- />
399- < Button
400- icon = "trash"
401- small
402- intent = "danger"
403- onClick = { ( ) => void removeChild ( section , child ) }
404- title = "Remove child"
405- />
406- </ ButtonGroup >
407- </ div >
408- ) ) }
484+ ) ;
485+ } ) }
409486 </ div >
410487 ) }
411488
0 commit comments