Skip to content

Commit

Permalink
Merge pull request #478 from illa-family/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
AruSeito authored Nov 11, 2022
2 parents f4abbab + 77fc8fc commit 3c71ab9
Show file tree
Hide file tree
Showing 34 changed files with 1,171 additions and 10 deletions.
9 changes: 9 additions & 0 deletions apps/builder/src/assets/widgetCover/menu.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 15 additions & 1 deletion apps/builder/src/i18n/locale/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,12 @@
"new": "New",
"title": "Title"
},
"menu_setter": {
"label": "Menus ({{number}})",
"new": "New",
"sub": "Sub",
"delete": "Delete"
},
"event_handler_list": {
"empty": "Trigger queries, control components, or call other APIs in response to component events.",
"incomplete_selection": "Incomplete selection",
Expand All @@ -406,7 +412,7 @@
"placeholder": "Select a page"
},
"select_view_setter": {
"placeholder": ""
"placeholder": "Select a view"
},
"tabs_setter": {
"tabs": "Tabs"
Expand All @@ -424,6 +430,7 @@
"invalid": "Invalid",
"paginationChange": "Page change",
"sortingChange": "Sort change",
"clickMenuItem": "Click",
"submit": "Submit",
"success": "Success"
}
Expand Down Expand Up @@ -451,6 +458,7 @@
"interaction": "INTERACTION",
"label": "LABEL",
"layout": "LAYOUT",
"menu": "MENU",
"options": "OPTIONS",
"pagination": "PAGINATION",
"row_selection": "ROW SELECTION",
Expand Down Expand Up @@ -749,6 +757,9 @@
},
"share": "Share",
"status": {
"403": {
"des": "Access denied"
},
"404": {
"again": "Refresh",
"des": "It seems that the page you were looking for could not be found."
Expand Down Expand Up @@ -962,6 +973,9 @@
"switch": {
"name": "Switch"
},
"menu": {
"name": "Menu"
},
"table": {
"ascend": "Asc",
"descend": "Desc",
Expand Down
14 changes: 14 additions & 0 deletions apps/builder/src/i18n/locale/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,12 @@
"new": "新建",
"title": "标题"
},
"menu_setter": {
"label": "菜单 ({{number}})",
"new": "新建",
"sub": "子菜单",
"delete": "删除"
},
"event_handler_list": {
"empty": "触发查询、控制组件或调用其他API以响应组件事件。",
"incomplete_selection": "不完整的选择",
Expand Down Expand Up @@ -424,6 +430,7 @@
"invalid": "校验失败",
"paginationChange": "翻页配置改变",
"sortingChange": "排序方式改变",
"clickMenuItem": "单击",
"submit": "提交",
"success": "成功后"
}
Expand Down Expand Up @@ -451,6 +458,7 @@
"interaction": "交互",
"label": "标签",
"layout": "布局",
"menu": "菜单",
"options": "选项",
"pagination": "翻页",
"row_selection": "行选择",
Expand Down Expand Up @@ -749,6 +757,9 @@
},
"share": "分享",
"status": {
"403": {
"des": "访问被拒绝"
},
"404": {
"again": "刷新",
"des": "您访问的页面不存在"
Expand Down Expand Up @@ -962,6 +973,9 @@
"switch": {
"name": "开关"
},
"menu": {
"name": "菜单"
},
"table": {
"ascend": "升序",
"descend": "降序",
Expand Down
9 changes: 7 additions & 2 deletions apps/builder/src/page/App/components/DotPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ export const DotPanel: FC = () => {
pageSortedKey,
homepageDisplayName,
} = rootExecutionProps
let { pageName = "page1" } = useParams()
let { pageName } = useParams()
const currentDisplayName = useMemo(() => {
if (mode === "production") {
return pageName || homepageDisplayName
return (
pageName ||
homepageDisplayName ||
pageSortedKey[currentPageIndex] ||
"page1"
)
} else {
return pageSortedKey[currentPageIndex] || homepageDisplayName
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { FC, useContext } from "react"
import { Reorder } from "framer-motion"
import { MenuListSetterContext } from "./context/menuListContext"
import { EmptyBody } from "./empty"
import { removeNativeStyle } from "@/page/App/components/PanelSetters/TableSetter/ColumnSetter/style"
import { MenuItem } from "@/page/App/components/PanelSetters/MenuSetter/MenuOptionSetter/menuItem"

export const ListBody: FC = () => {
const { columnItems, handleUpdateDsl, attrPath } = useContext(
MenuListSetterContext,
)

if (!columnItems || !Array.isArray(columnItems) || columnItems.length === 0)
return <EmptyBody />

return (
<Reorder.Group
axis="y"
initial={false}
values={columnItems}
onReorder={(value) => {
handleUpdateDsl(attrPath, value)
}}
css={removeNativeStyle}
>
{columnItems.map((item, index) => {
const { title, id, disabled, icon, subMenu } = item
return (
<Reorder.Item
initial={false}
css={removeNativeStyle}
key={item.id}
value={item}
>
<MenuItem {...item} index={index} />
</Reorder.Item>
)
})}
</Reorder.Group>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { createContext, FC, ReactNode, useCallback } from "react"
import { PanelFieldConfig } from "@/page/App/components/InspectPanel/interface"
import { generateNewSubMenuItem } from "../utils/generateNewMenu"
import { MenuList } from "@/widgetLibrary/MenuWidget/interface"

interface ProviderProps {
columnItems: MenuList[]
childrenSetter: PanelFieldConfig[]
widgetDisplayName: string
attrPath: string
handleUpdateDsl: (attrPath: string, value: any) => void
children: ReactNode
}

interface Inject extends Omit<ProviderProps, "children"> {
handleDeleteMenuItem: (index: number) => void
handleAddSubMenuItem: (index: number) => void
handleDeleteSubMenuItem: (index: number, subIndex: number) => void
}

export const MenuListSetterContext = createContext<Inject>({} as Inject)

export const MenusSetterProvider: FC<ProviderProps> = (props) => {
const { columnItems, attrPath, handleUpdateDsl } = props

const handleDeleteMenuItem = useCallback(
(index: number) => {
const updatedArray = columnItems.filter(
(optionItem: Record<string, any>, i: number) => {
return i !== index
},
)
handleUpdateDsl(attrPath, updatedArray)
},
[columnItems, handleUpdateDsl, attrPath],
)

const handleDeleteSubMenuItem = useCallback(
(index: number, subIndex: number) => {
const updatedArray = JSON.parse(JSON.stringify(columnItems))
updatedArray[index].subMenu = updatedArray[index].subMenu?.filter(
(optionItem: Record<string, any>, i: number) => {
return i !== subIndex
},
)
handleUpdateDsl(attrPath, updatedArray)
},
[columnItems, handleUpdateDsl, attrPath],
)

const handleAddSubMenuItem = useCallback(
(index: number) => {
const updatedArray = JSON.parse(JSON.stringify(columnItems))
const num = (updatedArray[index]?.subMenu?.length ?? 0) + 1
const newItem = generateNewSubMenuItem(num)
if (updatedArray[index].subMenu) {
updatedArray[index].subMenu.push(newItem)
} else {
updatedArray[index]["subMenu"] = [newItem]
}

handleUpdateDsl(attrPath, updatedArray)
},
[columnItems, handleUpdateDsl, attrPath],
)

const value = {
...props,
handleDeleteMenuItem,
handleAddSubMenuItem,
handleDeleteSubMenuItem,
}

return (
<MenuListSetterContext.Provider value={value}>
{props.children}
</MenuListSetterContext.Provider>
)
}

MenusSetterProvider.displayName = "ColumnsSetterProvider"
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { FC, useCallback, useContext, useState } from "react"
import { useTranslation } from "react-i18next"
import { DragPointIcon, AddIcon } from "@illa-design/icon"
import { Trigger } from "@illa-design/trigger"
import {
addIconStyle,
deleteButtonStyle,
dragItemStyle,
iconAreaStyle,
labelNameAndIconStyle,
labelNameWrapperStyle,
modalStyle,
movableIconWrapperStyle,
} from "./style"
import { DragIconAndLabelProps } from "./interface"
import { BaseModal } from "@/page/App/components/PanelSetters/PublicComponent/Modal"
import { MenuListSetterContext } from "./context/menuListContext"
import { Button } from "@illa-design/button"

export const DragIconAndLabel: FC<DragIconAndLabelProps> = (props) => {
const { index, title } = props
const [modalVisible, setModalVisible] = useState(false)
const {
widgetDisplayName,
attrPath,
childrenSetter,
handleAddSubMenuItem,
handleDeleteMenuItem,
} = useContext(MenuListSetterContext)

const { t } = useTranslation()

const handleCloseModal = useCallback(() => {
setModalVisible(false)
}, [])

return (
<Trigger
withoutPadding
colorScheme="white"
popupVisible={modalVisible}
content={
<BaseModal
_css={modalStyle}
title={title ?? ""}
handleCloseModal={handleCloseModal}
attrPath={`${attrPath}.${index}`}
widgetDisplayName={widgetDisplayName}
childrenSetter={childrenSetter}
extraElement={
<Button
css={deleteButtonStyle}
colorScheme="red"
variant="light"
onClick={() => {
handleDeleteMenuItem(index)
}}
>
{t("editor.inspect.setter_content.menu_setter.delete")}
</Button>
}
/>
}
trigger="click"
showArrow={false}
position="left"
clickOutsideToClose
onVisibleChange={(visible) => {
setModalVisible(visible)
}}
>
<div css={dragItemStyle}>
<div css={labelNameAndIconStyle}>
<span css={movableIconWrapperStyle} className="movableIconWrapper">
<DragPointIcon />
</span>
<span css={labelNameWrapperStyle}>
{title ||
t("editor.inspect.setter_content.option_list.list_no_label")}
</span>
</div>
<div
css={iconAreaStyle}
onClick={(event) => {
handleAddSubMenuItem(index)
event.stopPropagation()
}}
>
<AddIcon _css={addIconStyle} />
<span>{t("editor.inspect.setter_content.menu_setter.sub")}</span>
</div>
</div>
</Trigger>
)
}

DragIconAndLabel.displayName = "DragIconAndLabel"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { FC } from "react"
import { emptyEmptyBodyStyle } from "./style"

export const EmptyBody: FC = () => {
return <div css={emptyEmptyBodyStyle}>No columns</div>
}

EmptyBody.displayName = "ColumnsEmptyBody"
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { FC } from "react"
import { optionListHeaderStyle } from "./style"
import { HeaderProps } from "./interface"
import { useTranslation } from "react-i18next"

export const OptionListHeader: FC<HeaderProps> = (props) => {
const { labelName } = props
const { t } = useTranslation()

return (
<div css={optionListHeaderStyle}>
<div>{labelName}</div>
</div>
)
}

OptionListHeader.displayName = "OptionListHeader"
Loading

0 comments on commit 3c71ab9

Please sign in to comment.