-
-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
option to select binary checkbox states for integration with Tracker plugin #906
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,8 @@ import { TableColumn } from "cdm/FolderModel"; | |
import { c } from "helpers/StylesHelper"; | ||
import { CellComponentProps } from "cdm/ComponentsModel"; | ||
import { ParseService } from "services/ParseService"; | ||
import { InputType } from "helpers/Constants"; | ||
import {DEFAULT_SETTINGS, InputType} from "helpers/Constants"; | ||
import {Notice} from "obsidian"; | ||
|
||
function CheckboxCell(props: CellComponentProps) { | ||
const { defaultCell } = props; | ||
|
@@ -15,22 +16,23 @@ function CheckboxCell(props: CellComponentProps) { | |
const checkboxRow = tableState.data((state) => state.rows[row.index]); | ||
const columnsInfo = tableState.columns((state) => state.info); | ||
const configInfo = tableState.configState((state) => state.info); | ||
const isBinaryCellType = DEFAULT_SETTINGS.local_settings.binary_checkbox_type; | ||
const checkboxCell = tableState.data( | ||
(state) => | ||
ParseService.parseRowToCell( | ||
state.rows[row.index], | ||
tableColumn, | ||
InputType.CHECKBOX, | ||
isBinaryCellType ? InputType.NUMBER : InputType.CHECKBOX, | ||
configInfo.getLocalSettings() | ||
) as boolean | ||
) as boolean | number | ||
); | ||
|
||
const handleChange = async (event: React.ChangeEvent<HTMLInputElement>) => { | ||
const newValue = event.target.checked; | ||
editCheckbox(newValue); | ||
editCheckbox( isBinaryCellType ? (newValue ? 1 : 0) : newValue ); | ||
}; | ||
|
||
const editCheckbox = async (newValue: boolean) => { | ||
const editCheckbox = async (newValue: boolean | number) => { | ||
const newCell = ParseService.parseRowToLiteral( | ||
checkboxRow, | ||
tableColumn, | ||
|
@@ -55,13 +57,13 @@ function CheckboxCell(props: CellComponentProps) { | |
onKeyDown={(e) => { | ||
if (e.key === "Enter") { | ||
e.preventDefault(); | ||
editCheckbox(!checkboxCell); | ||
editCheckbox(isBinaryCellType ? (checkboxCell ? 1 : 0) : !checkboxCell); | ||
} | ||
}} | ||
> | ||
<input | ||
type="checkbox" | ||
checked={checkboxCell} | ||
checked={!!checkboxCell} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can use the service function of isTruthy avaliable in dataview api or dataviewService |
||
key={`checkbox-input-${row.index}`} | ||
onChange={handleChange} | ||
/> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,7 @@ class BehaviorSetttingsSection extends AbstractChain<ColumnSettingsHandlerRespon | |
case InputType.INLINKS: | ||
case InputType.OUTLINKS: | ||
case InputType.METADATA_TAGS: | ||
case InputType.CHECKBOX_TYPE: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the configuration as metadata info of the checkbox type I think it could be moved to column configuration, the idea of the flag to control the behavior its cool but I think it should be managed on columnConfig |
||
// do nothing | ||
break; | ||
default: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can create an specific type for this
type Checkbox = number | boolean