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

Commit 76f5d33

Browse files
committed
Merge branch 'customFilters'
2 parents 426bcb3 + 42d4fe9 commit 76f5d33

20 files changed

+710
-194
lines changed

src/cdm/TableStateInterface.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { ColumnOrderState, SortingState } from "@tanstack/react-table";
1+
import { SortingState } from "@tanstack/react-table";
22
import { ConfigColumn, RowDataType, TableColumn } from "cdm/FolderModel";
33
import { FilterSettings, GlobalSettings, LocalSettings } from "cdm/SettingsModel";
44
import { DatabaseView } from "DatabaseView";
5-
import { Link, Literal } from "obsidian-dataview";
5+
import { Literal } from "obsidian-dataview";
66
import { StoreApi, UseBoundStore } from "zustand";
77

88
export type TableActionResponse<T> = {
@@ -19,17 +19,24 @@ export type TableAction<T> = {
1919
/**
2020
* TABLE STATE INTERFACE
2121
*/
22+
export type EphimeralSettings = {
23+
enable_columns_filter: boolean,
24+
}
25+
2226
export interface ConfigState {
2327
ddbbConfig: LocalSettings;
2428
filters: FilterSettings;
2529
global: GlobalSettings;
30+
ephimeral: EphimeralSettings;
2631
actions: {
2732
alterFilters: (filters: Partial<FilterSettings>) => Promise<void>;
2833
alterConfig: (config: Partial<LocalSettings>) => void;
34+
alterEphimeral: (ephimeral: Partial<EphimeralSettings>) => Promise<void>;
2935
}
3036
info: {
3137
getLocalSettings: () => LocalSettings;
3238
getFilters: () => FilterSettings;
39+
getEphimeralSettings: () => EphimeralSettings;
3340
}
3441
}
3542

src/components/Columns.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import { DataviewService } from "services/DataviewService";
1616
import { Literal } from "obsidian-dataview/lib/data-model/value";
1717
import { DatabaseView } from "DatabaseView";
1818
import { obtainAllPossibleRows } from "helpers/VaultManagement";
19-
import rowContextMenuColumn from "components/RowContextMenu";
19+
import rowContextMenuColumn from "components/contextMenu/RowContextMenu";
2020
import { containsUpper } from "helpers/WindowElement";
21+
import { getFilterKeyInFunctionOfInputType } from "helpers/TableFiltersHelper";
2122

2223
/**
2324
* Add mandatory and configured metadata columns of the table
@@ -88,7 +89,6 @@ export async function obtainMetadataColumns(
8889
...MetadataDatabaseColumns.ADD_COLUMN,
8990
position: DatabaseLimits.MAX_COLUMNS + 1,
9091
};
91-
9292
return yamlColumns;
9393
}
9494

@@ -235,8 +235,7 @@ function columnOptions(
235235
LOGGER.debug(`=> columnOptions. column: ${JSON.stringify(column)}`);
236236
const options: RowSelectOption[] = column.options ?? [];
237237
if ((Object.values(InputType) as Array<string>).includes(column.input)) {
238-
LOGGER.debug(`<= columnOptions`, `return ${column.input} column`);
239-
return {
238+
const columnOption = {
240239
...(column as Partial<TableColumn>),
241240
position: column.position ?? index,
242241
key: column.key ?? columnKey,
@@ -248,6 +247,10 @@ function columnOptions(
248247
options: options,
249248
config: column.config,
250249
};
250+
// Custom react-table attributes
251+
columnOption["filterFn"] = getFilterKeyInFunctionOfInputType(column.input);
252+
LOGGER.debug(`<= columnOptions`, `return ${column.input} column`);
253+
return columnOption;
251254
} else {
252255
throw `Error: option ${column.input} not supported yet`;
253256
}

src/components/DefaultHeader.tsx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ import CodeIcon from "components/img/CodeIcon";
1717
import RelationBidirectionalIcon from "components/img/RelationBidirectionalIcon";
1818
import RollupIcon from "components/img/RollupIcon";
1919
import { AddColumnModal } from "components/modals/newColumn/addColumnModal";
20+
import {
21+
BaseFilter,
22+
BooleanFilter,
23+
DateRangeFilter,
24+
NumberFilter,
25+
TextFilter,
26+
} from "components/reducers/ColumnFilters";
2027
import { InputType, MetadataColumns } from "helpers/Constants";
2128
import { LOGGER } from "services/Logger";
2229
import { DatabaseHeaderProps, TableColumn } from "cdm/FolderModel";
23-
import ReactDOM from "react-dom";
2430
import { c } from "helpers/StylesHelper";
2531
import { AddColumnModalProps } from "cdm/ModalsModel";
2632

@@ -40,6 +46,10 @@ export default function DefaultHeader(headerProps: DatabaseHeaderProps) {
4046
state.actions,
4147
]);
4248

49+
const areColumnsFilterable = tableState.configState(
50+
(state) => state.ephimeral.enable_columns_filter
51+
);
52+
4353
const configInfo = tableState.configState((state) => state.info);
4454

4555
/** Column values */
@@ -50,9 +60,11 @@ export default function DefaultHeader(headerProps: DatabaseHeaderProps) {
5060
const [labelState, setLabelState] = useState(label);
5161

5262
let propertyIcon: JSX.Element;
63+
let columnSearch = <TextFilter {...headerProps} />;
5364
switch (input) {
5465
case InputType.NUMBER:
5566
propertyIcon = <HashIcon />;
67+
columnSearch = <NumberFilter {...headerProps} />;
5668
break;
5769
case InputType.TEXT:
5870
propertyIcon = <TextIcon />;
@@ -62,38 +74,48 @@ export default function DefaultHeader(headerProps: DatabaseHeaderProps) {
6274
break;
6375
case InputType.CALENDAR:
6476
propertyIcon = <CalendarIcon />;
77+
columnSearch = <DateRangeFilter {...headerProps} />;
6578
break;
6679
case InputType.CALENDAR_TIME:
6780
case InputType.METATADA_TIME:
6881
propertyIcon = <CalendarTimeIcon />;
82+
columnSearch = <DateRangeFilter {...headerProps} />;
6983
break;
7084
case InputType.MARKDOWN:
7185
propertyIcon = <MarkdownObsidian />;
86+
columnSearch = <BaseFilter {...headerProps} />;
7287
break;
7388
case InputType.TAGS:
7489
propertyIcon = <TagsIcon />;
7590
break;
7691
case InputType.INLINKS:
7792
propertyIcon = <IncomingLinkIcon />;
93+
columnSearch = <BaseFilter {...headerProps} />;
7894
break;
7995
case InputType.OUTLINKS:
8096
propertyIcon = <OutlinkIcon />;
97+
columnSearch = <BaseFilter {...headerProps} />;
8198
break;
8299
case InputType.TASK:
100+
propertyIcon = <TaskIcon />;
101+
columnSearch = <BaseFilter {...headerProps} />;
102+
break;
83103
case InputType.CHECKBOX:
84104
propertyIcon = <TaskIcon />;
105+
columnSearch = <BooleanFilter {...headerProps} />;
85106
break;
86107
case InputType.FORMULA:
87108
propertyIcon = <CodeIcon />;
88109
break;
89110
case InputType.RELATION:
90111
propertyIcon = <RelationBidirectionalIcon />;
112+
columnSearch = <BaseFilter {...headerProps} />;
91113
break;
92114
case InputType.ROLLUP:
93115
propertyIcon = <RollupIcon />;
94116
break;
95117
default:
96-
break;
118+
// Do nothing
97119
}
98120

99121
function handlerAddColumnToLeft() {
@@ -141,6 +163,9 @@ export default function DefaultHeader(headerProps: DatabaseHeaderProps) {
141163
</span>
142164
)}
143165
</div>
166+
{/** Header Filter */}
167+
{areColumnsFilterable && columnSearch}
168+
{/** Header Menu Popper */}
144169
<HeaderMenu
145170
headerProps={headerProps}
146171
propertyIcon={propertyIcon}

src/components/RowContextMenu.tsx

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

0 commit comments

Comments
 (0)