@@ -9,48 +9,56 @@ import { c } from "helpers/StylesHelper";
99import { Literal } from "obsidian-dataview/lib/data-model/value" ;
1010import { ActionTypes } from "helpers/Constants" ;
1111import NoteInfo from "services/NoteInfo" ;
12+ import { TableColumn , TableDataType } from "cdm/FolderModel" ;
1213
1314const TagsPortal = ( tagsProps : TagsProps ) => {
1415 const { intialState, column, dispatch, cellProperties, columns } = tagsProps ;
15- const { row } = cellProperties ;
16+ const { row, table } = cellProperties ;
17+ const tableColumn = column . columnDef as TableColumn ;
18+ const state = table . options . meta as TableDataType ;
1619 // Tags reference state
1720 const [ showSelectTags , setShowSelectTags ] = useState ( false ) ;
1821 // tags values state
1922 const [ tagsState , setTagsState ] = useState (
20- Array . isArray ( intialState . view . rows [ row . index ] [ column . key ] )
21- ? ( intialState . view . rows [ row . index ] [ column . key ] as Literal [ ] )
23+ Array . isArray ( intialState . view . rows [ row . index ] [ tableColumn . key ] )
24+ ? ( intialState . view . rows [ row . index ] [ tableColumn . key ] as Literal [ ] )
2225 : [ ]
2326 ) ;
2427
2528 /** Note info of current Cell */
2629 const note : NoteInfo = ( cellProperties . row . original as any ) . __note__ ;
2730
2831 function getColor ( tag : string ) {
29- const match = column . options . find (
32+ const match = tableColumn . options . find (
3033 ( option : { label : string } ) => option . label === tag
3134 ) ;
3235 if ( match ) {
3336 return match . backgroundColor ;
3437 } else {
3538 // In case of new tag, generate random color
3639 const color = randomColor ( ) ;
37- dispatch ( {
38- columns : columns ,
39- option : tag ,
40+ const newOption : RowSelectOption = {
41+ label : tag ,
4042 backgroundColor : color ,
41- columnId : column . id ,
42- type : ActionTypes . ADD_OPTION_TO_COLUMN ,
43+ } ;
44+ const currentColumn = state . columns . find (
45+ ( col : TableColumn ) => col . key === tableColumn . key
46+ ) ;
47+ currentColumn . options . push ( newOption ) ;
48+ state . view . diskConfig . updateColumnProperties ( column . id , {
49+ options : currentColumn . options ,
4350 } ) ;
4451 return color ;
4552 }
4653 }
54+
4755 const defaultValue = tagsState . map ( ( tag : string ) => ( {
4856 label : tag ,
4957 value : tag ,
5058 color : getColor ( tag ) ,
5159 } ) ) ;
5260
53- const multiOptions = column . options . map ( ( option : RowSelectOption ) => ( {
61+ const multiOptions = tableColumn . options . map ( ( option : RowSelectOption ) => ( {
5462 value : option . label ,
5563 label : option . label ,
5664 color : option . backgroundColor ,
@@ -63,7 +71,7 @@ const TagsPortal = (tagsProps: TagsProps) => {
6371 dispatch ( {
6472 type : ActionTypes . UPDATE_CELL ,
6573 file : note . getFile ( ) ,
66- key : column . key ,
74+ key : tableColumn . key ,
6775 value : arrayTags ,
6876 row : cellProperties . row ,
6977 columnId : column . id ,
@@ -72,7 +80,7 @@ const TagsPortal = (tagsProps: TagsProps) => {
7280 newValue
7381 . filter (
7482 ( tag : any ) =>
75- ! column . options . find ( ( option : any ) => option . label === tag . value )
83+ ! tableColumn . options . find ( ( option : any ) => option . label === tag . value )
7684 )
7785 . forEach ( ( tag : any ) => {
7886 dispatch ( {
@@ -118,6 +126,7 @@ const TagsPortal = (tagsProps: TagsProps) => {
118126 c ( "tags-container" ) + " cell-padding d-flex flex-wrap-wrap"
119127 }
120128 onClick = { ( ) => setShowSelectTags ( true ) }
129+ style = { { width : column . getSize ( ) } }
121130 >
122131 { tagsState . map ( ( tag : string ) => (
123132 < div key = { `key-${ tag } ` } >
0 commit comments