@pushwoosh/smart-components-kit 1.0.41 → 1.0.43
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/OpenActions/components/OpenActionsSummary/OpenActionsSummary.js +3 -3
- package/PlatformsConfigurationDrawer/components/DesktopPage/DesktopPage.js +7 -7
- package/PlatformsConfigurationDrawer/components/MainPage/MainPage.js +6 -6
- package/PlatformsConfigurationDrawer/components/MobilePage/MobilePage.js +7 -7
- package/PlatformsConfigurationDrawer/styled.js +6 -6
- package/Table/assets/box.svg +1 -0
- package/Table/assets/error.svg +1 -0
- package/Table/assets/notfound.svg +1 -0
- package/Table/components/DataTable/DataTable.d.ts +4 -0
- package/Table/components/DataTable/DataTable.js +78 -0
- package/Table/components/DataTable/index.d.ts +1 -0
- package/Table/components/DataTable/index.js +1 -0
- package/Table/components/DataTable/types.d.ts +26 -0
- package/Table/components/DataTable/types.js +1 -0
- package/Table/components/DataTableGetContext/DataTableGetContext.d.ts +4 -0
- package/Table/components/DataTableGetContext/DataTableGetContext.js +8 -0
- package/Table/components/DataTableGetContext/index.d.ts +1 -0
- package/Table/components/DataTableGetContext/index.js +1 -0
- package/Table/components/DataTableGetContext/types.d.ts +5 -0
- package/Table/components/DataTableGetContext/types.js +1 -0
- package/Table/components/DataTableList/DataTableList.d.ts +3 -0
- package/Table/components/DataTableList/DataTableList.js +80 -0
- package/Table/components/DataTableList/index.d.ts +1 -0
- package/Table/components/DataTableList/index.js +1 -0
- package/Table/components/DataTableList/types.d.ts +4 -0
- package/Table/components/DataTableList/types.js +1 -0
- package/Table/components/DataTablePagination/DataTablePagination.d.ts +3 -0
- package/Table/components/DataTablePagination/DataTablePagination.js +35 -0
- package/Table/components/DataTablePagination/index.d.ts +1 -0
- package/Table/components/DataTablePagination/index.js +1 -0
- package/Table/components/DataTablePagination/types.d.ts +5 -0
- package/Table/components/DataTablePagination/types.js +1 -0
- package/Table/components/DataTableSearchInput/DataTableSearchInput.d.ts +3 -0
- package/Table/components/DataTableSearchInput/DataTableSearchInput.js +40 -0
- package/Table/components/DataTableSearchInput/index.d.ts +1 -0
- package/Table/components/DataTableSearchInput/index.js +1 -0
- package/Table/components/DataTableSearchInput/types.d.ts +3 -0
- package/Table/components/DataTableSearchInput/types.js +1 -0
- package/Table/components/DataTableSortableCell/DataTableSortableCell.d.ts +3 -0
- package/Table/components/DataTableSortableCell/DataTableSortableCell.js +25 -0
- package/Table/components/DataTableSortableCell/index.d.ts +1 -0
- package/Table/components/DataTableSortableCell/index.js +1 -0
- package/Table/components/DataTableSortableCell/types.d.ts +4 -0
- package/Table/components/DataTableSortableCell/types.js +1 -0
- package/Table/components/Loading/Loading.d.ts +2 -0
- package/Table/components/Loading/Loading.js +20 -0
- package/Table/components/Loading/index.d.ts +1 -0
- package/Table/components/Loading/index.js +1 -0
- package/Table/components/Loading/styles.d.ts +1 -0
- package/Table/components/Loading/styles.js +6 -0
- package/Table/components/TablePagination/TablePagination.d.ts +3 -0
- package/Table/components/TablePagination/TablePagination.js +38 -0
- package/Table/components/TablePagination/index.d.ts +1 -0
- package/Table/components/TablePagination/index.js +1 -0
- package/Table/components/TablePagination/types.d.ts +10 -0
- package/Table/components/TablePagination/types.js +1 -0
- package/Table/context.d.ts +2 -0
- package/Table/context.js +2 -0
- package/Table/hooks/helpers.d.ts +2 -0
- package/Table/hooks/helpers.js +6 -0
- package/Table/hooks/index.d.ts +2 -0
- package/Table/hooks/index.js +2 -0
- package/Table/hooks/useDataTableContext.d.ts +11 -0
- package/Table/hooks/useDataTableContext.js +23 -0
- package/Table/hooks/useDataTableGetParams.d.ts +11 -0
- package/Table/hooks/useDataTableGetParams.js +53 -0
- package/Table/index.d.ts +10 -0
- package/Table/index.js +9 -0
- package/Table/styles.d.ts +247 -0
- package/Table/styles.js +62 -0
- package/Table/types.d.ts +20 -0
- package/Table/types.js +1 -0
- package/index.d.ts +5 -3
- package/index.js +5 -3
- package/package.json +8 -7
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import { DataTableContext } from '../../context';
|
|
3
|
+
import { TablePagination } from '../TablePagination';
|
|
4
|
+
export function DataTablePagination({
|
|
5
|
+
allLimits,
|
|
6
|
+
padding,
|
|
7
|
+
children
|
|
8
|
+
}) {
|
|
9
|
+
var _data$value;
|
|
10
|
+
const {
|
|
11
|
+
data,
|
|
12
|
+
params,
|
|
13
|
+
onChangeParams
|
|
14
|
+
} = useContext(DataTableContext);
|
|
15
|
+
return React.createElement(TablePagination, {
|
|
16
|
+
activePage: params.page,
|
|
17
|
+
totalPages: ((_data$value = data.value) === null || _data$value === void 0 ? void 0 : _data$value.totalPages) || 1,
|
|
18
|
+
limit: params.perPage,
|
|
19
|
+
allLimits: allLimits,
|
|
20
|
+
onChangePage: page => {
|
|
21
|
+
onChangeParams({
|
|
22
|
+
...params,
|
|
23
|
+
page
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
padding: padding,
|
|
27
|
+
onChangeLimit: perPage => {
|
|
28
|
+
onChangeParams({
|
|
29
|
+
...params,
|
|
30
|
+
page: 1,
|
|
31
|
+
perPage
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}, children);
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DataTablePagination } from './DataTablePagination';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DataTablePagination } from './DataTablePagination';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React, { useRef, useState, useEffect, useContext } from 'react';
|
|
2
|
+
import { SearchInput } from '@pushwoosh/dumb-components';
|
|
3
|
+
import { DataTableContext } from '../../context';
|
|
4
|
+
export function DataTableSearchInput(props) {
|
|
5
|
+
const context = useContext(DataTableContext);
|
|
6
|
+
const [inputValue, setInputValue] = useState(context.params.search);
|
|
7
|
+
const timeoutRef = useRef();
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
if (inputValue !== context.params.search) {
|
|
10
|
+
setInputValue(context.params.search);
|
|
11
|
+
}
|
|
12
|
+
}, [context.params.search]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
13
|
+
return React.createElement(SearchInput, {
|
|
14
|
+
...props,
|
|
15
|
+
value: inputValue,
|
|
16
|
+
"$onClear": () => {
|
|
17
|
+
setInputValue('');
|
|
18
|
+
context.onChangeParams({
|
|
19
|
+
...context.params,
|
|
20
|
+
search: '',
|
|
21
|
+
page: 1
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
onChange: event => {
|
|
25
|
+
const value = event.target.value;
|
|
26
|
+
setInputValue(value);
|
|
27
|
+
if (timeoutRef.current) {
|
|
28
|
+
clearTimeout(timeoutRef.current);
|
|
29
|
+
}
|
|
30
|
+
timeoutRef.current = setTimeout(() => {
|
|
31
|
+
context.onChangeParams({
|
|
32
|
+
...context.params,
|
|
33
|
+
search: value,
|
|
34
|
+
page: 1
|
|
35
|
+
});
|
|
36
|
+
timeoutRef.current = undefined;
|
|
37
|
+
}, 750);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DataTableSearchInput } from './DataTableSearchInput';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DataTableSearchInput } from './DataTableSearchInput';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import { SortButton } from '@pushwoosh/dumb-components';
|
|
3
|
+
import { DataTableContext } from '../../context';
|
|
4
|
+
export function DataTableSortableCell(props) {
|
|
5
|
+
const {
|
|
6
|
+
name,
|
|
7
|
+
children
|
|
8
|
+
} = props;
|
|
9
|
+
const {
|
|
10
|
+
params,
|
|
11
|
+
onChangeParams
|
|
12
|
+
} = useContext(DataTableContext);
|
|
13
|
+
return React.createElement(SortButton, {
|
|
14
|
+
name: name,
|
|
15
|
+
order: params.order === name ? params.direction : null,
|
|
16
|
+
onClick: sortParams => {
|
|
17
|
+
onChangeParams({
|
|
18
|
+
...params,
|
|
19
|
+
order: sortParams.name,
|
|
20
|
+
direction: sortParams.order || 'asc',
|
|
21
|
+
page: 1
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}, children);
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DataTableSortableCell } from './DataTableSortableCell';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DataTableSortableCell } from './DataTableSortableCell';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TextSkeleton } from '@pushwoosh/dumb-components';
|
|
3
|
+
import { Horizontal } from '@pushwoosh/kit-helpers';
|
|
4
|
+
import { Wrapper } from './styles';
|
|
5
|
+
const Row = ({
|
|
6
|
+
width
|
|
7
|
+
}) => React.createElement(Horizontal, {
|
|
8
|
+
"$alignItems": "center",
|
|
9
|
+
"$padding": "0 24px"
|
|
10
|
+
}, React.createElement(TextSkeleton, {
|
|
11
|
+
width: width
|
|
12
|
+
}));
|
|
13
|
+
export const Loading = () => React.createElement(Wrapper, null, Array.from({
|
|
14
|
+
length: 4
|
|
15
|
+
}).map((_, index) =>
|
|
16
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
17
|
+
React.createElement(Row, {
|
|
18
|
+
key: index,
|
|
19
|
+
width: `${index % 2 ? 35 : 50}%`
|
|
20
|
+
})));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Loading } from './Loading';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Loading } from './Loading';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const Wrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
import { Color, FontSize } from '@pushwoosh/kit-constants';
|
|
3
|
+
export const Wrapper = styled.div.withConfig({
|
|
4
|
+
displayName: "Wrapper",
|
|
5
|
+
componentId: "sc-x57qck-0"
|
|
6
|
+
})(["position:relative;font-size:", ";line-height:12px;background-color:", ";& > div{height:52px;border-bottom:1px solid ", ";& > div{transition:width 200ms linear;}}&:after{content:'';position:absolute;left:0;right:0;top:0;bottom:0;background-image:linear-gradient(to bottom,rgba(255,255,255,0),rgba(255,255,255,0.9));}"], FontSize.SMALL, Color.CLEAR, Color.DIVIDER);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { NativeSelect, Pagination } from '@pushwoosh/dumb-components';
|
|
3
|
+
import { Horizontal } from '@pushwoosh/kit-helpers';
|
|
4
|
+
export function TablePagination({
|
|
5
|
+
activePage,
|
|
6
|
+
totalPages,
|
|
7
|
+
limit,
|
|
8
|
+
allLimits,
|
|
9
|
+
padding = 24,
|
|
10
|
+
onChangePage,
|
|
11
|
+
onChangeLimit,
|
|
12
|
+
children
|
|
13
|
+
}) {
|
|
14
|
+
return React.createElement(Horizontal, {
|
|
15
|
+
"$alignItems": "center",
|
|
16
|
+
"$justifyContent": "space-between",
|
|
17
|
+
"$padding": padding
|
|
18
|
+
}, React.createElement(Horizontal, {
|
|
19
|
+
"$gap": 8,
|
|
20
|
+
"$alignItems": "center"
|
|
21
|
+
}, totalPages > 1 && React.createElement(Pagination, {
|
|
22
|
+
activePage: activePage,
|
|
23
|
+
totalPages: totalPages,
|
|
24
|
+
onChangePage: onChangePage
|
|
25
|
+
}), children), React.createElement(Horizontal, {
|
|
26
|
+
"$gap": 8,
|
|
27
|
+
"$alignItems": "center"
|
|
28
|
+
}, React.createElement("span", null, "Show on page:"), React.createElement(NativeSelect, {
|
|
29
|
+
name: "page",
|
|
30
|
+
value: limit,
|
|
31
|
+
onChange: event => {
|
|
32
|
+
onChangeLimit(Number(event.target.value));
|
|
33
|
+
}
|
|
34
|
+
}, allLimits.map(option => React.createElement("option", {
|
|
35
|
+
key: option,
|
|
36
|
+
value: option
|
|
37
|
+
}, option)))));
|
|
38
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TablePagination } from './TablePagination';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TablePagination } from './TablePagination';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PropsWithChildren } from 'react';
|
|
2
|
+
export type TablePaginationProps = PropsWithChildren<{
|
|
3
|
+
activePage: number;
|
|
4
|
+
totalPages: number;
|
|
5
|
+
limit: number;
|
|
6
|
+
allLimits: number[];
|
|
7
|
+
padding?: string | number;
|
|
8
|
+
onChangePage: (page: number) => void;
|
|
9
|
+
onChangeLimit: (limit: number) => void;
|
|
10
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/Table/context.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DataTableParams, DataTableContextType } from '../types';
|
|
2
|
+
export type DataTableContextProps<I, P extends DataTableParams> = {
|
|
3
|
+
getItems: (params: P) => Promise<{
|
|
4
|
+
items: I[];
|
|
5
|
+
total: number;
|
|
6
|
+
totalPages: number;
|
|
7
|
+
}>;
|
|
8
|
+
params: P;
|
|
9
|
+
onChangeParams: (params: P) => void;
|
|
10
|
+
};
|
|
11
|
+
export declare function useDataTableContext<I, P extends DataTableParams = DataTableParams>({ getItems, params, onChangeParams, }: DataTableContextProps<I, P>): DataTableContextType<I, P>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useLayoutEffect, useMemo } from 'react';
|
|
2
|
+
import { useAsyncFn, usePersistentFunction } from '@pushwoosh/kit-helpers';
|
|
3
|
+
export function useDataTableContext({
|
|
4
|
+
getItems,
|
|
5
|
+
params,
|
|
6
|
+
onChangeParams
|
|
7
|
+
}) {
|
|
8
|
+
const getItemsPersistent = usePersistentFunction(getItems);
|
|
9
|
+
const [listAsync, reload] = useAsyncFn(() => getItemsPersistent(params), [params], {
|
|
10
|
+
loading: true
|
|
11
|
+
});
|
|
12
|
+
useLayoutEffect(() => {
|
|
13
|
+
reload({
|
|
14
|
+
reset: true
|
|
15
|
+
});
|
|
16
|
+
}, [reload]);
|
|
17
|
+
return useMemo(() => ({
|
|
18
|
+
data: listAsync,
|
|
19
|
+
reload,
|
|
20
|
+
params,
|
|
21
|
+
onChangeParams: onChangeParams
|
|
22
|
+
}), [reload, params, listAsync, onChangeParams]);
|
|
23
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DataTableParams } from '../types';
|
|
2
|
+
type UseDataTableParamsParams<P extends DataTableParams> = {
|
|
3
|
+
defaultOrder: string;
|
|
4
|
+
defaultDirection?: 'asc' | 'desc';
|
|
5
|
+
defaultPerPage?: number;
|
|
6
|
+
customizeParams?: (obj: Record<string, string>, params: DataTableParams) => P;
|
|
7
|
+
prefix?: string;
|
|
8
|
+
};
|
|
9
|
+
type UseDataTableParamsReturn<P> = readonly [P, (params: P) => void];
|
|
10
|
+
export declare function useDataTableGetParams<P extends DataTableParams>({ defaultOrder, defaultDirection, defaultPerPage, customizeParams, prefix, }: UseDataTableParamsParams<P>): UseDataTableParamsReturn<P>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { useMemo, useRef } from 'react';
|
|
2
|
+
import { useHistory, useLocation } from 'react-router-dom';
|
|
3
|
+
import { usePersistentFunction } from '@pushwoosh/kit-helpers';
|
|
4
|
+
import { mapKeys, shallowEqual } from './helpers';
|
|
5
|
+
export function useDataTableGetParams({
|
|
6
|
+
defaultOrder,
|
|
7
|
+
defaultDirection = 'asc',
|
|
8
|
+
defaultPerPage = 10,
|
|
9
|
+
customizeParams,
|
|
10
|
+
prefix = ''
|
|
11
|
+
}) {
|
|
12
|
+
const history = useHistory();
|
|
13
|
+
const {
|
|
14
|
+
search: locationSearch
|
|
15
|
+
} = useLocation();
|
|
16
|
+
const customizeParamsRef = useRef(customizeParams);
|
|
17
|
+
customizeParamsRef.current = customizeParams;
|
|
18
|
+
const prevDataTableParamsRef = useRef({});
|
|
19
|
+
const dataTableParams = useMemo(() => {
|
|
20
|
+
const searchParams = new URLSearchParams(locationSearch);
|
|
21
|
+
const searchParamsWoPrefix = mapKeys(Object.fromEntries(searchParams), key => key.startsWith(prefix) ? key.slice(prefix.length) : key);
|
|
22
|
+
// eslint-disable-next-line no-nested-ternary
|
|
23
|
+
const realOrderDirection = !searchParamsWoPrefix.direction ? defaultDirection : searchParamsWoPrefix.direction === 'asc' ? 'asc' : 'desc';
|
|
24
|
+
const params = {
|
|
25
|
+
search: searchParamsWoPrefix.search ?? '',
|
|
26
|
+
order: searchParamsWoPrefix.order || defaultOrder,
|
|
27
|
+
direction: realOrderDirection,
|
|
28
|
+
page: +searchParamsWoPrefix.page || 1,
|
|
29
|
+
perPage: +searchParamsWoPrefix.perPage || defaultPerPage
|
|
30
|
+
};
|
|
31
|
+
// it is necessary to compare with the previous parameters so that there are no extra rerenders
|
|
32
|
+
const resultParams = customizeParamsRef.current ? customizeParamsRef.current(searchParamsWoPrefix, params) : params;
|
|
33
|
+
if (!shallowEqual(resultParams, prevDataTableParamsRef.current)) {
|
|
34
|
+
prevDataTableParamsRef.current = resultParams;
|
|
35
|
+
}
|
|
36
|
+
return prevDataTableParamsRef.current;
|
|
37
|
+
}, [locationSearch, defaultDirection, defaultOrder, defaultPerPage, prefix]);
|
|
38
|
+
const changeDataTableParams = usePersistentFunction(params => {
|
|
39
|
+
const searchParams = new URLSearchParams(locationSearch);
|
|
40
|
+
const paramsWithPrefix = mapKeys(params, key => `${prefix}${key}`);
|
|
41
|
+
for (const [key, value] of Object.entries(paramsWithPrefix)) {
|
|
42
|
+
if (value === undefined || value === null || value === '') {
|
|
43
|
+
searchParams.delete(key);
|
|
44
|
+
} else {
|
|
45
|
+
searchParams.set(key, String(value));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
history.push({
|
|
49
|
+
search: searchParams.toString()
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
return [dataTableParams, changeDataTableParams];
|
|
53
|
+
}
|
package/Table/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { DataTable } from './components/DataTable';
|
|
2
|
+
export { DataTableGetContext } from './components/DataTableGetContext';
|
|
3
|
+
export { DataTablePagination } from './components/DataTablePagination';
|
|
4
|
+
export { DataTableSearchInput } from './components/DataTableSearchInput';
|
|
5
|
+
export { DataTableSortableCell } from './components/DataTableSortableCell';
|
|
6
|
+
export { Loading } from './components/Loading';
|
|
7
|
+
export { TablePagination } from './components/TablePagination';
|
|
8
|
+
export { useDataTableContext, useDataTableGetParams } from './hooks';
|
|
9
|
+
export { Table, Td, Tr, Th, ElementHover, ItemDetailLink, ItemName, LockedText, Description, } from './styles';
|
|
10
|
+
export type { DataTableParams, DataTableData, DataTableContextType } from './types';
|
package/Table/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { DataTable } from './components/DataTable';
|
|
2
|
+
export { DataTableGetContext } from './components/DataTableGetContext';
|
|
3
|
+
export { DataTablePagination } from './components/DataTablePagination';
|
|
4
|
+
export { DataTableSearchInput } from './components/DataTableSearchInput';
|
|
5
|
+
export { DataTableSortableCell } from './components/DataTableSortableCell';
|
|
6
|
+
export { Loading } from './components/Loading';
|
|
7
|
+
export { TablePagination } from './components/TablePagination';
|
|
8
|
+
export { useDataTableContext, useDataTableGetParams } from './hooks';
|
|
9
|
+
export { Table, Td, Tr, Th, ElementHover, ItemDetailLink, ItemName, LockedText, Description } from './styles';
|