Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Added sorting feature in list/grid components#1644

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
FalkWolsky merged 4 commits intodevfromlist-comp-sortable
Apr 19, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
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
163 changes: 129 additions & 34 deletionsclient/packages/lowcoder/src/comps/comps/listViewComp/listView.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
import{defaultasPagination}from"antd/es/pagination";
import{EditorContext}from"comps/editorState";
import{BackgroundColorContext}from"comps/utils/backgroundColorContext";
import_from"lodash";
import_,{findIndex}from"lodash";
import{ConstructorToView,deferAction}from"lowcoder-core";
import{HintPlaceHolder,ScrollBar,pageItemRender}from"lowcoder-design";
import{DragIcon,HintPlaceHolder,ScrollBar,pageItemRender}from"lowcoder-design";
import{RefObject,useContext,createContext,useMemo,useRef,useEffect}from"react";
importReactResizeDetectorfrom"react-resize-detector";
importstyledfrom"styled-components";
Expand All@@ -22,6 +22,10 @@ import { useMergeCompStyles } from "@lowcoder-ee/util/hooks";
import{childrenToProps}from"@lowcoder-ee/comps/generators/multi";
import{AnimationStyleType}from"@lowcoder-ee/comps/controls/styleControlConstants";
import{getBackgroundStyle}from"@lowcoder-ee/util/styleUtils";
import{DndContext}from"@dnd-kit/core";
import{SortableContext,useSortable}from"@dnd-kit/sortable";
import{CSS}from"@dnd-kit/utilities";
import{JSONObject}from"@lowcoder-ee/index.sdk";

constListViewWrapper=styled.div<{$style:any;$paddingWidth:string,$animationStyle:AnimationStyleType}>`
height: 100%;
Expand DownExpand Up@@ -63,6 +67,22 @@ const ListOrientationWrapper = styled.div<{
flex-direction:${(props)=>(props.$isHorizontal ?"row" :"column")};
`;

constStyledDragIcon=styled(DragIcon)`
height: 16px;
width: 16px;
color: #8b8fa3;
&:hover {
cursor: grab;
outline: none;
}
&:focus {
cursor: grab;
outline: none;
}
`;

typeMinHorizontalWidthContextType={
horizontalWidth:string,
minHorizontalWidth?:string,
Expand All@@ -73,19 +93,48 @@ const MinHorizontalWidthContext = createContext<MinHorizontalWidthContextType>({
minHorizontalWidth:'100px',
});

constContainerInListView=(props:ContainerBaseProps)=>{
constContainerInListView=(props:ContainerBaseProps&{itemIdx:number,enableSorting?:boolean})=>{
const{
horizontalWidth,
minHorizontalWidth
}=useContext(MinHorizontalWidthContext);

const{ attributes, listeners, setNodeRef, transform, transition}=useSortable({
id:String(props.itemIdx),
});

if(!props.enableSorting){
return(
<div
style={{
width:horizontalWidth,
minWidth:minHorizontalWidth||'0px',
}}
>
<InnerGrid
{...props}
emptyRows={15}
containerPadding={[4,4]}
hintPlaceholder={HintPlaceHolder}
/>
</div>
)
}

return(
<div
ref={setNodeRef}
style={{
width:horizontalWidth,
minWidth:minHorizontalWidth||'0px',
transform:CSS.Transform.toString(transform),
transition,
display:'flex',
flexWrap:'nowrap',
alignItems:'center',
}}
>
{<StyledDragIcon{...attributes}{...listeners}/>}
<InnerGrid
{...props}
emptyRows={15}
Expand All@@ -107,6 +156,7 @@ type ListItemProps = {
unMountFn?:()=>void;
minHorizontalWidth?:string;
horizontalWidth:string;
enableSorting?:boolean;
};

functionListItem({
Expand All@@ -122,6 +172,7 @@ function ListItem({
scrollContainerRef,
minHeight,
horizontalGridCells,
enableSorting,
}=props;

// disable the unmount function to save user's state with pagination
Expand All@@ -133,35 +184,37 @@ function ListItem({
// }, []);

return(
<MinHorizontalWidthContext.Provider
value={{
horizontalWidth,
minHorizontalWidth
<MinHorizontalWidthContext.Provider
value={{
horizontalWidth,
minHorizontalWidth
}}
>
<ContainerInListView
itemIdx={itemIdx}
layout={containerProps.layout}
items={gridItemCompToGridItems(containerProps.items)}
horizontalGridCells={horizontalGridCells}
positionParams={containerProps.positionParams}
// all layout changes should only reflect on the commonContainer
dispatch={itemIdx===offset ?containerProps.dispatch :_.noop}
style={{
height:"100%",
// in case of horizontal mode, minHorizontalWidth is 0px
width:minHorizontalWidth||'100%',
backgroundColor:"transparent",
// flex: "auto",
}}
>
<ContainerInListView
layout={containerProps.layout}
items={gridItemCompToGridItems(containerProps.items)}
horizontalGridCells={horizontalGridCells}
positionParams={containerProps.positionParams}
// all layout changes should only reflect on the commonContainer
dispatch={itemIdx===offset ?containerProps.dispatch :_.noop}
style={{
height:"100%",
// in case of horizontal mode, minHorizontalWidth is 0px
width:minHorizontalWidth||'100%',
backgroundColor:"transparent",
// flex: "auto",
}}
autoHeight={autoHeight}
isDroppable={itemIdx===offset}
isDraggable={itemIdx===offset}
isResizable={itemIdx===offset}
isSelectable={itemIdx===offset}
scrollContainerRef={scrollContainerRef}
overflow={"hidden"}
minHeight={minHeight}
enableGridLines={true}
autoHeight={autoHeight}
isDroppable={itemIdx===offset}
isDraggable={itemIdx===offset}
isResizable={itemIdx===offset}
isSelectable={itemIdx===offset}
scrollContainerRef={scrollContainerRef}
overflow={"hidden"}
minHeight={minHeight}
enableGridLines={true}
enableSorting={enableSorting}
/>
</MinHorizontalWidthContext.Provider>
);
Expand DownExpand Up@@ -190,6 +243,7 @@ export function ListView(props: Props) {
()=>getData(children.noOfRows.getView()),
[children.noOfRows]
);
constlistData=useMemo(()=>children.listData.getView(),[children.listData]);
consthorizontalGridCells=useMemo(()=>children.horizontalGridCells.getView(),[children.horizontalGridCells]);
constautoHeight=useMemo(()=>children.autoHeight.getView(),[children.autoHeight]);
constshowHorizontalScrollbar=useMemo(()=>children.showHorizontalScrollbar.getView(),[children.showHorizontalScrollbar]);
Expand All@@ -213,6 +267,13 @@ export function ListView(props: Props) {
total,
};
},[children.pagination,totalCount]);

constenableSorting=useMemo(()=>children.enableSorting.getView(),[children.enableSorting]);

useEffect(()=>{
children.listData.dispatchChangeValueAction(data);
},[JSON.stringify(data)]);

conststyle=children.style.getView();
constanimationStyle=children.animationStyle.getView();

Expand All@@ -229,6 +290,7 @@ export function ListView(props: Props) {
// log.log("List. listHeight: ", listHeight, " minHeight: ", minHeight);
constrenders=_.range(0,noOfRows).map((rowIdx)=>{
// log.log("renders. i: ", i, "containerProps: ", containerProps, " text: ", Object.values(containerProps.items as Record<string, any>)[0].children.comp.children.text);
constitems=_.range(0,noOfColumns);
constrender=(
<div
key={rowIdx}
Expand All@@ -238,7 +300,7 @@ export function ListView(props: Props) {
}}
>
<FlexWrapper>
{_.range(0,noOfColumns).map((colIdx)=>{
{items.map((colIdx)=>{
constitemIdx=rowIdx*noOfColumns+colIdx+pageInfo.offset;
if(
itemIdx>=pageInfo.total||
Expand All@@ -250,7 +312,7 @@ export function ListView(props: Props) {
constcontainerProps=containerFn(
{
[itemIndexName]:itemIdx,
[itemDataName]:getCurrentItemParams(data,itemIdx)
[itemDataName]:getCurrentItemParams(listDataasJSONObject[],itemIdx)
},
String(itemIdx)
).getView();
Expand All@@ -259,6 +321,7 @@ export function ListView(props: Props) {
deferAction(ContextContainerComp.batchDeleteAction([String(itemIdx)]))
);
};

return(
<ListItem
key={itemIdx}
Expand All@@ -272,12 +335,14 @@ export function ListView(props: Props) {
unMountFn={unMountFn}
horizontalWidth={`${100/noOfColumns}%`}
minHorizontalWidth={horizontal ?minHorizontalWidth :undefined}
enableSorting={enableSorting}
/>
);
})}
</FlexWrapper>
</div>
);

returnrender;
});

Expand All@@ -289,6 +354,23 @@ export function ListView(props: Props) {

useMergeCompStyles(childrenProps,comp.dispatch);

consthandleDragEnd=(e:{active:{id:string};over:{id:string}|null})=>{
if(!e.over){
return;
}
constfromIndex=Number(e.active.id);
consttoIndex=Number(e.over.id);
if(fromIndex<0||toIndex<0||fromIndex===toIndex){
return;
}

constnewData=[...listData];
const[movedItem]=newData.splice(fromIndex,1);
newData.splice(toIndex,0,movedItem);

children.listData.dispatchChangeValueAction(newData);
};

// log.debug("renders: ", renders);
return(
<BackgroundColorContext.Providervalue={style.background}>
Expand All@@ -306,7 +388,20 @@ export function ListView(props: Props) {
$isGrid={noOfColumns>1}
$autoHeight={autoHeight}
>
{renders}
{!enableSorting
?renders
:(
<DndContextonDragEnd={handleDragEnd}>
<SortableContext
items={
_.range(0,totalCount).map((colIdx)=>String(colIdx))
}
>
{renders}
</SortableContext>
</DndContext>
)
}
</ListOrientationWrapper>
)}
>
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,7 +29,7 @@ import {
withFunction,
WrapContextNodeV2,
}from"lowcoder-core";
import{JSONValue}from"util/jsonTypes";
import{JSONArray,JSONValue}from"util/jsonTypes";
import{depthEqual,lastValueIfEqual,shallowEqual}from"util/objectUtils";
import{CompTree,getAllCompItems,IContainer}from"../containerBase";
import{SimpleContainerComp,toSimpleContainerData}from"../containerBase/simpleContainerComp";
Expand All@@ -43,6 +43,7 @@ import { SliderControl } from "@lowcoder-ee/comps/controls/sliderControl";

constchildrenMap={
noOfRows:withIsLoadingMethod(NumberOrJSONObjectArrayControl),// FIXME: migrate "noOfRows" to "data"
listData:stateComp<JSONArray>([]),
noOfColumns:withDefault(NumberControl,1),
itemIndexName:withDefault(StringControl,"i"),
itemDataName:withDefault(StringControl,"currentItem"),
Expand All@@ -60,6 +61,7 @@ const childrenMap = {
animationStyle:styleControl(AnimationStyle,'animationStyle'),
horizontal:withDefault(BoolControl,false),
minHorizontalWidth:withDefault(RadiusControl,'100px'),
enableSorting:withDefault(BoolControl,false),
};

constListViewTmpComp=newUICompBuilder(childrenMap,()=><></>)
Expand DownExpand Up@@ -116,7 +118,7 @@ export class ListViewImplComp extends ListViewTmpComp implements IContainer {
const{ itemCount}=getData(this.children.noOfRows.getView());
constitemIndexName=this.children.itemIndexName.getView();
constitemDataName=this.children.itemDataName.getView();
constdataExposingNode=this.children.noOfRows.exposingNode();
constdataExposingNode=this.children.listData.exposingNode();
constcontainerComp=this.children.container;
// for each container expose each comps with params
constexposingRecord=_(_.range(0,itemCount))
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -57,6 +57,9 @@ export function listPropertyView(compType: ListCompType) {
<Sectionname={sectionNames.interaction}>
{hiddenPropertyView(children)}
{showDataLoadingIndicatorsPropertyView(children)}
{children.enableSorting.propertyView({
label:trans('listView.enableSorting'),
})}
</Section>
)}

Expand Down
3 changes: 2 additions & 1 deletionclient/packages/lowcoder/src/i18n/locales/en.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2598,7 +2598,8 @@ export const en = {
"itemDataNameDesc": "The Variable Name Referring to the Item's Data Object, Default as {default}",
"itemsDesc": "Exposing Data of Components in List",
"dataDesc": "The JSON Data Used in the Current List",
"dataTooltip": "If You just Set a Number, This Field Will Be Regarded as Row Count, and the Data Will Be Regarded as Empty."
"dataTooltip": "If You just Set a Number, This Field Will Be Regarded as Row Count, and the Data Will Be Regarded as Empty.",
"enableSorting": "Allow Sorting"
},
"navigation": {
"addText": "Add Submenu Item",
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp