|
1 | 1 | import { ColumnSettingsHandlerResponse } from "cdm/ModalsModel"; |
2 | | -import { ColorPickerProps } from "cdm/StyleModel"; |
3 | | -import { ColorPicker } from "components/styles/ColorPicker"; |
4 | | -import { randomColor } from "helpers/Colors"; |
| 2 | +import { randomColor, castStringtoHsl, castHslToString } from "helpers/Colors"; |
5 | 3 | import { ButtonComponent, Notice, Setting } from "obsidian"; |
6 | 4 | import { AbstractHandlerClass } from "patterns/AbstractHandler"; |
7 | 5 | import React from "react"; |
@@ -63,51 +61,65 @@ export class SelectedColumnOptionsHandler extends AbstractHandlerClass<ColumnSet |
63 | 61 | }); |
64 | 62 |
|
65 | 63 | options.forEach((option, index) => { |
66 | | - const colorPickerProps: ColorPickerProps = { |
67 | | - modal: columnSettingsManager.modal, |
68 | | - options: options, |
69 | | - option: option, |
70 | | - columnId: column.id, |
71 | | - }; |
72 | | - |
73 | | - const optionContainer = new Setting(containerEl).addExtraButton((cb) => { |
74 | | - cb.setIcon("cross") |
75 | | - .setTooltip("Delete") |
76 | | - .onClick(async (): Promise<void> => { |
77 | | - const removedOption = options[index]; |
78 | | - options.splice(index, 1); |
79 | | - // Persist changes |
80 | | - await view.diskConfig.updateColumnProperties(column.id, { |
81 | | - options: options, |
| 64 | + new Setting(containerEl) |
| 65 | + // Show current label |
| 66 | + .addText((text) => { |
| 67 | + text.setValue(option.label).setDisabled(true); |
| 68 | + }) |
| 69 | + // Color picker for background color |
| 70 | + .addColorPicker((colorPicker) => { |
| 71 | + colorPicker |
| 72 | + .setValueHsl(castStringtoHsl(option.backgroundColor)) |
| 73 | + .onChange(async () => { |
| 74 | + const optionIndex = options.findIndex( |
| 75 | + (option) => option.label === option.label |
| 76 | + ); |
| 77 | + options[optionIndex].backgroundColor = castHslToString( |
| 78 | + colorPicker.getValueHsl() |
| 79 | + ); |
| 80 | + await view.diskConfig.updateColumnProperties(column.id, { |
| 81 | + options: options, |
| 82 | + }); |
| 83 | + columnHandlerResponse.columnSettingsManager.modal.enableReset = |
| 84 | + true; |
82 | 85 | }); |
83 | | - |
84 | | - dataState.actions |
85 | | - .removeOptionForAllRows( |
86 | | - column, |
87 | | - removedOption.label, |
88 | | - columnsState.info.getAllColumns(), |
89 | | - configState.info.getLocalSettings() |
90 | | - ) |
91 | | - .then(() => { |
92 | | - new Notice( |
93 | | - `Option ${removedOption.label} was removed from all rows`, |
94 | | - 1500 |
95 | | - ); |
96 | | - }) |
97 | | - .catch((err) => { |
98 | | - const errMsg = `Error removing ${removedOption.label}`; |
99 | | - LOGGER.error(errMsg, err); |
100 | | - new Notice(errMsg, 3000); |
| 86 | + }) |
| 87 | + // Delete button |
| 88 | + .addExtraButton((cb) => { |
| 89 | + cb.setIcon("cross") |
| 90 | + .setTooltip("Delete") |
| 91 | + .onClick(async (): Promise<void> => { |
| 92 | + const removedOption = options[index]; |
| 93 | + options.splice(index, 1); |
| 94 | + // Persist changes |
| 95 | + await view.diskConfig.updateColumnProperties(column.id, { |
| 96 | + options: options, |
101 | 97 | }); |
102 | | - columnHandlerResponse.columnSettingsManager.modal.enableReset = |
103 | | - true; |
104 | | - // Force refresh of settings |
105 | | - columnSettingsManager.reset(columnHandlerResponse); |
106 | | - }); |
107 | | - }); |
108 | | - createRoot(optionContainer.settingEl.createDiv()).render( |
109 | | - <ColorPicker {...colorPickerProps} /> |
110 | | - ); |
| 98 | + |
| 99 | + dataState.actions |
| 100 | + .removeOptionForAllRows( |
| 101 | + column, |
| 102 | + removedOption.label, |
| 103 | + columnsState.info.getAllColumns(), |
| 104 | + configState.info.getLocalSettings() |
| 105 | + ) |
| 106 | + .then(() => { |
| 107 | + new Notice( |
| 108 | + `Option ${removedOption.label} was removed from all rows`, |
| 109 | + 1500 |
| 110 | + ); |
| 111 | + }) |
| 112 | + .catch((err) => { |
| 113 | + const errMsg = `Error removing ${removedOption.label}`; |
| 114 | + LOGGER.error(errMsg, err); |
| 115 | + new Notice(errMsg, 3000); |
| 116 | + }); |
| 117 | + columnHandlerResponse.columnSettingsManager.modal.enableReset = |
| 118 | + true; |
| 119 | + // Force refresh of settings |
| 120 | + columnSettingsManager.reset(columnHandlerResponse); |
| 121 | + }); |
| 122 | + }); |
111 | 123 | }); |
112 | 124 |
|
113 | 125 | return this.goNext(columnHandlerResponse); |
|
0 commit comments