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

Commit e80d58c

Browse files
committed
Merge branch '605-fr-self-referencing-relation'
2 parents 28c2b20 + 86d7651 commit e80d58c

File tree

13 files changed

+152
-166
lines changed

13 files changed

+152
-166
lines changed

package-lock.json

Lines changed: 94 additions & 106 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,30 @@
2020
"license": "MIT",
2121
"devDependencies": {
2222
"@faker-js/faker": "7.6.0",
23-
"@rollup/plugin-commonjs": "23.0.4",
24-
"@rollup/plugin-json": "5.0.2",
23+
"@rollup/plugin-commonjs": "23.0.7",
24+
"@rollup/plugin-json": "6.0.0",
2525
"@rollup/plugin-node-resolve": "15.0.1",
26-
"@rollup/plugin-replace": "5.0.1",
26+
"@rollup/plugin-replace": "5.0.2",
2727
"@rollup/plugin-typescript": "10.0.1",
2828
"@rollup/plugin-terser": "0.1.0",
2929
"@testing-library/jest-dom": "5.16.5",
3030
"@testing-library/react": "13.4.0",
3131
"@types/jest": "29.2.4",
3232
"@types/luxon": "3.1.0",
33-
"@types/node": "18.11.15",
33+
"@types/node": "18.11.17",
3434
"@types/react": "18.0.26",
3535
"@types/react-csv": "1.1.3",
3636
"@types/react-datepicker": "4.8.0",
3737
"@types/react-dom": "18.0.9",
3838
"@types/react-window": "1.8.5",
3939
"@typescript-eslint/eslint-plugin": "5.46.1",
4040
"@typescript-eslint/parser": "5.46.1",
41-
"eslint": "8.29.0",
41+
"eslint": "8.30.0",
4242
"jest": "29.3.1",
4343
"jest-mock-extended": "3.0.1",
4444
"jest-environment-jsdom": "29.3.1",
4545
"obsidian": "0.16.3",
46-
"rollup": "3.7.4",
46+
"rollup": "3.7.5",
4747
"rollup-plugin-typescript2": "0.34.1",
4848
"ts-jest": "29.0.3",
4949
"tslib": "2.4.1",

src/DatabaseView.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,12 @@ export class DatabaseView extends TextFileView implements HoverParent {
147147
async initDatabase(): Promise<void> {
148148
try {
149149
LOGGER.info(`=>initDatabase ${this.file.path}`);
150-
this.checkRequiredLibraries();
151150
// Load the database file
152151
this.diskConfig = new DatabaseInfo(this.file);
153152
await this.diskConfig.initDatabaseconfigYaml(
154153
this.plugin.settings.local_settings
155154
);
155+
156156
let yamlColumns: Record<string, DatabaseColumn> =
157157
this.diskConfig.yaml.columns;
158158
// Complete the columns with the metadata columns
@@ -256,7 +256,7 @@ export class DatabaseView extends TextFileView implements HoverParent {
256256
this.rootContainer.unmount();
257257
this.rootContainer = createRoot(this.tableContainer);
258258
this.detachViewComponents();
259-
this.initDatabase();
259+
await this.initDatabase();
260260
}
261261

262262
clear(): void {
@@ -350,16 +350,4 @@ export class DatabaseView extends TextFileView implements HoverParent {
350350
openFilters() {
351351
this.emitter.emit(EMITTERS_GROUPS.SHORTCUT, EMITTERS_SHORTCUT.OPEN_FILTERS);
352352
}
353-
/****************************************************************
354-
* VIEW VALIDATIONS
355-
* **************************************************************/
356-
private checkRequiredLibraries(): void {
357-
if (!DataviewService.indexIsLoaded) {
358-
new Notice(
359-
`Dataview plugin is not loaded yet. Please wait a few seconds and refresh the page.`,
360-
1000
361-
);
362-
DataviewService.indexIsLoaded = true;
363-
}
364-
}
365353
}

src/api/obsidian-projects-api.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class ProjectAPI extends ProjectView {
4949
const actualFields = fields
5050
.filter((field) => !projectsMetadataColumns.contains(field.name));
5151

52-
if (currentColumnsLength !== actualFields.length) {
52+
if (currentColumnsLength < actualFields.length) {
5353
const newColumns: Record<string, DatabaseColumn> = {};
5454
actualFields.forEach((field, index) => {
5555
const { name, type } = field;
@@ -59,7 +59,7 @@ class ProjectAPI extends ProjectView {
5959
*
6060
* Could we add the config to the data object? I can manage a map of views with that
6161
*/
62-
const inputType = this.mapperTypeToInputType(type);
62+
const inputType = this.projectsTypeToPluginTypeMapper(type);
6363
const key = dbTrim(name);
6464
const newColumn: DatabaseColumn = {
6565
input: inputType,
@@ -114,10 +114,14 @@ class ProjectAPI extends ProjectView {
114114
async onClose() {
115115
this.view.destroy();
116116
this.view = null;
117-
this.enableAutoReload = false;
118117
LOGGER.debug("Closing project view ", this.getDisplayName());
119118
}
120119

120+
/**
121+
* Generate the local settings for the database
122+
* @param projectView
123+
* @returns
124+
*/
121125
private generateLocalSettings(projectView: ProjectViewProps): LocalSettings {
122126
const { project } = projectView;
123127
const localSettings: LocalSettings = {
@@ -147,14 +151,14 @@ class ProjectAPI extends ProjectView {
147151
return localSettings;
148152
}
149153

150-
private mapperTypeToInputType(type: string): string {
154+
/**
155+
* Maps the data type from the projects to the plugin data type
156+
* @param type
157+
* @returns
158+
*/
159+
private projectsTypeToPluginTypeMapper(type: string): string {
151160
let inputType = "";
152161
switch (type) {
153-
case DataFieldType.String:
154-
case DataFieldType.Link:
155-
case DataFieldType.Unknown:
156-
inputType = InputType.TEXT;
157-
break;
158162
case DataFieldType.Number:
159163
inputType = InputType.NUMBER;
160164
break;
@@ -167,6 +171,10 @@ class ProjectAPI extends ProjectView {
167171
case DataFieldType.List:
168172
inputType = InputType.TAGS;
169173
break;
174+
// Default to text
175+
case DataFieldType.String:
176+
case DataFieldType.Link:
177+
case DataFieldType.Unknown:
170178
default:
171179
inputType = InputType.TEXT;
172180
}

src/components/cellTypes/Editor/RelationEditor.tsx

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,31 @@ const RelationEditor = (props: RelationEditorComponentProps) => {
4545
persistChange(relationValue.map((link) => link.value));
4646
};
4747

48-
const relationRowsCallBack = useCallback(async () => {
49-
const relationRows = await recordRowsFromRelation(
50-
tableColumn.config.related_note_path,
51-
DEFAULT_SETTINGS.local_settings,
52-
columnsInfo.getAllColumns()
53-
);
54-
const multiOptions = Object.entries(relationRows).map(([key, value]) => ({
55-
label: value,
56-
value: key,
57-
color: StyleVariables.TEXT_NORMAL,
58-
}));
59-
60-
setRelationOptions(multiOptions);
61-
}, []);
62-
6348
useEffect(() => {
64-
relationRowsCallBack();
49+
setTimeout(async () => {
50+
const relationRows = await recordRowsFromRelation(
51+
tableColumn.config.related_note_path,
52+
DEFAULT_SETTINGS.local_settings,
53+
columnsInfo.getAllColumns()
54+
);
55+
const multiOptions = Object.entries(relationRows).map(([key, value]) => ({
56+
label: value,
57+
value: key,
58+
color: StyleVariables.BACKGROUND_SECONDARY,
59+
}));
60+
61+
setRelationOptions(multiOptions);
62+
}, 0);
6563
}, []);
6664

6765
return (
6866
<div className={c("relation")}>
6967
<Select
7068
defaultValue={relationValue}
69+
components={{
70+
DropdownIndicator: () => null,
71+
IndicatorSeparator: () => null,
72+
}}
7173
closeMenuOnSelect={false}
7274
isSearchable
7375
isMulti

src/components/cellTypes/RelationCell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const RelationCell = (mdProps: CellComponentProps) => {
5555
5
5656
);
5757
}
58-
}, [relationRow, dirtyCell]);
58+
}, [row, column, dirtyCell]);
5959

6060
const persistChange = (newPaths: string[]) => {
6161
const oldPaths = relationCell

src/components/cellTypes/RollupCell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const RollupCell = (mdProps: CellComponentProps) => {
6767
);
6868
}
6969
}
70-
}, [row]);
70+
}, [cell, row, column]);
7171
return (
7272
<span
7373
ref={formulaRef}

src/components/modals/columnSettings/handlers/dropdowns/DatabaseSelectorHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class DatabaseSelectorHandler extends AbstractHandlerClass<ColumnSettings
1818
});
1919
columnSettingsManager.modal.enableReset = true;
2020
}
21-
const avaliableDDBB = recordAllDatabases(view.file.path);
21+
const avaliableDDBB = recordAllDatabases();
2222

2323
new Setting(containerEl)
2424
.setName(this.settingTitle)

src/components/modals/newColumn/handlers/QuickOptionsColumnsHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class QuickOptionsColumnsHandler extends AbstractHandlerClass<AddColumnMo
6969
columnSetting
7070
.addDropdown((dropdown) => {
7171
dropdown.addOptions(typesRecord);
72-
dropdown.setValue(DynamicInputType.TEXT);
72+
dropdown.setValue(column.input);
7373
dropdown.onChange(selectTypeHandler);
7474
});
7575
// Delete column

src/components/styles/TagsStyles.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ const CustomTagsStyles: StylesConfig<any, true, GroupBase<any>> = {
4949
},
5050
multiValueLabel: (styles) => ({
5151
...styles,
52-
color: "black",
52+
color: StyleVariables.TEXT_NORMAL,
5353
}),
5454
multiValueRemove: (styles, { data }) => ({
5555
...styles,
56-
color: "black",
56+
color: StyleVariables.TEXT_NORMAL,
5757
":hover": {
5858
backgroundColor: data.color + " !important",
59-
color: "white",
59+
color: StyleVariables.TEXT_ACCENT,
6060
},
6161
})
6262
};

0 commit comments

Comments
 (0)