Skip to content

Commit

Permalink
Merge branch '25-fr-inline-field-supported'
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelGB committed May 6, 2022
2 parents be09528 + ebd2855 commit 7486ceb
Show file tree
Hide file tree
Showing 28 changed files with 403 additions and 215 deletions.
9 changes: 8 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,12 @@ module.exports = {
sourceType: "module",
},
plugins: ["@typescript-eslint"],
rules: {},
rules: {
"@typescript-eslint/ban-ts-comment": [
"error",
{
"ts-ignore": false
}
],
},
};
Empty file added __mocks__/StateManager.ts
Empty file.
5 changes: 4 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
## 0.1.2
*Published on 2022/05/04*
### Improved
- Now DnD of file column and persist order are supported. [ISSUE#18](https://github.com/RafaelGB/obsidian-db-folder/issues/18)
### No longer broken
- Change select cell type no crash the view anymore. This is a but introduced in 0.1.1.
## 0.1.1
*Published on 2022/05/03*
### Improved
- The width of columns are adjusted when a column is added of removed
### No longer broken
- Now if you update a cell and then use global filter, the value is updated correctly [ISSUE#23](https://github.com/RafaelGB/obsidian-db-folder/issues/23)
## 0.1.0
*Published on 2022/05/02*
### Shiny new things
- New button to download a CSV file with the current data (supports filtering!). Temporally this feature is inside menu bar. We are working on move it into the actual file options of Obsidian [ISSUE#15](https://github.com/RafaelGB/obsidian-db-folder/issues/15)
### Improved
Expand All @@ -23,7 +26,7 @@
- Add prefix to the className of components, so interference with other plugins is less probable. [ISSUE#19](https://github.com/RafaelGB/obsidian-bd-folder/issues/19)
- When column folder is activated and a file is moved, now link is updated correctly
## 0.0.7
*Published on 04/27/2022*
*Published on 2022/04/27*
### Shiny new things
- New local property `group_folder_column` to specify a select column type column. This column will be used to group the notes into subfolders with the same cell value. The subfolder will be created if it does not exist. [ISSUE#11](https://github.com/RafaelGB/obsidian-bd-folder/issues/11)

Expand Down
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module.exports = {
verbose: true,
preset: 'ts-jest',
testEnvironment: 'jsdom',
moduleDirectories: ["node_modules", "src"],
transform: {
'^.+\\.ts$': 'ts-jest',
},
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'jsdom',
moduleFileExtensions: ['js', 'ts', 'tsx']
};
25 changes: 12 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"dev": "rollup --config rollup.config.js -w",
"build": "rollup --config rollup.config.js",
"test": "jest --env=node --colors --coverage test",
"test": "jest --colors --coverage test",
"pretest": "eslint --ignore-path .gitignore src/**/*.ts"
},
"keywords": [
Expand All @@ -20,32 +20,31 @@
"devDependencies": {
"@rollup/plugin-commonjs": "22.0.0",
"@rollup/plugin-json": "4.1.0",
"@rollup/plugin-node-resolve": "13.2.1",
"@rollup/plugin-node-resolve": "13.3.0",
"@rollup/plugin-typescript": "8.3.2",
"@types/jest": "27.4.1",
"@types/jest": "27.5.0",
"@types/faker": "6.6.9",
"@testing-library/jest-dom": "5.16.4",
"@testing-library/react": "12.1.2",
"@types/node": "17.0.25",
"@types/node": "17.0.31",
"@types/react": "17.0.43",
"@types/react-dom": "17.0.14",
"@types/react-table": "7.7.10",
"@types/react-table": "7.7.11",
"@types/react-window": "1.8.5",
"@types/react-beautiful-dnd": "13.1.2",
"@types/react-csv": "1.1.2",
"@typescript-eslint/eslint-plugin": "5.20.0",
"@typescript-eslint/parser": "5.20.0",
"@typescript-eslint/eslint-plugin": "5.22.0",
"@typescript-eslint/parser": "5.22.0",
"eslint": "8.14.0",
"jest": "27.5.1",
"jest-mock-extended": "2.0.5",
"obsidian": "0.14.6",
"obsidian-dataview": "0.5.17",
"rollup": "2.70.2",
"svelte-check": "2.7.0",
"svelte-jester": "2.3.2",
"svelte-preprocess": "4.10.6",
"obsidian-dataview": "0.5.18",
"rollup": "2.72.0",
"ts-jest": "27.1.4",
"tslib": "2.4.0",
"typescript": "4.6.4",
"@faker-js/faker": "6.2.0"
"@faker-js/faker": "6.3.1"
},
"dependencies": {
"@material-ui/core": "4.12.4",
Expand Down
2 changes: 1 addition & 1 deletion src/DatabaseView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import ReactDOM from "react-dom";
import DatabaseInfo from "services/DatabaseInfo";
import { LOGGER } from "services/Logger";
import { SettingsModal } from "Settings";
import { StateManager } from "StateManager";
import StateManager from "StateManager";
export const databaseIcon = "blocks";

export class DatabaseView extends TextFileView implements HoverParent {
Expand Down
2 changes: 1 addition & 1 deletion src/StateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DatabaseView } from "DatabaseView";
import { App, TFile } from 'obsidian';
import { LOGGER } from "services/Logger";
import { DatabaseSettings } from 'Settings';
export class StateManager {
export default class StateManager {
private onEmpty: () => void;
private getGlobalSettings: () => DatabaseSettings;
private viewSet: Set<DatabaseView> = new Set();
Expand Down
18 changes: 18 additions & 0 deletions src/__tests__/IO/columns.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { obtainMetadataColumns, obtainColumnsFromFolder } from "components/Columns";
import { MetadataColumns } from "helpers/Constants";
import { generateYamlColumns } from "mock/mockTableUtils";
describe("Columns", () => {
/** Metadata columns */
test('obtainMetadataColumns()', async () => {
// Check if mandatory columns exists
const columnsRecord = await obtainMetadataColumns(generateYamlColumns(5));
expect(columnsRecord).toHaveProperty(MetadataColumns.FILE);
expect(columnsRecord).toHaveProperty(MetadataColumns.ADD_COLUMN);
});
/** Table columns */
test('obtainColumnsFromFolder()', async () => {
const columnsRecord = await obtainMetadataColumns(generateYamlColumns(5));
const tableColumns = await obtainColumnsFromFolder(columnsRecord);
expect(tableColumns.length >= 5).toBeTruthy();
});
});
63 changes: 63 additions & 0 deletions src/__tests__/lab.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { MockProxy, mock, mockDeep, DeepMockProxy } from 'jest-mock-extended';
import { labTest1 } from 'mock/labTest';
import { App, TFile } from 'obsidian';
test('test', () => {
// const tfileArrayMock: MockProxy<TFile[]> = mock<TFile[]>();
// tfileArrayMock
// // @ts-ignore
// const mockObj: DeepMockProxy<App> = mockDeep<App>();
// global.app = mockObj;
// mockObj.vault.getFiles.mockReturnValue(fakeGetFilesResponse);
// expect(labTest1()).toEqual(fakeGetFilesResponse);
});

const fakeGetFilesResponse: TFile[] = [
{
"name": "file1",
"path": "path1",
"parent": {
"name": "folder1",
"children": [
{
"name": "file2",
"path": "path2",
"vault": null,
"parent": null,
},
],
"isRoot": () => true,
"vault": null,
"path": "path1",
"parent": null
},
"basename": "file1",
"vault": null,
"extension": "",
"stat": null
},
{
"name": "file2",
"path": "path2",
"parent": {
"name": "folder1",
"children": [
{
"name": "file2",
"path": "path2",
"vault": null,
"parent": null,
},
],
"isRoot": () => true,
"vault": null,
"path": "path1",
"parent": null
},
"basename": "file2",
"vault": null,
"extension": "",
"stat": null
},
];


45 changes: 37 additions & 8 deletions src/__tests__/reactTable.test.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,44 @@
import { render, screen } from "@testing-library/react";
import obsidian from "obsidian";
import { Database } from "components/index/Database";
import { TableDataType } from "cdm/FolderModel";
import { makeData } from "mock/mockUtils";
import { makeData } from "mock/mockTableUtils";
import React from "react";
import {
DeepMockProxy,
mockDeep,
mock,
MockProxy,
mockReset,
} from "jest-mock-extended";
import { App } from "obsidian";
import StateManager from "StateManager";

// jest.mock("obsidian");
/**
* @jest-environment jsdom
*/
describe("React-table", () => {
// @ts-ignore
const mockGlobalApp: DeepMockProxy<App> = mockDeep<App>();
/**
* Run this before each test.
*/
beforeAll(() => {
mockReset(mockGlobalApp);
global.app = mockGlobalApp;
});

test("Render without crashing", () => {
// const mockedTableData: TableDataType = makeData(10);
// render(<Database {...mockedTableData} />);
// const titleLabel = screen.getByText(" title");
// expect(titleLabel).toBeInTheDocument();
test("Render without crashing", async () => {
const mockedTableData: TableDataType = await makeData(10);
//mockedTableData.stateManager = StateManager();
render(<Database {...mockedTableData} />);
const titleLabel = screen.getByText(" title");
expect(titleLabel).toBeInTheDocument();
});

/**
* Run this after each test.
*/
afterAll(() => {
global.app = undefined;
});
});
6 changes: 6 additions & 0 deletions src/cdm/DatabaseModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type DatabaseColumn = {
isMetadata?: boolean,
skipPersist?: boolean,
csvCandidate?: boolean,
isInline?: boolean,
[key: string]: RowType
}

Expand All @@ -24,4 +25,9 @@ export type DatabaseYaml = {
columns: Record<string, DatabaseColumn>
/** database local configuration */
config?: LocalSettings
}

export type RowDatabaseFields = {
frontmatter: Record<string, any>;
inline: Record<string, any>;
}
5 changes: 3 additions & 2 deletions src/cdm/FolderModel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DatabaseView } from "DatabaseView";
import { Dispatch } from "react";
import { StateManager } from "StateManager";
import StateManager from "StateManager";
import { RowType } from "cdm/RowTypeModel";
import { RowSelectOption } from "cdm/RowSelectModel";
import NoteInfo from "services/NoteInfo";
Expand Down Expand Up @@ -49,6 +49,7 @@ export type TableColumn = {
getResizerProps?: any,
isMetadata?: boolean,
skipPersist?: boolean,
isInline?: boolean,
csvCandidate: boolean
}

Expand All @@ -64,7 +65,7 @@ export type TableDataType = {
data: Array<RowDataType>,
skipReset: boolean,
view: DatabaseView,
stateManager?: StateManager,
stateManager: StateManager,
dispatch?: Dispatch<any>
}
export interface DatabaseHeaderProps {
Expand Down
1 change: 1 addition & 0 deletions src/components/Columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ async function columnOptions(
isMetadata: column.isMetadata ?? false,
skipPersist: column.skipPersist ?? false,
csvCandidate: column.csvCandidate ?? true,
isInline: column.isInline ?? false,
};
/**
* return plain text
Expand Down
2 changes: 1 addition & 1 deletion src/components/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { DragDropContext, Droppable, Draggable } from "react-beautiful-dnd";
import { TableDataType, RowDataType, TableColumn } from "cdm/FolderModel";
import { DatabaseView } from "DatabaseView";
import { StateManager } from "StateManager";
import StateManager from "StateManager";
import { getNormalizedPath } from "helpers/VaultManagement";
import { ActionTypes, DatabaseCore } from "helpers/Constants";
import PlusIcon from "components/img/Plus";
Expand Down
Loading

0 comments on commit 7486ceb

Please sign in to comment.