11import { CellComponentProps } from "cdm/ComponentsModel" ;
22import { TableColumn } from "cdm/FolderModel" ;
3- import { InputType } from "helpers/Constants" ;
3+ import { InputType , StyleVariables } from "helpers/Constants" ;
44import { c , getAlignmentClassname } from "helpers/StylesHelper" ;
55import { Notice } from "obsidian" ;
66import { Link } from "obsidian-dataview" ;
7- import React , { useEffect , useRef , useState } from "react" ;
7+ import React , { useRef , useState } from "react" ;
88import { DataviewService } from "services/DataviewService" ;
99import { ParseService } from "services/ParseService" ;
1010import RelationEditor from "components/cellTypes/Editor/RelationEditor" ;
11- import { MarkdownService } from "services/MarkdownRenderService" ;
11+ import Relationship from "components/RelationShip" ;
12+ import { grey } from "helpers/Colors" ;
1213
1314const RelationCell = ( mdProps : CellComponentProps ) => {
1415 const { defaultCell } = mdProps ;
1516 const { table, row, column } = defaultCell ;
16- const { tableState } = table . options . meta ;
17+ const { tableState, view } = table . options . meta ;
1718 const tableColumn = column . columnDef as TableColumn ;
1819 const relationRow = tableState . data ( ( state ) => state . rows [ row . index ] ) ;
1920 const dataActions = tableState . data ( ( state ) => state . actions ) ;
@@ -29,34 +30,8 @@ const RelationCell = (mdProps: CellComponentProps) => {
2930 ) as Link [ ]
3031 ) ;
3132
32- const containerCellRef = useRef < HTMLDivElement > ( ) ;
3333 const [ dirtyCell , setDirtyCell ] = useState ( false ) ;
3434
35- /**
36- * Render markdown content of Obsidian on load
37- */
38- useEffect ( ( ) => {
39- if ( relationCell . length === 0 || dirtyCell ) {
40- // End useEffect
41- return ;
42- }
43-
44- if ( containerCellRef . current !== undefined ) {
45- containerCellRef . current . innerHTML = "" ;
46- const mdRelations = relationCell
47- . map ( ( relation ) => {
48- return relation . markdown ( ) ;
49- } )
50- . join ( "," ) ;
51- MarkdownService . renderMarkdown (
52- defaultCell ,
53- `[ ${ mdRelations } ]` ,
54- containerCellRef . current ,
55- 5
56- ) ;
57- }
58- } , [ row , column , dirtyCell ] ) ;
59-
6035 const persistChange = ( newPaths : string [ ] ) => {
6136 const oldPaths = relationCell
6237 ? relationCell . map ( ( relation ) => relation . path )
@@ -115,9 +90,14 @@ const RelationCell = (mdProps: CellComponentProps) => {
11590 relationCell = { relationCell }
11691 />
11792 ) : (
118- < span
119- ref = { containerCellRef }
93+ < div
12094 onDoubleClick = { handleOnClick }
95+ onKeyDown = { ( e ) => {
96+ if ( e . key === "Enter" ) {
97+ e . preventDefault ( ) ;
98+ handleOnClick ( ) ;
99+ }
100+ } }
121101 style = { { width : column . getSize ( ) } }
122102 className = { c (
123103 getAlignmentClassname (
@@ -126,14 +106,19 @@ const RelationCell = (mdProps: CellComponentProps) => {
126106 [ "tabIndex" ]
127107 )
128108 ) }
129- onKeyDown = { ( e ) => {
130- if ( e . key === "Enter" ) {
131- e . preventDefault ( ) ;
132- handleOnClick ( ) ;
133- }
134- } }
135109 tabIndex = { 0 }
136- />
110+ >
111+ { relationCell
112+ ? relationCell . map ( ( link : Link , index ) => (
113+ < Relationship
114+ key = { `relation-${ index } -${ tableColumn . key } -${ link . path } ` }
115+ value = { link . markdown ( ) }
116+ backgroundColor = { tableColumn . config . relation_color || grey ( 300 ) }
117+ view = { view }
118+ />
119+ ) )
120+ : null }
121+ </ div >
137122 ) ;
138123} ;
139124
0 commit comments