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

Commit 0ec1ca3

Browse files
committed
metadata column checkbox added
1 parent 2038079 commit 0ec1ca3

File tree

15 files changed

+155
-86
lines changed

15 files changed

+155
-86
lines changed

docs/docs/changelog.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 1.4.0
2+
### Shiny new things
3+
- New metadata column: File tasks! You can see the tasks that are associated with each file and interact with them. Powered with tasklist render of dataview. [ISSUE#54](https://github.com/RafaelGB/obsidian-db-folder/issues/54)
4+
5+
### Improved
6+
- Extra margin added to the botton and top of every cell is removed. Markdown obsidian renderer add html tagging that affected the margin. [ISSUE#71](https://github.com/RafaelGB/obsidian-db-folder/issues/71)
7+
8+
### No longer broken
9+
- Column settings of a type that has a type without behavior section does not produce a console error now and section tittle is not shown.
110
## 1.3.2
211
*Published on 2022/05/24*
312
### Improved

src/Settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface LocalSettings {
2929
remove_field_when_delete_column: boolean;
3030
show_metadata_created: boolean;
3131
show_metadata_modified: boolean;
32+
show_metadata_tasks: boolean;
3233
}
3334

3435
export interface DatabaseSettings {
@@ -52,6 +53,7 @@ export const DEFAULT_SETTINGS: DatabaseSettings = {
5253
group_folder_column: '',
5354
show_metadata_created: false,
5455
show_metadata_modified: false,
56+
show_metadata_tasks: false
5557
}
5658
};
5759

src/components/Cell.tsx

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import CalendarPortal from "./portals/CalendarPortal";
1010
import { TableColumn } from "cdm/FolderModel";
1111
import CalendarTimePortal from "components/portals/CalendarTimePortal";
1212
import { renderMarkdown } from "components/markdown/MarkdownRenderer";
13+
import { DataviewService } from "services/DataviewService";
1314

1415
export default function DefaultCell(cellProperties: Cell) {
1516
const dataDispatch = (cellProperties as any).dataDispatch;
@@ -24,6 +25,7 @@ export default function DefaultCell(cellProperties: Cell) {
2425
/** Ref to cell container */
2526
const containerCellRef = useRef<HTMLDivElement>();
2627
const editableMdRef = useRef<HTMLInputElement>();
28+
const taskRef = useRef<HTMLDivElement>();
2729
/** state of cell value */
2830
const [contextValue, setContextValue] = useState({
2931
value: initialValue,
@@ -38,11 +40,25 @@ export default function DefaultCell(cellProperties: Cell) {
3840
);
3941
// set contextValue when cell is loaded
4042
useEffect(() => {
41-
if (!dirtyCell && initialValue !== contextValue.value) {
42-
setContextValue({
43-
value: initialValue,
44-
update: false,
45-
});
43+
switch (dataType) {
44+
case DataTypes.TASK:
45+
//TODO - this is a hack. find why is layout effect called twice
46+
taskRef.current.innerHTML = "";
47+
DataviewService.getDataviewAPI().taskList(
48+
contextValue.value,
49+
false,
50+
taskRef.current,
51+
(cellProperties as any).initialState.view,
52+
(cellProperties as any).initialState.view.file.path
53+
);
54+
break;
55+
default:
56+
if (!dirtyCell && initialValue !== contextValue.value) {
57+
setContextValue({
58+
value: initialValue,
59+
update: false,
60+
});
61+
}
4662
}
4763
}, []);
4864

@@ -54,7 +70,6 @@ export default function DefaultCell(cellProperties: Cell) {
5470

5571
useEffect(() => {
5672
if (!dirtyCell && containerCellRef.current) {
57-
renderMarkdown;
5873
//TODO - this is a hack. find why is layout effect called twice
5974
containerCellRef.current.innerHTML = "";
6075
renderMarkdown(
@@ -191,9 +206,8 @@ export default function DefaultCell(cellProperties: Cell) {
191206
);
192207

193208
case DataTypes.TASK:
194-
return (
195-
<span ref={containerCellRef} className={`${c("md_cell")}`}></span>
196-
);
209+
return <div ref={taskRef} className="data-input"></div>;
210+
197211
/** Default option */
198212
default:
199213
LOGGER.warn(`Unknown data type: ${dataType}`);

src/components/Columns.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ export async function obtainMetadataColumns(
4545
delete yamlColumns[MetadataColumns.MODIFIED];
4646
}
4747

48+
if (localSetting.show_metadata_tasks) {
49+
// If Modified is not already in the table, add it
50+
yamlColumns[MetadataColumns.TASKS] = {
51+
...MetadataDatabaseColumns.TASKS,
52+
...(yamlColumns[MetadataColumns.TASKS] ?? {}),
53+
};
54+
} else {
55+
delete yamlColumns[MetadataColumns.TASKS];
56+
}
57+
4858
yamlColumns[MetadataColumns.ADD_COLUMN] = MetadataDatabaseColumns.ADD_COLUMN;
4959
return yamlColumns;
5060
}

src/components/Header.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ export default function Header(headerProps: DatabaseHeaderProps) {
9494
propertyIcon = <MarkdownObsidian />;
9595
break;
9696
case DataTypes.TASK:
97-
// TODO : add a markdown icon
9897
propertyIcon = <TaskIcon />;
9998
break;
10099
default:

src/components/HeaderMenu.tsx

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -81,23 +81,28 @@ const HeaderMenu = (headerMenuProps: HeaderMenuProps) => {
8181
/**
8282
* Array of action buttons asociated to the header
8383
*/
84-
const buttons = [
85-
{
86-
onClick: (e: any) => {
87-
setSortBy([{ id: column.id, desc: false }]);
88-
setExpanded(false);
84+
const buttons = [];
85+
if (column.dataType !== DataTypes.TASK) {
86+
buttons.push(
87+
{
88+
onClick: (e: any) => {
89+
setSortBy([{ id: column.id, desc: false }]);
90+
setExpanded(false);
91+
},
92+
icon: <ArrowUpIcon />,
93+
label: "Sort ascending",
8994
},
90-
icon: <ArrowUpIcon />,
91-
label: "Sort ascending",
92-
},
93-
{
94-
onClick: (e: any) => {
95-
setSortBy([{ id: column.id, desc: true }]);
96-
setExpanded(false);
97-
},
98-
icon: <ArrowDownIcon />,
99-
label: "Sort descending",
100-
},
95+
{
96+
onClick: (e: any) => {
97+
setSortBy([{ id: column.id, desc: true }]);
98+
setExpanded(false);
99+
},
100+
icon: <ArrowDownIcon />,
101+
label: "Sort descending",
102+
}
103+
);
104+
}
105+
buttons.push(
101106
{
102107
onClick: (e: any) => {
103108
dispatch({
@@ -123,8 +128,8 @@ const HeaderMenu = (headerMenuProps: HeaderMenuProps) => {
123128
},
124129
icon: <ArrowRightIcon />,
125130
label: "Insert right",
126-
},
127-
];
131+
}
132+
);
128133
/**
129134
* Add extra buttons if column is not a metadata
130135
*/
@@ -213,19 +218,6 @@ const HeaderMenu = (headerMenuProps: HeaderMenuProps) => {
213218
icon: <CalendarTimeIcon />,
214219
label: MetadataLabels.CALENDAR_TIME,
215220
},
216-
{
217-
onClick: (e: any) => {
218-
dispatch({
219-
type: ActionTypes.UPDATE_COLUMN_TYPE,
220-
columnId: column.id,
221-
dataType: DataTypes.TASK,
222-
});
223-
setShowType(false);
224-
setExpanded(false);
225-
},
226-
icon: <TaskIcon />,
227-
label: MetadataLabels.TASK,
228-
},
229221
];
230222

231223
const typePopper = usePopper(typeReferenceElement, typePopperElement, {

src/components/markdown/MarkdownRenderer.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,6 @@ function handleEmbeds(dom: HTMLDivElement, view: DatabaseView, depth: number) {
6565
if (MediaExtensions.VIDEO.contains(target.extension)) {
6666
return handleVideo(el, target, view);
6767
}
68-
69-
// if (target.extension === "md") {
70-
// return await handleMarkdown(el, target, normalizedPath, view, depth);
71-
// }
72-
73-
//return handleUnknownFile(el, target);
7468
})
7569
);
7670
}

src/components/modals/ColumnSections.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,32 @@ export function behavior_settings_section(settingHandlerResponse: ColumnHandlerR
2626
return handlers[0].handle(settingHandlerResponse);
2727
}
2828

29+
/**
30+
* Every column type has a different behavior section
31+
* @param settingHandlerResponse
32+
* @returns
33+
*/
2934
export function particular_settings_section(settingHandlerResponse: ColumnHandlerResponse): ColumnHandlerResponse {
30-
const particular_section = settingHandlerResponse.containerEl.createDiv("column-section-container-particular");
31-
// title of the section
32-
add_setting_header(particular_section, `Particular properties of "${settingHandlerResponse.column.dataType
33-
}" column type`, 'h3');
34-
/**
35-
* Obtain all classes than extends from AbstractHandler
36-
*/
3735
const handlers = [
3836
...addParticularInputSettings(settingHandlerResponse.column.dataType)
3937
]
40-
let i = 1;
41-
while (i < handlers.length) {
42-
handlers[i - 1].setNext(handlers[i]);
43-
i++;
44-
}
38+
if (handlers.length > 0) {
39+
const particular_section = settingHandlerResponse.containerEl.createDiv("column-section-container-particular");
40+
// title of the section
41+
add_setting_header(particular_section, `Particular properties of "${settingHandlerResponse.column.dataType
42+
}" column type`, 'h3');
4543

46-
settingHandlerResponse.containerEl = particular_section;
47-
return handlers[0].handle(settingHandlerResponse);
44+
let i = 1;
45+
while (i < handlers.length) {
46+
handlers[i - 1].setNext(handlers[i]);
47+
i++;
48+
}
49+
50+
settingHandlerResponse.containerEl = particular_section;
51+
return handlers[0].handle(settingHandlerResponse);
52+
} else {
53+
return settingHandlerResponse;
54+
}
4855
}
4956

5057
function addParticularInputSettings(dataType: string): ColumnHandler[] {

src/components/reducers/DatabaseDispatch.tsx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -210,20 +210,6 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
210210
$set: parsedData,
211211
},
212212
});
213-
case DataTypes.TASK:
214-
return update(state, {
215-
skipReset: { $set: true },
216-
columns: {
217-
$set: [
218-
...state.columns.slice(0, typeIndex),
219-
{ ...state.columns[typeIndex], dataType: action.dataType },
220-
...state.columns.slice(typeIndex + 1, state.columns.length),
221-
],
222-
},
223-
data: {
224-
$set: parsedData,
225-
},
226-
});
227213
default:
228214
/**
229215
* GENERIC update change

src/helpers/Constants.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const MetadataColumns = Object.freeze({
3535
CREATED: `__created__`,
3636
MODIFIED: `__modified__`,
3737
ADD_COLUMN: `__add_column__`,
38+
TASKS: `__tasks__`
3839
});
3940

4041
export const MetadataLabels = Object.freeze({
@@ -53,6 +54,7 @@ export const DEFAULT_COLUMN_CONFIG = Object.freeze({
5354
media_height: 100,
5455
isInline: false
5556
});
57+
5658
export const MetadataDatabaseColumns = Object.freeze({
5759
FILE:
5860
{
@@ -94,7 +96,17 @@ export const MetadataDatabaseColumns = Object.freeze({
9496
skipPersist: false,
9597
csvCandidate: true,
9698
config: DEFAULT_COLUMN_CONFIG
97-
}
99+
},
100+
TASKS: {
101+
key: MetadataColumns.TASKS,
102+
input: DataTypes.TASK,
103+
label: MetadataLabels.TASK,
104+
accessor: MetadataColumns.TASKS,
105+
isMetadata: true,
106+
skipPersist: false,
107+
csvCandidate: true,
108+
config: DEFAULT_COLUMN_CONFIG
109+
},
98110
});
99111

100112
export const TableColumnsTemplate: Partial<TableColumn> =

0 commit comments

Comments
 (0)