@firedesktop/react-base 1.19.1 → 1.20.0
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/.eslintcache +1 -1
- package/.vscode/settings.json +3 -0
- package/dist/components/AppIcon.js +117 -154
- package/dist/components/AppIcon.js.map +1 -1
- package/dist/components/AppInput.js +13 -4
- package/dist/components/AppInput.js.map +1 -1
- package/dist/components/AppPagination.d.ts +11 -0
- package/dist/components/AppPagination.js +77 -0
- package/dist/components/AppPagination.js.map +1 -0
- package/dist/components/Spin.js +2 -1
- package/dist/components/Spin.js.map +1 -1
- package/dist/components/Toaster/Toaster.js +2 -2
- package/dist/components/Toaster/Toaster.js.map +1 -1
- package/dist/components/Toaster/Types.d.ts +1 -1
- package/dist/components/index.d.ts +2 -1
- package/dist/components/index.js +2 -1
- package/dist/components/index.js.map +1 -1
- package/dist/styles/base.css +31 -0
- package/dist/utils/configuration/ConfigurationLoader.js +2 -1
- package/dist/utils/configuration/ConfigurationLoader.js.map +1 -1
- package/dist/utils/fetch/Types.d.ts +1 -1
- package/dist/utils/fetch/fetchWrapper.d.ts +5 -5
- package/dist/utils/fetch/fetchWrapper.js +16 -16
- package/dist/utils/fetch/fetchWrapper.js.map +1 -1
- package/dist/utils/labels/LanguageLoader.js +2 -1
- package/dist/utils/labels/LanguageLoader.js.map +1 -1
- package/package.json +12 -11
- package/src/App.tsx +47 -4
- package/src/lib/components/AppPagination.tsx +123 -0
- package/src/lib/components/Toaster/Types.ts +1 -1
- package/src/lib/components/index.ts +2 -1
- package/src/lib/styles/base.css +31 -0
- package/src/lib/utils/fetch/Types.ts +1 -1
- package/src/lib/utils/fetch/fetchWrapper.ts +13 -11
- package/src/lib/utils/labels/LanguageManager.ts +0 -1
- package/tsconfig.json +2 -2
package/src/App.tsx
CHANGED
|
@@ -6,10 +6,11 @@ import { Components, ConfigurationLoader, Utils, LanguageLoader } from './lib';
|
|
|
6
6
|
|
|
7
7
|
import TestLabelFunction from './TestLabelFunction';
|
|
8
8
|
|
|
9
|
-
import '
|
|
10
|
-
import '
|
|
11
|
-
import '
|
|
12
|
-
import '
|
|
9
|
+
import 'bootstrap/dist/css/bootstrap.min.css';
|
|
10
|
+
import '@syncfusion/ej2-base/styles/bootstrap4.css';
|
|
11
|
+
import '@syncfusion/ej2-buttons/styles/bootstrap4.css';
|
|
12
|
+
import '@syncfusion/ej2-icons/styles/bootstrap4.css';
|
|
13
|
+
import '@syncfusion/ej2-popups/styles/bootstrap4.css';
|
|
13
14
|
|
|
14
15
|
import './lib/styles/base.css';
|
|
15
16
|
import './lib/styles/syncfusion_bootstrap4.css';
|
|
@@ -30,6 +31,7 @@ const appReducer = (state = {}, action: any) => {
|
|
|
30
31
|
function App() {
|
|
31
32
|
const [options, setOptions] = useState<{ value: string }[]>([]);
|
|
32
33
|
const [spinning, setSpinning] = useState(false);
|
|
34
|
+
const [activePage, setActivePage] = useState(4);
|
|
33
35
|
|
|
34
36
|
|
|
35
37
|
function onGenericServerError(status: number) {
|
|
@@ -49,7 +51,42 @@ function App() {
|
|
|
49
51
|
|
|
50
52
|
const runner = new Utils.Fetch.FetchWrapper(null, labels, status_401, status_403);
|
|
51
53
|
|
|
54
|
+
// var req = new XMLHttpRequest();
|
|
55
|
+
// req.open('POST', 'https://192.168.12.164:656/flowbot/Authentication/LoginWithForm', true);
|
|
56
|
+
// req.setRequestHeader('Content-Type', 'application/json');
|
|
57
|
+
// req.setRequestHeader('X-Token', '');
|
|
58
|
+
// req.addEventListener('readystatechange', function (ev: Event) {
|
|
59
|
+
// debugger;
|
|
60
|
+
// console.log(ev);
|
|
61
|
+
// // if (this.readyState === 4 && (this.status === 401 || this.status === 403)) {
|
|
62
|
+
// // window.location.href = '#/logoff';
|
|
63
|
+
// // }
|
|
64
|
+
// }, false);
|
|
65
|
+
// req.onreadystatechange = function () {
|
|
66
|
+
// if (req.readyState === 4) {
|
|
67
|
+
// if (req.status >= 200 && req.status < 400) {
|
|
68
|
+
// debugger;
|
|
69
|
+
// } else if (req.status === 400) {
|
|
70
|
+
// debugger;
|
|
71
|
+
// } else if (req.status === 401 || req.status === 403) {
|
|
72
|
+
// debugger;
|
|
73
|
+
// } else {
|
|
74
|
+
// debugger;
|
|
75
|
+
// }
|
|
76
|
+
// }
|
|
77
|
+
// };
|
|
78
|
+
// req.send();
|
|
79
|
+
|
|
52
80
|
setSpinning(true);
|
|
81
|
+
// runner.post('https://192.168.12.164:656/flowbot/Authentication/LoginWithForm', undefined, undefined, { username: 'admin', password: 'a' })
|
|
82
|
+
// .then((authentication: any) => {
|
|
83
|
+
// console.log(authentication);
|
|
84
|
+
// setSpinning(false);
|
|
85
|
+
|
|
86
|
+
// }).catch((errorMessage: any) => {
|
|
87
|
+
// console.log(errorMessage);
|
|
88
|
+
// setSpinning(false);
|
|
89
|
+
// });
|
|
53
90
|
runner.get('https://my-json-server.typicode.com/typicode/demo/posts', null, onGenericServerError, null, false, false).then(response => {
|
|
54
91
|
// @ts-ignore
|
|
55
92
|
const values = response.map(x => {
|
|
@@ -75,12 +112,18 @@ function App() {
|
|
|
75
112
|
};
|
|
76
113
|
};
|
|
77
114
|
|
|
115
|
+
|
|
116
|
+
const onPageChange = (nextPage: number) => {
|
|
117
|
+
setActivePage(nextPage);
|
|
118
|
+
};
|
|
119
|
+
|
|
78
120
|
// @ts-ignore
|
|
79
121
|
const store = createStore(appReducer);
|
|
80
122
|
|
|
81
123
|
return (
|
|
82
124
|
|
|
83
125
|
<Provider store={store}>
|
|
126
|
+
<Components.AppPagination activePage={activePage} itemsPerPage={10} onPageChange={onPageChange} totalItems={8} maxSize={9} />
|
|
84
127
|
<Components.Spin spinning={spinning} />
|
|
85
128
|
<Components.AppIcon name={'Pin'} className='dark-pink-svg' />
|
|
86
129
|
<TestLabelFunction />
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { AppIcon } from '.';
|
|
3
|
+
|
|
4
|
+
type PropType = {
|
|
5
|
+
activePage: number,
|
|
6
|
+
itemsPerPage: number,
|
|
7
|
+
maxSize?: number,
|
|
8
|
+
onPageChange: (page: number) => void,
|
|
9
|
+
pageFontSize?: number,
|
|
10
|
+
totalItems: number
|
|
11
|
+
};
|
|
12
|
+
function AppPagination({ activePage, itemsPerPage, maxSize = 5, onPageChange, pageFontSize = 14, totalItems }: PropType) {
|
|
13
|
+
const calculatePagination = (activePage: number, itemsPerPage: number, maxSize: number, totalItems: number): { totalPages: number, paginationArray: Array<number> } => {
|
|
14
|
+
if (totalItems) {
|
|
15
|
+
return pagination(activePage, itemsPerPage, maxSize, totalItems);
|
|
16
|
+
} else {
|
|
17
|
+
return {
|
|
18
|
+
totalPages: 1,
|
|
19
|
+
paginationArray: [1]
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const pagination = (activePage: number, itemsPerPage: number, maxSize: number, totalItems: number): { totalPages: number, paginationArray: Array<number> } => {
|
|
25
|
+
const totalPages = Math.ceil((totalItems || 1) / itemsPerPage);
|
|
26
|
+
const allPages = Array.from(Array(totalPages), (_, x) => x + 1);
|
|
27
|
+
|
|
28
|
+
if (maxSize >= allPages.length)
|
|
29
|
+
return { totalPages, paginationArray: Array.from(new Set(allPages)) };
|
|
30
|
+
|
|
31
|
+
const paginationArray = [];
|
|
32
|
+
const beforePages = Math.trunc(maxSize / 2);
|
|
33
|
+
let firstPageToShow = activePage;
|
|
34
|
+
while (true) {
|
|
35
|
+
if (firstPageToShow === 1 || firstPageToShow === activePage - beforePages)
|
|
36
|
+
break;
|
|
37
|
+
firstPageToShow--;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const delta = firstPageToShow + maxSize - 1 - totalPages;
|
|
41
|
+
const endPage = firstPageToShow + maxSize - 1 >= totalPages ? totalPages : firstPageToShow + maxSize - 1;
|
|
42
|
+
if (delta > 0)
|
|
43
|
+
firstPageToShow -= delta;
|
|
44
|
+
console.log(endPage);
|
|
45
|
+
for (let index = firstPageToShow; index <= endPage; index++)
|
|
46
|
+
paginationArray.push(index);
|
|
47
|
+
|
|
48
|
+
return { totalPages, paginationArray: Array.from(new Set(paginationArray)) };
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const { paginationArray, totalPages } = calculatePagination(activePage, itemsPerPage, maxSize, totalItems);
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
const goToFirst = (event: React.MouseEvent<HTMLLIElement>) => {
|
|
55
|
+
event.preventDefault();
|
|
56
|
+
if (activePage !== 1)
|
|
57
|
+
onPageChange(1);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const goToLast = (event: React.MouseEvent<HTMLLIElement>) => {
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
if (activePage !== totalPages)
|
|
63
|
+
onPageChange(totalPages);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const goToMext = (event: React.MouseEvent<HTMLLIElement>) => {
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
if (activePage !== totalPages)
|
|
69
|
+
onPageChange(activePage + 1);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const goToPrev = (event: React.MouseEvent<HTMLLIElement>) => {
|
|
73
|
+
event.preventDefault();
|
|
74
|
+
if (activePage !== 1)
|
|
75
|
+
onPageChange(activePage - 1);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<nav aria-label="Page navigation">
|
|
80
|
+
<ul className="pagination">
|
|
81
|
+
{/* First */}
|
|
82
|
+
<li className="page-item" onClick={goToFirst}>
|
|
83
|
+
<span aria-hidden="true">
|
|
84
|
+
<AppIcon name={'arrow-first'} />
|
|
85
|
+
</span>
|
|
86
|
+
</li>
|
|
87
|
+
{/* Prev */}
|
|
88
|
+
<li className="page-item disabled" onClick={goToPrev}>
|
|
89
|
+
<span aria-hidden="true">
|
|
90
|
+
<AppIcon name={'arrow-prev'} />
|
|
91
|
+
</span>
|
|
92
|
+
</li>
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
{paginationArray.map((page: number, index: number) => (
|
|
96
|
+
<li key={index}
|
|
97
|
+
className={`page-item ${page === activePage ? 'active' : ''}`}
|
|
98
|
+
onClick={() => onPageChange(page)}
|
|
99
|
+
style={{ borderRadius: 5 }} >
|
|
100
|
+
<span aria-hidden="true" style={{ fontSize: pageFontSize }}>
|
|
101
|
+
{page} <span className="sr-only">(current)</span>
|
|
102
|
+
</span>
|
|
103
|
+
</li>
|
|
104
|
+
))}
|
|
105
|
+
|
|
106
|
+
{/* Next */}
|
|
107
|
+
<li className="page-item" onClick={goToMext}>
|
|
108
|
+
<span aria-hidden="true">
|
|
109
|
+
<AppIcon name={'arrow-next'} />
|
|
110
|
+
</span>
|
|
111
|
+
</li>
|
|
112
|
+
{/* Last */}
|
|
113
|
+
<li className="page-item" onClick={goToLast}>
|
|
114
|
+
<span aria-hidden="true">
|
|
115
|
+
<AppIcon name={'arrow-last'} />
|
|
116
|
+
</span>
|
|
117
|
+
</li>
|
|
118
|
+
</ul>
|
|
119
|
+
</nav>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export default AppPagination;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import AppIcon from './AppIcon';
|
|
2
2
|
import AppInput from './AppInput';
|
|
3
|
+
import AppPagination from './AppPagination';
|
|
3
4
|
import Spin from './Spin';
|
|
4
5
|
import Toaster from './Toaster/Toaster';
|
|
5
6
|
import * as Toaster_Types from './Toaster/Types';
|
|
6
7
|
|
|
7
|
-
export { AppIcon, AppInput, Spin, Toaster, Toaster_Types };
|
|
8
|
+
export { AppIcon, AppInput, AppPagination, Spin, Toaster, Toaster_Types };
|
package/src/lib/styles/base.css
CHANGED
|
@@ -365,4 +365,35 @@
|
|
|
365
365
|
.AppInput_form svg{
|
|
366
366
|
position: absolute;
|
|
367
367
|
}
|
|
368
|
+
|
|
369
|
+
/*******************************************************************************/
|
|
370
|
+
/* AppPagination */
|
|
371
|
+
.page-item {
|
|
372
|
+
cursor: pointer;
|
|
373
|
+
margin-left: 2px;
|
|
374
|
+
margin-right: 2px;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
.page-item span {
|
|
378
|
+
width: 28px;
|
|
379
|
+
height: 27px;
|
|
380
|
+
display: flex;
|
|
381
|
+
justify-content: center;
|
|
382
|
+
align-items: center;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
.page-item.active span {
|
|
386
|
+
background: var(--background-color);
|
|
387
|
+
border-radius: 5px;
|
|
388
|
+
width: 28px;
|
|
389
|
+
height: 27px;
|
|
390
|
+
padding: 0;
|
|
391
|
+
text-align: center;
|
|
392
|
+
display: flex;
|
|
393
|
+
justify-content: center;
|
|
394
|
+
align-items: center;
|
|
395
|
+
color: #ffffff !important;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
|
|
368
399
|
|
|
@@ -26,23 +26,25 @@ class FetchWrapper {
|
|
|
26
26
|
this.labels = Constants.labels;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
get = (url: string, token?: string, onGenericServerError?: (status: number) => void, params?: Blob | any, isFile = false,
|
|
30
|
-
return this.generic('GET', url, token, onGenericServerError, params, isFile,
|
|
29
|
+
get = (url: string, token?: string, onGenericServerError?: (status: number) => void, params?: Blob | any, isFile = false, isBlobInReturn = false) => {
|
|
30
|
+
return this.generic('GET', url, token, onGenericServerError, params, isFile, isBlobInReturn);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
post = (url: string, token?: string, onGenericServerError?: (status: number) => void, params?: Blob | any, isFile = false,
|
|
34
|
-
|
|
33
|
+
post = (url: string, token?: string, onGenericServerError?: (status: number) => void, params?: Blob | any, isFile = false, isBlobInReturn = false,
|
|
34
|
+
additionalParams: Types.AdditionalParamsType[] = []) => {
|
|
35
|
+
return this.generic('POST', url, token, onGenericServerError, params, isFile, isBlobInReturn, this.apiVersion, additionalParams);
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
put = (url: string, token?: string, onGenericServerError?: (status: number) => void, params?: Blob | any, isFile = false,
|
|
38
|
-
return this.generic('PUT', url, token, onGenericServerError, params, isFile,
|
|
38
|
+
put = (url: string, token?: string, onGenericServerError?: (status: number) => void, params?: Blob | any, isFile = false, isBlobInReturn = false) => {
|
|
39
|
+
return this.generic('PUT', url, token, onGenericServerError, params, isFile, isBlobInReturn);
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
delete = (url: string, token?: string, onGenericServerError?: (status: number) => void, params?: Blob | any, isFile = false,
|
|
42
|
-
return this.generic('DELETE', url, token, onGenericServerError, params, isFile,
|
|
42
|
+
delete = (url: string, token?: string, onGenericServerError?: (status: number) => void, params?: Blob | any, isFile = false, isBlobInReturn = false) => {
|
|
43
|
+
return this.generic('DELETE', url, token, onGenericServerError, params, isFile, isBlobInReturn);
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
generic = (method: string, url: string, token?: string, onGenericServerError?: (status: number) => void, params?: Blob | any, isFile = false,
|
|
46
|
+
generic = (method: string, url: string, token?: string, onGenericServerError?: (status: number) => void, params?: Blob | any, isFile = false,
|
|
47
|
+
isBlobInReturn = false, version = this.apiVersion, additionalParams: Types.AdditionalParamsType[] = []) => {
|
|
46
48
|
// Headers & Body
|
|
47
49
|
let body: BodyInit;
|
|
48
50
|
const headers = new Headers();
|
|
@@ -62,7 +64,7 @@ class FetchWrapper {
|
|
|
62
64
|
if (additionalParams) {
|
|
63
65
|
for (let index = 0; index < additionalParams.length; index++) {
|
|
64
66
|
const element = additionalParams[index];
|
|
65
|
-
formData.append(element.name, element.value);
|
|
67
|
+
formData.append(element.name, '' + element.value);
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
} else {
|
|
@@ -90,7 +92,7 @@ class FetchWrapper {
|
|
|
90
92
|
if (response.status < 200 || response.status >= 300)
|
|
91
93
|
throw response;
|
|
92
94
|
|
|
93
|
-
return
|
|
95
|
+
return isBlobInReturn ? response.blob() : response.json();
|
|
94
96
|
})
|
|
95
97
|
.then(json => {
|
|
96
98
|
return json;
|
package/tsconfig.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"declaration": true,
|
|
14
14
|
"esModuleInterop": true,
|
|
15
15
|
"forceConsistentCasingInFileNames": true,
|
|
16
|
-
"jsx": "react",
|
|
16
|
+
"jsx": "react-jsx",
|
|
17
17
|
"module": "esnext",
|
|
18
18
|
"moduleResolution": "node",
|
|
19
19
|
"noFallthroughCasesInSwitch": true,
|
|
@@ -27,4 +27,4 @@
|
|
|
27
27
|
"include": [
|
|
28
28
|
"src/lib"
|
|
29
29
|
]
|
|
30
|
-
}
|
|
30
|
+
}
|