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

Commit d6dd0df

Browse files
committed
Merge branch 'add_options_sanitize'
2 parents 0322851 + 73e8af4 commit d6dd0df

File tree

6 files changed

+59
-24
lines changed

6 files changed

+59
-24
lines changed

src/components/cellTypes/SelectCell.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { TableColumn } from "cdm/FolderModel";
1010
import CreatableSelect from "react-select/creatable";
1111
import CustomTagsStyles from "components/styles/TagsStyles";
1212
import { c, getAlignmentClassname } from "helpers/StylesHelper";
13+
import { satinizedColumnOption } from "helpers/FileManagement";
1314
import { ActionMeta, OnChangeValue } from "react-select";
1415
import { ParseService } from "services/ParseService";
1516
import { InputType } from "helpers/Constants";
@@ -65,11 +66,14 @@ const SelectCell = (popperProps: CellComponentProps) => {
6566
newValue: OnChangeValue<SelectValue, false>,
6667
actionMeta: ActionMeta<RowSelectOption>
6768
) => {
68-
const selectValue = newValue ? newValue.value.toString() : "";
69+
const sanitized = satinizedColumnOption(
70+
newValue ? newValue.value.toString() : ""
71+
);
72+
6973
const newCell = ParseService.parseRowToLiteral(
7074
selectRow,
7175
tableColumn,
72-
selectValue
76+
sanitized
7377
);
7478

7579
// Update on disk & memory
@@ -86,7 +90,7 @@ const SelectCell = (popperProps: CellComponentProps) => {
8690
if (actionMeta.action === "create-option") {
8791
await columnActions.addOptionToColumn(
8892
tableColumn,
89-
selectValue,
93+
sanitized,
9094
randomColor()
9195
);
9296
}

src/components/cellTypes/TagsCell.tsx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { c, getAlignmentClassname } from "helpers/StylesHelper";
1313
import { TableColumn } from "cdm/FolderModel";
1414
import { ParseService } from "services/ParseService";
1515
import { InputType } from "helpers/Constants";
16+
import { satinizedColumnOption } from "helpers/FileManagement";
1617

1718
const TagsCell = (tagsProps: CellComponentProps) => {
1819
const { defaultCell } = tagsProps;
@@ -67,7 +68,9 @@ const TagsCell = (tagsProps: CellComponentProps) => {
6768
newValue: OnChangeValue<SelectValue, true>,
6869
actionMeta: ActionMeta<RowSelectOption>
6970
) => {
70-
const arrayTags = newValue.map((tag) => `${tag.value}`);
71+
const arrayTags = newValue.map(
72+
(tag) => `${satinizedColumnOption(tag.value)}`
73+
);
7174
const newCell = ParseService.parseRowToLiteral(
7275
tagsRow,
7376
tableColumn,
@@ -84,14 +87,20 @@ const TagsCell = (tagsProps: CellComponentProps) => {
8487
);
8588

8689
// Add new option to column options
87-
newValue
88-
.filter(
89-
(tag) =>
90-
!tableColumn.options.find((option) => option.label === tag.value)
91-
)
92-
.forEach((tag) => {
93-
columnActions.addOptionToColumn(tableColumn, tag.value, randomColor());
94-
});
90+
if (actionMeta.action === "create-option") {
91+
newValue
92+
.filter(
93+
(tag) =>
94+
!tableColumn.options.find((option) => option.label === tag.value)
95+
)
96+
.forEach((tag) => {
97+
columnActions.addOptionToColumn(
98+
tableColumn,
99+
tag.value,
100+
randomColor()
101+
);
102+
});
103+
}
95104
};
96105

97106
function TagsForm() {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { RowSelectOption } from "cdm/ComponentsModel";
22
import { ColumnSettingsHandlerResponse } from "cdm/ModalsModel";
33
import { randomColor, castStringtoHsl, castHslToString } from "helpers/Colors";
4+
import { satinizedColumnOption } from "helpers/FileManagement";
45
import { ButtonComponent, Notice, Setting } from "obsidian";
56
import { AbstractHandlerClass } from "patterns/chain/AbstractHandler";
67
import { LOGGER } from "services/Logger";
@@ -53,7 +54,8 @@ export class SelectedColumnOptionsHandler extends AbstractHandlerClass<ColumnSet
5354
.setPlaceholder("label of option")
5455
.setValue(newLabel)
5556
.onChange(async (value: string): Promise<void> => {
56-
newLabel = value;
57+
newLabel = satinizedColumnOption(value);
58+
text.setValue(newLabel);
5759
});
5860
text.inputEl.onkeydown = (e: KeyboardEvent) => {
5961
switch (e.key) {

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { DynamicInputType } from "helpers/Constants";
55
import { t } from "lang/helpers";
66
import { Setting } from "obsidian";
77
import { AbstractHandlerClass } from "patterns/chain/AbstractHandler";
8-
import { StringSuggest } from "settings/suggesters/StringSuggester";
98

109
export class QuickOptionsColumnsHandler extends AbstractHandlerClass<AddColumnModalHandlerResponse> {
1110
settingTitle: string = "Column quick options";
@@ -68,14 +67,10 @@ export class QuickOptionsColumnsHandler extends AbstractHandlerClass<AddColumnMo
6867
if (!column.isMetadata) {
6968
// Select type
7069
columnSetting
71-
.addSearch(cb => {
72-
new StringSuggest(
73-
cb.inputEl,
74-
typesRecord
75-
);
76-
cb.setPlaceholder("Select type...")
77-
.setValue(column.input)
78-
.onChange(selectTypeHandler);
70+
.addDropdown((dropdown) => {
71+
dropdown.addOptions(typesRecord);
72+
dropdown.setValue(DynamicInputType.TEXT);
73+
dropdown.onChange(selectTypeHandler);
7974
});
8075
// Delete column
8176
columnSetting

src/helpers/FileManagement.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,19 @@ export async function create_row_file(
179179
ddbbConfig
180180
);
181181
return filepath;
182+
}
183+
184+
/**
185+
* Remove all not readable characters of yaml and trim the string
186+
*
187+
* Example:
188+
* input: "\- some text"
189+
* output: "some text"
190+
* @param option
191+
* @returns
192+
*/
193+
export function satinizedColumnOption(option: string): string {
194+
return option
195+
.replace("\\", "")
196+
.trim();
182197
}

src/services/ParseService.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { LocalSettings } from "cdm/SettingsModel";
77
import { RowDataType, TableColumn } from "cdm/FolderModel";
88
import { deepMerge, generateLiteral, obtainAnidatedLiteral } from "helpers/DataObjectHelper";
99
import { parseLuxonDatetimeToString, parseLuxonDateToString, parseStringToLuxonDate, parseStringToLuxonDatetime } from "helpers/LuxonHelper";
10+
import { satinizedColumnOption } from "helpers/FileManagement";
1011

1112
class Parse {
1213

@@ -58,6 +59,9 @@ class Parse {
5859
case InputType.RELATION:
5960
parsedLiteral = this.parseToLink(wrapped);
6061
break;
62+
case InputType.SELECT:
63+
parsedLiteral = this.parseToSelect(wrapped, localSettings);
64+
break;
6165
case InputType.TASK:
6266
case InputType.FORMULA:
6367
case InputType.ROLLUP:
@@ -205,6 +209,12 @@ class Parse {
205209
}
206210
}
207211

212+
private parseToSelect(wrapped: WrappedLiteral, localSettings: LocalSettings): string {
213+
return satinizedColumnOption(
214+
this.parseToText(wrapped, localSettings).toString(),
215+
);
216+
}
217+
208218
private parseToText(wrapped: WrappedLiteral, localSettings: LocalSettings): string | DataObject {
209219
switch (wrapped.type) {
210220
case 'object':
@@ -337,9 +347,9 @@ class Parse {
337347

338348
private parseToOptionsArray(wrapped: WrappedLiteral): Literal {
339349
if (wrapped.type !== 'array') {
340-
return wrapped.value.toString().split(",").map(s => s.toString().trim());
350+
return wrapped.value.toString().split(",").map(s => satinizedColumnOption(s.toString().trim()));
341351
}
342-
return wrapped.value.map(v => DataviewService.getDataviewAPI().value.toString(v));
352+
return wrapped.value.map(v => satinizedColumnOption(DataviewService.getDataviewAPI().value.toString(v)));
343353
}
344354

345355
private handleYamlBreaker(value: string, localSettings: LocalSettings, isInline?: boolean): string {

0 commit comments

Comments
 (0)