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

Commit 28b44a5

Browse files
committed
all possible columns option added
1 parent ea3291e commit 28b44a5

File tree

14 files changed

+81
-24
lines changed

14 files changed

+81
-24
lines changed

src/cdm/FolderModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export interface TableColumn extends BaseColumn {
6767

6868
export type RowDataType = {
6969
id: number,
70-
note: NoteInfo,
70+
__note__: NoteInfo,
7171
[key: string]: Literal | NoteInfo
7272
}
7373

src/components/Cell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default function DefaultCell(cellProperties: Cell) {
2424
/** Type of cell */
2525
const dataType = (cellProperties.column as any).dataType;
2626
/** Note info of current Cell */
27-
const note: NoteInfo = (cellProperties.row.original as any).note;
27+
const note: NoteInfo = (cellProperties.row.original as any).__note__;
2828
/** Ref to cell container */
2929
const containerCellRef = useRef<HTMLDivElement>();
3030
const editableMdRef = useRef<HTMLInputElement>();

src/components/Checkbox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function CheckboxCell(props: CheckboxProps) {
1414
const { column, cellProperties } = props;
1515
const dataDispatch = (cellProperties as any).dataDispatch;
1616
/** Note info of current Cell */
17-
const note: NoteInfo = (cellProperties.row.original as any).note;
17+
const note: NoteInfo = (cellProperties.row.original as any).__note__;
1818
/** state of cell value */
1919
const { contextValue, setContextValue } = useContext(CellContext);
2020
const [checked, setChecked] = useState(contextValue.value === 1);

src/components/Columns.tsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
MetadataColumns,
66
MetadataDatabaseColumns,
77
} from "helpers/Constants";
8-
import { TableColumn } from "cdm/FolderModel";
8+
import { RowDataType, TableColumn } from "cdm/FolderModel";
99
import { LOGGER } from "services/Logger";
1010
import { DatabaseColumn } from "cdm/DatabaseModel";
1111
import { RowSelectOption } from "cdm/ComponentsModel";
@@ -118,6 +118,33 @@ export async function obtainColumnsFromFile(
118118
return columns;
119119
}
120120

121+
export function obtainColumnsFromRows(
122+
rows: RowDataType[]
123+
): Record<string, DatabaseColumn> {
124+
const columns: Record<string, DatabaseColumn> = {};
125+
// Obtain unique keys from source
126+
const keys = rows.reduce((acc, row) => {
127+
const keys = Object.keys(row);
128+
return [...acc, ...keys];
129+
}, [] as string[]);
130+
// Add keys to columns
131+
keys
132+
// Check metadata columns to not be added
133+
.filter((key) => !(key.startsWith("__") && key.endsWith("__")))
134+
.forEach((key, index) => {
135+
columns[key] = {
136+
input: DataTypes.TEXT,
137+
accessor: key,
138+
label: key,
139+
key: key,
140+
position: index,
141+
config: DEFAULT_COLUMN_CONFIG,
142+
};
143+
});
144+
145+
return columns;
146+
}
147+
121148
function getInputInFuctionOfLiteral(literal: Literal) {
122149
const wrappedLiteral = DataviewService.wrapLiteral(literal);
123150
let input = DataTypes.TEXT;

src/components/HeaderMenu.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const HeaderMenu = (headerMenuProps: HeaderMenuProps) => {
2626
labelState,
2727
setLabelState,
2828
} = headerMenuProps;
29-
const { column, rows, initialState } = headerMenuProps.headerProps;
29+
const { column, rows, tableData } = headerMenuProps.headerProps;
3030
const dispatch = (headerMenuProps.headerProps as any).dataDispatch;
3131
/** Column values */
3232
const [keyState, setkeyState] = useState(dbTrim(column.key));
@@ -297,10 +297,7 @@ const HeaderMenu = (headerMenuProps: HeaderMenuProps) => {
297297
<div
298298
className="menu-item sort-button"
299299
onClick={() => {
300-
new ColumnModal(
301-
initialState.view,
302-
headerMenuProps
303-
).open();
300+
new ColumnModal(tableData.view, headerMenuProps).open();
304301
setExpanded(false);
305302
}}
306303
>

src/components/headerActions/handlers/buttons/AddColumnHandlerAction.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ export default class AddColumnHandlerAction extends AbstractHeaderAction {
2020
*/
2121
private addColumnButtons(): void {
2222
const { hooks } = this.globalHeaderActionResponse;
23-
const { column, initialState } =
23+
const { column, tableData } =
2424
this.globalHeaderActionResponse.headerMenuProps.headerProps;
2525
const newButtons: any[] = [];
2626
newButtons.push(
2727
{
2828
onClick: (e: any) => {
29-
initialState.dispatch({
29+
tableData.dispatch({
3030
type: ActionTypes.ADD_COLUMN_TO_LEFT,
3131
columnId: column.id,
3232
focus: false,
@@ -41,7 +41,7 @@ export default class AddColumnHandlerAction extends AbstractHeaderAction {
4141
},
4242
{
4343
onClick: (e: any) => {
44-
initialState.dispatch({
44+
tableData.dispatch({
4545
type: ActionTypes.ADD_COLUMN_TO_RIGHT,
4646
columnId: column.id,
4747
focus: false,
@@ -65,10 +65,10 @@ export default class AddColumnHandlerAction extends AbstractHeaderAction {
6565
*/
6666
private adjustWidthOfTheColumnsWhenAdd(wantedPosition: number) {
6767
const { hooks } = this.globalHeaderActionResponse;
68-
const { initialState, column, rows } =
68+
const { tableData, column, rows } =
6969
this.globalHeaderActionResponse.headerMenuProps.headerProps;
7070
let columnNumber =
71-
initialState.columns.length - initialState.shadowColumns.length;
71+
tableData.columns.length - tableData.shadowColumns.length;
7272
// Check if column name already exists
7373
while (
7474
this.globalHeaderActionResponse.headerMenuProps.headerProps.allColumns.find(

src/components/portals/CalendarPortal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const CalendarPortal = (calendarProps: CalendarProps) => {
1414
/** state of cell value */
1515
const [showDatePicker, setShowDatePicker] = useState(false);
1616
/** Note info of current Cell */
17-
const note: NoteInfo = (cellProperties.row.original as any).note;
17+
const note: NoteInfo = (cellProperties.row.original as any).__note__;
1818
const [calendarState, setCalendarState] = useState(
1919
intialState.view.rows[row.index][column.key]
2020
);

src/components/portals/CalendarTimePortal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const CalendarTimePortal = (calendarTimeProps: CalendarProps) => {
1717
// Selector popper state
1818

1919
/** Note info of current Cell */
20-
const note: NoteInfo = (cellProperties.row.original as any).note;
20+
const note: NoteInfo = (cellProperties.row.original as any).__note__;
2121

2222
function handleCalendarChange(date: Date) {
2323
const newValue = DateTime.fromJSDate(date);

src/components/portals/TagsPortal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const TagsPortal = (tagsProps: TagsProps) => {
2323
);
2424

2525
/** Note info of current Cell */
26-
const note: NoteInfo = (cellProperties.row.original as any).note;
26+
const note: NoteInfo = (cellProperties.row.original as any).__note__;
2727

2828
function getColor(tag: string) {
2929
const match = column.options.find(

src/components/reducers/DatabaseDispatch.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
9090
...rowRecord.inline,
9191
...metadata,
9292
id: state.view.rows.length + 1,
93-
note: new NoteInfo(
93+
__note__: new NoteInfo(
9494
{
9595
...rowRecord.frontmatter,
9696
...rowRecord.inline,
@@ -121,7 +121,7 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
121121
Promise.all(
122122
state.view.rows.map(async (row: RowDataType) => {
123123
await updateRowFileProxy(
124-
row.note.getFile(),
124+
row.__note__.getFile(),
125125
action.columnId,
126126
action.newKey,
127127
state,
@@ -361,7 +361,7 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
361361
Promise.all(
362362
state.view.rows.map(async (row: RowDataType) => {
363363
updateRowFileProxy(
364-
row.note.getFile(),
364+
row.__note__.getFile(),
365365
action.key,
366366
undefined, // delete does not need this field
367367
state,
@@ -412,7 +412,7 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
412412
? `${state.view.file.parent.path}/${action.value}/${action.file.name}`
413413
: `${state.view.file.parent.path}/${action.file.name}`;
414414

415-
action.row.original.note = new NoteInfo(
415+
action.row.original.__note__ = new NoteInfo(
416416
{
417417
...action.row,
418418
file: {
@@ -433,7 +433,7 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
433433
[action.row.index]: {
434434
$merge: {
435435
[MetadataColumns.FILE]: action.row[MetadataColumns.FILE],
436-
note: action.row.original.note,
436+
note: action.row.original.__note__,
437437
[update_option_cell_column_key]: action.value,
438438
},
439439
},

0 commit comments

Comments
 (0)