Skip to content

Implemented pagination in some APIs. #1351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 39 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
16d8e1a
Added pagination ui
Imiss-U1025 Nov 14, 2024
b6d8a1b
Removed Your Folder Component
Imiss-U1025 Nov 26, 2024
efa56c3
Added utilities for pagination.
Imiss-U1025 Nov 26, 2024
a602426
Implemented pagination in Your App.
Imiss-U1025 Nov 26, 2024
fd62105
Implemented pagination in trash.
Imiss-U1025 Nov 27, 2024
3d9f56d
Imported types from util/pagination
Imiss-U1025 Nov 27, 2024
fa580fb
Added utilities for pagination.
Imiss-U1025 Nov 27, 2024
7bc6eb6
Implemented pagination in User Group List.
Imiss-U1025 Nov 27, 2024
41927a3
Implemented pagination in Data Sources.
Imiss-U1025 Nov 27, 2024
f2140e4
Implemented pagination in groupUsersPermission.
Imiss-U1025 Nov 27, 2024
8c82fd1
Implemented pagination in organizations's member.
Imiss-U1025 Nov 28, 2024
d65c2d5
Implemented pagination in Query Library and made fetchJsDatasourcePag…
Imiss-U1025 Nov 28, 2024
cce98cd
Implemented pagination in login.
Imiss-U1025 Nov 28, 2024
e2c1efc
Implemented realtime processing of create new folder in HomeView.
Imiss-U1025 Nov 28, 2024
3ce6469
Change search method in query library.
Imiss-U1025 Nov 28, 2024
a0a6fa1
Changed search method in Data Sources.
Imiss-U1025 Nov 28, 2024
b27f13f
Changed search method in marketplace.
Imiss-U1025 Nov 28, 2024
f51f681
Processed immediate activity in TrashView.
Imiss-U1025 Nov 29, 2024
cfe991d
Processed immediate activity in Your Apps.
Imiss-U1025 Nov 29, 2024
add7083
Processed immediate activity in Setting/UserGroup.
Imiss-U1025 Nov 29, 2024
a65c737
Added back button in your apps.
Imiss-U1025 Nov 29, 2024
1d41e80
Processed immediate activity in Query Library.
Imiss-U1025 Nov 29, 2024
4e1e0c0
Processed immediate activity in Data Sources.
Imiss-U1025 Nov 29, 2024
90648dc
Removed unnessary APIs.
Imiss-U1025 Nov 29, 2024
b332980
Fixed Search functions.
Imiss-U1025 Nov 29, 2024
34ce989
Fixed pagination of folders and UI.
Imiss-U1025 Nov 29, 2024
071e0ab
Fixed an issue that can not search Navigation.
Imiss-U1025 Nov 29, 2024
24469a3
Fixed loading indicator in setting/permission.
Imiss-U1025 Dec 1, 2024
56ff238
Fixed an issue that does not display 'Add member' button and 'Remove …
Imiss-U1025 Dec 2, 2024
346760c
Optimized called APIs and in User groups.
Imiss-U1025 Dec 2, 2024
3d75c3a
Fixed an issue that call double API in login.
Imiss-U1025 Dec 3, 2024
ffd2889
Does not show Pagination when No data in Data Source.
Imiss-U1025 Dec 3, 2024
32b3c3b
Implemented update-on-action when import file and create new Data Sou…
Imiss-U1025 Dec 3, 2024
bed5f55
Removed unnessary API calling (folders/elements) when first loading.
Imiss-U1025 Dec 3, 2024
6f9b821
Updating Yarn Lock
Dec 3, 2024
326d27e
Fixed an issue that app does not move to folder.
Imiss-U1025 Dec 3, 2024
9fcd924
Added categories dropdown button in Your apps.
Imiss-U1025 Dec 3, 2024
8886606
Fixed an Navigation issue in Trash and Your Apps.
Imiss-U1025 Dec 4, 2024
0364857
Merge branch 'dev' into feature-pagination
FalkWolsky Dec 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implemented pagination in Your App.
  • Loading branch information
Imiss-U1025 committed Dec 2, 2024
commit a602426f85b3c89ed1ef571ceecbb3d5247090ae
35 changes: 23 additions & 12 deletions client/packages/lowcoder-design/src/components/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,35 @@ interface ISearch {
placeholder: string;
value: string;
onChange: (value: React.ChangeEvent<HTMLInputElement>) => void;
onEnterPress?: (value: string) => void; // Added for capturing Enter key press
disabled?: boolean;
}

export const Search = (props: ISearch & InputProps) => {
const { value, onChange, style, disabled, placeholder, ...others } = props;
const { value, onChange, style, disabled, placeholder, onEnterPress, ...others } = props;

const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
onChange && onChange(e);
};

// Handling Enter key press
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === 'Enter' && onEnterPress) {
onEnterPress(value);
}
};

return (
<SearchDiv style={style}>
<SearchInput
disabled={disabled}
placeholder={placeholder}
onChange={handleChange}
value={value}
prefix={<SearchIcon />}
{...others}
/>
</SearchDiv>
<SearchDiv style={style}>
<SearchInput
disabled={disabled}
placeholder={placeholder}
onChange={handleChange}
onKeyDown={handleKeyDown} // Listening for key down events
value={value}
prefix={<SearchIcon />}
{...others}
/>
</SearchDiv>
);
};
};
8 changes: 8 additions & 0 deletions client/packages/lowcoder/src/api/apiResponses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ export interface GenericApiResponse<T> {
data: T;
}

export interface GenericApiPaginationResponse<T> {
total: number;
success: boolean;
code: number;
message: string;
data: T;
}

export interface FetchGroupApiResponse<T> extends GenericApiResponse<T> {
totalAdmins: number,
totalAdminsAndDevelopers: number,
Expand Down
9 changes: 8 additions & 1 deletion client/packages/lowcoder/src/api/folderApi.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import Api from "./api";
import { AxiosPromise } from "axios";
import { GenericApiResponse } from "./apiResponses";
import {GenericApiPaginationResponse, GenericApiResponse} from "./apiResponses";
import {
CreateFolderPayload,
DeleteFolderPayload,
FetchFolderElementsPaginationPayload,
FetchFolderElementsPayload,
MoveToFolderPayload,
UpdateFolderPayload,
Expand Down Expand Up @@ -40,4 +41,10 @@ export class FolderApi extends Api {
): AxiosPromise<GenericApiResponse<(ApplicationMeta | FolderMeta)[]>> {
return Api.get(FolderApi.url + `/elements`, { id: request.folderId });
}

static fetchFolderElementsPagination(
request: FetchFolderElementsPaginationPayload
): AxiosPromise<GenericApiPaginationResponse<(ApplicationMeta | FolderMeta)[]>> {
return Api.get(FolderApi.url + `/elements`, { ...request });
}
}
92 changes: 57 additions & 35 deletions client/packages/lowcoder/src/pages/ApplicationV2/HomeLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ const EmptyView = styled.div`
const PaginationLayout = styled.div`
display: flex;
justify-content: center;
margin-top: 40px;
margin-top: -20px;
margin-bottom: 20px;
`

Expand Down Expand Up @@ -308,13 +308,39 @@ export interface HomeLayoutProps {
localMarketplaceApps?: Array<ApplicationMeta>;
globalMarketplaceApps?: Array<ApplicationMeta>;
mode: HomeLayoutMode;
setCurrentPage?: any;
setPageSize?: any;
currentPage?: number;
pageSize?: number;
total?: number;
setSearchValues?: any;
typeFilter?: number;
setTypeFilter?: any;
}

export function HomeLayout(props: HomeLayoutProps) {
const { breadcrumb = [],
elements = [],
localMarketplaceApps = [],
globalMarketplaceApps = [],
mode ,
setCurrentPage,
setPageSize,
pageSize,
currentPage,
setSearchValues,
total,
typeFilter,
setTypeFilter,
} = props;
console.log("elements", elements, total);
const handlePageChange = (page: number) => {
setCurrentPage(page);
};

const { breadcrumb = [], elements = [], localMarketplaceApps = [], globalMarketplaceApps = [], mode } = props;

console.log("folder", elements);
const handlePageSizeChange = (current: number, size: number) => {
setPageSize(size);
};

const categoryOptions = [
{ label: <FilterMenuItem>{trans("home.allCategories")}</FilterMenuItem>, value: 'All' },
Expand All @@ -331,10 +357,9 @@ export function HomeLayout(props: HomeLayoutProps) {
const user = useSelector(getUser);
const isFetching = useSelector(isFetchingFolderElements);
const isSelfHost = window.location.host !== 'app.lowcoder.cloud';
const [typeFilter, setTypeFilter] = useState<HomeResKey>("All");
const [categoryFilter, setCategoryFilter] = useState<ApplicationCategoriesEnum | "All">("All");
const [searchValue, setSearchValue] = useState("");
const [visibility, setVisibility] = useState(true);
const [visibility, setVisibility] = useState(mode !== "marketplace");
const [layout, setLayout] = useState<HomeLayoutType>(
checkIsMobile(window.innerWidth) ? "card" : getHomeLayout()
);
Expand All @@ -352,7 +377,15 @@ export function HomeLayout(props: HomeLayoutProps) {
return null;
}

var displayElements = elements;
var displayElements = elements.sort((a, b) => {
if (a.folder && !b.folder) {
return -1; // a is a folder and should come first
} else if (!a.folder && b.folder) {
return 1; // b is a folder and should come first
} else {
return 0; // both are folders or both are not, keep original order
}
});

if (mode === "marketplace" && isSelfHost) {
const markedLocalApps = localMarketplaceApps.map(app => ({ ...app, isLocalMarketplace: true }));
Expand All @@ -364,27 +397,7 @@ export function HomeLayout(props: HomeLayoutProps) {
const markedLocalApps = localMarketplaceApps.map(app => ({ ...app, isLocalMarketplace: true }));
displayElements = [...markedLocalApps];
}

const resList: HomeRes[] = displayElements
.filter((e) =>
searchValue
? e.name?.toLocaleLowerCase().includes(searchValue?.toLocaleLowerCase()) ||
e.createBy?.toLocaleLowerCase().includes(searchValue?.toLocaleLowerCase())
: true
)
.filter((e) => {
if (HomeResTypeEnum[typeFilter].valueOf() === HomeResTypeEnum.All) {
return true;
}
if (e.folder) {
return HomeResTypeEnum[typeFilter] === HomeResTypeEnum.Folder;
} else {
if (typeFilter === "Navigation") {
return NavigationTypes.map((t) => t.valueOf()).includes(e.applicationType);
}
return HomeResTypeEnum[typeFilter].valueOf() === e.applicationType;
}
})
.filter((e) => {
// If "All" is selected, do not filter out any elements based on category
if (categoryFilter === 'All' || !categoryFilter) {
Expand Down Expand Up @@ -425,7 +438,6 @@ export function HomeLayout(props: HomeLayoutProps) {
}
);

console.log(resList);

const getFilterMenuItem = (type: HomeResTypeEnum) => {
const Icon = HomeResInfo[type].icon;
Expand Down Expand Up @@ -474,7 +486,7 @@ export function HomeLayout(props: HomeLayoutProps) {

{showNewUserGuide(user) && <HomepageTourV2 />}

<HomeView>
<HomeView>
<StyleHomeCover>
<h1 style={{color: "#ffffff", marginTop : "12px"}}>
{mode === "marketplace" && trans("home.appMarketplace")}
Expand All @@ -491,8 +503,11 @@ export function HomeLayout(props: HomeLayoutProps) {
{mode !== "folders" && mode !== "module" && (
<FilterDropdown
variant="borderless"
value={typeFilter}
onChange={(value: any) => setTypeFilter(value as HomeResKey)}
value={HomeResTypeEnum[typeFilter || 0]}
onChange={(value: any) => {
console.log(HomeResTypeEnum[value])
setTypeFilter(HomeResTypeEnum[value])}
}
options={[
getFilterMenuItem(HomeResTypeEnum.All),
getFilterMenuItem(HomeResTypeEnum.Application),
Expand All @@ -519,6 +534,7 @@ export function HomeLayout(props: HomeLayoutProps) {
placeholder={trans("search")}
value={searchValue}
onChange={(e) => setSearchValue(e.target.value)}
onEnterPress={(value) => setSearchValues(value)}
style={{ width: "192px", height: "32px", margin: "0" }}
/>
{mode !== "trash" && mode !== "marketplace" && user.orgDev && (
Expand Down Expand Up @@ -615,15 +631,21 @@ export function HomeLayout(props: HomeLayoutProps) {
</>
)}
</ContentWrapper>
{visibility ? <div>
<Divider />
{visibility && resList.length ? <div>
<PaginationLayout>
<Pagination total={50} showSizeChanger />
<Pagination
current={currentPage}
pageSize={pageSize}
onChange={handlePageChange}
onShowSizeChange={handlePageSizeChange}
total={total}
showSizeChanger
/>
</PaginationLayout>
</div> : null}
</Card>

</HomeView>
</HomeView>

</Wrapper>
);
Expand Down
56 changes: 51 additions & 5 deletions client/packages/lowcoder/src/pages/ApplicationV2/HomeView.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,50 @@
import { useSelector } from "react-redux";
import { HomeLayout } from "./HomeLayout";
import { getUser } from "../../redux/selectors/usersSelectors";
import { folderElementsSelector } from "../../redux/selectors/folderSelector";
import { Helmet } from "react-helmet";
import { trans } from "i18n";
import {useState, useEffect } from "react";
import {fetchFolderElements} from "@lowcoder-ee/util/pagination/axios";
import {ApplicationMeta, FolderMeta} from "@lowcoder-ee/constants/applicationConstants";
import {ApplicationPaginationType} from "@lowcoder-ee/util/pagination/type";

interface ElementsState {
elements: (ApplicationMeta | FolderMeta)[];
total: number;
}

export function HomeView() {
const elements = useSelector(folderElementsSelector)[""];
const [elements, setElements] = useState<ElementsState>({ elements: [], total: 1 });
const [currentPage, setCurrentPage] = useState(1);
const [pageSize, setPageSize] = useState(10);
const [searchValues, setSearchValues] = useState("");
const [typeFilter, setTypeFilter] = useState<number>(0);
useEffect( () => {
try{

fetchFolderElements({
pageNum:currentPage,
pageSize:pageSize,
applicationType: ApplicationPaginationType[typeFilter],
name: searchValues,
}).then(
data => {
console.log(data)
if (data.success) {
setElements({elements: data.data || [], total: data.total || 1})
}
else
console.error("ERROR: fetchFolderElements", data.error)
}
);
} catch (error) {
console.error('Failed to fetch data:', error);
}
}, [currentPage, pageSize, searchValues, typeFilter]
);

console.log(currentPage, pageSize);

const user = useSelector(getUser);

if (!user.currentOrgId) {
Expand All @@ -16,9 +54,17 @@ export function HomeView() {
return (
<>
<Helmet>{<title>{trans("productName")} {trans("home.home")}</title>}</Helmet>
<HomeLayout
elements={elements}
mode={"view"}
<HomeLayout
elements={elements.elements}
mode={"view"}
currentPage ={currentPage}
setCurrentPage={setCurrentPage}
pageSize={pageSize}
setPageSize={setPageSize}
total={elements.total}
setSearchValues={setSearchValues}
typeFilter={typeFilter}
setTypeFilter={setTypeFilter}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ export interface FetchFolderElementsPayload {
folderId?: string;
}

export interface FetchFolderElementsPaginationPayload {
pageNum?: number;
pageSize?: number;
name?: string;
applicationType?: string;
}

export const fetchFolderElements = (
payload: FetchFolderElementsPayload
): ReduxAction<FetchFolderElementsPayload> => {
Expand Down