Skip to content

Commit

Permalink
Merge branch '442-fr-edit-nested-metadata'
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelGB committed Oct 15, 2022
2 parents 8e7e956 + b0a9076 commit 25fc289
Show file tree
Hide file tree
Showing 65 changed files with 817 additions and 471 deletions.
7 changes: 7 additions & 0 deletions docs/docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 2.7.2
### Shiny new things
- Edit nested metadata arrives! You can now edit nested metadata in the cell editor [ISSUE#442](https://github.com/RafaelGB/obsidian-db-folder/issues/442)
### Performance
- Editions use a new method to update the notes under a queue. It should prevent the plugin from locking the UI when editing a lot of notes or errors editing the same note multiple times
### No longer broken
- support for stack tabs. If a ddbb note is included Obsidian does not crash anymore [ISSUE#435](https://github.com/RafaelGB/obsidian-db-folder/issues/435)
## 2.7.1
- Hotfix for 2.7.0 of global settings developer options
- Experimental support for Objects on text fields
Expand Down
4 changes: 2 additions & 2 deletions manifest-beta.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"id": "dbfolder",
"name": "DB Folder",
"version": "2.7.1",
"minAppVersion": "0.15.9",
"version": "2.7.2",
"minAppVersion": "0.16.3",
"description": "Folder with the capability to store and retrieve data from a folder like database",
"author": "RafaelGB",
"authorUrl": "https://github.com/RafaelGB/obsidian-bd-folder",
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"id": "dbfolder",
"name": "DB Folder",
"version": "2.7.1",
"minAppVersion": "0.15.9",
"version": "2.7.2",
"minAppVersion": "0.16.3",
"description": "Folder with the capability to store and retrieve data from a folder like database",
"author": "RafaelGB",
"authorUrl": "https://github.com/RafaelGB/obsidian-bd-folder",
Expand Down
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-dbfolder",
"version": "2.7.1",
"version": "2.7.2",
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
"main": "main.js",
"scripts": {
Expand All @@ -19,34 +19,34 @@
"license": "MIT",
"devDependencies": {
"@faker-js/faker": "7.5.0",
"@rollup/plugin-commonjs": "22.0.2",
"@rollup/plugin-json": "4.1.0",
"@rollup/plugin-node-resolve": "14.1.0",
"@rollup/plugin-replace": "4.0.0",
"@rollup/plugin-typescript": "8.5.0",
"@rollup/plugin-commonjs": "23.0.0",
"@rollup/plugin-json": "5.0.0",
"@rollup/plugin-node-resolve": "15.0.0",
"@rollup/plugin-replace": "5.0.0",
"@rollup/plugin-typescript": "9.0.1",
"@testing-library/jest-dom": "5.16.5",
"@testing-library/react": "13.4.0",
"@types/jest": "29.0.3",
"@types/jest": "29.1.2",
"@types/luxon": "3.0.1",
"@types/node": "18.7.22",
"@types/node": "18.8.4",
"@types/react": "18.0.21",
"@types/react-color": "3.0.6",
"@types/react-csv": "1.1.3",
"@types/react-datepicker": "4.4.2",
"@types/react-dom": "18.0.6",
"@types/react-window": "1.8.5",
"@typescript-eslint/eslint-plugin": "5.38.0",
"@typescript-eslint/parser": "5.38.0",
"eslint": "8.24.0",
"jest": "29.0.3",
"@typescript-eslint/eslint-plugin": "5.40.0",
"@typescript-eslint/parser": "5.40.0",
"eslint": "8.25.0",
"jest": "29.1.2",
"jest-mock-extended": "3.0.1",
"obsidian": "0.16.3",
"rollup": "2.79.1",
"rollup-plugin-terser": "7.0.2",
"rollup-plugin-typescript2": "0.34.0",
"ts-jest": "29.0.2",
"rollup-plugin-typescript2": "0.34.1",
"ts-jest": "29.0.3",
"tslib": "2.4.0",
"typescript": "4.8.3"
"typescript": "4.8.4"
},
"dependencies": {
"@emotion/styled": "11.10.4",
Expand All @@ -59,7 +59,7 @@
"fuse.js": "6.6.2",
"luxon": "3.0.4",
"monkey-around": "2.3.0",
"obsidian-dataview": "0.5.46",
"obsidian-dataview": "0.5.47",
"react": "18.2.0",
"react-color": "2.19.3",
"react-csv": "2.2.2",
Expand All @@ -68,6 +68,6 @@
"react-popper": "2.3.0",
"react-select": "5.4.0",
"react-window": "1.8.7",
"zustand": "4.1.1"
"zustand": "4.1.2"
}
}
15 changes: 12 additions & 3 deletions src/cdm/FolderModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,36 @@ export type Models = {
}

export interface ConfigColumn {
/** Mandatory */
enable_media_view: boolean;
link_alias_enabled: boolean;
media_width: number;
media_height: number;
isInline: boolean;
/** Circunstancial */
content_alignment?: string;
wrap_content?: boolean;
// Text
link_alias_enabled?: boolean;
// Tasks
task_hide_completed?: boolean;
// Formulas
formula_query?: string;
persist_formula?: boolean;
/** Extras from yaml */
[key: string]: Literal;
}

export type BaseColumn = {
/** Mandatory */
accessorKey: string;
label: string;
key: string;
input: string;
csvCandidate?: boolean;
config: ConfigColumn;
/** Circunstancial */
nestedKey?: string;
options?: RowSelectOption[];
csvCandidate?: boolean;
width?: number;
position?: number;
isMetadata?: boolean;
Expand All @@ -63,7 +73,6 @@ export type BaseColumn = {
isHidden?: boolean;
skipPersist?: boolean;
isDragDisabled?: boolean;
config: ConfigColumn;
}
export type TableColumn = ColumnDef<RowDataType, Literal> & BaseColumn;

Expand Down
2 changes: 1 addition & 1 deletion src/cdm/ModalsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type ColumnSettingsHandlerResponse = {

export type ColumnSettingsModalProps = {
dataState: Pick<DataState, "actions">,
columnState: Pick<ColumnsState, "info">,
columnState: Pick<ColumnsState, "info" | "actions">,
configState: Pick<ConfigState, "info">,
view: DatabaseView,
headerMenuProps: HeaderMenuProps
Expand Down
2 changes: 1 addition & 1 deletion src/cdm/StyleModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ColumnSettingsModal } from "components/modals/columnSettings/ColumnSett

type BaseStyleProps = {
modal: ColumnSettingsModal;
columnKey: string;
columnId: string;
};

export type ColorPickerProps = {
Expand Down
5 changes: 3 additions & 2 deletions src/cdm/TableStateInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export interface DataState {
dataviewRefresh: (column: TableColumn[], ddbbConfig: LocalSettings, filterConfig: FilterSettings) => void;
renameFile: (rowIndex: number) => Promise<void>;
saveDataFromFile: (file: File, columns: TableColumn[], config: LocalSettings) => Promise<void>;
groupFiles: () => Promise<void>;
groupFiles: () => Promise<void>;
}
}

Expand All @@ -60,7 +60,8 @@ export interface ColumnsState {
remove: (column: TableColumn) => void;
alterSorting: (column: TableColumn) => void;
addOptionToColumn: (column: TableColumn, option: string, backgroundColor: string) => void;
alterColumnType: (column: TableColumn, input: string, parsedRows?: RowDataType[]) => void;
alterColumnType: (column: TableColumn, input: string, parsedRows?: RowDataType[]) => Promise<void>;
alterColumnId: (column: TableColumn, root: string, nestedIds: string[]) => Promise<void>;
alterColumnLabel: (column: TableColumn, label: string) => Promise<void>;
alterColumnSize: (id: string, width: number) => void;
alterIsHidden: (column: TableColumn, isHidden: boolean) => void;
Expand Down
2 changes: 2 additions & 0 deletions src/components/Columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export async function obtainColumnsFromFile(
accessorKey: key,
label: key,
key: key,
id: key,
position: index,
config: DEFAULT_COLUMN_CONFIG,
};
Expand Down Expand Up @@ -198,6 +199,7 @@ export async function obtainColumnsFromRows(
accessorKey: key,
label: key,
key: key,
id: key,
position: index,
config: DEFAULT_COLUMN_CONFIG,
};
Expand Down
16 changes: 8 additions & 8 deletions src/components/DefaultCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import React from "react";
import { InputType } from "helpers/Constants";
import { LOGGER } from "services/Logger";
import { RowDataType, TableColumn } from "cdm/FolderModel";
import SelectPortal from "components/portals/SelectPortal";
import CalendarPortal from "components/portals/CalendarPortal";
import CalendarTimePortal from "components/portals/CalendarTimePortal";
import SelectCell from "components/cellTypes/SelectCell";
import CalendarCell from "components/cellTypes/CalendarCell";
import CalendarTimeCell from "components/cellTypes/CalendarTimeCell";
import CheckboxCell from "components/cellTypes/CheckboxCell";
import TaskCell from "components/cellTypes/TaskCell";
import MarkdownCell from "components/cellTypes/MarkdownCell";
import TagsPortal from "components/portals/TagsPortal";
import TagsCell from "components/cellTypes/TagsCell";
import NumberCell from "components/cellTypes/NumberCell";
import TextCell from "components/cellTypes/TextCell";
import MetadataTimeCell from "components/cellTypes/MetadataTimeCell";
Expand Down Expand Up @@ -43,23 +43,23 @@ export default function DefaultCell(

/** Calendar option */
case InputType.CALENDAR:
return <CalendarPortal defaultCell={defaultCell} />;
return <CalendarCell defaultCell={defaultCell} />;

/** Calendar with time option */
case InputType.CALENDAR_TIME:
return <CalendarTimePortal defaultCell={defaultCell} />;
return <CalendarTimeCell defaultCell={defaultCell} />;

/** Metadata options related with date/datetime */
case InputType.METATADA_TIME:
return <MetadataTimeCell defaultCell={defaultCell} />;

/** Selector option */
case InputType.SELECT:
return <SelectPortal defaultCell={defaultCell} />;
return <SelectCell defaultCell={defaultCell} />;

/** Tags option */
case InputType.TAGS:
return <TagsPortal defaultCell={defaultCell} />;
return <TagsCell defaultCell={defaultCell} />;

/** Tasks option */
case InputType.TASK:
Expand Down
74 changes: 5 additions & 69 deletions src/components/HeaderMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ import { ColumnSettingsModal } from "components/modals/columnSettings/ColumnSett
import { TableColumn } from "cdm/FolderModel";
import { HeaderActionResponse } from "cdm/HeaderActionModel";
import { HeaderMenuProps } from "cdm/HeaderModel";
import { destination_folder } from "helpers/FileManagement";
import { FileGroupingService } from "services/FileGroupingService";

const HeaderMenu = (headerMenuProps: HeaderMenuProps) => {
const { table, column } = headerMenuProps.headerProps;
const { view } = table.options.meta;
const [columnsInfo, columnActions] = table.options.meta.tableState.columns(
(state) => [state.info, state.actions]
);
Expand All @@ -24,8 +21,6 @@ const HeaderMenu = (headerMenuProps: HeaderMenuProps) => {
const configInfo = table.options.meta.tableState.configState(
(state) => state.info
);
const configActions = table.options.meta.tableState.configState((state) => state.actions);
const ddbbConfig = table.options.meta.tableState.configState( (store) => store.ddbbConfig);

/** Header props */
const {
Expand Down Expand Up @@ -91,71 +86,9 @@ const HeaderMenu = (headerMenuProps: HeaderMenuProps) => {
strategy: "fixed",
});

function isValidLabel(newKey: string): boolean {
if (table.getAllColumns().find((o: any) => o.id === newKey)) {
return false;
}

if (newKey === undefined || newKey === null) {
return false;
}

if (newKey.length === 0) {
return false;
}

return true;
}

function persistLabelChange() {
// trim label will get a valid yaml key
const newKey = dbTrim(labelState);
// Check if key already exists. If so, mark it as invalid
if (!isValidLabel(newKey)) {
setLabelStateInvalid(true);
return;
}
// Update state of ordered
const updateOrderWithNewKey = table.options.state.columnOrder.map((o) =>
o === column.id ? newKey : o
);
table.setColumnOrder(updateOrderWithNewKey);

setkeyState(newKey);

// Update sorted columns
if (column.getIsSorted()) {
const alterSort = table.options.state.sorting.map((o) => {
if (o.id === column.id) {
o.id = newKey;
}
return o;
});
table.setSorting(alterSort);
}

// Update state of altered column
columnActions
.alterColumnLabel(column.columnDef as TableColumn, labelState)
.then(() => {
dataActions.updateDataAfterLabelChange(
column.columnDef as TableColumn,
labelState,
columnsInfo.getAllColumns(),
configInfo.getLocalSettings()
);
});
// Rename column in group_folder_column
const groupFolderColumn =
ddbbConfig.group_folder_column.split(",");
if (groupFolderColumn.includes(column.columnDef.id)) {
const newGroupFolderColumn = groupFolderColumn
.map((item) => item === column.columnDef.id? newKey : item)
.join(",");
configActions.alterConfig({ group_folder_column: newGroupFolderColumn });
// Reorganize files and remove empty folders
dataActions.groupFiles()
}
columnActions.alterColumnLabel(column.columnDef as TableColumn, labelState);
}

function handleKeyDown(e: any) {
Expand Down Expand Up @@ -300,7 +233,10 @@ const HeaderMenu = (headerMenuProps: HeaderMenuProps) => {
onClick={() => {
new ColumnSettingsModal({
dataState: { actions: dataActions },
columnState: { info: columnsInfo },
columnState: {
info: columnsInfo,
actions: columnActions,
},
configState: { info: configInfo },
view: table.options.meta.view,
headerMenuProps: headerMenuProps,
Expand Down
34 changes: 0 additions & 34 deletions src/components/behavior/CustomSortingFn.ts

This file was deleted.

Loading

0 comments on commit 25fc289

Please sign in to comment.