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

Commit 94d4558

Browse files
committed
Merge branch 'feature/improved_filters'
2 parents b1dcf37 + 30f787b commit 94d4558

35 files changed

+469
-359
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/cdm/ComponentsModel.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,4 @@ export type EditorCellComponentProps = {
2828
export type RelationEditorComponentProps = {
2929
persistChange: (newPath: string[]) => void;
3030
relationCell: Link[];
31-
} & CellComponentProps;
32-
33-
export type DataviewFiltersProps = {
34-
table: Table<RowDataType>;
35-
};
36-
export type AtomicFilterComponentProps = {
37-
recursiveIndex: number[];
38-
level: number;
39-
atomicFilter: AtomicFilter;
40-
possibleColumns: ColumnFilterOption[];
41-
} & DataviewFiltersProps;
42-
43-
export type ColumnFilterOption = {
44-
key: string;
45-
enabled: boolean;
46-
type: string;
47-
}
48-
49-
export type GroupFilterComponentProps = {
50-
group: FilterGroup;
51-
recursiveIndex: number[];
52-
level: number;
53-
table: Table<RowDataType>;
54-
possibleColumns: ColumnFilterOption[];
55-
};
31+
} & CellComponentProps;

src/cdm/FolderModel.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ export interface DatabaseHeaderProps {
115115
table: Table<RowDataType>
116116
}
117117

118+
export type ColumnFilterProps = Pick<DatabaseHeaderProps, 'column'>;
119+
118120
export type RelationshipProps = {
119121
option: ColumnOption
120122
view: CustomView,

src/cdm/ModalsModel.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ import { RowDataType, TableColumn } from "cdm/FolderModel";
22
import { AutomationState, ColumnsState, ConfigState, DataState, RowTemplateState } from "cdm/TableStateInterface";
33
import { ColumnSettingsManager } from "components/modals/columnSettings/ColumnSettingsModal";
44
import { AddColumnModalManager } from "components/modals/newColumn/addColumnModal";
5-
import { FiltersModalManager } from "components/modals/filters/FiltersModal";
65
import { Table } from "@tanstack/react-table";
76
import { AddRowModalManager } from "components/modals/addRow/AddRowModal";
87
import { CustomView } from "views/AbstractView";
98

109
/**
1110
* Base class for all modal responses.
1211
*/
13-
type BaseModalHandlerResponse = {
12+
export type BaseModalHandlerResponse = {
1413
containerEl: HTMLElement;
1514
};
1615

@@ -71,17 +70,4 @@ export type AddRowModalProps = {
7170
configState: Pick<ConfigState, "info" | "actions">
7271
view: CustomView,
7372
table: Table<RowDataType>
74-
}
75-
76-
/***************************************
77-
* FILTERS MODAL
78-
***************************************/
79-
80-
/** Filters Modal */
81-
export type FiltersModalProps = {
82-
table: Table<RowDataType>,
83-
possibleColumns: string[]
84-
}
85-
export type FiltersModalHandlerResponse = {
86-
filtersModalManager: FiltersModalManager
87-
} & BaseModalHandlerResponse;
73+
};

src/components/Columns.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { Literal } from "obsidian-dataview/lib/data-model/value";
1717
import { obtainAllPossibleRows } from "helpers/VaultManagement";
1818
import rowContextMenuColumn from "components/contextMenu/RowContextMenu";
1919
import { containsUpper } from "helpers/WindowElement";
20-
import { getFilterKeyInFunctionOfInputType } from "helpers/TableFiltersHelper";
20+
import ReactTableMapper from "lib/features/filters/mappers/ReactTableMapper";
2121

2222
/**
2323
* Add mandatory and configured metadata columns of the table
@@ -234,7 +234,9 @@ function columnOptions(
234234
config: column.config,
235235
};
236236
// Custom react-table attributes
237-
columnOption["filterFn"] = getFilterKeyInFunctionOfInputType(column.input);
237+
columnOption["filterFn"] = ReactTableMapper.inputTypeToFilterKey(
238+
column.input
239+
);
238240
return columnOption;
239241
} else {
240242
throw `Error: option ${column.input} not supported yet`;

src/components/modals/filters/handlers/DataviewFiltersComponent.tsx

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

src/components/reducers/ColumnFilters.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DatabaseHeaderProps } from "cdm/FolderModel";
1+
import { ColumnFilterProps, DatabaseHeaderProps } from "cdm/FolderModel";
22
import { DynamicDebouncedInput } from "components/behavior/DebouncedInputFn";
33
import DatePicker from "react-datepicker";
44
import React, { useState } from "react";
@@ -10,7 +10,7 @@ import { StyleVariables } from "helpers/Constants";
1010
* @param headerProps
1111
* @returns
1212
*/
13-
export function BaseFilter(headerProps: DatabaseHeaderProps) {
13+
export function BaseFilter(headerProps: ColumnFilterProps) {
1414
const { column } = headerProps;
1515

1616
return (
@@ -35,7 +35,7 @@ export function BaseFilter(headerProps: DatabaseHeaderProps) {
3535
* @param headerProps
3636
* @returns
3737
*/
38-
export function TextFilter(headerProps: DatabaseHeaderProps) {
38+
export function TextFilter(headerProps: ColumnFilterProps) {
3939
const { column } = headerProps;
4040

4141
const sortedUniqueValues = React.useMemo(
@@ -69,7 +69,7 @@ export function TextFilter(headerProps: DatabaseHeaderProps) {
6969
);
7070
}
7171

72-
export function NumberFilter(headerProps: DatabaseHeaderProps) {
72+
export function NumberFilter(headerProps: ColumnFilterProps) {
7373
const { column } = headerProps;
7474
const minRaw = Number(column.getFacetedMinMaxValues()?.[0] ?? undefined);
7575
const maxRaw = Number(column.getFacetedMinMaxValues()?.[1] ?? undefined);
@@ -131,7 +131,7 @@ export function NumberFilter(headerProps: DatabaseHeaderProps) {
131131
);
132132
}
133133

134-
export function DateRangeFilter(headerProps: DatabaseHeaderProps) {
134+
export function DateRangeFilter(headerProps: ColumnFilterProps) {
135135
const { column } = headerProps;
136136
const [startDate, setStartDate] = useState(null);
137137
const [endDate, setEndDate] = useState(null);
@@ -191,7 +191,7 @@ export function DateRangeFilter(headerProps: DatabaseHeaderProps) {
191191
);
192192
}
193193

194-
export function BooleanFilter(headerProps: DatabaseHeaderProps) {
194+
export function BooleanFilter(headerProps: ColumnFilterProps) {
195195
const { column } = headerProps;
196196
const [value, setValue] = useState<number | string>("All");
197197

src/components/reducers/DataviewFilters.tsx

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,56 @@
1-
import { DataviewFiltersProps } from "cdm/ComponentsModel";
1+
import { FiltersModal } from "@features/filters";
2+
import {
3+
ColumnFilterOption,
4+
TableFiltersProps,
5+
} from "@features/filters/model/FiltersModel";
26
import { obtainColumnsFromRows } from "components/Columns";
37
import MenuDownIcon from "components/img/MenuDownIcon";
4-
import { FiltersModal } from "components/modals/filters/FiltersModal";
5-
import { EMITTERS_GROUPS, EMITTERS_SHORTCUT } from "helpers/Constants";
8+
import {
9+
EMITTERS_GROUPS,
10+
EMITTERS_SHORTCUT,
11+
InputType,
12+
} from "helpers/Constants";
613
import { c } from "helpers/StylesHelper";
714
import React, { useEffect } from "react";
815

9-
export default function EditFiltersButton(props: DataviewFiltersProps) {
16+
export default function EditFiltersButton(props: TableFiltersProps) {
1017
const { table } = props;
1118
const { tableState, view } = table.options.meta;
1219
const [configInfo, filters] = tableState.configState((state) => [
1320
state.info,
1421
state.filters,
15-
state.actions,
1622
]);
1723
const columns = tableState.columns((state) => state.columns);
1824

19-
const openFiltersGroupHandler = async () => {
20-
new Promise<string[]>((resolve, reject) => {
21-
// Empty conditions to refresh the dataview
22-
const emptyFilterConditions = { ...filters };
23-
emptyFilterConditions.conditions = [];
24-
resolve(
25-
obtainColumnsFromRows(
26-
view.file.parent.path,
27-
configInfo.getLocalSettings(),
28-
emptyFilterConditions,
29-
columns
30-
)
25+
const obtainPossibleColumns = async (): Promise<ColumnFilterOption[]> => {
26+
const emptyFilterConditions = { ...filters };
27+
const allColumns = await obtainColumnsFromRows(
28+
view.file.parent.path,
29+
configInfo.getLocalSettings(),
30+
emptyFilterConditions,
31+
columns
32+
);
33+
34+
const columnOptions: ColumnFilterOption[] = [];
35+
allColumns.forEach((column) => {
36+
const possibleColumn = columns.find(
37+
(dbColumn) => dbColumn.key === column
3138
);
32-
}).then((columns) => {
33-
new FiltersModal({
34-
table,
35-
possibleColumns: columns.sort((a, b) => a.localeCompare(b)),
36-
}).open();
39+
40+
columnOptions.push({
41+
enabled: possibleColumn !== undefined,
42+
key: column,
43+
type: possibleColumn ? possibleColumn.input : InputType.TEXT,
44+
});
3745
});
46+
return columnOptions.sort((a, b) => a.key.localeCompare(b.key));
47+
};
48+
49+
const openFiltersGroupHandler = async () => {
50+
new FiltersModal({
51+
table,
52+
possibleColumns: await obtainPossibleColumns(),
53+
}).open();
3854
};
3955

4056
/**

0 commit comments

Comments
 (0)