Skip to content

Commit

Permalink
chore: clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
lawvs committed Jul 18, 2024
1 parent 896cc2b commit d2f8431
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
defaultOptions,
openFlattenFilterDialog,
type CreateAdvancedFilterProps,
} from "./create-advanced-filter.js";
import { EMPTY_ROOT_FILTER, defaultStorage } from "./utils.js";
} from "../create-advanced-filter.js";
import { EMPTY_ROOT_FILTER, defaultStorage } from "../utils.js";

export type UseAdvancedFilterProps<Data = unknown> =
CreateAdvancedFilterProps<Data>;
Expand Down
2 changes: 1 addition & 1 deletion packages/filter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export { createTheme } from "@mui/material/styles";
export { createAdvancedFilter } from "./create-advanced-filter.js";
export { FlattenFilterBuilder } from "./flatten-filter-builder.js";
export { FlattenFilterDialog } from "./flatten-filter-dialog.js";
export { useAdvancedFilter } from "./use-advanced-filter.js";
export { useAdvancedFilter } from "./hooks/use-advanced-filter.js";

export {
ThemeProvider as FilterThemeProvider,
Expand Down
12 changes: 9 additions & 3 deletions packages/filter/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {
FilterField,
FilterGroup,
FilterId,
FnSchema,
LooseFilterRule,
StandardFnSchema,
Expand All @@ -12,11 +12,11 @@ import type { ZodType } from "zod";
* @deprecated
*/
export type FlattenFilterGroup = {
id: FilterGroup["id"];
id: FilterId;
type: "FilterGroup";
op: "or";
conditions: {
id: FilterGroup["id"];
id: FilterId;
type: "FilterGroup";
op: "and";
conditions: LooseFilterRule[];
Expand All @@ -26,6 +26,12 @@ export type FlattenFilterGroup = {
export type BasicFilterProps<Data = unknown> = {
schema: ZodType<Data>;
filterList: FnSchema[];
/**
* The maximum nesting depth limit of the filter rule.
*
* @default 2
*/
// maxNestedDepth?: number;
/**
* The maximum depth of searching for filter fields.
*
Expand Down
3 changes: 2 additions & 1 deletion packages/filter/src/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const FilterGroupContainer = ({
// if (isRoot) {
// return children;
// }
const text = filterGroup.op === "or" ? "Or" : "And";
return (
<div
className="filter-builder-group-container"
Expand All @@ -27,7 +28,7 @@ export const FilterGroupContainer = ({
marginRight: 12,
}}
>
{filterGroup.op === "or" ? "Or" : "And"}
{text}
</div>
<div
style={{
Expand Down
1 change: 1 addition & 0 deletions packages/filter/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export const fromFilterMap = (
result.conditions = root.conditionIds.map((id) => {
const item = map[id];
if (!item) {
console.error("Invalid condition ID", id, map, rootKey);
throw new Error("Invalid condition ID");
}
if (item.type === "Filter") {
Expand Down

0 comments on commit d2f8431

Please sign in to comment.