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

Commit c4c42ee

Browse files
committed
Merge branch '443-fr-allow-renaming-labels-for-tags-and-select-field-types'
2 parents 25c3156 + 87c1777 commit c4c42ee

File tree

12 files changed

+61
-77
lines changed

12 files changed

+61
-77
lines changed

docs/docs/changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.7.3
2+
### Improved
3+
- Use of Obsidian 1.0 color picker [ISSUE#497](https://github.com/RafaelGB/obsidian-db-folder/issues/497)
4+
### No longer broken
5+
- Hotfix with rename ids breaking the rendering of the plugin [ISSUE#505](https://github.com/RafaelGB/obsidian-db-folder/issues/505)
16
## 2.7.2
27
### Shiny new things
38
- Edit nested metadata arrives! You can now edit nested metadata in the cell editor [ISSUE#442](https://github.com/RafaelGB/obsidian-db-folder/issues/442)

manifest-beta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "dbfolder",
33
"name": "DB Folder",
4-
"version": "2.7.2",
4+
"version": "2.7.3",
55
"minAppVersion": "0.16.3",
66
"description": "Folder with the capability to store and retrieve data from a folder like database",
77
"author": "RafaelGB",

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "dbfolder",
33
"name": "DB Folder",
4-
"version": "2.7.2",
4+
"version": "2.7.3",
55
"minAppVersion": "0.16.3",
66
"description": "Folder with the capability to store and retrieve data from a folder like database",
77
"author": "RafaelGB",

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obsidian-dbfolder",
3-
"version": "2.7.2",
3+
"version": "2.7.3",
44
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
55
"main": "main.js",
66
"scripts": {
@@ -28,7 +28,7 @@
2828
"@testing-library/react": "13.4.0",
2929
"@types/jest": "29.1.2",
3030
"@types/luxon": "3.0.1",
31-
"@types/node": "18.8.4",
31+
"@types/node": "18.11.0",
3232
"@types/react": "18.0.21",
3333
"@types/react-csv": "1.1.3",
3434
"@types/react-datepicker": "4.4.2",
@@ -37,7 +37,7 @@
3737
"@typescript-eslint/eslint-plugin": "5.40.0",
3838
"@typescript-eslint/parser": "5.40.0",
3939
"eslint": "8.25.0",
40-
"jest": "29.1.2",
40+
"jest": "29.2.0",
4141
"jest-mock-extended": "3.0.1",
4242
"obsidian": "0.16.3",
4343
"rollup": "2.79.1",

src/cdm/TableStateInterface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export interface ColumnsState {
5959
addToRight: (column: TableColumn, customName?: string) => void;
6060
remove: (column: TableColumn) => void;
6161
alterSorting: (column: TableColumn) => void;
62-
addOptionToColumn: (column: TableColumn, option: string, backgroundColor: string) => void;
62+
addOptionToColumn: (column: TableColumn, option: string, backgroundColor: string) => Promise<void>;
6363
alterColumnType: (column: TableColumn, input: string, parsedRows?: RowDataType[]) => Promise<void>;
6464
alterColumnId: (column: TableColumn, root: string, nestedIds: string[]) => Promise<void>;
6565
alterColumnLabel: (column: TableColumn, label: string) => Promise<void>;

src/components/DefaultHeader.tsx

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { useState } from "react";
2-
import { randomColor } from "helpers/Colors";
32
import TextIcon from "components/img/Text";
43
import MultiIcon from "components/img/Multi";
54
import HashIcon from "components/img/Hash";
@@ -21,33 +20,8 @@ import { LOGGER } from "services/Logger";
2120
import { DatabaseHeaderProps, TableColumn } from "cdm/FolderModel";
2221
import ReactDOM from "react-dom";
2322
import { c } from "helpers/StylesHelper";
24-
import { RowSelectOption } from "cdm/ComponentsModel";
2523
import { AddColumnModalProps } from "cdm/ModalsModel";
2624

27-
/**
28-
* Generate column Options with Select type
29-
* @param options
30-
* @param rows
31-
* @param columnId
32-
* @returns
33-
*/
34-
function setOptionsOfSelectDataType(
35-
options: RowSelectOption[],
36-
rows: any,
37-
columnId: string
38-
): any[] {
39-
rows.forEach((row: any) => {
40-
const rowValue = row.original[columnId];
41-
let match = options.find(
42-
(option: { label: string }) => option.label === rowValue
43-
);
44-
if (!match && rowValue !== undefined && rowValue !== "") {
45-
options.push({ label: rowValue, backgroundColor: randomColor() });
46-
}
47-
});
48-
return options;
49-
}
50-
5125
/**
5226
* Default headers of the table
5327
* @param headerProps
@@ -85,7 +59,6 @@ export default function DefaultHeader(headerProps: DatabaseHeaderProps) {
8559
propertyIcon = <TextIcon />;
8660
break;
8761
case InputType.SELECT:
88-
setOptionsOfSelectDataType(options, table.getRowModel().rows, id);
8962
propertyIcon = <MultiIcon />;
9063
break;
9164
case InputType.CALENDAR:

src/components/cellTypes/SelectCell.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,31 @@ const SelectCell = (popperProps: CellComponentProps) => {
3838
const match = tableColumn.options.find(
3939
(option: { label: string }) => option.label === selectCell
4040
);
41-
return (match && match.backgroundColor) || grey(200);
41+
if (match) {
42+
return match.backgroundColor;
43+
} else {
44+
// In case of new select, generate random color
45+
const color = randomColor();
46+
columnActions.addOptionToColumn(tableColumn, selectCell, color);
47+
return color;
48+
}
4249
}
4350

44-
const defaultValue = {
45-
label: selectCell?.toString(),
46-
value: selectCell?.toString(),
47-
color: getColor(),
48-
};
51+
const defaultValue = useMemo(
52+
() => ({
53+
label: selectCell?.toString(),
54+
value: selectCell?.toString(),
55+
color: selectCell ? getColor() : grey(200),
56+
}),
57+
[selectCell]
58+
);
4959

5060
const multiOptions = useMemo(
5161
() =>
5262
tableColumn.options
5363
.filter(
5464
(option: RowSelectOption) =>
55-
option.label !== undefined && option.label !== null
65+
option && option.label !== undefined && option.label !== null
5666
)
5767
.sort((a, b) => a.label.localeCompare(b.label))
5868
.map((option: RowSelectOption) => ({

src/components/cellTypes/TagsCell.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,7 @@ const TagsCell = (tagsProps: CellComponentProps) => {
4343
} else {
4444
// In case of new tag, generate random color
4545
const color = randomColor();
46-
const newOption: RowSelectOption = {
47-
label: tag,
48-
backgroundColor: color,
49-
};
50-
const currentColumn = columnsInfo
51-
.getAllColumns()
52-
.find((col: TableColumn) => col.key === tableColumn.key);
53-
currentColumn.options.push(newOption);
54-
table.options.meta.view.diskConfig.updateColumnProperties(column.id, {
55-
options: currentColumn.options,
56-
});
46+
columnActions.addOptionToColumn(tableColumn, tag, color);
5747
return color;
5848
}
5949
}
@@ -73,7 +63,7 @@ const TagsCell = (tagsProps: CellComponentProps) => {
7363
tableColumn.options
7464
.filter(
7565
(option: RowSelectOption) =>
76-
option.label !== undefined && option.label !== null
66+
option && option.label !== undefined && option.label !== null
7767
)
7868
.sort((a, b) => a.label.localeCompare(b.label))
7969
.map((option: RowSelectOption) => ({

src/components/modals/columnSettings/handlers/ColumnIdInputHandler.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ export class ColumnIdInputHandler extends AbstractHandlerClass<ColumnSettingsHan
2525
.onClick(async (): Promise<void> => {
2626
const arrayKey = value.split('.');
2727
const rootKey = arrayKey.shift();
28-
29-
if (!this.validateNewId(rootKey, arrayKey, columnsState.info.getAllColumns())) {
30-
new Notice(`Error saving id. There is a conflict with another column id or the id is empty`, 3000);
28+
const validateMessage = this.validateNewId(rootKey, arrayKey, columnsState.info.getAllColumns());
29+
if (validateMessage) {
30+
new Notice(`Error saving id. ${validateMessage}`, 3000);
3131
return;
3232
}
3333
// Update state of altered column
@@ -61,14 +61,23 @@ export class ColumnIdInputHandler extends AbstractHandlerClass<ColumnSettingsHan
6161

6262
return this.goNext(response);
6363
}
64-
private validateNewId(rootKey: string, arrayKey: string[], columns: TableColumn[]): boolean {
64+
private validateNewId(rootKey: string, arrayKey: string[], columns: TableColumn[]): string {
6565
const candidateId = `${rootKey}${arrayKey.length > 0 ? `-${arrayKey.join('-')}` : ''}`;
66+
// Check if new root key is not empty
6667
if (!rootKey) {
67-
return false;
68+
return "The root key is required";
69+
}
70+
// Validate special characters in root key
71+
if (rootKey.match(/[^a-zA-Z0-9_]/)) {
72+
return "The root key can only contain letters, numbers and underscores";
6873
}
74+
// Validate if new root key is not duplicated
6975
const conflictId = columns.some((column: TableColumn) =>
7076
column.id === candidateId
7177
);
72-
return !conflictId;
78+
if (conflictId) {
79+
return "The id already exists";
80+
}
81+
return '';
7382
}
7483
}

src/components/modals/columnSettings/handlers/SelectedColumnOptionsHandler.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { ColumnSettingsHandlerResponse } from "cdm/ModalsModel";
22
import { randomColor, castStringtoHsl, castHslToString } from "helpers/Colors";
33
import { ButtonComponent, Notice, Setting } from "obsidian";
44
import { AbstractHandlerClass } from "patterns/AbstractHandler";
5-
import React from "react";
6-
import { createRoot } from "react-dom/client";
75
import { LOGGER } from "services/Logger";
86

97
export class SelectedColumnOptionsHandler extends AbstractHandlerClass<ColumnSettingsHandlerResponse> {
@@ -71,10 +69,7 @@ export class SelectedColumnOptionsHandler extends AbstractHandlerClass<ColumnSet
7169
colorPicker
7270
.setValueHsl(castStringtoHsl(option.backgroundColor))
7371
.onChange(async () => {
74-
const optionIndex = options.findIndex(
75-
(option) => option.label === option.label
76-
);
77-
options[optionIndex].backgroundColor = castHslToString(
72+
options[index].backgroundColor = castHslToString(
7873
colorPicker.getValueHsl()
7974
);
8075
await view.diskConfig.updateColumnProperties(column.id, {

0 commit comments

Comments
 (0)