@@ -36,6 +36,7 @@ export function Note({ ref, note, active = false, sectionTitles, onEditNote, onD
3636 } ) ;
3737
3838 const [ noteContentError , setNoteContentError ] = useState ( "" ) ;
39+ const [ noteLabelsError , setNoteLabelsError ] = useState ( "" ) ;
3940 const { metadata } = useMetadataContext ( ) ;
4041 const { version } = useVersionContext ( ) ;
4142 const { getHashFromLocationParams } = useGetLocationParamsToHash ( ) ;
@@ -46,6 +47,7 @@ export function Note({ ref, note, active = false, sectionTitles, onEditNote, onD
4647 const content = textAreaRef . current ?. value ?? "" ;
4748 const mathValidationError = validateMath ( content ) ;
4849 setNoteContentError ( "" ) ;
50+ setNoteLabelsError ( "" ) ;
4951
5052 if ( mathValidationError ) {
5153 setNoteContentError ( mathValidationError ) ;
@@ -57,6 +59,11 @@ export function Note({ ref, note, active = false, sectionTitles, onEditNote, onD
5759 return ;
5860 }
5961
62+ if ( noteDirty . labels . length === 0 ) {
63+ setNoteLabelsError ( "Select at least one label" ) ;
64+ return ;
65+ }
66+
6067 noteDirty . content = content ;
6168
6269 onEditNote ( note , noteDirty ) ;
@@ -70,10 +77,14 @@ export function Note({ ref, note, active = false, sectionTitles, onEditNote, onD
7077 setIsEditing ( true ) ;
7178 setNoteDirty ( { ...note . original } ) ;
7279 setNoteContentError ( "" ) ;
80+ setNoteLabelsError ( "" ) ;
7381 } , [ note , isEditable ] ) ;
7482
7583 const handleNoteLabelsChange = useCallback ( ( labels : string [ ] ) => {
7684 setNoteDirty ( ( prevNoteDirty ) => ( { ...prevNoteDirty , labels } ) ) ;
85+ if ( labels . length > 0 ) {
86+ setNoteLabelsError ( "" ) ;
87+ }
7788 } , [ ] ) ;
7889
7990 const handleDeleteClick = useCallback ( ( ) => {
@@ -82,6 +93,7 @@ export function Note({ ref, note, active = false, sectionTitles, onEditNote, onD
8293
8394 const handleCancelClick = useCallback ( ( ) => {
8495 setNoteContentError ( "" ) ;
96+ setNoteLabelsError ( "" ) ;
8597 setIsEditing ( false ) ;
8698 } , [ ] ) ;
8799
@@ -284,6 +296,7 @@ export function Note({ ref, note, active = false, sectionTitles, onEditNote, onD
284296 < NoteLayout . TextArea className = { noteContentError ? "error" : "" } ref = { textAreaRef } />
285297 { noteContentError ? < div className = "validation-message" > { noteContentError } </ div > : null }
286298 < NoteLayout . Labels />
299+ { noteLabelsError ? < div className = "validation-message" > { noteLabelsError } </ div > : null }
287300 < div className = "actions gap-2" >
288301 < Button variant = "ghost" intent = "destructive" size = "sm" onClick = { handleDeleteClick } >
289302 Delete
0 commit comments