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

Commit 2263e32

Browse files
committed
Merge branch '46-vs-improve-css-of-calendar-datepicker'
2 parents 13485d4 + 7366b35 commit 2263e32

File tree

11 files changed

+108
-53
lines changed

11 files changed

+108
-53
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"react-popper": "2.3.0",
6363
"react-table": "7.7.0",
6464
"react-window": "1.8.7",
65-
"react-datepicker": "4.7.0",
65+
"react-datepicker": "4.8.0",
6666
"regenerator-runtime": "0.13.9",
6767
"luxon": "2.4.0"
6868
}

src/cdm/FolderModel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,6 @@ export type NoteContentAction = {
123123
file: TFile,
124124
action: string,
125125
regexp: RegExp,
126+
content?: string,
126127
newValue?: string
127128
}

src/components/HeaderMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ const HeaderMenu = (headerMenuProps: HeaderMenuProps) => {
218218
setExpanded(false);
219219
},
220220
icon: <CalendarIcon />,
221-
label: DataTypes.CALENDAR,
221+
label: MetadataLabels.CALENDAR,
222222
},
223223
{
224224
onClick: (e: any) => {

src/components/portals/CalendarPortal.tsx

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import DatePicker from "react-datepicker";
66
import NoteInfo from "services/NoteInfo";
77
import { Portal } from "@material-ui/core";
88
import { CalendarProps } from "cdm/DatabaseModel";
9+
import { c } from "helpers/StylesHelper";
910

1011
const CalendarPortal = (calendarProps: CalendarProps) => {
1112
const { column, cellProperties } = calendarProps;
@@ -15,14 +16,14 @@ const CalendarPortal = (calendarProps: CalendarProps) => {
1516
// Selector popper state
1617
/** state of cell value */
1718
const { contextValue, setContextValue } = useContext(CellContext);
18-
19+
const [showDatePicker, setShowDatePicker] = useState(false);
1920
/** Note info of current Cell */
2021
const note: NoteInfo = (cellProperties.row.original as any).note;
21-
const [calendarState, setCalendarState] = useState(
22-
DateTime.isDateTime(contextValue.value)
23-
? contextValue.value.toJSDate()
24-
: null
25-
);
22+
23+
function handleOnClick(event: any) {
24+
event.preventDefault();
25+
setShowDatePicker(true);
26+
}
2627

2728
function handleCalendarChange(date: Date) {
2829
const newValue = DateTime.fromJSDate(date);
@@ -31,33 +32,43 @@ const CalendarPortal = (calendarProps: CalendarProps) => {
3132
type: ActionTypes.UPDATE_CELL,
3233
file: note.getFile(),
3334
key: column.key,
34-
value: DateTime.fromJSDate(date).toFormat("yyyy-MM-dd"),
35+
value: newValue.toFormat("yyyy-MM-dd"),
3536
row: cellProperties.row,
3637
columnId: column.id,
3738
});
3839

39-
setCalendarState(date);
4040
setContextValue({
4141
value: newValue,
4242
update: true,
4343
});
44+
setShowDatePicker(false);
4445
}
4546

4647
const CalendarContainer = (containerProps: any) => {
4748
const el = document.getElementById("popper-container");
4849
return <Portal container={el}>{containerProps.children}</Portal>;
4950
};
5051

51-
return (
52-
<div className="data-input calendar">
53-
<DatePicker
54-
dateFormat="yyyy-MM-dd"
55-
selected={calendarState}
56-
onChange={handleCalendarChange}
57-
popperContainer={CalendarContainer}
58-
placeholderText="Pick a date..."
59-
/>
60-
</div>
52+
return showDatePicker ? (
53+
<DatePicker
54+
dateFormat="yyyy-MM-dd"
55+
selected={
56+
DateTime.isDateTime(contextValue.value)
57+
? contextValue.value.toJSDate()
58+
: null
59+
}
60+
onChange={handleCalendarChange}
61+
popperContainer={CalendarContainer}
62+
onBlur={() => setShowDatePicker(false)}
63+
autoFocus
64+
className="data-input calendar"
65+
/>
66+
) : (
67+
<span className={`data-input ${c("calendar")}`} onClick={handleOnClick}>
68+
{DateTime.isDateTime(contextValue.value)
69+
? contextValue.value.toFormat("yyyy-MM-dd")
70+
: "Pick a date..."}
71+
</span>
6172
);
6273
};
6374

src/components/reducers/DatabaseDispatch.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { TableColumn, TableDataType, RowDataType } from "cdm/FolderModel";
1111
import { LOGGER } from "services/Logger";
1212
import { ActionType } from "react-table";
1313
import { VaultManagerDB } from "services/FileManagerService";
14-
import { moveFile, updateRowFile } from "helpers/VaultManagement";
14+
import { moveFile, updateRowFileProxy } from "helpers/VaultManagement";
1515
import { randomColor } from "helpers/Colors";
1616
import {
1717
DatabaseColumn,
@@ -110,7 +110,7 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
110110

111111
await Promise.all(
112112
state.data.map(async (row: RowDataType) => {
113-
await updateRowFile(
113+
await updateRowFileProxy(
114114
row.note.getFile(),
115115
action.columnId,
116116
action.newKey,
@@ -315,7 +315,7 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
315315
if (state.view.diskConfig.yaml.config.remove_field_when_delete_column) {
316316
Promise.all(
317317
state.data.map(async (row: RowDataType) => {
318-
updateRowFile(
318+
updateRowFileProxy(
319319
row.note.getFile(),
320320
action.key,
321321
undefined, // delete does not need this field
@@ -382,13 +382,14 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
382382
(column) => column.id === action.columnId
383383
);
384384
// Save on disk
385-
updateRowFile(
385+
updateRowFileProxy(
386386
action.file,
387387
action.key,
388388
action.value,
389389
state,
390390
UpdateRowOptions.COLUMN_VALUE
391391
);
392+
392393
const update_option_cell_column_key =
393394
state.columns[update_cell_index].key;
394395
return update(state, {

src/helpers/Constants.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ export const MetadataLabels = Object.freeze({
4141
ADD_COLUMN: '+',
4242
CREATED: 'Created',
4343
MODIFIED: 'Modified',
44-
CALENDAR_TIME: 'Calendar time',
44+
CALENDAR: 'Date',
45+
CALENDAR_TIME: 'Datetime',
4546
});
4647

4748
export const MetadataDatabaseColumns = Object.freeze({
@@ -110,13 +111,16 @@ export const DatabaseFrontmatterOptions = Object.freeze({
110111
'---',
111112
'',
112113
'<%%',
114+
'name: new database',
115+
'description: new description',
113116
'columns:',
114117
' column1:',
115118
' input: text',
116119
' key: column1',
117120
' accessor: column1',
118121
' label: Column 1',
119122
' position: 0',
123+
'filters:',
120124
].join('\n')
121125
});
122126

src/helpers/VaultManagement.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const noBreakSpace = /\u00A0/g;
1818
* @returns
1919
*/
2020
export function hasFrontmatterKey(data: string): boolean {
21-
const frontmatterRegex = /^---\n+.*---\n/g
21+
const frontmatterRegex = /^---[\s\S]+?---/g;
2222
return frontmatterRegex.test(data);
2323
}
2424

@@ -82,6 +82,12 @@ export async function adapterTFilesToRows(folderPath: string, columns: TableColu
8282
LOGGER.debug(`<= adapterTFilesToRows. number of rows:${rows.length}`);
8383
return rows;
8484
}
85+
export async function updateRowFileProxy(file: TFile, columnId: string, newValue: string, state: TableDataType, option: string): Promise<void> {
86+
await updateRowFile(file, columnId, newValue, state, option).catch(e => {
87+
LOGGER.error(`updateRowFileProxy. Error:${e}`);
88+
throw e;
89+
});
90+
}
8591

8692
/**
8793
* Modify the file asociated to the row in function of input options
@@ -155,15 +161,18 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: str
155161
}
156162

157163
async function persistFrontmatter(deletedColumn?: string): Promise<void> {
158-
const frontmatterGroupRegex = new RegExp(`(^---\\n)+(.*)+(^---)`, "gm");
164+
const frontmatterGroupRegex = /^---[\s\S]+?---/g;
165+
const frontmatterFieldsText = parseFrontmatterFieldsToString(rowFields, currentFrontmatter, deletedColumn);
166+
console.log(frontmatterFieldsText);
159167
const noteObject = {
160168
action: 'replace',
161169
file: file,
162170
regexp: frontmatterGroupRegex,
163-
newValue: `${parseFrontmatterFieldsToString(rowFields, currentFrontmatter, deletedColumn)}`
171+
newValue: `${frontmatterFieldsText}`
164172
};
165173
await VaultManagerDB.editNoteContent(noteObject);
166174
}
175+
167176
/*******************************************************************************************
168177
* INLINE GROUP FUNCTIONS
169178
*******************************************************************************************/

src/main.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,13 @@ export default class DBFolderPlugin extends Plugin {
210210
defaultConfiguration(): string {
211211
const local_settings = this.settings.local_settings;
212212
return [
213-
`configuration:`,
213+
`config:`,
214214
` enable_show_state: ${local_settings.enable_show_state}`,
215-
'%%>'
215+
` group_folder_column: `,
216+
` remove_field_when_delete_column: ${local_settings.remove_field_when_delete_column}`,
217+
` show_metadata_created: ${local_settings.show_metadata_created}`,
218+
` show_metadata_modified: ${local_settings.show_metadata_modified}`,
219+
`%%>`
216220
].join('\n');
217221
}
218222
registerEvents() {
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { YamlHandlerResponse } from 'cdm/MashallModel';
22
import { AbstractYamlHandler } from 'parsers/handlers/marshall/AbstractYamlPropertyHandler';
3+
import { LocalSettings } from 'Settings';
34

45
export class MarshallConfigHandler extends AbstractYamlHandler {
56
handlerName: string = 'configuration';
@@ -9,33 +10,38 @@ export class MarshallConfigHandler extends AbstractYamlHandler {
910
if (handlerResponse.yaml.config) {
1011
this.localYaml.config = handlerResponse.yaml.config;
1112
// if enable_show_state is not defined, load default
12-
if (handlerResponse.yaml.config.enable_show_state === undefined) {
13+
if (checkNullable(handlerResponse.yaml.config.enable_show_state)) {
1314
this.addError(`There was not enable_debug_mode key in yaml. Default will be loaded`);
1415
this.localYaml.config.enable_show_state = false;
1516
}
17+
1618
// if group_folder_column is not defined, load default
17-
if (handlerResponse.yaml.config.group_folder_column === undefined) {
18-
this.addError(`There was not group_folder_column key in yaml. Default will be loaded`);
19+
if (checkNullable(handlerResponse.yaml.config.group_folder_column)) {
1920
this.localYaml.config.group_folder_column = '';
2021
}
22+
2123
// if remove_field_when_delete_column is not defined, load default
22-
if (handlerResponse.yaml.config.remove_field_when_delete_column === undefined) {
24+
if (checkNullable(handlerResponse.yaml.config.remove_field_when_delete_column)) {
2325
this.addError(`There was not remove_field_when_delete_column key in yaml. Default will be loaded`);
2426
this.localYaml.config.remove_field_when_delete_column = false;
2527
}
2628

2729
// if show_metadata_created is not defined, load default
28-
if (handlerResponse.yaml.config.show_metadata_created === undefined) {
30+
if (checkNullable(handlerResponse.yaml.config.show_metadata_created)) {
2931
this.addError(`There was not show_metadata_created key in yaml. Default will be loaded`);
3032
this.localYaml.config.show_metadata_created = false;
3133
}
3234

3335
// if show_metadata_modified is not defined, load default
34-
if (handlerResponse.yaml.config.show_metadata_modified === undefined) {
36+
if (checkNullable(handlerResponse.yaml.config.show_metadata_modified)) {
3537
this.addError(`There was not show_metadata_modified key in yaml. Default will be loaded`);
3638
this.localYaml.config.show_metadata_modified = false;
3739
}
3840
}
3941
return this.goNext(handlerResponse);
4042
}
43+
}
44+
45+
function checkNullable<T>(value: T): boolean {
46+
return value === null || value === undefined;
4147
}

src/services/FileManagerService.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ class VaultManager {
3232
async editNoteContent(note: NoteContentAction): Promise<string> {
3333
LOGGER.debug(`=> editNoteContent. action:${note.action} filePath:${note.file.path}`);
3434
try {
35-
const tfileContent = await this.obtainContentFromTfile(note.file);
36-
const line_string = new FileContent(tfileContent);
37-
let releasedContent = tfileContent;
35+
let releasedContent = note.content;
36+
if (releasedContent === undefined) {
37+
releasedContent = await this.obtainContentFromTfile(note.file);
38+
}
39+
const line_string = new FileContent(releasedContent);
40+
3841
switch (note.action) {
3942
case 'remove':
4043
releasedContent = line_string.remove(note.regexp).value;

0 commit comments

Comments
 (0)