Skip to content

Antd Upgrade #307

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 14 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor: antd component changes
  • Loading branch information
raheeliftikhar5 committed Jul 24, 2023
commit 47c172309ec5e0c4ab6f712c4fb5ae9ea0ab6fcb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export function Dropdown<T extends OptionsType>(props: DropdownProps<T>) {
<CustomSelect
open={props.open}
listHeight={props.lineHeight}
dropdownClassName="ob-dropdown-control-select"
popupClassName="ob-dropdown-control-select"
showSearch={props.showSearch}
filterOption={(input, option) => {
if (props.optionFilterProp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function TriggeredDialog(props: {
</div>
)}
<CustomModal
visible={visible}
open={visible}
title={modalTitle}
destroyOnClose
onCancel={() => setVisible(false)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { RgbaStringColorPicker } from "react-colorful";
import { Popover } from "antd";
import { ActionType } from '@rc-component/trigger/lib/interface';
import {
alphaOfRgba,
toRGBA,
Expand All @@ -14,7 +15,7 @@ import { changeValueAction } from "lowcoder-core";

interface ColorSelectProps {
color: string;
trigger?: string;
trigger?: ActionType;
dispatch?: (value: any) => void;
changeColor?: (value: any) => void;
}
Expand All @@ -35,7 +36,7 @@ export const ColorSelect = (props: ColorSelectProps) => {
<Popover
trigger={trigger}
destroyTooltipOnHide={true}
onVisibleChange={(value) => {
onOpenChange={(value) => {
pickerColor.current = toRGBA(color);
setVisible(value);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ function CustomSelect(props: CustomSelectProps & AntdSelectProps) {
innerRef,
className,
border,
dropdownClassName = "custom-ant-select-dropdown",
popupClassName = "custom-ant-select-dropdown",
...restProps
} = props;
return (
<SelectWrapper className={className} ref={innerRef} border={border}>
<AntdSelect
dropdownClassName={dropdownClassName}
dropdownMatchSelectWidth={false}
popupClassName={popupClassName}
popupMatchSelectWidth={false}
suffixIcon={<PackUpIcon />}
{...restProps}
>
Expand Down
2 changes: 1 addition & 1 deletion client/packages/lowcoder-design/src/components/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ const FormSelect = (props: any) => {
onChange(x);
props.afterChange && props.afterChange(x);
}}
dropdownMatchSelectWidth={false}
popupMatchSelectWidth={false}
placeholder={props.placeholder}
dropdownRender={props.dropdownRender}
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import type { IconDefinition } from "@fortawesome/free-regular-svg-icons";
import { Popover } from "antd";
import { ActionType } from '@rc-component/trigger/lib/interface';
import { TacoInput } from "components/tacoInput";
import { Tooltip } from "components/toolTip";
import { trans } from "i18n/design";
Expand Down Expand Up @@ -274,7 +275,7 @@ export const IconSelectBase = (props: {
children?: ReactNode;
visible?: boolean;
setVisible?: (v: boolean) => void;
trigger?: string;
trigger?: ActionType;
leftOffset?: number;
parent?: HTMLElement | null;
searchKeywords?: Record<string, string>;
Expand All @@ -285,8 +286,8 @@ export const IconSelectBase = (props: {
trigger={props.trigger}
placement="left"
align={{ offset: [props.leftOffset ?? 0, 0, 0, 0] }}
visible={props.visible}
onVisibleChange={setVisible}
open={props.visible}
onOpenChange={setVisible}
getPopupContainer={parent ? () => parent : undefined}
// hide the original background when dragging the popover is allowed
overlayInnerStyle={{ border: "none", boxShadow: "none", background: "transparent" }}
Expand Down
12 changes: 6 additions & 6 deletions client/packages/lowcoder-design/src/components/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ const SimplePopover = (props: {
destroyTooltipOnHide
content={contentWithBox}
trigger="click"
visible={visible}
onVisibleChange={setVisible}
open={visible}
onOpenChange={setVisible}
placement="left"
overlayStyle={{ width: "310px" }}
>
Expand Down Expand Up @@ -100,8 +100,8 @@ const CustomPopover = (props: {
<Popover
content={contentWithBox}
trigger="click"
visible={visible}
onVisibleChange={setVisible}
open={visible}
onOpenChange={setVisible}
placement={props.type === "query" ? "top" : "left"}
overlayStyle={{ width: "310px" }}
align={{
Expand Down Expand Up @@ -225,8 +225,8 @@ const EditPopover = (props: EditPopoverProps) => {
</>
)}
trigger="click"
visible={visible}
onVisibleChange={setVisible}
open={visible}
onOpenChange={setVisible}
placement="bottomRight"
// overlayStyle={{ width: "88px" }}
align={{
Expand Down
6 changes: 4 additions & 2 deletions client/packages/lowcoder-design/src/components/toolTip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,11 @@ function ToolTipLabel(
color="#2c2c2c"
title={title && <TooltipTitleWrapper>{title}</TooltipTitleWrapper>}
overlayInnerStyle={{ maxWidth: "232px", whiteSpace: "break-spaces" }}
arrowPointAtCenter={true}
arrow={{
pointAtCenter: true
}}
placement="top"
defaultVisible={false}
defaultOpen={false}
trigger="hover"
popupVisible={!!title}
style={tooltipStyle}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const PermissionDialog = (props: {

return (
<StepModal
visible={visible}
open={visible}
destroyOnClose
onCancel={() => {
setActiveStepKey("view");
Expand Down
2 changes: 1 addition & 1 deletion client/packages/lowcoder/src/components/ResCreatePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ export function ResCreatePanel(props: ResCreateModalProps) {
</ScrollBar>
</Content>
<CreateDataSourceModal
visible={visible}
open={visible}
onCancel={() => setVisible(false)}
onCreated={() => setVisible(false)}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { AjvError, ErrorListProps, UISchemaSubmitButtonOptions, withTheme } from "@rjsf/core";
import { withTheme } from '@rjsf/core';
import { RJSFValidationError, ErrorListProps, UISchemaSubmitButtonOptions } from "@rjsf/utils";
import validator from "@rjsf/validator-ajv8";
// import Ajv from "@rjsf/validator-ajv8";
import { Button } from "antd";
import { BoolControl } from "comps/controls/boolControl";
import { jsonObjectExposingStateControl } from "comps/controls/codeStateControl";
Expand Down Expand Up @@ -107,7 +110,7 @@ function convertData(schema?: JSONSchema7, data?: any) {
// refer to ajv-i18n, https://github.com/ajv-validator/ajv-i18n/blob/master/messages/index.js
// https://github.com/ajv-validator/ajv/tree/6a671057ea6aae690b5967ee26a0ddf8452c6297#Validation-keywords
// JSON schema refer to https://json-schema.org/understanding-json-schema/reference/
function getErrorMessage(error: AjvError): string {
function getErrorMessage(error: RJSFValidationError): string {
switch (error.name) {
case "required":
return trans("jsonSchemaForm.required");
Expand All @@ -133,7 +136,7 @@ function getErrorMessage(error: AjvError): string {
return "";
}

function transformErrors(errors: AjvError[]): AjvError[] {
function transformErrors(errors: RJSFValidationError[]): RJSFValidationError[] {
return errors.map((error) => {
const message = getErrorMessage(error);
if (message) {
Expand Down Expand Up @@ -194,13 +197,14 @@ let FormBasicComp = (function () {
<Container $style={props.style}>
<ErrorBoundary>
<Form
validator={validator}
schema={props.schema}
uiSchema={props.uiSchema}
formData={convertData(props.schema, props.data.value)}
onSubmit={() => onSubmit(props)}
onChange={(e) => props.data.onChange(e.formData)}
transformErrors={(errors) => transformErrors(errors)}
ErrorList={ErrorList}
// ErrorList={ErrorList}
children={
<Button
hidden={buttonOptions?.norender}
Expand Down
22 changes: 15 additions & 7 deletions client/packages/lowcoder/src/comps/comps/preLoadComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,24 @@ enum TabKey {
function PreloadConfigModal(props: ChildrenInstance) {
const [activeKey, setActiveKey] = useState(TabKey.JavaScript);
const { showScriptsAndStyleModal, changeExternalState } = useContext(ExternalEditorContext);

const tabItems = [
{
key: TabKey.JavaScript,
label: 'JavaScript',
children: <JavaScriptTabPane comp={props.script} />
},
{
key: TabKey.CSS,
label: 'CSS',
children: <CSSTabPane comp={props.css} />
},
]
return (
<CustomModal
draggable
mask={activeKey !== TabKey.CSS}
visible={showScriptsAndStyleModal}
open={showScriptsAndStyleModal}
title={trans("preLoad.scriptsAndStyles")}
destroyOnClose
onCancel={() => changeExternalState?.({ showScriptsAndStyleModal: false })}
Expand All @@ -259,13 +272,8 @@ function PreloadConfigModal(props: ChildrenInstance) {
onChange={(k) => setActiveKey(k as TabKey)}
style={{ marginBottom: 8, marginTop: 4 }}
activeKey={activeKey}
items={ tabItems }
>
<Tabs.TabPane key={TabKey.JavaScript} tab="JavaScript">
<JavaScriptTabPane comp={props.script} />
</Tabs.TabPane>
<Tabs.TabPane key={TabKey.CSS} tab="CSS">
<CSSTabPane comp={props.css} />
</Tabs.TabPane>
</Tabs>
</CustomModal>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Tag } from "antd";
import { PresetColorTypes } from "antd/lib/_util/colors";
import { PresetStatusColorTypes } from "antd/lib/_util/colors";
import { TagsContext } from "components/table/EditableCell";
import {
ColumnTypeCompBuilder,
Expand All @@ -16,7 +16,7 @@ import { hashToNum } from "util/stringUtils";
import { CustomSelect, PackUpIcon } from "lowcoder-design";
import { ScrollBar } from "lowcoder-design";

const colors = PresetColorTypes;
const colors = PresetStatusColorTypes;

const isStringArray = (value: any) => {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ function ToolbarPopover(props: {
const popOverRef = useRef<HTMLDivElement>(null);
return (
<Popover
visible={visible}
open={visible}
overlayStyle={{ pointerEvents: "auto" }}
content={
<div
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { message, Tabs } from "antd";
import { Tabs } from "antd";
import { JSONObject, JSONValue } from "util/jsonTypes";
import { CompAction, CompActionTypes, deleteCompAction, wrapChildAction } from "lowcoder-core";
import { DispatchType, RecordConstructorToView, wrapDispatch } from "lowcoder-core";
Expand Down Expand Up @@ -32,8 +32,7 @@ import { BoolCodeControl } from "comps/controls/codeControl";
import { DisabledContext } from "comps/generators/uiCompBuilder";
import { EditorContext } from "comps/editorState";
import { checkIsMobile } from "util/commonUtils";

const { TabPane } = Tabs;
import { messageInstance } from "lowcoder-design";

const EVENT_OPTIONS = [
{
Expand Down Expand Up @@ -163,6 +162,56 @@ const TabbedContainer = (props: TabbedContainerProps) => {

// log.debug("TabbedContainer. props: ", props);

const tabItems = visibleTabs.map((tab) => {
// log.debug("Tab. tab: ", tab, " containers: ", containers);
const id = String(tab.id);
const childDispatch = wrapDispatch(wrapDispatch(dispatch, "containers"), id);
const containerProps = containers[id].children;
const hasIcon = tab.icon.props.value;
const label = (
<>
{tab.iconPosition === "left" && hasIcon && (
<span style={{ marginRight: "4px" }}>{tab.icon}</span>
)}
{tab.label}
{tab.iconPosition === "right" && hasIcon && (
<span style={{ marginLeft: "4px" }}>{tab.icon}</span>
)}
</>
);
return {
label,
key: tab.key,
forceRender: true,
children: (
<BackgroundColorContext.Provider value={props.style.background}>
<ContainerInTab
layout={containerProps.layout.getView()}
items={gridItemCompToGridItems(containerProps.items.getView())}
positionParams={containerProps.positionParams.getView()}
dispatch={childDispatch}
autoHeight={props.autoHeight}
containerPadding={[paddingWidth, 20]}
/>
</BackgroundColorContext.Provider>
)
}
// return (
// <TabPane tab={label} key={tab.key} forceRender>
// <BackgroundColorContext.Provider value={props.style.background}>
// <ContainerInTab
// layout={containerProps.layout.getView()}
// items={gridItemCompToGridItems(containerProps.items.getView())}
// positionParams={containerProps.positionParams.getView()}
// dispatch={childDispatch}
// autoHeight={props.autoHeight}
// containerPadding={[paddingWidth, 20]}
// />
// </BackgroundColorContext.Provider>
// </TabPane>
// );
})

return (
<div style={{padding: props.style.margin}}>
<StyledTabs
Expand All @@ -178,39 +227,8 @@ const TabbedContainer = (props: TabbedContainerProps) => {
animated
$isMobile={isMobile}
// tabBarGutter={32}
items={tabItems}
>
{visibleTabs.map((tab) => {
// log.debug("Tab. tab: ", tab, " containers: ", containers);
const id = String(tab.id);
const childDispatch = wrapDispatch(wrapDispatch(dispatch, "containers"), id);
const containerProps = containers[id].children;
const hasIcon = tab.icon.props.value;
const label = (
<>
{tab.iconPosition === "left" && hasIcon && (
<span style={{ marginRight: "4px" }}>{tab.icon}</span>
)}
{tab.label}
{tab.iconPosition === "right" && hasIcon && (
<span style={{ marginLeft: "4px" }}>{tab.icon}</span>
)}
</>
);
return (
<TabPane tab={label} key={tab.key} forceRender>
<BackgroundColorContext.Provider value={props.style.background}>
<ContainerInTab
layout={containerProps.layout.getView()}
items={gridItemCompToGridItems(containerProps.items.getView())}
positionParams={containerProps.positionParams.getView()}
dispatch={childDispatch}
autoHeight={props.autoHeight}
containerPadding={[paddingWidth, 20]}
/>
</BackgroundColorContext.Provider>
</TabPane>
);
})}
</StyledTabs>
</div>
);
Expand Down Expand Up @@ -293,7 +311,7 @@ class TabbedContainerImplComp extends TabbedContainerBaseComp implements IContai
} as CompAction;
}
if (value.type === "delete" && this.children.tabs.getView().length <= 1) {
message.warn(trans("tabbedContainer.atLeastOneTabError"));
messageInstance.warning(trans("tabbedContainer.atLeastOneTabError"));
// at least one tab
return this;
}
Expand Down
Loading