@commercelayer/app-elements 0.0.78 → 0.0.79
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Async-163e6f77.js → Async-2e9c3da2.js} +5 -3
- package/dist/{InputDateComponent-6853e317.js → InputDateComponent-fe3ffd00.js} +4 -2
- package/dist/{Select-a7b98c9a.js → Select-be90391b.js} +5 -3
- package/dist/helpers/appsNavigation.d.ts +1 -0
- package/dist/hooks/useOverlayNavigation.d.ts +1 -0
- package/dist/{main-740e7f02.js → main-bd408fbe.js} +12557 -11009
- package/dist/main.d.ts +18 -0
- package/dist/main.js +151 -127
- package/dist/{overrides-f9354b78.js → overrides-684ed062.js} +2 -2
- package/dist/providers/TokenProvider/MockTokenProvider.d.ts +1 -0
- package/dist/style.css +1 -1
- package/dist/ui/atoms/A.d.ts +1 -0
- package/dist/ui/atoms/Avatar.d.ts +1 -0
- package/dist/ui/atoms/AvatarLetter.d.ts +1 -0
- package/dist/ui/atoms/BlockCode.d.ts +1 -0
- package/dist/ui/atoms/ButtonFilter.d.ts +1 -0
- package/dist/ui/atoms/Card.d.ts +2 -0
- package/dist/ui/atoms/Container.d.ts +1 -0
- package/dist/ui/atoms/CopyToClipboard.d.ts +1 -0
- package/dist/ui/atoms/Hr.d.ts +1 -0
- package/dist/ui/atoms/Icon.d.ts +1 -0
- package/dist/ui/atoms/Pagination.d.ts +1 -0
- package/dist/ui/atoms/Progress.d.ts +1 -0
- package/dist/ui/atoms/StatusDot.d.ts +1 -0
- package/dist/ui/atoms/Steps.d.ts +1 -0
- package/dist/ui/atoms/dropdown/DropdownMenu.d.ts +1 -0
- package/dist/ui/atoms/dropdown/DropdownMenuDivider.d.ts +1 -0
- package/dist/ui/atoms/dropdown/DropdownMenuItem.d.ts +1 -0
- package/dist/ui/atoms/tables/Td.d.ts +1 -0
- package/dist/ui/atoms/tables/Th.d.ts +1 -0
- package/dist/ui/atoms/tables/Tr.d.ts +1 -0
- package/dist/ui/composite/ContextMenu.d.ts +1 -0
- package/dist/ui/composite/PageError.d.ts +1 -0
- package/dist/ui/composite/PageSkeleton.d.ts +1 -0
- package/dist/ui/composite/SearchBar.d.ts +1 -0
- package/dist/ui/forms/Input.d.ts +1 -0
- package/dist/ui/forms/InputCheckbox.d.ts +1 -0
- package/dist/ui/forms/InputCurrency/index.d.ts +1 -0
- package/dist/ui/forms/InputCurrencyRange.d.ts +1 -0
- package/dist/ui/forms/InputDate/InputDateComponent.d.ts +1 -0
- package/dist/ui/forms/InputDate/index.d.ts +1 -0
- package/dist/ui/forms/InputDateRange.d.ts +1 -0
- package/dist/ui/forms/InputFeedback.d.ts +1 -0
- package/dist/ui/forms/InputFile.d.ts +1 -0
- package/dist/ui/forms/InputJson.d.ts +1 -0
- package/dist/ui/forms/InputReadonly.d.ts +1 -0
- package/dist/ui/forms/InputSelect/Async.d.ts +1 -0
- package/dist/ui/forms/InputSelect/Select.d.ts +1 -0
- package/dist/ui/forms/InputSelect/overrides.d.ts +1 -0
- package/dist/ui/forms/InputSpinner.d.ts +1 -0
- package/dist/ui/forms/InputTextArea.d.ts +1 -0
- package/dist/ui/forms/InputToggleBox.d.ts +1 -0
- package/dist/ui/forms/InputToggleListBox.d.ts +1 -0
- package/dist/ui/forms/Label.d.ts +1 -0
- package/dist/ui/forms/ToggleButtons.d.ts +1 -0
- package/dist/ui/hook-form/HookedForm.d.ts +34 -0
- package/dist/ui/hook-form/HookedInput.d.ts +17 -0
- package/dist/ui/hook-form/HookedInputCheckbox.d.ts +17 -0
- package/dist/ui/hook-form/HookedInputCurrency.d.ts +18 -0
- package/dist/ui/hook-form/HookedInputDate.d.ts +18 -0
- package/dist/ui/hook-form/HookedInputDateRange.d.ts +19 -0
- package/dist/ui/hook-form/HookedInputMetadata.d.ts +19 -0
- package/dist/ui/hook-form/HookedInputSelect.d.ts +34 -0
- package/dist/ui/hook-form/HookedInputSpinner.d.ts +17 -0
- package/dist/ui/hook-form/HookedInputToggleBox.d.ts +21 -0
- package/dist/ui/hook-form/HookedInputToggleListBox.d.ts +21 -0
- package/dist/ui/hook-form/HookedRelationshipSelector.d.ts +18 -0
- package/dist/ui/hook-form/HookedToggleButtons.d.ts +18 -0
- package/dist/ui/hook-form/HookedValidationApiError.d.ts +22 -0
- package/dist/ui/hook-form/HookedValidationError.d.ts +12 -0
- package/dist/ui/hook-form/setApiFormErrors.d.ts +19 -0
- package/dist/ui/hook-form/setApiFormErrors.test.d.ts +1 -0
- package/dist/ui/hook-form/useValidationFeedback.d.ts +4 -0
- package/dist/ui/internals/InputWrapper.d.ts +1 -0
- package/dist/ui/resources/Filters/FieldCurrencyRange.d.ts +7 -0
- package/dist/ui/resources/Filters/FieldItem.d.ts +7 -0
- package/dist/ui/resources/Filters/FieldTimeRange.d.ts +7 -0
- package/dist/ui/resources/Filters/FiltersForm.d.ts +17 -0
- package/dist/ui/resources/Filters/FiltersNav.d.ts +25 -0
- package/dist/ui/resources/Filters/FiltersSearchBar.d.ts +28 -0
- package/dist/ui/resources/Filters/adaptFormValuesToSdk.d.ts +19 -0
- package/dist/ui/resources/Filters/adaptFormValuesToSdk.test.d.ts +1 -0
- package/dist/ui/resources/Filters/adaptFormValuesToUrlQuery.d.ts +11 -0
- package/dist/ui/resources/Filters/adaptFormValuesToUrlQuery.test.d.ts +1 -0
- package/dist/ui/resources/Filters/adaptUrlQueryToFormValues.d.ts +11 -0
- package/dist/ui/resources/Filters/adaptUrlQueryToFormValues.test.d.ts +1 -0
- package/dist/ui/resources/Filters/adaptUrlQueryToSdk.d.ts +14 -0
- package/dist/ui/resources/Filters/adaptUrlQueryToSdk.test.d.ts +1 -0
- package/dist/ui/resources/Filters/adaptUrlQueryToUrlQuery.d.ts +11 -0
- package/dist/ui/resources/Filters/adaptUrlQueryToUrlQuery.test.d.ts +1 -0
- package/dist/ui/resources/Filters/adapters.d.ts +2 -0
- package/dist/ui/resources/Filters/adapters.types.d.ts +20 -0
- package/dist/ui/resources/Filters/index.d.ts +5 -0
- package/dist/ui/resources/Filters/mockedInstructions.d.ts +2 -0
- package/dist/ui/resources/Filters/timeUtils.d.ts +36 -0
- package/dist/ui/resources/Filters/timeUtils.test.d.ts +1 -0
- package/dist/ui/resources/Filters/types.d.ts +130 -0
- package/dist/ui/resources/Filters/useFilters.d.ts +59 -0
- package/dist/ui/resources/Filters/utils.d.ts +29 -0
- package/dist/ui/resources/Filters/utils.test.d.ts +1 -0
- package/dist/ui/resources/OrderSummary.d.ts +1 -0
- package/dist/ui/resources/RelationshipSelector/Checkbox.d.ts +1 -0
- package/dist/ui/resources/RelationshipSelector/FullList.d.ts +1 -0
- package/dist/ui/resources/RelationshipSelector/index.d.ts +1 -0
- package/dist/ui/resources/ResourceList/utils.d.ts +1 -0
- package/dist/ui/tables/TableData.d.ts +1 -0
- package/dist/{unsupportedIterableToArray-1a2db0a9.js → unsupportedIterableToArray-a4407b22.js} +1 -1
- package/dist/utils/htmltags.d.ts +1 -0
- package/package.json +8 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { type FilterItemCurrencyRange } from './types';
|
|
3
|
+
interface FieldCurrencyRangeProps {
|
|
4
|
+
item: FilterItemCurrencyRange;
|
|
5
|
+
}
|
|
6
|
+
export declare function FieldCurrencyRange({ item }: FieldCurrencyRangeProps): JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { type FilterItemOptions, type FilterItemTextSearch } from './types';
|
|
3
|
+
interface FieldProps {
|
|
4
|
+
item: FilterItemOptions | FilterItemTextSearch;
|
|
5
|
+
}
|
|
6
|
+
export declare function FieldItem({ item }: FieldProps): JSX.Element | null;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { FiltersInstructions } from './types';
|
|
3
|
+
export interface FiltersFormProps {
|
|
4
|
+
/**
|
|
5
|
+
* Array of instruction items to build the filters behaviors
|
|
6
|
+
*/
|
|
7
|
+
instructions: FiltersInstructions;
|
|
8
|
+
/**
|
|
9
|
+
* New queryString generated on submit to be used to navigate to the listing page
|
|
10
|
+
*/
|
|
11
|
+
onSubmit: (queryString: string) => void;
|
|
12
|
+
}
|
|
13
|
+
declare function FiltersForm({ instructions, onSubmit }: FiltersFormProps): JSX.Element;
|
|
14
|
+
declare namespace FiltersForm {
|
|
15
|
+
var displayName: string;
|
|
16
|
+
}
|
|
17
|
+
export { FiltersForm };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { type FiltersInstructions } from './types';
|
|
3
|
+
export interface FiltersNavProps {
|
|
4
|
+
/**
|
|
5
|
+
* Array of instruction items to build the filters behaviors
|
|
6
|
+
*/
|
|
7
|
+
instructions: FiltersInstructions;
|
|
8
|
+
/**
|
|
9
|
+
* Url query string to be parsed.
|
|
10
|
+
* It must be "reactive", so most of the time it should come for router.
|
|
11
|
+
*/
|
|
12
|
+
queryString: string;
|
|
13
|
+
/**
|
|
14
|
+
* Callback function triggered when user interacts with the filters buttons.
|
|
15
|
+
* Implemented function should update the url query string / search params,
|
|
16
|
+
* based on the new queryString received as argument.
|
|
17
|
+
*/
|
|
18
|
+
onUpdate: (newQueryString: string) => void;
|
|
19
|
+
/**
|
|
20
|
+
* Callback function triggered when user clicks on the "Edit filters" button.
|
|
21
|
+
* Implemented function should open the filters form.
|
|
22
|
+
*/
|
|
23
|
+
onFilterClick: (queryString: string, filterPredicate?: string) => void;
|
|
24
|
+
}
|
|
25
|
+
export declare function FiltersNav({ instructions, onFilterClick: onBtnLabelClick, onUpdate, queryString }: FiltersNavProps): JSX.Element;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { type FiltersInstructions } from './types';
|
|
3
|
+
export interface FilterSearchBarProps {
|
|
4
|
+
/**
|
|
5
|
+
* Array of instruction items to build the filters behaviors
|
|
6
|
+
*/
|
|
7
|
+
instructions: FiltersInstructions;
|
|
8
|
+
/**
|
|
9
|
+
* Callback function triggered when user interacts with the search input.
|
|
10
|
+
* Implemented function should update the url query string / search params,
|
|
11
|
+
* based on the new queryString received as argument.
|
|
12
|
+
*/
|
|
13
|
+
onUpdate: (queryString: string) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Url query string to be parsed.
|
|
16
|
+
* It must be "reactive", so most of the time it should come for router.
|
|
17
|
+
*/
|
|
18
|
+
queryString: string;
|
|
19
|
+
/**
|
|
20
|
+
* Input placeholder
|
|
21
|
+
*/
|
|
22
|
+
placeholder?: string;
|
|
23
|
+
}
|
|
24
|
+
declare function FiltersSearchBar({ instructions, placeholder, onUpdate, queryString }: FilterSearchBarProps): JSX.Element;
|
|
25
|
+
declare namespace FiltersSearchBar {
|
|
26
|
+
var displayName: string;
|
|
27
|
+
}
|
|
28
|
+
export { FiltersSearchBar };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type QueryFilter } from '@commercelayer/sdk/lib/cjs/query';
|
|
2
|
+
import { type CurrencyRangeFieldValue, type FiltersInstructions, type UiFilterName, type UiFilterValue } from './types';
|
|
3
|
+
export interface AdaptFormValuesToSdkParams<FilterFormValues> {
|
|
4
|
+
formValues: FilterFormValues;
|
|
5
|
+
timezone?: string;
|
|
6
|
+
instructions: FiltersInstructions;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Covert FilterFormValues in SDK filter object
|
|
10
|
+
* @param formValues a valid FilterFormValues object
|
|
11
|
+
* @returns an object of type QueryFilter to be used in the SDK stripping out empty or undefined values
|
|
12
|
+
*/
|
|
13
|
+
export declare function adaptFormValuesToSdk<FilterFormValues extends Record<UiFilterName, UiFilterValue | CurrencyRangeFieldValue>>({ formValues, instructions, timezone }: AdaptFormValuesToSdkParams<FilterFormValues>): QueryFilter;
|
|
14
|
+
export declare function extractEnforcedValues(instructions: FiltersInstructions): QueryFilter;
|
|
15
|
+
/**
|
|
16
|
+
* Be sure to have all the default values
|
|
17
|
+
* to prevent listing draft or pending orders
|
|
18
|
+
*/
|
|
19
|
+
export declare function enforceDefaultFiltersWhenEmpty(filters: QueryFilter, enforcedValues: QueryFilter): QueryFilter;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type FiltersInstructions, type FormFullValues } from './types';
|
|
2
|
+
export interface AdaptFormValuesToUrlQueryParams<FilterFormValues extends FormFullValues> {
|
|
3
|
+
formValues: FilterFormValues;
|
|
4
|
+
instructions: FiltersInstructions;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Covert FilterFormValues in url query string
|
|
8
|
+
* @param formValues a valid FilterFormValues object
|
|
9
|
+
* @returns a string ready to be used in URL
|
|
10
|
+
*/
|
|
11
|
+
export declare function adaptFormValuesToUrlQuery<FilterFormValues extends FormFullValues>({ formValues, instructions }: AdaptFormValuesToUrlQueryParams<FilterFormValues>): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type FiltersInstructions, type FormFullValues, type UiFilterName, type UiFilterValue } from './types';
|
|
2
|
+
export interface AdaptUrlQueryToFormValuesParams {
|
|
3
|
+
queryString: string;
|
|
4
|
+
instructions: FiltersInstructions;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Covert query string in filters form values
|
|
8
|
+
* @param qs url query string
|
|
9
|
+
* @returns an object containing FilterFormValues
|
|
10
|
+
*/
|
|
11
|
+
export declare function adaptUrlQueryToFormValues<FilterFormValues extends Record<UiFilterName, UiFilterValue>>({ queryString, instructions }: AdaptUrlQueryToFormValuesParams): FilterFormValues & FormFullValues;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type QueryFilter } from '@commercelayer/sdk/lib/cjs/query';
|
|
2
|
+
import { type FiltersInstructions } from './types';
|
|
3
|
+
export interface AdaptUrlQueryToSdkParams {
|
|
4
|
+
queryString: string;
|
|
5
|
+
instructions: FiltersInstructions;
|
|
6
|
+
timezone?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Covert URL query string in SDK filter object
|
|
10
|
+
* @param qs url query string
|
|
11
|
+
* @returns an object of type QueryFilter to be used in the SDK
|
|
12
|
+
* stripping out empty or undefined values and enforcing default status_in when empty
|
|
13
|
+
*/
|
|
14
|
+
export declare function adaptUrlQueryToSdk({ queryString, instructions, timezone }: AdaptUrlQueryToSdkParams): QueryFilter;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type FiltersInstructions } from './types';
|
|
2
|
+
export interface AdaptUrlQueryToUrlQueryParams {
|
|
3
|
+
queryString: string;
|
|
4
|
+
instructions: FiltersInstructions;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Parse current URL query string to return a new query string that contains only valid form values
|
|
8
|
+
* @param qs url query string
|
|
9
|
+
* @returns an object of type QueryFilter to be used in the SDK stripping out empty or undefined values
|
|
10
|
+
*/
|
|
11
|
+
export declare function adaptUrlQueryToUrlQuery({ queryString, instructions }: AdaptUrlQueryToUrlQueryParams): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type QueryFilter } from '@commercelayer/sdk/lib/cjs/query';
|
|
2
|
+
import { type AdaptFormValuesToSdkParams } from './adaptFormValuesToSdk';
|
|
3
|
+
import { type AdaptFormValuesToUrlQueryParams } from './adaptFormValuesToUrlQuery';
|
|
4
|
+
import { type AdaptUrlQueryToFormValuesParams } from './adaptUrlQueryToFormValues';
|
|
5
|
+
import { type AdaptUrlQueryToSdkParams } from './adaptUrlQueryToSdk';
|
|
6
|
+
import { type AdaptUrlQueryToUrlQueryParams } from './adaptUrlQueryToUrlQuery';
|
|
7
|
+
import { type FiltersInstructions, type FormFullValues, type PageInfoFormValues, type TimeRangeFormValues, type UiFilterName, type UiFilterValue } from './types';
|
|
8
|
+
interface MakeFilterAdaptersParams {
|
|
9
|
+
instructions: FiltersInstructions;
|
|
10
|
+
}
|
|
11
|
+
interface MakeFilterAdaptersReturn<FilterFormValues extends FormFullValues> {
|
|
12
|
+
adaptFormValuesToUrlQuery: (params: Pick<AdaptFormValuesToUrlQueryParams<FormFullValues>, 'formValues'>) => string;
|
|
13
|
+
adaptFormValuesToSdk: (params: Pick<AdaptFormValuesToSdkParams<FilterFormValues>, 'formValues' | 'timezone'>) => QueryFilter;
|
|
14
|
+
adaptUrlQueryToFormValues: (params: Pick<AdaptUrlQueryToFormValuesParams, 'queryString'>) => FilterFormValues & TimeRangeFormValues & PageInfoFormValues;
|
|
15
|
+
adaptUrlQueryToSdk: (params: Pick<AdaptUrlQueryToSdkParams, 'queryString' | 'timezone'>) => QueryFilter;
|
|
16
|
+
adaptUrlQueryToUrlQuery: (params: Pick<AdaptUrlQueryToUrlQueryParams, 'queryString'>) => string;
|
|
17
|
+
validInstructions: FiltersInstructions;
|
|
18
|
+
}
|
|
19
|
+
export type MakeFiltersAdapters = <FilterFormValues extends Record<UiFilterName, UiFilterValue>>({ instructions }: MakeFilterAdaptersParams) => MakeFilterAdaptersReturn<FilterFormValues>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { TimeRangeFormValues, TimeRangePreset } from './types';
|
|
3
|
+
interface MakerSdkFilterTimeParams {
|
|
4
|
+
timePreset?: TimeRangePreset;
|
|
5
|
+
timeFrom?: Date | null;
|
|
6
|
+
timeTo?: Date | null;
|
|
7
|
+
timezone?: string;
|
|
8
|
+
sdkFilterName?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const makeSdkFilterTime: ({ timePreset, timeFrom, timeTo, timezone, sdkFilterName }: MakerSdkFilterTimeParams) => Record<string, string | undefined>;
|
|
11
|
+
export declare function getTimeRangeCustomLabel(timeFrom: Date, timeTo: Date, timezone?: string | undefined): string;
|
|
12
|
+
export declare function getTimeRangePresetName(timeRangePreset: TimeRangePreset): string;
|
|
13
|
+
export declare const timeRangeValidationSchema: z.ZodEffects<z.ZodObject<{
|
|
14
|
+
timeFrom: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
|
|
15
|
+
timeTo: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
|
|
16
|
+
timePreset: z.ZodNullable<z.ZodOptional<z.ZodEnum<["today", "last7days", "last30days", "custom"]>>>;
|
|
17
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
18
|
+
timeFrom: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
|
|
19
|
+
timeTo: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
|
|
20
|
+
timePreset: z.ZodNullable<z.ZodOptional<z.ZodEnum<["today", "last7days", "last30days", "custom"]>>>;
|
|
21
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
22
|
+
timeFrom: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
|
|
23
|
+
timeTo: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
|
|
24
|
+
timePreset: z.ZodNullable<z.ZodOptional<z.ZodEnum<["today", "last7days", "last30days", "custom"]>>>;
|
|
25
|
+
}, z.ZodTypeAny, "passthrough">>, z.objectOutputType<{
|
|
26
|
+
timeFrom: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
|
|
27
|
+
timeTo: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
|
|
28
|
+
timePreset: z.ZodNullable<z.ZodOptional<z.ZodEnum<["today", "last7days", "last30days", "custom"]>>>;
|
|
29
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
30
|
+
timeFrom: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
|
|
31
|
+
timeTo: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
|
|
32
|
+
timePreset: z.ZodNullable<z.ZodOptional<z.ZodEnum<["today", "last7days", "last30days", "custom"]>>>;
|
|
33
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
34
|
+
export declare const timeRangeFilterUiNames: Array<keyof TimeRangeFormValues>;
|
|
35
|
+
export declare function isTimeRangeFilterUiName(filterUiName: string): filterUiName is keyof TimeRangeFormValues;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { type InputCurrencyRangeProps } from '../../forms/InputCurrencyRange';
|
|
2
|
+
import { type RelationshipSelectorProps } from '../../resources/RelationshipSelector';
|
|
3
|
+
export declare const filtrableTimeRangePreset: readonly ["today", "last7days", "last30days", "custom"];
|
|
4
|
+
export type UiFilterName = string;
|
|
5
|
+
export type UiFilterValue = string | string[] | boolean | Date | undefined;
|
|
6
|
+
export type TimeRangePreset = (typeof filtrableTimeRangePreset)[number];
|
|
7
|
+
export interface TimeRangeFormValues {
|
|
8
|
+
timePreset?: TimeRangePreset | null;
|
|
9
|
+
timeFrom?: Date | null;
|
|
10
|
+
timeTo?: Date | null;
|
|
11
|
+
}
|
|
12
|
+
type CurrencyRangeSdkPredicate = string;
|
|
13
|
+
export interface CurrencyRangeFieldValue {
|
|
14
|
+
from?: number | null;
|
|
15
|
+
to?: number | null;
|
|
16
|
+
currencyCode?: string | null;
|
|
17
|
+
}
|
|
18
|
+
export type CurrencyRangeFormValues = Record<CurrencyRangeSdkPredicate, CurrencyRangeFieldValue>;
|
|
19
|
+
export interface PageInfoFormValues {
|
|
20
|
+
viewTitle?: string;
|
|
21
|
+
}
|
|
22
|
+
export type FormFullValues = Record<UiFilterName, UiFilterValue | CurrencyRangeFieldValue> & TimeRangeFormValues & PageInfoFormValues;
|
|
23
|
+
export interface BaseFilterItem {
|
|
24
|
+
/**
|
|
25
|
+
* Label of the filter field in form component
|
|
26
|
+
*/
|
|
27
|
+
label: string;
|
|
28
|
+
/**
|
|
29
|
+
* Flag to hide the filter field in form component
|
|
30
|
+
*/
|
|
31
|
+
hidden?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Instruction to use this item to build the sdk query
|
|
34
|
+
*/
|
|
35
|
+
sdk: {
|
|
36
|
+
/**
|
|
37
|
+
* SDK predicate to use in the query (example: `status_in` or `name_cont`)
|
|
38
|
+
*/
|
|
39
|
+
predicate: string;
|
|
40
|
+
/**
|
|
41
|
+
* Set the default options to use in the query when this filter is not selected.
|
|
42
|
+
* Example, you have no `status_in` selected in UI, but if this option is `['placed', 'approved']`, the query will always contain
|
|
43
|
+
* a `status_in` predicate with `placed` and `approved` statuses. This helps to avoid getting status we never want to see (eg: 'draft')
|
|
44
|
+
*/
|
|
45
|
+
defaultOptions?: string[];
|
|
46
|
+
/**
|
|
47
|
+
* Custom function to transform the form value to the SDK value
|
|
48
|
+
*/
|
|
49
|
+
parseFormValue?: (value: unknown) => string | number | boolean | undefined;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export type FilterItemOptions = BaseFilterItem & {
|
|
53
|
+
type: 'options';
|
|
54
|
+
render: {
|
|
55
|
+
/**
|
|
56
|
+
* UI component to render
|
|
57
|
+
*/
|
|
58
|
+
component: 'toggleButtons';
|
|
59
|
+
/**
|
|
60
|
+
* props required for the UI component
|
|
61
|
+
*/
|
|
62
|
+
props: {
|
|
63
|
+
mode: 'multi' | 'single';
|
|
64
|
+
/**
|
|
65
|
+
* an option can be hidden from the UI but still be used in the query
|
|
66
|
+
* Example: we wont show the button to filter `pending` status in the UI, but we still want to accept it for a predefined list)
|
|
67
|
+
*/
|
|
68
|
+
options: Array<{
|
|
69
|
+
label: string;
|
|
70
|
+
value: string;
|
|
71
|
+
isHidden?: boolean;
|
|
72
|
+
}>;
|
|
73
|
+
};
|
|
74
|
+
} | {
|
|
75
|
+
/**
|
|
76
|
+
* UI component to render
|
|
77
|
+
*/
|
|
78
|
+
component: 'relationshipSelector';
|
|
79
|
+
/**
|
|
80
|
+
* props required for the UI component
|
|
81
|
+
*/
|
|
82
|
+
props: Omit<RelationshipSelectorProps, 'onChange' | 'defaultValues' | 'title'>;
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
export interface FilterItemTextSearch extends Omit<BaseFilterItem, 'sdk'> {
|
|
86
|
+
type: 'textSearch';
|
|
87
|
+
render: {
|
|
88
|
+
/**
|
|
89
|
+
* UI component to render
|
|
90
|
+
*/
|
|
91
|
+
component: 'searchBar';
|
|
92
|
+
};
|
|
93
|
+
sdk: Pick<BaseFilterItem['sdk'], 'predicate'>;
|
|
94
|
+
}
|
|
95
|
+
export interface FilterItemTime extends Omit<BaseFilterItem, 'sdk'> {
|
|
96
|
+
type: 'timeRange';
|
|
97
|
+
sdk: {
|
|
98
|
+
/**
|
|
99
|
+
* SDK predicate to use in the query (example: `updated_at` or `updated_at`).
|
|
100
|
+
* Don't use `_gteq` or `_lteq` suffixes, they will be generated by the filter method based on the following key
|
|
101
|
+
* Example given the key `updated_at`, the generated predicate will be `updated_at_gteq` or `updated_at_lteq` depending on the preset
|
|
102
|
+
*/
|
|
103
|
+
predicate: string;
|
|
104
|
+
};
|
|
105
|
+
render: {
|
|
106
|
+
component: 'dateRangePicker';
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
export interface FilterItemCurrencyRange extends Omit<BaseFilterItem, 'sdk'> {
|
|
110
|
+
type: 'currencyRange';
|
|
111
|
+
sdk: {
|
|
112
|
+
/**
|
|
113
|
+
* SDK predicate to use in the query (example: `total_amount_cents` or `subtotal_amount_cents`).
|
|
114
|
+
* Don't use `_gteq` or `_lteq` suffixes, they will be generated by the filter method based on the following key
|
|
115
|
+
* Example given the key `total_amount_cents`, the generated predicate will be `total_amount_cents_gteq` or `total_amount_cents_lteq`
|
|
116
|
+
* It will also add the `currency_code_eq` predicate
|
|
117
|
+
*/
|
|
118
|
+
predicate: string;
|
|
119
|
+
};
|
|
120
|
+
render: {
|
|
121
|
+
component: 'inputCurrencyRange';
|
|
122
|
+
props: Omit<InputCurrencyRangeProps, 'onChange' | 'fromCents' | 'toCents' | 'defaultCurrency' | 'currencyList'>;
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export type FiltersInstructionItem = FilterItemOptions | FilterItemTextSearch | FilterItemTime | FilterItemCurrencyRange;
|
|
126
|
+
export type FiltersInstructions = FiltersInstructionItem[];
|
|
127
|
+
export declare function isItemOptions(item: FiltersInstructionItem): item is FilterItemOptions;
|
|
128
|
+
export declare function isTextSearch(item: FiltersInstructionItem): item is FilterItemTextSearch;
|
|
129
|
+
export declare function isCurrencyRange(item: FiltersInstructionItem): item is FilterItemCurrencyRange;
|
|
130
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { type ResourceListProps } from '../../resources/ResourceList';
|
|
3
|
+
import { type ListableResourceType } from '@commercelayer/sdk/lib/cjs/api';
|
|
4
|
+
import { type QueryFilter } from '@commercelayer/sdk/lib/cjs/query';
|
|
5
|
+
import { type FiltersFormProps } from './FiltersForm';
|
|
6
|
+
import { type FiltersNavProps } from './FiltersNav';
|
|
7
|
+
import { makeFilterAdapters } from './adapters';
|
|
8
|
+
import { type FiltersInstructions } from './types';
|
|
9
|
+
interface UseFiltersProps {
|
|
10
|
+
/**
|
|
11
|
+
* Array of instruction items to build the filters behaviors
|
|
12
|
+
*/
|
|
13
|
+
instructions: FiltersInstructions;
|
|
14
|
+
}
|
|
15
|
+
interface UseFiltersHook {
|
|
16
|
+
/**
|
|
17
|
+
* Helper methods to transform filters from/to url query string, sdk and form values
|
|
18
|
+
*/
|
|
19
|
+
adapters: ReturnType<typeof makeFilterAdapters>;
|
|
20
|
+
/**
|
|
21
|
+
* Search bar component with filters navigation buttons
|
|
22
|
+
*/
|
|
23
|
+
SearchWithNav: (props: Pick<FiltersNavProps, 'onFilterClick' | 'queryString'> & {
|
|
24
|
+
/**
|
|
25
|
+
* Callback triggered when user interact with search bar or remove a filter from the buttons
|
|
26
|
+
*/
|
|
27
|
+
onUpdate: (newQueryString: string) => void;
|
|
28
|
+
hideSearchBar?: boolean;
|
|
29
|
+
hideFiltersNav?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Placeholder text for the search bar
|
|
32
|
+
* @default 'Search...'
|
|
33
|
+
*/
|
|
34
|
+
searchBarPlaceholder?: string;
|
|
35
|
+
}) => JSX.Element;
|
|
36
|
+
/**
|
|
37
|
+
* Form component with filters fields based on provided instructions
|
|
38
|
+
*/
|
|
39
|
+
FiltersForm: (props: Pick<FiltersFormProps, 'onSubmit'>) => JSX.Element;
|
|
40
|
+
/**
|
|
41
|
+
* Filtered ResourceList component based on current active filters
|
|
42
|
+
*/
|
|
43
|
+
FilteredList: <TResource extends ListableResourceType>(props: Pick<ResourceListProps<TResource>, 'Item' | 'type' | 'query' | 'emptyState' | 'actionButton'>) => JSX.Element;
|
|
44
|
+
/**
|
|
45
|
+
* SDK filters object to be used in the sdk query
|
|
46
|
+
*/
|
|
47
|
+
sdkFilters: QueryFilter | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Returns `true` if there is at least one filter activated by the user.
|
|
50
|
+
* This does not include the text filter or presets, but only ones manually set by the user.
|
|
51
|
+
*/
|
|
52
|
+
hasActiveFilter: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* view title to be used in the page
|
|
55
|
+
*/
|
|
56
|
+
viewTitle?: string;
|
|
57
|
+
}
|
|
58
|
+
export declare function useFilters({ instructions }: UseFiltersProps): UseFiltersHook;
|
|
59
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type FilterItemOptions, type FiltersInstructions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Show the filter label with the counter for selected options
|
|
4
|
+
* or just the total of available options when nothing is selected
|
|
5
|
+
* @param options
|
|
6
|
+
* @returns string
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* "Markets · 2 of 4"
|
|
10
|
+
* "Markets · 4"
|
|
11
|
+
*/
|
|
12
|
+
export declare function computeFilterLabel({ label, totalCount, selectedCount }: {
|
|
13
|
+
label: string;
|
|
14
|
+
totalCount: number;
|
|
15
|
+
selectedCount: number;
|
|
16
|
+
}): string;
|
|
17
|
+
/**
|
|
18
|
+
* Get total count of active filter groups from URL query string.
|
|
19
|
+
* @param includeTextSearch if `true` will count `text` filter as active filter group
|
|
20
|
+
* @returns number of active filters
|
|
21
|
+
* Example: if we have 3 markets selected, will still count as `1` active filter group
|
|
22
|
+
* If we have 3 markets and 1 status selected, will count as `2`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getActiveFilterCountFromUrl({ includeTextSearch, instructions, queryString }: {
|
|
25
|
+
includeTextSearch?: boolean;
|
|
26
|
+
instructions: FiltersInstructions;
|
|
27
|
+
queryString: string;
|
|
28
|
+
}): number;
|
|
29
|
+
export declare function getAllowedValuesFromItemOptions(instructionItem: FilterItemOptions): string[] | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/utils/htmltags.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
export declare function enforceAllowedTags<AllowedTags extends ReadonlyArray<keyof JSX.IntrinsicElements>, Tag extends AllowedTags[number], DefaultTag extends AllowedTags[number]>({ tag, allowedTags, defaultTag }: {
|
|
2
3
|
tag?: Tag;
|
|
3
4
|
allowedTags: AllowedTags;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercelayer/app-elements",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.79",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -28,10 +28,12 @@
|
|
|
28
28
|
"classnames": "^2.3.2",
|
|
29
29
|
"jwt-decode": "^3.1.2",
|
|
30
30
|
"lodash": "^4.17.21",
|
|
31
|
+
"query-string": "^8.1.0",
|
|
31
32
|
"react": "^18.2.0",
|
|
32
33
|
"react-currency-input-field": "^3.6.11",
|
|
33
34
|
"react-datepicker": "^4.16.0",
|
|
34
35
|
"react-dom": "^18.2.0",
|
|
36
|
+
"react-hook-form": "^7.45.2",
|
|
35
37
|
"react-select": "^5.7.4",
|
|
36
38
|
"swr": "^2.2.0",
|
|
37
39
|
"ts-invariant": "^0.10.3",
|
|
@@ -40,6 +42,7 @@
|
|
|
40
42
|
},
|
|
41
43
|
"devDependencies": {
|
|
42
44
|
"@commercelayer/eslint-config-ts-react": "^1.0.1",
|
|
45
|
+
"@hookform/resolvers": "^3.1.1",
|
|
43
46
|
"@phosphor-icons/react": "v2.0.10",
|
|
44
47
|
"@tailwindcss/forms": "^0.5.4",
|
|
45
48
|
"@testing-library/jest-dom": "^5.17.0",
|
|
@@ -65,6 +68,10 @@
|
|
|
65
68
|
},
|
|
66
69
|
"peerDependencies": {
|
|
67
70
|
"@commercelayer/sdk": "^5.x",
|
|
71
|
+
"query-string": "^8.1.x",
|
|
72
|
+
"react": "^18.2.x",
|
|
73
|
+
"react-dom": "^18.2.x",
|
|
74
|
+
"react-hook-form": "^7.43.x",
|
|
68
75
|
"wouter": "^2.x"
|
|
69
76
|
},
|
|
70
77
|
"scripts": {
|