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

Commit a5bebb3

Browse files
committed
funcional work, needs an optimization
1 parent ee4f524 commit a5bebb3

File tree

6 files changed

+47
-10
lines changed

6 files changed

+47
-10
lines changed

src/cdm/DatabaseModel.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,9 @@ export type FilterCondition = {
3939
field: string;
4040
operator: string;
4141
value?: any;
42+
}
43+
44+
export type OptionSelect = {
45+
label: string;
46+
backgroundColor: string;
4247
}

src/components/Cell.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ActionTypes, DataTypes } from "helpers/Constants";
2-
import React, { useLayoutEffect, useRef, useState } from "react";
2+
import React, { useEffect, useLayoutEffect, useRef, useState } from "react";
33
import ContentEditable, { ContentEditableEvent } from "react-contenteditable";
44
import { LOGGER } from "services/Logger";
55
import { Cell } from "react-table";
@@ -28,6 +28,7 @@ function getFilePath(cellValue: string): string {
2828
}
2929

3030
export default function DefaultCell(cellProperties: Cell) {
31+
console.log("render cell");
3132
const dataDispatch = (cellProperties as any).dataDispatch;
3233
/** Initial state of cell */
3334
const initialValue = cellProperties.value;
@@ -44,10 +45,20 @@ export default function DefaultCell(cellProperties: Cell) {
4445
});
4546
/** state for keeping the timeout to trigger the editior */
4647
const [editNoteTimeout, setEditNoteTimeout] = useState(null);
48+
const [dirtyCell, setDirtyCell] = useState(false);
4749
/** states for selector option */
4850
LOGGER.debug(
4951
`<=> Cell.rendering dataType: ${dataType}. value: ${contextValue.value}`
5052
);
53+
// set contextValue when cell is loaded
54+
useEffect(() => {
55+
if (!dirtyCell && initialValue !== contextValue.value) {
56+
setContextValue({
57+
value: initialValue,
58+
update: false,
59+
});
60+
}
61+
}, []);
5162

5263
const handleKeyDown = (event: any) => {
5364
if (event.key === "Enter") {
@@ -62,6 +73,7 @@ export default function DefaultCell(cellProperties: Cell) {
6273
}
6374
// first update the input text as user type
6475
setContextValue({ value: event.target.value, update: false });
76+
setDirtyCell(true);
6577
// initialize a setimeout by wrapping in our editNoteTimeout so that we can clear it out using clearTimeout
6678
setEditNoteTimeout(
6779
setTimeout(() => {
@@ -81,6 +93,7 @@ export default function DefaultCell(cellProperties: Cell) {
8193
row: cellProperties.row,
8294
columnId: (cellProperties.column as any).id,
8395
});
96+
setDirtyCell(false);
8497
}
8598

8699
function getCellElement() {

src/components/portals/CalendarPortal.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { TableColumn, TableDataType } from "cdm/FolderModel";
22
import { CellContext } from "components/contexts/CellContext";
33
import { ActionTypes, DataTypes, StyleVariables } from "helpers/Constants";
4-
import React, { useContext, useEffect, useState } from "react";
4+
import React, { useContext, useState } from "react";
55
import Calendar from "react-calendar";
6-
import ReactDOM, { unmountComponentAtNode } from "react-dom";
6+
import ReactDOM from "react-dom";
77
import { DateTime } from "luxon";
88
import { usePopper } from "react-popper";
99
import { Cell } from "react-table";
@@ -29,9 +29,13 @@ const CalendarPortal = (calendarProps: CalendarProps) => {
2929

3030
/** Note info of current Cell */
3131
const note: NoteInfo = (cellProperties.row.original as any).note;
32-
3332
const [calendarState, setCalendarState] = useState(
34-
(contextValue.value as DateTime).toJSDate()
33+
(
34+
DataviewService.parseLiteral(
35+
cellProperties.value,
36+
DataTypes.CALENDAR
37+
) as DateTime
38+
).toJSDate()
3539
);
3640

3741
function handleCalendarChange(date: Date) {

src/components/reducers/DatabaseDispatch.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ import { ActionType } from "react-table";
1313
import { VaultManagerDB } from "services/FileManagerService";
1414
import { moveFile, updateRowFile } from "helpers/VaultManagement";
1515
import { randomColor } from "helpers/Colors";
16-
import { DatabaseColumn, RowDatabaseFields } from "cdm/DatabaseModel";
16+
import {
17+
DatabaseColumn,
18+
OptionSelect,
19+
RowDatabaseFields,
20+
} from "cdm/DatabaseModel";
1721
import NoteInfo from "services/NoteInfo";
1822
import { DataviewService } from "services/DataviewService";
23+
import { obtainUniqueOptionValues } from "helpers/SelectHelper";
1924

2025
export function databaseReducer(state: TableDataType, action: ActionType) {
2126
LOGGER.debug(
@@ -166,13 +171,13 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
166171
...row,
167172
[action.columnId]: DataviewService.parseLiteral(
168173
row[action.columnId],
169-
action.dataType // Destination type to parse
174+
action.TEXT // Destination type to parse
170175
),
171176
}));
172177
// Update state
173178
switch (action.dataType) {
174179
case DataTypes.SELECT:
175-
const options: any = [];
180+
const options: OptionSelect[] = [];
176181
// Generate selected options
177182
parsedData.forEach((row) => {
178183
if (row[action.columnId]) {
@@ -191,7 +196,7 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
191196
{
192197
...state.columns[typeIndex],
193198
dataType: action.dataType,
194-
options: [...state.columns[typeIndex].options, ...options],
199+
options: obtainUniqueOptionValues(options),
195200
},
196201
...state.columns.slice(typeIndex + 1, state.columns.length),
197202
],

src/helpers/SelectHelper.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { OptionSelect } from "cdm/DatabaseModel";
2+
3+
export function obtainUniqueOptionValues(arrayOptions: OptionSelect[]): OptionSelect[] {
4+
const uniqueValues: OptionSelect[] = [];
5+
arrayOptions.forEach(option => {
6+
if (!uniqueValues.some(unique => unique.label === option.label)) {
7+
uniqueValues.push(option);
8+
}
9+
});
10+
return uniqueValues;
11+
}

src/services/FileManagerService.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ class VaultManager {
6565

6666
ontainCurrentFrontmatter(content: string): Record<string, string> {
6767
const match = content.match(/^---\s+([\w\W]+?)\s+---/);
68-
console.log("probando");
6968
if (match) {
7069
const frontmatterRaw = match[1];
7170
const yaml = parseYaml(frontmatterRaw);

0 commit comments

Comments
 (0)