Skip to content

Commit

Permalink
Merge pull request #1571 from AndyFong/hotfix/r-display-editor-form
Browse files Browse the repository at this point in the history
fix(Display): editor layer upload bg image & onChange old value error
  • Loading branch information
scottsut authored Mar 17, 2020
2 parents d4aa487 + bc031ac commit 4d7428f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion webapp/app/assets/json/slideSettings/rectangle.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"name": "backgroundImage",
"title": "背景图片",
"component": "upload",
"action": "slide/widget/{id}/bgImage",
"action": "slide/widget/{layerId}/bgImage",
"accept": "image/*",
"autoUpdate": true,
"labelCol": 12,
Expand Down
2 changes: 1 addition & 1 deletion webapp/app/assets/json/slideSettings/slide.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"name": "backgroundImage",
"title": "背景图片",
"component": "upload",
"action": "slide/{id}/upload/bgImage",
"action": "slide/{slideId}/upload/bgImage",
"accept": "image/*",
"autoUpdate": true,
"labelCol": 12,
Expand Down
15 changes: 6 additions & 9 deletions webapp/app/containers/Display/components/Setting/Form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ interface ISettingFormProps extends FormComponentProps {
}

const SettingForm: React.FC<ISettingFormProps> = (props, ref) => {
const { form, setting, slideId } = props
const { form, setting, slideId, layerId } = props

useImperativeHandle(ref, () => form)

return (
<Form className="display-setting-form" labelAlign="left">
<SlideSettingContext.Provider value={{ form, slideId, size: 'small' }}>
<SlideSettingContext.Provider value={{ form, slideId, layerId, size: 'small' }}>
{setting.params.map((param) => (
<ItemGroup key={param.name} param={param} />
))}
Expand All @@ -58,7 +58,6 @@ const SettingForm: React.FC<ISettingFormProps> = (props, ref) => {
}

let cachedValues = {}
let debouncedChange = null

export default Form.create<ISettingFormProps>({
onValuesChange: (props, changedValues) => {
Expand All @@ -67,12 +66,10 @@ export default Form.create<ISettingFormProps>({
}
cachedValues = { ...cachedValues, ...changedValues }
const { onChange, layerId } = props
if (!debouncedChange) {
debouncedChange = debounce((layerId) => {
onChange({ ...cachedValues }, layerId)
cachedValues = {}
}, 1000)
}
const debouncedChange = debounce((layerId) => {
onChange({ ...cachedValues }, layerId)
cachedValues = {}
}, 1000)
debouncedChange(layerId)
}
})(forwardRef(SettingForm))
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ interface IItemProps {

const Item: React.FC<IItemProps> = (props) => {
const { item } = props
const { form, size, slideId } = useContext(SlideSettingContext)
const { form, size, slideId, layerId } = useContext(SlideSettingContext)
let visible = true
const { relatedItems } = item
if (Array.isArray(relatedItems)) {
Expand Down Expand Up @@ -131,10 +131,9 @@ const Item: React.FC<IItemProps> = (props) => {
)
break
case 'upload':
const action = `${api.display}/${item.action}`.replace(
/({id})/,
slideId.toString()
)
const action = `${api.display}/${item.action}`
.replace(/({slideId})/, slideId ? `${slideId}` : '')
.replace(/({layerId})/, layerId ? `${layerId}` : '')
const img = form.getFieldValue(item.name)
control = (
<Upload name={item.name} action={action}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const SlideSettingContext = React.createContext<{
form: WrappedFormUtils
size: 'large' | 'small' | 'default'
slideId?: number
layerId?: number
}>({
form: null,
size: 'small'
Expand Down

0 comments on commit 4d7428f

Please sign in to comment.