Skip to content

Commit

Permalink
fix(QueryBuilder): export types and defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
HQFOX committed Oct 19, 2023
1 parent 146af80 commit 29cb9fa
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 71 deletions.
6 changes: 6 additions & 0 deletions docs/overview/migration/MigrationV5.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Here's what there is to know about this migration:
- [Time Picker](#time-picker)
- [Table Renderer - Expand Column](#table-renderer-expand-column)
- [Drawer](#drawer)
- [Query Builder](#query-builder)

## React packages <a id="react-packages" />

Expand Down Expand Up @@ -785,3 +786,8 @@ this prop was deprecated by the underlining component from material ui and you s
- The deprecated props `hours`, `minutes`, and `seconds` were removed.
- Users should now use either `defaultValue` or `value` to set the time, in an uncontrolled or controlled way respectively (which follows the `HvTimePickerValue` type).
- The `HvTimePickerValue` no longer has the `period` property, as it uses the 24-hour format for consistency

### Query Builder <a id="query-builder" />

- All of the types exported from this component now have the `HvQueryBuilder` prefix. (e.g. the type: `Attribute` is now `HvQueryBuilderAttribute`).
- The default values from this component have also change to have a `hvQueryBuilder` prefix. (e.g. `defaultLabels` is now `hvQuerybuilderDefaultLabels`)
22 changes: 12 additions & 10 deletions packages/core/src/components/QueryBuilder/Context.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createContext } from "react";
import {
AskAction,
Attribute,
QueryAction,
HvQueryBuilderAskAction,
HvQueryBuilderAttribute,
HvQueryBuilderQueryAction,
QueryBuilderLabels,
QueryCombinator,
QueryOperator,
HvQueryBuilderQueryCombinator,
HvQueryBuilderQueryOperator,
} from "./types";

export const defaultOperators = {
Expand Down Expand Up @@ -311,12 +311,14 @@ export const defaultLabels = {
};

interface QueryBuilderContextValue {
dispatchAction: React.Dispatch<QueryAction>;
askAction: React.Dispatch<React.SetStateAction<AskAction | undefined>>;
dispatchAction: React.Dispatch<HvQueryBuilderQueryAction>;
askAction: React.Dispatch<
React.SetStateAction<HvQueryBuilderAskAction | undefined>
>;
selectLocation?: React.Dispatch<unknown>;
attributes?: Record<string, Attribute>;
operators: Record<string, QueryOperator[]>;
combinators: QueryCombinator[];
attributes?: Record<string, HvQueryBuilderAttribute>;
operators: Record<string, HvQueryBuilderQueryOperator[]>;
combinators: HvQueryBuilderQueryCombinator[];
maxDepth: number;
labels: QueryBuilderLabels;
initialTouched: boolean;
Expand Down
30 changes: 15 additions & 15 deletions packages/core/src/components/QueryBuilder/QueryBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import { ConfirmationDialog } from "./ConfirmationDialog";
import { QueryBuilderContext } from "./Context";
import { RuleGroup } from "./RuleGroup";
import {
AskAction,
Attribute,
Query,
QueryBuilderLabels,
QueryCombinator,
QueryOperator,
HvQueryBuilderAskAction,
HvQueryBuilderAttribute,
HvQueryBuilderQuery,
HvQueryBuilderLabels,
HvQueryBuilderQueryCombinator,
HvQueryBuilderQueryOperator,
} from "./types";
import { clearNodeIds, emptyGroup } from "./utils";
import reducer from "./utils/reducer";
Expand All @@ -33,32 +33,32 @@ export { staticClasses as queryBuilderClasses };
export type HvQueryBuilderClasses = ExtractNames<typeof useClasses>;

export interface HvQueryBuilderProps {
attributes?: Record<string, Attribute>;
attributes?: Record<string, HvQueryBuilderAttribute>;
/**
* The query rules operators by attribute type and combinator.
*/
operators?: Record<string, QueryOperator[]>;
operators?: Record<string, HvQueryBuilderQueryOperator[]>;
/**
* The query combinators operands.
*/
combinators?: QueryCombinator[];
combinators?: HvQueryBuilderQueryCombinator[];
/**
* The initial query representation.
*/
query?: Query;
query?: HvQueryBuilderQuery;
/**
* Callback fired when query changes.
* @param {Query} value - the query representation.
* @param {HvQueryBuilderQuery} value - the query representation.
*/
onChange?: (value: Query) => void;
onChange?: (value: HvQueryBuilderQuery) => void;
/**
* Max depth of nested query groups.
*/
maxDepth?: number;
/**
* An object containing all the labels.
*/
labels?: QueryBuilderLabels;
labels?: HvQueryBuilderLabels;
/**
* A flag indicating if the Query Builder is in read only mode.
*/
Expand Down Expand Up @@ -88,9 +88,9 @@ export const HvQueryBuilder = (props: HvQueryBuilderProps) => {
} = useDefaultProps("HvQueryBuilder", props);
const { classes } = useClasses(classesProp);

const [pendingAction, askAction] = useState<AskAction>();
const [pendingAction, askAction] = useState<HvQueryBuilderAskAction>();
const currentAttributes = useRef<
Record<string, Attribute> | undefined | null
Record<string, HvQueryBuilderAttribute> | undefined | null
>(null);
const [state, dispatchAction] = useReducer(
reducer,
Expand Down
9 changes: 6 additions & 3 deletions packages/core/src/components/QueryBuilder/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export * from "./QueryBuilder";
export * from "./ConfirmationDialog";
export * from "./Rule";
export * from "./RuleGroup";
export {
defaultCombinators as hvQuerybuilderDefaultCombinators,
defaultLabels as hvQuerybuilderDefaultLabels,
defaultOperators as hvQuerybuilderDefaultOperators,
} from "./Context";
export * from "./types";
86 changes: 43 additions & 43 deletions packages/core/src/components/QueryBuilder/types.ts
Original file line number Diff line number Diff line change
@@ -1,123 +1,123 @@
export interface Attribute extends Record<string, unknown> {
export interface HvQueryBuilderAttribute extends Record<string, unknown> {
id?: string;
label: string;
type: string;
value?: unknown;
order?: number;
}

export interface NumericRange {
export interface HvQueryBuilderNumericRange {
from: number | string;
to: number | string;
}

export interface DateTimeStrings {
export interface HvQueryBuilderDateTimeStrings {
date?: string;
time?: string;
}

export interface DateTimeRange {
start?: DateTimeStrings;
end?: DateTimeStrings;
export interface HvQueryBuilderDateTimeRange {
start?: HvQueryBuilderDateTimeStrings;
end?: HvQueryBuilderDateTimeStrings;
}

export type QueryRuleValue =
export type HvQueryBuilderQueryRuleValue =
| string
| number
| boolean
| NumericRange
| DateTimeStrings
| DateTimeRange;
| HvQueryBuilderNumericRange
| HvQueryBuilderDateTimeStrings
| HvQueryBuilderDateTimeRange;

export interface QueryRule {
export interface HvQueryBuilderQueryRule {
id?: number | string;
attribute?: string;
operator?: string;
value?: QueryRuleValue;
value?: HvQueryBuilderQueryRuleValue;
}

export interface Query {
export interface HvQueryBuilderQuery {
id?: number;
combinator: string;
rules: Array<QueryRule>;
rules: Array<HvQueryBuilderQueryRule>;
}

export interface QueryCombinator {
export interface HvQueryBuilderQueryCombinator {
operand: string;
label: string;
}

export interface QueryOperator {
export interface HvQueryBuilderQueryOperator {
operator: string;
label: string;
combinators: string[];
}

interface DialogLabels {
interface HvQueryBuilderDialogLabels {
dialogTitle: string;
dialogMessage: string;
dialogConfirm: string;
dialogCancel: string;
dialogCloseTooltip: string;
}

interface ResetQueryAction {
interface HvQueryBuilderResetQueryAction {
type: "reset-query";
}

interface ResetGroupAction {
interface HvQueryBuilderResetGroupAction {
type: "reset-group";
id?: number;
}

interface AddRemoveAction {
interface HvQueryBuilderAddRemoveAction {
type: "add-rule" | "add-group" | "remove-node";
id?: number;
}

interface SetCombinatorAction {
interface HvQueryBuilderSetCombinatorAction {
type: "set-combinator";
id?: number;

combinator: string;
}

interface SetAttributeAction {
interface HvQueryBuilderSetAttributeAction {
type: "set-attribute";
id?: number;

attribute?: string | null;
operator?: string | null;
value?: QueryRuleValue | null;
value?: HvQueryBuilderQueryRuleValue | null;
}

interface SetOperatorAction {
interface HvQueryBuilderSetOperatorAction {
type: "set-operator";
id?: number;

operator: string | null;
value?: QueryRuleValue | null;
value?: HvQueryBuilderQueryRuleValue | null;
}

interface SetValueAction {
interface HvQueryBuilderSetValueAction {
type: "set-value";
id?: number;

value: QueryRuleValue | null;
value: HvQueryBuilderQueryRuleValue | null;
}

export type QueryAction =
| ResetQueryAction
| ResetGroupAction
| AddRemoveAction
| SetCombinatorAction
| SetAttributeAction
| SetOperatorAction
| SetValueAction;
export type HvQueryBuilderQueryAction =
| HvQueryBuilderResetQueryAction
| HvQueryBuilderResetGroupAction
| HvQueryBuilderAddRemoveAction
| HvQueryBuilderSetCombinatorAction
| HvQueryBuilderSetAttributeAction
| HvQueryBuilderSetOperatorAction
| HvQueryBuilderSetValueAction;

export interface AskAction {
actions: QueryAction[];
dialog: DialogLabels;
export interface HvQueryBuilderAskAction {
actions: HvQueryBuilderQueryAction[];
dialog: HvQueryBuilderDialogLabels;
}

export interface ValueComponentProps {
Expand All @@ -126,12 +126,12 @@ export interface ValueComponentProps {
value?: unknown;
}

export interface QueryBuilderLabels {
export interface HvQueryBuilderLabels {
query?: {
delete?: {
ariaLabel: string;
tooltip?: string;
} & DialogLabels;
} & HvQueryBuilderDialogLabels;
addRule?: {
label: string;
};
Expand Down Expand Up @@ -208,17 +208,17 @@ export interface QueryBuilderLabels {
delete: {
ariaLabel: string;
tooltip?: string;
} & DialogLabels;
} & HvQueryBuilderDialogLabels;
};
group: {
delete: {
ariaLabel: string;
tooltip?: string;
} & DialogLabels;
} & HvQueryBuilderDialogLabels;
reset: {
ariaLabel: string;
tooltip?: string;
} & DialogLabels;
} & HvQueryBuilderDialogLabels;
addRule: {
label: string;
};
Expand Down

0 comments on commit 29cb9fa

Please sign in to comment.