Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit 5a1a107

Browse files
committed
new relation design
1 parent eebaf72 commit 5a1a107

File tree

6 files changed

+61
-41
lines changed

6 files changed

+61
-41
lines changed

src/cdm/FolderModel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export interface ConfigColumn {
5555
// Relations
5656
related_note_path?: string;
5757
bidirectional_relation?: boolean;
58+
relation_color?: string;
5859
// Rollups
5960
asociated_relation_id?: string;
6061
rollup_action?: string;

src/components/cellTypes/RelationCell.tsx

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import { CellComponentProps } from "cdm/ComponentsModel";
22
import { TableColumn } from "cdm/FolderModel";
3-
import { InputType } from "helpers/Constants";
3+
import { InputType, StyleVariables } from "helpers/Constants";
44
import { c, getAlignmentClassname } from "helpers/StylesHelper";
55
import { Notice } from "obsidian";
66
import { Link } from "obsidian-dataview";
7-
import React, { useEffect, useRef, useState } from "react";
7+
import React, { useRef, useState } from "react";
88
import { DataviewService } from "services/DataviewService";
99
import { ParseService } from "services/ParseService";
1010
import 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

1314
const 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

src/components/modals/columnSettings/ColumnSections.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ import { RollupActionHandler } from "./handlers/rollups/RollupActionHandler";
1717
import { RollupKeyHandler } from "./handlers/rollups/RollupKeyHandler";
1818
import { RollupPersistToggleHandler } from "./handlers/rollups/RollupPersistToggleHandler";
1919
import { RollupFormulaHandler } from "./handlers/rollups/RollupFormulaHandler";
20-
import { BidirectionalRelationToggleHandler } from "./handlers/automations/BidirectionalRelationToggleHandler";
20+
import { BidirectionalRelationToggleHandler } from "./handlers/relations/BidirectionalRelationToggleHandler";
21+
import { RelationColorSelectorHandler } from "./handlers/relations/RelationColorSelectorHandler";
2122
import { InputType } from "helpers/Constants";
2223
import { AbstractChain } from "patterns/chain/AbstractFactoryChain";
2324
import { AbstractHandler } from "patterns/chain/AbstractHandler";
2425
import { t } from "lang/helpers";
2526

26-
2727
class StyleSetttingsSection extends AbstractChain<ColumnSettingsHandlerResponse> {
2828
private input: string = InputType.TEXT;
2929
protected runBefore(columnHandlerResponse: ColumnSettingsHandlerResponse): ColumnSettingsHandlerResponse {
@@ -145,6 +145,7 @@ class ParticularSetttingsSection extends AbstractChain<ColumnSettingsHandlerResp
145145
case InputType.RELATION:
146146
particularHandlers.push(new DatabaseSelectorHandler());
147147
particularHandlers.push(new BidirectionalRelationToggleHandler());
148+
particularHandlers.push(new RelationColorSelectorHandler());
148149
break;
149150
case InputType.ROLLUP:
150151
particularHandlers.push(new RollupAsociatedRelationHandler());

src/components/modals/columnSettings/handlers/automations/BidirectionalRelationToggleHandler.ts renamed to src/components/modals/columnSettings/handlers/relations/BidirectionalRelationToggleHandler.ts

File renamed without changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { ColumnSettingsHandlerResponse } from "cdm/ModalsModel";
2+
import { AbstractHandlerClass } from "patterns/chain/AbstractHandler";
3+
import { Setting } from "obsidian";
4+
import { t } from "lang/helpers";
5+
import { castHslToString, castStringtoHsl } from "helpers/Colors";
6+
7+
export class RelationColorSelectorHandler extends AbstractHandlerClass<ColumnSettingsHandlerResponse> {
8+
settingTitle: string = t("column_settings_modal_relation_color_title");
9+
handle(columnHandlerResponse: ColumnSettingsHandlerResponse): ColumnSettingsHandlerResponse {
10+
const { column, containerEl, columnSettingsManager } = columnHandlerResponse;
11+
const { view } = columnSettingsManager.modal;
12+
13+
new Setting(containerEl)
14+
.setName(this.settingTitle)
15+
.setDesc(t("column_settings_modal_relation_color_desc"))
16+
.addColorPicker((colorPicker) => {
17+
colorPicker
18+
.setValueHsl(castStringtoHsl(column.config.relation_color))
19+
.onChange(async () => {
20+
const newColor = castHslToString(
21+
colorPicker.getValueHsl()
22+
);
23+
await view.diskConfig.updateColumnConfig(column.id, {
24+
relation_color: newColor,
25+
});
26+
columnSettingsManager.modal.enableReset = true;
27+
});
28+
})
29+
return this.goNext(columnHandlerResponse);
30+
}
31+
}

src/lang/locale/en.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ export default {
215215
"column_settings_modal_selected_column_options_notice_update_error": "Error editing {0}",
216216
"column_settings_modal_selected_column_options_notice_delete_success": "Label {0} was deleted successfully for all the notes!",
217217
"column_settings_modal_selected_column_options_notice_delete_error": "Error deleting {0}",
218+
"column_settings_modal_relation_color_title": "Relation color",
219+
"column_settings_modal_relation_color_desc": "Select the color of the relation",
218220
/** TEXT MODAL */
219221
"text_modal_default_placeholder": "Insert text...",
220222
/******************************************

0 commit comments

Comments
 (0)