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

Commit ee46384

Browse files
committed
Merge branch 'master' into imed-docu-branch
2 parents 2154cf4 + 9156d5e commit ee46384

File tree

8 files changed

+52
-37
lines changed

8 files changed

+52
-37
lines changed

src/cdm/TableStateInterface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export interface DataState {
4040
updateCell: (rowIndex: number, column: TableColumn, value: Literal, columns: TableColumn[], ddbbConfig: LocalSettings, isMovingFile?: boolean) => void;
4141
parseDataOfColumn: (column: TableColumn, input: string, ddbbConfig: LocalSettings) => void;
4242
updateDataAfterLabelChange: (column: TableColumn, label: string, columns: TableColumn[], ddbbConfig: LocalSettings) => Promise<void>;
43-
removeRow: (row: RowDataType) => void;
43+
removeRow: (row: RowDataType) => Promise<void>;
4444
removeDataOfColumn: (column: TableColumn) => void;
4545
removeOptionForAllRows: (column: TableColumn, option: string, columns: TableColumn[],
4646
ddbbConfig: LocalSettings) => Promise<void>;

src/components/RowContextMenu.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const rowContextMenuColumn: TableColumn = {
4848
const handleDeleteRow = () => {
4949
rowActions.removeRow(row.original);
5050
};
51+
5152
return (
5253
<>
5354
<IconButton

src/components/Table.tsx

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,26 @@ const defaultColumn: Partial<ColumnDef<RowDataType>> = {
6060
export function Table(tableData: TableDataType) {
6161
/** Main information about the table */
6262
const { view, tableStore } = tableData;
63-
const [columns, columnActions, columnsInfo] = tableStore.columns((state) => [
64-
state.columns,
65-
state.actions,
66-
state.info,
67-
]);
68-
const [rows, dataActions] = tableStore.data((state) => [
69-
state.rows,
70-
state.actions,
71-
]);
63+
const columns = tableStore.columns((state) => state.columns);
64+
const columnActions = tableStore.columns((state) => state.actions);
65+
const columnsInfo = tableStore.columns((state) => state.info);
66+
const rows = tableStore.data((state) => state.rows);
67+
const dataActions = tableStore.data((state) => state.actions);
68+
7269
LOGGER.debug(
7370
`=> Table. number of columns: ${columns.length}. number of rows: ${rows.length}`
7471
);
7572

76-
const [ddbbConfig, globalConfig, configActions] = tableStore.configState(
77-
(store) => [store.ddbbConfig, store.global, store.actions]
73+
const cell_size_config = tableStore.configState(
74+
(store) => store.ddbbConfig.cell_size
75+
);
76+
const sticky_first_column_config = tableStore.configState(
77+
(store) => store.ddbbConfig.sticky_first_column
7878
);
7979

80+
const globalConfig = tableStore.configState((store) => store.global);
81+
const configActions = tableStore.configState((store) => store.actions);
82+
const configInfo = tableStore.configState((store) => store.info);
8083
/** Plugin services */
8184
const stateManager: StateManager = tableData.stateManager;
8285
const filePath = stateManager.file.path;
@@ -186,7 +189,6 @@ export function Table(tableData: TableDataType) {
186189
},
187190
[stateManager, filePath]
188191
);
189-
190192
const table: Table<RowDataType> = useReactTable({
191193
columns: columns,
192194
data: rows,
@@ -236,7 +238,7 @@ export function Table(tableData: TableDataType) {
236238
onColumnOrderChange: setColumnOrder,
237239
// Hack to force react-table to use all columns when filtering
238240
getColumnCanGlobalFilter: (column) => true,
239-
globalFilterFn: globalDatabaseFilterFn(ddbbConfig),
241+
globalFilterFn: globalDatabaseFilterFn(configInfo.getLocalSettings()),
240242
meta: {
241243
tableState: tableStore,
242244
view: view,
@@ -262,7 +264,7 @@ export function Table(tableData: TableDataType) {
262264
}
263265

264266
function handleAddNewRow() {
265-
dataActions.addRow(inputNewRow, columns, ddbbConfig);
267+
dataActions.addRow(inputNewRow, columns, configInfo.getLocalSettings());
266268
setInputNewRow("");
267269
newRowRef.current.value = "";
268270
}
@@ -303,8 +305,8 @@ export function Table(tableData: TableDataType) {
303305
key={`div-table`}
304306
className={`${c(
305307
"table noselect cell_size_" +
306-
ddbbConfig.cell_size +
307-
(ddbbConfig.sticky_first_column ? " sticky_first_column" : "")
308+
cell_size_config +
309+
(sticky_first_column_config ? " sticky_first_column" : "")
308310
)}`}
309311
onMouseOver={onMouseOver}
310312
onClick={onClick}

src/components/TableHeader.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ import { useDrag, useDrop } from "react-dnd";
66
import { RowDataType } from "cdm/FolderModel";
77
import { DnDConfiguration } from "helpers/Constants";
88

9-
interface DragItem {
10-
index: number;
11-
id: string;
12-
type: string;
13-
}
14-
159
export default function TableHeader(headerProps: TableHeaderProps) {
1610
const { table, header, reorderColumn, headerIndex } = headerProps;
1711
const { view } = table.options.meta;

src/mock/mockDataviewUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ export const generateStateManager = (): StateManager => {
77
app.workspace.getMostRecentLeaf(),
88
null
99
);
10-
const stateManager = new StateManager(initialView, null, null, null);
10+
const stateManager = new StateManager(initialView, null, null);
1111
return stateManager;
1212
};

src/services/NoteInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { resolve_tfile } from "helpers/FileManagement";
99
* Keep info about a note and offer methods to manipulate it
1010
*/
1111
export default class NoteInfo {
12-
private filepath: string;
12+
public filepath: string;
1313
private page: Record<string, Literal>;
1414
constructor(page: Record<string, Literal>) {
1515
this.page = page;

src/stateManagement/data/handlers/AddRowHandlerAction.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,18 @@ export default class AddRowlHandlerAction extends AbstractTableAction<DataState>
1313
handle(tableActionResponse: TableActionResponse<DataState>): TableActionResponse<DataState> {
1414
const { view, set, implementation } = tableActionResponse;
1515
implementation.actions.addRow = (filename: string, columns: TableColumn[], ddbbConfig: LocalSettings) => set((state) => {
16-
const trimedFilename = filename.replace(/\.[^/.]+$/, "").trim();
17-
const filepath = `${view.file.parent.path}/${trimedFilename}.md`;
16+
let trimedFilename = filename.replace(/\.[^/.]+$/, "").trim();
17+
let filepath = `${view.file.parent.path}/${trimedFilename}.md`;
18+
// Validate possible duplicates
19+
let sufixOfDuplicate = 0;
20+
while (state.rows.find((row) => row.__note__.filepath === filepath)) {
21+
sufixOfDuplicate++;
22+
filepath = `${view.file.parent.path}/${trimedFilename}-${sufixOfDuplicate}.md`;
23+
}
24+
if (sufixOfDuplicate > 0) {
25+
trimedFilename = `${trimedFilename}-${sufixOfDuplicate}`;
26+
filename = `${trimedFilename} copy(${sufixOfDuplicate})`;
27+
}
1828
const rowRecord: RowDatabaseFields = { inline: {}, frontmatter: {} };
1929
columns
2030
.filter((column: TableColumn) => !column.isMetadata)
Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
import { RowDataType } from "cdm/FolderModel";
22
import { DataState, TableActionResponse } from "cdm/TableStateInterface";
3+
import { Notice } from "obsidian";
34
import { VaultManagerDB } from "services/FileManagerService";
45
import { AbstractTableAction } from "stateManagement/AbstractTableAction";
56

67
export default class RemoveRowHandlerAction extends AbstractTableAction<DataState> {
78
handle(tableActionResponse: TableActionResponse<DataState>): TableActionResponse<DataState> {
89
const { set, implementation } = tableActionResponse;
9-
implementation.actions.removeRow = (rowToRemove: RowDataType) =>
10-
set((state) => {
11-
const filteredRows = state.rows.filter(
12-
(r) => r.__note__.getFile().path !== rowToRemove.__note__.getFile().path
13-
);
14-
VaultManagerDB.removeNote(rowToRemove.__note__.getFile());
15-
return {
16-
rows: filteredRows
17-
}
18-
});
10+
implementation.actions.removeRow = async (rowToRemove: RowDataType) => {
11+
try {
12+
await VaultManagerDB.removeNote(rowToRemove.__note__.getFile());
13+
set((state) => {
14+
const filteredRows = state.rows.filter(
15+
(r) => r.__note__.filepath !== rowToRemove.__note__.filepath
16+
);
17+
return {
18+
rows: filteredRows
19+
}
20+
})
21+
} catch (error) {
22+
new Notice(`Error: Could not remove note from database. path does not exist: ${rowToRemove.__note__.filepath}`);
23+
}
24+
25+
};
1926
tableActionResponse.implementation = implementation;
2027
return this.goNext(tableActionResponse);
28+
2129
}
2230
}

0 commit comments

Comments
 (0)