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

Commit 18e402c

Browse files
committed
Merge branch '30-bug-if-dnd-column-then-edit-label-column-is-moved-to-the-end-of-table'
2 parents 9dc0862 + bbe8b21 commit 18e402c

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

src/cdm/FolderModel.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { RowSelectOption } from "cdm/RowSelectModel";
66
import NoteInfo from "services/NoteInfo";
77
import { TFile } from "obsidian";
88
import { DatabaseColumn } from "cdm/DatabaseModel";
9+
import { Column } from "react-table";
910

1011
export type Group = Parameter | Parameters | FolderModel | Models;
1112
type Parameter = {
@@ -81,7 +82,8 @@ export interface DatabaseHeaderProps {
8182
getHooks: any,
8283
state: any,
8384
dispatch: any,
84-
allColumns: any,
85+
allColumns: Column[],
86+
setColumnOrder: (cols: string[]) => void,
8587
rows: any,
8688
initialRows: any,
8789
flatRows: any,

src/components/HeaderMenu.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import MultiIcon from "components/img/Multi";
1515
import HashIcon from "components/img/Hash";
1616
import AdjustmentsIcon from "components/img/AdjustmentsIcon";
1717
import React, { useContext, useEffect, useState } from "react";
18-
import { ActionType } from "react-table";
18+
import { ActionType, Column } from "react-table";
1919
import { usePopper } from "react-popper";
2020
import { HeaderContext } from "components/contexts/HeaderContext";
2121
import { FormControlLabel, FormGroup, Switch } from "@material-ui/core";
@@ -49,7 +49,7 @@ const HeaderMenu = (headerMenuProps: HeaderMenuProps) => {
4949
isInline,
5050
setIsInline,
5151
} = headerMenuProps;
52-
const { column, columns, rows, initialState } = headerMenuProps.headerProps;
52+
const { column, rows, initialState } = headerMenuProps.headerProps;
5353
const dispatch = (headerMenuProps.headerProps as any).dataDispatch;
5454
/** Column values */
5555
const [keyState, setkeyState] = useState(dbTrim(column.key));
@@ -211,6 +211,9 @@ const HeaderMenu = (headerMenuProps: HeaderMenuProps) => {
211211
function persistLabelChange() {
212212
// trim label will get a valid yaml key
213213
const newKey = dbTrim(labelState);
214+
const futureOrder = headerMenuProps.headerProps.allColumns.map(
215+
(o: Column) => (o.id === column.id ? newKey : o.id)
216+
);
214217
dispatch({
215218
type: ActionTypes.UPDATE_COLUMN_LABEL,
216219
columnId: column.id,
@@ -225,10 +228,15 @@ const HeaderMenu = (headerMenuProps: HeaderMenuProps) => {
225228
newKey,
226229
labelState
227230
);
231+
232+
/*
233+
To adjust column settings to the new key, we need to update the order
234+
of the columns with it and calculate the new width
235+
*/
228236
delete columnWidthState.widthRecord[column.id];
229237
setColumnWidthState(columnWidthState);
238+
headerMenuProps.headerProps.setColumnOrder(futureOrder);
230239
}
231-
232240
function handleKeyDown(e: any) {
233241
if (e.key === "Enter") {
234242
persistLabelChange();

src/components/Table.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
useGlobalFilter,
88
useColumnOrder,
99
useFilters,
10+
Column,
1011
} from "react-table";
1112
import { DragDropContext, Droppable, Draggable } from "react-beautiful-dnd";
1213
import { TableDataType, RowDataType, TableColumn } from "cdm/FolderModel";
@@ -243,7 +244,7 @@ export function Table(initialState: TableDataType) {
243244
<DragDropContext
244245
key={`DragDropContext-${i}`}
245246
onDragStart={() => {
246-
currentColOrder.current = allColumns.map((o: any) => o.id);
247+
currentColOrder.current = allColumns.map((o: Column) => o.id);
247248
}}
248249
onDragUpdate={(dragUpdateObj, b) => {
249250
if (!isDragUpdate) {

src/components/reducers/DatabaseDispatch.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { moveFile, updateRowFile } from "helpers/VaultManagement";
1515
import { randomColor } from "helpers/Colors";
1616
import { DatabaseColumn, RowDatabaseFields } from "cdm/DatabaseModel";
1717
import NoteInfo from "services/NoteInfo";
18-
import { dbTrim } from "helpers/StylesHelper";
1918

2019
export function databaseReducer(state: TableDataType, action: ActionType) {
2120
LOGGER.debug(

src/helpers/VaultManagement.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const noBreakSpace = /\u00A0/g;
1717
* @returns
1818
*/
1919
function hasFrontmatterKey(data: string): boolean {
20-
const frontmatterRegex = /---\s+([\w\W]+?)\s+---/
20+
const frontmatterRegex = /^---\n+.*---\n/g
2121
return frontmatterRegex.test(data);
2222
}
2323

@@ -114,6 +114,7 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: str
114114
}
115115
rowFields.frontmatter[columnId] = newValue;
116116
await persistFrontmatter();
117+
await inlineRemoveColumn();
117118
}
118119

119120
// Modify key of a column

0 commit comments

Comments
 (0)