Skip to content

Commit

Permalink
Merge branch 'fix/list-select-item' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Wangtaofeng committed Mar 1, 2024
2 parents 5ca195e + f3098ca commit 40d8b8f
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 37 deletions.
2 changes: 1 addition & 1 deletion apps/builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"private": true,
"author": "ILLA Cloud <opensource@illasoft.com>",
"license": "Apache-2.0",
"version": "4.5.8",
"version": "4.5.9",
"scripts": {
"dev": "vite --strictPort --force",
"build-cloud": "NODE_OPTIONS=--max-old-space-size=12288 vite build --mode cloud",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ const RenderComponentCanvasContainer: FC<
data-canvas-container={displayName}
data-column-number={columnNumber}
data-unit-width={unitWidth}
data-list-widget-container
>
{isEditMode && (
<DragShadowPreview
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const RenderComponentCanvasWithJson: FC<{
<div
css={outerComponentCanvasContainerWithJsonStyle(containerPadding)}
ref={canvasRef}
data-list-widget-container
>
{componentTree}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,11 @@ const ListWidgetWithAutoPagination: FC<ListWidgetPropsWithChildrenNodes> = (
loading,
)}
ref={itemRef}
onClick={() => {
handleUpdateSelectedItem(
selectIndexForMark === 0 ? undefined : 0,
)
onClick={(e) => {
const isClickOnContainer = !!(
e.target as HTMLElement
)?.getAttribute("data-list-widget-container")
handleUpdateSelectedItem(0, isClickOnContainer)
}}
>
<RenderTemplateContainer
Expand Down Expand Up @@ -279,10 +280,11 @@ const ListWidgetWithAutoPagination: FC<ListWidgetPropsWithChildrenNodes> = (
itemHeight,
itemPadding?.size,
)}
onClick={() => {
handleUpdateSelectedItem(
selectIndexForMark === index ? undefined : index,
)
onClick={(e) => {
const isClickOnContainer = !!(
e.target as HTMLElement
)?.getAttribute("data-list-widget-container")
handleUpdateSelectedItem(index, isClickOnContainer)
}}
>
<RenderCopyContainer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,12 @@ const ListWidgetWithServerPagination: FC<ListWidgetPropsWithChildrenNodes> = (
isEditMode,
loading,
)}
onClick={() => {
handleUpdateSelectedItem(0)
onClick={(e) => {
const isClickOnContainer = !!(
e.target as HTMLElement
)?.getAttribute("data-list-widget-container")

handleUpdateSelectedItem(0, isClickOnContainer)
}}
>
<RenderTemplateContainer
Expand Down Expand Up @@ -346,8 +350,12 @@ const ListWidgetWithServerPagination: FC<ListWidgetPropsWithChildrenNodes> = (
itemPadding?.size,
)}
ref={itemRef}
onClick={() => {
handleUpdateSelectedItem(index)
onClick={(e) => {
const isClickOnContainer = !!(
e.target as HTMLElement
)?.getAttribute("data-list-widget-container")

handleUpdateSelectedItem(index, isClickOnContainer)
}}
>
<RenderCopyContainer
Expand Down
12 changes: 9 additions & 3 deletions apps/builder/src/widgetLibrary/PC/GridListWidget/gridList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,22 @@ export const GridListWidget: FC<GridListWidgetProps> = (props) => {
}, [childrenNode, dataSources, transTemplateContainerNodes])

const handleUpdateSelectedItem = useCallback(
(index?: number) => {
(index?: number, isContainerClick?: boolean) => {
if (!Array.isArray(dataSources) || disabled) return
if (selectIndexForMark === index || index === undefined) {
if (
(selectIndexForMark === index && isContainerClick) ||
index === undefined
) {
setSelectIndexForMark(undefined)
} else {
setSelectIndexForMark(index)
}
new Promise((resolve) => {
let value
if (index === undefined || index < 0 || index > dataSources.length) {
if (
index === undefined ||
(selectIndexForMark === index && isContainerClick)
) {
value = {
selectedItem: undefined,
selectedIndex: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ export interface RenderCopyContainerProps {

export interface ListWidgetPropsWithChildrenNodes extends GridListWidgetProps {
copyComponents: ComponentTreeNode[] | null
handleUpdateSelectedItem: (index?: number) => void
handleUpdateSelectedItem: (index?: number, isContainerClick?: boolean) => void
selectIndexForMark?: number
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,11 @@ const ListWidgetWithAutoPagination: FC<ListWidgetPropsWithChildrenNodes> = (
isEditMode,
loading,
)}
onClick={() => {
handleUpdateSelectedItem(
selectIndexForMark === 0 ? undefined : 0,
)
onClick={(e) => {
const isClickOnContainer = !!(
e.target as HTMLElement
)?.getAttribute("data-list-widget-container")
handleUpdateSelectedItem(0, isClickOnContainer)
}}
>
<RenderTemplateContainer
Expand Down Expand Up @@ -245,10 +246,11 @@ const ListWidgetWithAutoPagination: FC<ListWidgetPropsWithChildrenNodes> = (
itemPadding?.size,
)}
key={node.displayName}
onClick={() => {
handleUpdateSelectedItem(
selectIndexForMark === index ? undefined : index,
)
onClick={(e) => {
const isClickOnContainer = !!(
e.target as HTMLElement
)?.getAttribute("data-list-widget-container")
handleUpdateSelectedItem(index, isClickOnContainer)
}}
>
<RenderCopyContainer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,11 @@ const ListWidgetWithServerPagination: FC<ListWidgetPropsWithChildrenNodes> = (
isEditMode,
loading,
)}
onClick={() => {
handleUpdateSelectedItem(
selectIndexForMark === 0 ? undefined : 0,
)
onClick={(e) => {
const isClickOnContainer = !!(
e.target as HTMLElement
)?.getAttribute("data-list-widget-container")
handleUpdateSelectedItem(0, isClickOnContainer)
}}
>
<RenderTemplateContainer
Expand Down Expand Up @@ -311,10 +312,11 @@ const ListWidgetWithServerPagination: FC<ListWidgetPropsWithChildrenNodes> = (
itemPadding?.size,
)}
key={node.displayName}
onClick={() => {
handleUpdateSelectedItem(
selectIndexForMark === index ? undefined : index,
)
onClick={(e) => {
const isClickOnContainer = !!(
e.target as HTMLElement
)?.getAttribute("data-list-widget-container")
handleUpdateSelectedItem(index, isClickOnContainer)
}}
>
<RenderCopyContainer
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/src/widgetLibrary/PC/ListWidget/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ export interface RenderCopyContainerProps {
export interface ListWidgetPropsWithChildrenNodes extends ListWidgetProps {
copyComponents: ComponentTreeNode[] | null
selectIndexForMark?: number
handleUpdateSelectedItem: (index?: number) => void
handleUpdateSelectedItem: (index?: number, isContainerClick?: boolean) => void
}
12 changes: 9 additions & 3 deletions apps/builder/src/widgetLibrary/PC/ListWidget/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,22 @@ export const ListWidget: FC<ListWidgetProps> = (props) => {
}, [childrenNode, dataSources, transTemplateContainerNodes])

const handleUpdateSelectedItem = useCallback(
(index?: number) => {
(index?: number, isContainerClick?: boolean) => {
if (!Array.isArray(dataSources) || disabled) return
if (selectIndexForMark === index || index === undefined) {
if (
(selectIndexForMark === index && isContainerClick) ||
index === undefined
) {
setSelectIndexForMark(undefined)
} else {
setSelectIndexForMark(index)
}
new Promise((resolve) => {
let value
if (index === undefined || index < 0 || index > dataSources.length) {
if (
index === undefined ||
(selectIndexForMark === index && isContainerClick)
) {
value = {
selectedItem: undefined,
selectedIndex: undefined,
Expand Down

0 comments on commit 40d8b8f

Please sign in to comment.