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

Commit ca2c543

Browse files
committed
improve order of metadata created and modified adding time
1 parent 8175b96 commit ca2c543

File tree

8 files changed

+68
-109
lines changed

8 files changed

+68
-109
lines changed

src/components/Cell.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export default function DefaultCell(cellProperties: Cell) {
112112
//innerRef={containerCellRef}
113113
/>
114114
);
115+
115116
/** Number option */
116117
case DataTypes.NUMBER:
117118
return (
@@ -131,6 +132,15 @@ export default function DefaultCell(cellProperties: Cell) {
131132
return (
132133
<span ref={containerCellRef} className={`${c("md_cell")}`}></span>
133134
);
135+
136+
/** Calendar with time option */
137+
case DataTypes.CALENDAR_TIME:
138+
return (
139+
<span className="data-input calendar-time">
140+
{contextValue.value.toString()}
141+
</span>
142+
);
143+
134144
/** Selector option */
135145
case DataTypes.SELECT:
136146
return (
@@ -145,6 +155,7 @@ export default function DefaultCell(cellProperties: Cell) {
145155
/>
146156
</CellContext.Provider>
147157
);
158+
148159
/** Calendar option */
149160
case DataTypes.CALENDAR:
150161
return (
@@ -156,6 +167,7 @@ export default function DefaultCell(cellProperties: Cell) {
156167
/>
157168
</CellContext.Provider>
158169
);
170+
159171
/** Default option */
160172
default:
161173
LOGGER.warn(`Unknown data type: ${dataType}`);

src/components/Columns.tsx

Lines changed: 12 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -68,115 +68,27 @@ export async function obtainColumnsFromFolder(
6868
return sortColumnsByPosition(columns);
6969
}
7070

71-
function parseDatabaseToTableColumn(
72-
databaseColumn: DatabaseColumn,
73-
columnKey: string,
74-
index: number
75-
): TableColumn {
76-
const tableColumn: TableColumn = {
77-
...(databaseColumn as Partial<TableColumn>),
78-
id: columnKey,
79-
dataType: databaseColumn.input,
80-
position: databaseColumn.position ?? index,
81-
key: databaseColumn.key ?? columnKey,
82-
label: databaseColumn.label,
83-
accessor: databaseColumn.accessor ?? dbTrim(databaseColumn.label),
84-
csvCandidate: databaseColumn.csvCandidate ?? true,
85-
};
86-
return tableColumn;
87-
}
88-
89-
async function columnOptions(
71+
function columnOptions(
9072
columnKey: string,
9173
index: number,
9274
column: DatabaseColumn
93-
): Promise<TableColumn> {
75+
): TableColumn {
9476
LOGGER.debug(`=> columnOptions. column: ${JSON.stringify(column)}`);
9577
const options: RowSelectOption[] = [];
96-
const tableRow: TableColumn = parseDatabaseToTableColumn(
97-
column,
98-
columnKey,
99-
index
100-
);
101-
/**
102-
* return plain text
103-
* @returns {TableColumn}
104-
*/
105-
function isText(): TableColumn {
106-
LOGGER.debug(`<= columnOptions`, `return text column`);
107-
return {
108-
...tableRow,
109-
dataType: DataTypes.TEXT,
110-
options: options,
111-
};
112-
}
113-
114-
/**
115-
* return number
116-
* @returns {TableColumn}
117-
*/
118-
function isNumber(): TableColumn {
119-
LOGGER.debug(`<= columnOptions`, `return number column`);
120-
return {
121-
...tableRow,
122-
dataType: DataTypes.NUMBER,
123-
options: options,
124-
};
125-
}
126-
/**
127-
* return selector
128-
* @returns {TableColumn}
129-
*/
130-
function isSelect(): TableColumn {
131-
LOGGER.debug(`<= columnOptions`, `return select column`);
132-
return {
133-
...tableRow,
134-
dataType: DataTypes.SELECT,
135-
options: options,
136-
};
137-
}
138-
139-
/**
140-
* return markdown rendered text
141-
* @returns {TableColumn}
142-
*/
143-
function isMarkdown(): TableColumn {
144-
LOGGER.debug(`<= columnOptions`, `return markdown column`);
145-
return {
146-
...tableRow,
147-
dataType: DataTypes.MARKDOWN,
148-
options: options,
149-
};
150-
}
151-
152-
function isNewColumn(): TableColumn {
153-
LOGGER.debug(`<= columnOptions`, `return new column`);
154-
return {
155-
...tableRow,
156-
dataType: DataTypes.NEW_COLUMN,
157-
options: options,
158-
};
159-
}
16078

161-
function isCalendar(): TableColumn {
162-
LOGGER.debug(`<= columnOptions`, `return calendar column`);
79+
if (Object.values(DataTypes).includes(column.input)) {
80+
LOGGER.debug(`<= columnOptions`, `return ${column.input} column`);
16381
return {
164-
...tableRow,
165-
dataType: DataTypes.CALENDAR,
82+
...(column as Partial<TableColumn>),
83+
position: column.position ?? index,
84+
key: column.key ?? columnKey,
85+
accessor: column.accessor ?? dbTrim(column.label),
86+
csvCandidate: column.csvCandidate ?? true,
87+
id: columnKey,
88+
label: column.label,
89+
dataType: column.input,
16690
options: options,
16791
};
168-
}
169-
170-
// Record of options
171-
let inputs: Record<string, any> = {};
172-
inputs[DataTypes.TEXT] = isText;
173-
inputs[DataTypes.NUMBER] = isNumber;
174-
inputs[DataTypes.SELECT] = isSelect;
175-
inputs[DataTypes.MARKDOWN] = isMarkdown;
176-
inputs[DataTypes.NEW_COLUMN] = isNewColumn;
177-
inputs[DataTypes.CALENDAR] = isCalendar;
178-
if (inputs.hasOwnProperty(column.input)) {
179-
return await inputs[column.input]();
18092
} else {
18193
throw `Error: option ${column.input} not supported yet`;
18294
}

src/components/Header.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import PlusIcon from "components/img/Plus";
77
import HeaderMenu from "components/HeaderMenu";
88
import CalendarIcon from "components/img/CalendarIcon";
99
import MarkdownObsidian from "components/img/Markdown";
10+
import CalendarTimeIcon from "components/img/CalendarTime";
1011
import {
1112
ActionTypes,
1213
DataTypes,
@@ -78,6 +79,9 @@ export default function Header(headerProps: DatabaseHeaderProps) {
7879
case DataTypes.CALENDAR:
7980
propertyIcon = <CalendarIcon />;
8081
break;
82+
case DataTypes.CALENDAR_TIME:
83+
propertyIcon = <CalendarTimeIcon />;
84+
break;
8185
case DataTypes.MARKDOWN:
8286
// TODO : add a markdown icon
8387
propertyIcon = <MarkdownObsidian />;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from "react";
2+
3+
export default function CalendarTimeIcon() {
4+
return (
5+
<svg
6+
width="24"
7+
height="24"
8+
viewBox="0 0 24 24"
9+
strokeWidth="2"
10+
stroke="currentColor"
11+
fill="none"
12+
strokeLinecap="round"
13+
strokeLinejoin="round"
14+
>
15+
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
16+
<path d="M11.795 21h-6.795a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v4" />
17+
<circle cx="18" cy="18" r="4" />
18+
<path d="M15 3v4" />
19+
<path d="M7 3v4" />
20+
<path d="M3 11h16" />
21+
<path d="M18 16.496v1.504l1 1" />
22+
</svg>
23+
);
24+
}

src/components/portals/CalendarPortal.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@ const CalendarPortal = (calendarProps: CalendarProps) => {
5252
});
5353
}
5454

55-
if (contextValue.value instanceof DateTime) {
56-
console.log("calendar datatime value");
57-
} else {
58-
console.log("calendar differ value");
59-
}
60-
6155
function handlerOnClick(e: any) {
6256
if (!column.isMetadata) {
6357
const portalActive = document.getElementById("unique-calendar-portal");

src/helpers/Constants.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const DataTypes = Object.freeze({
2323
SELECT: 'select',
2424
MARKDOWN: 'markdown',
2525
CALENDAR: 'calendar',
26+
CALENDAR_TIME: 'calendar_time',
2627
NEW_COLUMN: 'new_column'
2728
});
2829

@@ -66,7 +67,7 @@ export const MetadataDatabaseColumns = Object.freeze({
6667
},
6768
CREATED: {
6869
key: MetadataColumns.CREATED,
69-
input: DataTypes.CALENDAR,
70+
input: DataTypes.CALENDAR_TIME,
7071
label: MetadataLabels.CREATED,
7172
accessor: MetadataColumns.CREATED,
7273
isMetadata: true,
@@ -76,7 +77,7 @@ export const MetadataDatabaseColumns = Object.freeze({
7677
},
7778
MODIFIED: {
7879
key: MetadataColumns.MODIFIED,
79-
input: DataTypes.CALENDAR,
80+
input: DataTypes.CALENDAR_TIME,
8081
label: MetadataLabels.MODIFIED,
8182
accessor: MetadataColumns.MODIFIED,
8283
isMetadata: true,

src/services/DataviewService.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ class DataviewProxy {
6868
case DataTypes.CALENDAR:
6969
parsedLiteral = this.parseToCalendar(wrapped);
7070
break;
71+
case DataTypes.CALENDAR_TIME:
72+
parsedLiteral = this.parseToCalendarTime(wrapped);
73+
break;
7174
case DataTypes.NUMBER:
7275
parsedLiteral = wrapped.type === 'number' ? literal : Number(literal);
7376
break;
@@ -100,6 +103,14 @@ class DataviewProxy {
100103
return literal.value;
101104
}
102105
}
106+
107+
private parseToCalendarTime(literal: WrappedLiteral): Literal {
108+
if (literal.type === 'string') {
109+
return DateTime.fromISO(literal.value);
110+
} else {
111+
return literal.value;
112+
}
113+
}
103114
}
104115

105116
export const DataviewService = DataviewProxy.getInstance();

src/services/NoteInfo.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { TFile } from "obsidian";
44
import { VaultManagerDB } from "services/FileManagerService";
55
import { DateTime } from "luxon";
66
import { DataviewService } from "./DataviewService";
7+
import { Literal } from "obsidian-dataview/lib/data-model/value";
78
/**
89
* Keep info about a note and offer methods to manipulate it
910
*/
@@ -36,7 +37,7 @@ export default class NoteInfo {
3637
/** Parse data with the type of column */
3738
columns.forEach(column => {
3839
if (aFile[column.key] !== undefined) {
39-
aFile[column.key] = DataviewService.parseLiteral(aFile[column.key], column.dataType);
40+
aFile[column.key] = DataviewService.parseLiteral((aFile[column.key]) as Literal, column.dataType);
4041
}
4142
});
4243
return aFile;

0 commit comments

Comments
 (0)