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

Commit 7a175c8

Browse files
committed
Merge branch 'bug-pr-feedback-official-release'
2 parents d8b61fa + 2a9f119 commit 7a175c8

25 files changed

+506
-137
lines changed

docs/changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.3.0
2+
### Shiny new things
3+
- Improve css styling [ISSUE#31](https://github.com/RafaelGB/obsidian-db-folder/pull/31) [artisticat1](https://github.com/artisticat1)
4+
5+
16
## 0.2.2
27
*Published on 2022/05/08*
38
### No longer broken

src/DatabaseView.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ export class DatabaseView extends TextFileView implements HoverParent {
125125
yamlColumns = await obtainMetadataColumns(yamlColumns);
126126
// Obtain base information about columns
127127
const columns = await obtainColumnsFromFolder(yamlColumns);
128-
const rows = await adapterTFilesToRows(this.file.parent.path);
128+
const rows = await adapterTFilesToRows(
129+
this.file.parent.path,
130+
this.diskConfig.yaml.filters
131+
);
129132
// Define table properties
130133
const tableProps: TableDataType = {
131134
columns: columns,

src/Settings.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { DatabaseView } from "DatabaseView";
55
import { LOGGER } from "services/Logger";
66
import { developer_settings_section } from "settings/DeveloperSection";
77
import { columns_settings_section } from "settings/ColumnsSection";
8+
import { folder_settings_section } from "settings/FolderSection";
89
import { StyleClasses } from "helpers/Constants";
910
import { SettingHandlerResponse } from "settings/handlers/AbstractSettingHandler";
1011

@@ -79,9 +80,12 @@ export class SettingsManager {
7980
containerEl.addClass(StyleClasses.SETTINGS_MODAL);
8081
add_setting_header(containerEl, heading, 'h2');
8182

83+
const settingBody = containerEl.createDiv();
84+
settingBody.addClass(StyleClasses.SETTINGS_MODAL_BODY);
85+
containerEl.setAttribute("id", StyleClasses.SETTINGS_MODAL_BODY);
8286
const settingHandlerResponse: SettingHandlerResponse = {
8387
settingsManager: this,
84-
containerEl: containerEl,
88+
containerEl: settingBody,
8589
local: local,
8690
errors: {},
8791
view: view,
@@ -90,19 +94,23 @@ export class SettingsManager {
9094
}
9195

9296
constructSettingBody(settingHandlerResponse: SettingHandlerResponse) {
97+
if (settingHandlerResponse.local) {
98+
/** Folder section */
99+
folder_settings_section(settingHandlerResponse);
100+
}
93101
/** Columns section */
94102
columns_settings_section(settingHandlerResponse);
95103
/** Developer section */
96104
developer_settings_section(settingHandlerResponse);
97105
}
98106

99107
reset(response: SettingHandlerResponse) {
100-
const parentElement = response.containerEl.parentElement;
108+
const settingsElement = document.getElementById(StyleClasses.SETTINGS_MODAL_BODY);
101109
// remove all sections
102-
parentElement.empty();
110+
settingsElement.empty();
103111

104112
response.errors = {};
105-
response.containerEl = parentElement;
113+
response.containerEl = settingsElement;
106114
this.constructSettingBody(response);
107115
}
108116

src/__tests__/reactTable.test.tsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,35 @@ import {
77
DeepMockProxy,
88
mockDeep,
99
mock,
10-
MockProxy,
1110
mockReset,
11+
MockProxy,
1212
} from "jest-mock-extended";
13-
import { App } from "obsidian";
13+
import { App, FileStats, TFolder, Vault } from "obsidian";
1414
import StateManager from "StateManager";
15+
import { DatabaseView } from "DatabaseView";
16+
17+
// void mock
18+
const greetImplementation = (dataview: MockProxy<StateManager>) => {};
19+
const mockFn = jest.fn(greetImplementation);
1520

21+
// const mockStateManager: MockProxy<StateManager> = {
22+
// app: global.app,
23+
// file: {
24+
// path: "mockedPath",
25+
// basename: "mockedBasename",
26+
// name: "mockedName",
27+
// parent: mock<TFolder>(),
28+
// vault: mock<Vault>(),
29+
// stat: mock<FileStats>(),
30+
// extension: "md",
31+
// },
32+
// onEmpty: jest.fn(),
33+
// getGlobalSettings: jest.fn(),
34+
// unregisterView: mockFn,
35+
// registerView: jest.fn(),
36+
// getAView: mock<DatabaseView>(),
37+
// forceRefresh: jest.fn(),
38+
// };
1639
/**
1740
* @jest-environment jsdom
1841
*/
@@ -29,7 +52,7 @@ describe("React-table", () => {
2952

3053
test("Render without crashing", async () => {
3154
const mockedTableData: TableDataType = await makeData(10);
32-
//mockedTableData.stateManager = StateManager();
55+
// mockedTableData.stateManager = mockStateManager;
3356
render(<Database {...mockedTableData} />);
3457
const titleLabel = screen.getByText(" title");
3558
expect(titleLabel).toBeInTheDocument();

src/cdm/DatabaseModel.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { RowType } from "cdm/RowTypeModel"
2+
import { Literal } from "obsidian-dataview/lib/data-model/value";
23
import { LocalSettings } from "Settings"
34

45
/** database column */
@@ -16,18 +17,26 @@ export type DatabaseColumn = {
1617
}
1718

1819
/** database yaml */
19-
export type DatabaseYaml = {
20+
export interface DatabaseYaml {
2021
/** database name */
21-
name: string,
22+
name: string;
2223
/** database description */
23-
description: string,
24+
description: string;
2425
/** database columns */
25-
columns: Record<string, DatabaseColumn>
26+
columns: Record<string, DatabaseColumn>;
2627
/** database local configuration */
27-
config?: LocalSettings
28+
config: LocalSettings;
29+
/** dataview filters */
30+
filters?: FilterCondition[];
2831
}
2932

3033
export type RowDatabaseFields = {
3134
frontmatter: Record<string, any>;
3235
inline: Record<string, any>;
36+
}
37+
38+
export type FilterCondition = {
39+
field: string;
40+
operator: string;
41+
value?: any;
3342
}

src/components/Table.tsx

Lines changed: 46 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ import PlusIcon from "components/img/Plus";
1919
import { LOGGER } from "services/Logger";
2020
import DefaultCell from "components/Cell";
2121
import Header from "components/Header";
22-
import { useDraggableInPortal } from "components/portals/UseDraggableInPortal";
2322
import { c } from "helpers/StylesHelper";
2423
import { HeaderNavBar } from "components/NavBar";
2524
import { getColumnsWidthStyle } from "components/styles/ColumnWidthStyle";
2625
import { HeaderContext } from "components/contexts/HeaderContext";
26+
import { getDndListStyle, getDndItemStyle } from "./styles/DnDStyle";
2727

2828
const defaultColumn = {
2929
minWidth: 50,
@@ -191,11 +191,8 @@ export function Table(initialState: TableDataType) {
191191
const [columnsWidthState, setColumnsWidthState] = React.useState(
192192
getColumnsWidthStyle(rows, columns)
193193
);
194-
195-
const [isDragUpdate, setDragUpdate] = React.useState(false);
196194
// Manage DnD
197195
const currentColOrder = React.useRef(null);
198-
const renderDraggable = useDraggableInPortal();
199196
// Manage input of new row
200197
const [inputNewRow, setInputNewRow] = React.useState("");
201198
const newRowRef = React.useRef(null);
@@ -248,9 +245,6 @@ export function Table(initialState: TableDataType) {
248245
currentColOrder.current = allColumns.map((o: Column) => o.id);
249246
}}
250247
onDragUpdate={(dragUpdateObj, b) => {
251-
if (!isDragUpdate) {
252-
setDragUpdate(true);
253-
}
254248
const colOrder = [...currentColOrder.current];
255249
const sIndex = dragUpdateObj.source.index;
256250
const dIndex =
@@ -272,24 +266,23 @@ export function Table(initialState: TableDataType) {
272266

273267
// clear the current order
274268
currentColOrder.current = null;
275-
setDragUpdate(false);
276269
}}
277270
>
278271
<Droppable
279272
key={`Droppable-${i}`}
280273
droppableId="droppable"
281274
direction="horizontal"
282275
>
283-
{(droppableProvided, snapshot) => (
276+
{(provided, snapshot) => (
284277
<div
285278
key={`div-Droppable-${i}`}
279+
{...provided.droppableProps}
286280
{...headerGroup.getHeaderGroupProps({
287281
style: {
288-
...headerGroup.getHeaderGroupProps().style,
289-
maxWidth: `${totalColumnsWidth}px`,
282+
...getDndListStyle(snapshot.isDraggingOver),
290283
},
291284
})}
292-
ref={droppableProvided.innerRef}
285+
ref={provided.innerRef}
293286
className={`${c("tr header-group")}`}
294287
>
295288
{headerGroup.headers.map((column, index) => (
@@ -299,29 +292,28 @@ export function Table(initialState: TableDataType) {
299292
index={index}
300293
isDragDisabled={(column as any).skipPersist}
301294
>
302-
{renderDraggable((provided) => {
295+
{(provided, snapshot) => {
303296
const tableCellBaseProps = {
304-
...column.getHeaderProps(),
305-
className: `${c("th noselect")} header`,
306-
key: `div-Draggable-${column.id}`,
307297
...provided.draggableProps,
308298
...provided.dragHandleProps,
299+
...column.getHeaderProps({
300+
style: {
301+
width: `${
302+
columnsWidthState.widthRecord[column.id]
303+
}px`,
304+
...getDndItemStyle(
305+
snapshot.isDragging,
306+
provided.draggableProps.style
307+
),
308+
},
309+
}),
310+
className: `${c("th noselect")} header`,
311+
key: `div-Draggable-${column.id}`,
309312
// {...extraProps}
310313
ref: provided.innerRef,
311314
};
312-
const tableCellProps = isDragUpdate
313-
? tableCellBaseProps
314-
: {
315-
...tableCellBaseProps,
316-
style: {
317-
...column.getHeaderProps().style,
318-
width: `${columnsWidthState.widthRecord[column.id]
319-
}px`,
320-
},
321-
};
322-
323315
return (
324-
<div {...tableCellProps}>
316+
<div {...tableCellBaseProps}>
325317
<HeaderContext.Provider
326318
value={{
327319
columnWidthState: columnsWidthState,
@@ -332,10 +324,10 @@ export function Table(initialState: TableDataType) {
332324
</HeaderContext.Provider>
333325
</div>
334326
);
335-
})}
327+
}}
336328
</Draggable>
337329
))}
338-
{droppableProvided.placeholder}
330+
{provided.placeholder}
339331
</div>
340332
)}
341333
</Droppable>
@@ -347,27 +339,27 @@ export function Table(initialState: TableDataType) {
347339
{rows.map((row, i) => {
348340
prepareRow(row);
349341
return (
350-
<div {...row.getRowProps()} className={`${c("tr")}`} key={row.id}>
342+
<div
343+
{...row.getRowProps({
344+
style: {
345+
maxWidth: `${totalColumnsWidth}px`,
346+
},
347+
})}
348+
className={`${c("tr")}`}
349+
key={row.id}
350+
>
351351
{row.cells.map((cell) => {
352352
const tableCellBaseProps = {
353353
...cell.getCellProps({
354354
style: {
355-
...cell.getCellProps().style,
356-
maxWidth: `${totalColumnsWidth}px`,
355+
width: columnsWidthState.widthRecord[cell.column.id],
357356
},
358357
}),
359358
className: `${c("td")}`,
360359
};
361-
const tableCellProps = isDragUpdate
362-
? tableCellBaseProps
363-
: {
364-
...tableCellBaseProps,
365-
style: {
366-
...tableCellBaseProps.style,
367-
width: columnsWidthState.widthRecord[cell.column.id],
368-
},
369-
};
370-
return <div {...tableCellProps}>{cell.render("Cell")}</div>;
360+
return (
361+
<div {...tableCellBaseProps}>{cell.render("Cell")}</div>
362+
);
371363
})}
372364
</div>
373365
);
@@ -383,14 +375,17 @@ export function Table(initialState: TableDataType) {
383375
placeholder="filename of new row"
384376
/>
385377
</div>
386-
<div className={`${c("td")}`} onClick={() => {
387-
dataDispatch({
388-
type: ActionTypes.ADD_ROW,
389-
filename: inputNewRow,
390-
});
391-
setInputNewRow("");
392-
newRowRef.current.value = "";
393-
}}>
378+
<div
379+
className={`${c("td")}`}
380+
onClick={() => {
381+
dataDispatch({
382+
type: ActionTypes.ADD_ROW,
383+
filename: inputNewRow,
384+
});
385+
setInputNewRow("");
386+
newRowRef.current.value = "";
387+
}}
388+
>
394389
<span className="svg-icon svg-gray" style={{ marginRight: 4 }}>
395390
<PlusIcon />
396391
</span>

src/components/portals/UseDraggableInPortal.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/components/styles/DndStyle.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { StyleVariables } from "helpers/Constants";
2+
3+
export const getDndItemStyle = (isDragging: boolean, draggableStyle: any) => ({
4+
// change background colour if dragging
5+
background: isDragging ? StyleVariables.BACKGROUND_SECONDARY : StyleVariables.BACKGROUND_PRIMARY,
6+
// styles we need to apply on draggables
7+
...draggableStyle,
8+
});
9+
10+
export const getDndListStyle = (isDraggingOver: boolean) => ({
11+
background: isDraggingOver ? 'lightblue' : StyleVariables.BACKGROUND_PRIMARY,
12+
height: '100%',
13+
width: '100%',
14+
top: '0'
15+
});

0 commit comments

Comments
 (0)