Skip to content

Commit cd7494b

Browse files
committed
Implemented pagination in Data Sources.
1 parent 7c9aaf0 commit cd7494b

File tree

5 files changed

+90
-16
lines changed

5 files changed

+90
-16
lines changed

client/packages/lowcoder/src/api/datasourceApi.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { JSONArray } from "util/jsonTypes";
88
import { AuthType, HttpOAuthGrantType } from "pages/datasource/form/httpDatasourceForm";
99
import { Datasource } from "@lowcoder-ee/constants/datasourceConstants";
1010
import { DataSourcePluginMeta } from "lowcoder-sdk/dataSource";
11+
import {fetchDBRequestType, GenericApiPaginationResponse} from "@lowcoder-ee/util/pagination/type";
1112

1213
export interface PreparedStatementConfig {
1314
enableTurnOffPreparedStatement: boolean;
@@ -172,6 +173,11 @@ export class DatasourceApi extends Api {
172173
return Api.get(DatasourceApi.url + `/listByOrg?orgId=${orgId}`);
173174
}
174175

176+
static fetchDatasourcePaginationByOrg(request: fetchDBRequestType): AxiosPromise<GenericApiPaginationResponse<DatasourceInfo[]>> {
177+
const {orgId, ...res} = request;
178+
return Api.get(DatasourceApi.url + `/listByOrg?orgId=${orgId}`, {...res});
179+
}
180+
175181
static createDatasource(
176182
datasourceConfig: Partial<Datasource>
177183
): AxiosPromise<GenericApiResponse<Datasource>> {

client/packages/lowcoder/src/pages/datasource/datasourceList.tsx

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import styled from "styled-components";
22
import { EditPopover, PointIcon, Search, TacoButton } from "lowcoder-design";
3-
import React, { useState } from "react";
3+
import React, {useEffect, useState} from "react";
44
import { useDispatch, useSelector } from "react-redux";
55
import { getDataSource, getDataSourceLoading, getDataSourceTypesMap } from "../../redux/selectors/datasourceSelectors";
66
import { deleteDatasource } from "../../redux/reduxActions/datasourceActions";
@@ -17,6 +17,10 @@ import { DatasourcePermissionDialog } from "../../components/PermissionDialog/Da
1717
import DataSourceIcon from "components/DataSourceIcon";
1818
import { Helmet } from "react-helmet";
1919
import LoadingOutlined from "@ant-design/icons/LoadingOutlined";
20+
import PaginationComp from "@lowcoder-ee/util/pagination/Pagination";
21+
import {DatasourceInfo} from "@lowcoder-ee/api/datasourceApi";
22+
import {fetchDatasourcePagination} from "@lowcoder-ee/util/pagination/axios";
23+
import {getUser} from "@lowcoder-ee/redux/selectors/usersSelectors";
2024

2125
const DatasourceWrapper = styled.div`
2226
display: flex;
@@ -103,11 +107,41 @@ const StyledTable = styled(Table)`
103107
export const DatasourceList = () => {
104108
const dispatch = useDispatch();
105109
const [searchValue, setSearchValue] = useState("");
110+
const [searchValues, setSearchValues] = useState("");
106111
const [isCreateFormShow, showCreateForm] = useState(false);
107112
const [shareDatasourceId, setShareDatasourceId] = useState<string | undefined>(undefined);
108113
const datasource = useSelector(getDataSource);
114+
const currentUser = useSelector(getUser);
115+
const orgId = currentUser.currentOrgId;
109116
const datasourceLoading = useSelector(getDataSourceLoading);
110117
const plugins = useSelector(getDataSourceTypesMap);
118+
interface ElementsState {
119+
elements: DatasourceInfo[];
120+
total: number;
121+
}
122+
console.log(datasource);
123+
124+
const [elements, setElements] = useState<ElementsState>({ elements: [], total: 0 });
125+
const [currentPage, setCurrentPage] = useState(1);
126+
const [pageSize, setPageSize] = useState(10);
127+
128+
useEffect( () => {
129+
fetchDatasourcePagination(
130+
{
131+
orgId: orgId,
132+
pageNum: currentPage,
133+
pageSize: pageSize,
134+
name: searchValues
135+
}
136+
).then(result => {
137+
if (result.success){
138+
setElements({elements: result.data || [], total: result.total || 1})
139+
}
140+
else
141+
console.error("ERROR: fetchFolderElements", result.error)
142+
})
143+
}, [currentPage, pageSize, searchValues]
144+
)
111145

112146
return (
113147
<>
@@ -140,6 +174,7 @@ export const DatasourceList = () => {
140174
placeholder={trans("search")}
141175
value={searchValue}
142176
onChange={(e) => setSearchValue(e.target.value)}
177+
onEnterPress={(value) => setSearchValues(value)}
143178
style={{ width: "192px", height: "32px", margin: "0 12px 0 0" }} />
144179
<AddBtn buttonType={"primary"} onClick={() => showCreateForm(true)}>
145180
{trans("home.newDatasource")}
@@ -267,19 +302,7 @@ export const DatasourceList = () => {
267302
),
268303
},
269304
]}
270-
dataSource={datasource
271-
.filter((info) => {
272-
if (info.datasource.creationSource === 2) {
273-
return false;
274-
}
275-
if (!isEmpty(searchValue)) {
276-
return (
277-
info.datasource.name.toLowerCase().includes(searchValue.trim().toLowerCase()) ||
278-
info.datasource.type.toLowerCase().includes(searchValue.trim().toLowerCase())
279-
);
280-
}
281-
return true;
282-
})
305+
dataSource={elements.elements
283306
.map((info, i) => ({
284307
key: i,
285308
id: info.datasource.id,
@@ -296,6 +319,13 @@ export const DatasourceList = () => {
296319
creator: info.creatorName,
297320
edit: info.edit,
298321
}))} />
322+
<PaginationComp
323+
currentPage={currentPage}
324+
pageSize={pageSize}
325+
setPageSize={setPageSize}
326+
setCurrentPage={setCurrentPage}
327+
total={elements.total}
328+
/>
299329
</BodyWrapper>
300330
{shareDatasourceId && (
301331
<DatasourcePermissionDialog
@@ -305,6 +335,8 @@ export const DatasourceList = () => {
305335
!visible && setShareDatasourceId(undefined);
306336
} } />
307337
)}
308-
</DatasourceWrapper></>
338+
</DatasourceWrapper>
339+
340+
</>
309341
);
310342
};

client/packages/lowcoder/src/pages/setting/permission/orgUsersPermission.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,11 @@ function OrgUsersPermission(props: UsersPermissionProp) {
300300
}
301301

302302
const mapStateToProps = (state: AppState) => {
303+
console.log({
304+
orgUsersFetching: state.ui.org.orgUsersFetching,
305+
orgUsers: state.ui.org.orgUsers,
306+
currentUser: getUser(state),
307+
})
303308
return {
304309
orgUsersFetching: state.ui.org.orgUsersFetching,
305310
orgUsers: state.ui.org.orgUsers,

client/packages/lowcoder/src/util/pagination/axios.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { FolderApi } from "@lowcoder-ee/api/folderApi";
22
import ApplicationApi from "@lowcoder-ee/api/applicationApi";
3-
import {fetchAppRequestType, fetchFolderRequestType, orgGroupRequestType} from "@lowcoder-ee/util/pagination/type";
3+
import {
4+
fetchAppRequestType,
5+
fetchDBRequestType,
6+
fetchFolderRequestType,
7+
orgGroupRequestType
8+
} from "@lowcoder-ee/util/pagination/type";
49
import OrgApi from "@lowcoder-ee/api/orgApi";
10+
import { DatasourceApi } from "@lowcoder-ee/api/datasourceApi";
511

612
export const fetchFolderElements = async (request: fetchFolderRequestType) => {
713
try {
@@ -53,4 +59,21 @@ export const fetchOrgGroups = async (request: orgGroupRequestType) => {
5359
error: error
5460
};
5561
}
62+
}
63+
64+
export const fetchDatasourcePagination = async (request: fetchDBRequestType)=> {
65+
try {
66+
const response = await DatasourceApi.fetchDatasourcePaginationByOrg(request);
67+
return {
68+
success: true,
69+
data: response.data.data,
70+
total: response.data.total
71+
}
72+
} catch (error: any) {
73+
console.error('Failed to fetch data:', error);
74+
return {
75+
success: false,
76+
error: error
77+
};
78+
}
5679
}

client/packages/lowcoder/src/util/pagination/type.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ export interface fetchFolderRequestType {
3434
applicationType?: string;
3535
}
3636

37+
export interface fetchDBRequestType {
38+
orgId: string;
39+
pageNum?: number;
40+
pageSize?: number;
41+
name?: string;
42+
type?: string;
43+
}
44+
3745
export interface orgGroupRequestType{
3846
pageNum?: number;
3947
pageSize?: number;

0 commit comments

Comments
 (0)