diff --git a/src/components/article/boxes/ArticleViewBrand.jsx b/src/components/article/boxes/ArticleViewBrand.jsx index ea04bd6..ecabc09 100644 --- a/src/components/article/boxes/ArticleViewBrand.jsx +++ b/src/components/article/boxes/ArticleViewBrand.jsx @@ -147,7 +147,14 @@ export default class ArticleViewBrand extends Component { isDirty={brandDraftDirty} canSave={brandDraftValid} display={{value.name || null}} - edit={} + edit={({ draft, onChange, inputRef }) => ( + + )} /> ); } diff --git a/src/components/article/boxes/ArticleViewEANs.jsx b/src/components/article/boxes/ArticleViewEANs.jsx index 81263fe..a934347 100644 --- a/src/components/article/boxes/ArticleViewEANs.jsx +++ b/src/components/article/boxes/ArticleViewEANs.jsx @@ -112,7 +112,9 @@ export default class ArticleViewEANs extends Component { isDirty={eansDraftDirty} canSave={eansDraftValid} display={} - edit={} + edit={({ draft, onChange, inputRef }) => ( + + )} /> ); } diff --git a/src/components/article/boxes/ArticleViewName.jsx b/src/components/article/boxes/ArticleViewName.jsx index a71afd2..f576b3e 100644 --- a/src/components/article/boxes/ArticleViewName.jsx +++ b/src/components/article/boxes/ArticleViewName.jsx @@ -179,24 +179,20 @@ class NameDisplay extends Component { class NameEdit extends Component { render() { - const { draft, onChange, inputRef, name, categoryIds } = this.props; - const currentName = draft?.name ?? name; - const currentCategoryIds = draft?.categoryIds ?? categoryIds; + const { name, categoryIds } = this.props; return ( onChange({ ...draft, name: nextName })} + value={name} + onChange={() => {}} sx={articleNameFieldSx} /> onChange({ ...draft, categoryIds: nextIds })} /> ); @@ -217,6 +213,7 @@ export default class ArticleViewName extends Component { let article = null; if (nameChanged) { + console.log('nameChanged', name, articleData.name); const nameRes = await store.article.update(articleData.sku, { name }); article = nameRes.article; } @@ -248,12 +245,16 @@ export default class ArticleViewName extends Component { } edit={ {}} + onCategoryIdsChange={() => {}} + onIsDirtyChange={() => {}} /> } /> diff --git a/src/components/article/boxes/ArticleViewPrice.jsx b/src/components/article/boxes/ArticleViewPrice.jsx index db82b4c..639176a 100644 --- a/src/components/article/boxes/ArticleViewPrice.jsx +++ b/src/components/article/boxes/ArticleViewPrice.jsx @@ -512,13 +512,16 @@ export default class ArticleViewPrice extends Component { onSave={this.handleSave} isDirty={priceDraftDirty} canSave={priceDraftValid} - overlay={ + overlay={({ editing, draft, onChange }) => ( - } + )} display={ } - edit={ + edit={({ draft, onChange, inputRef }) => ( - } + )} /> ); } diff --git a/src/components/panels/EditablePanelTile.jsx b/src/components/panels/EditablePanelTile.jsx index 19d6dff..2e7f0e0 100644 --- a/src/components/panels/EditablePanelTile.jsx +++ b/src/components/panels/EditablePanelTile.jsx @@ -1,4 +1,4 @@ -import { Component, cloneElement, createRef, isValidElement } from 'react'; +import { Component, createRef } from 'react'; import CloseOutlinedIcon from '@mui/icons-material/CloseOutlined'; import EditOutlinedIcon from '@mui/icons-material/EditOutlined'; import SaveOutlinedIcon from '@mui/icons-material/SaveOutlined'; @@ -20,10 +20,10 @@ function valuesEqual(a, b) { * Panel tile with centralized inline-edit chrome. * Pass `onSave` to enable edit UI; omit it for read-only tiles (no edit icon). * - * Content is element props (not render callbacks): + * Content: * display — React node shown when not editing - * edit — element cloned with { draft, onChange, inputRef } while editing - * overlay — optional element cloned with { editing, draft, onChange } + * edit — React node, or ( { draft, onChange, inputRef } ) => node, while editing + * overlay — optional ( { editing, draft, onChange } ) => node */ class EditablePanelTileBase extends Component { constructor(props) { @@ -199,12 +199,15 @@ class EditablePanelTileBase extends Component { const { display, edit } = this.props; const { editing, draft } = this.state; - if (editing && draft != null && isValidElement(edit)) { - return cloneElement(edit, { - draft, - onChange: this.handleDraftChange, - inputRef: this.inputRef, - }); + if (editing && draft != null) { + if (typeof edit === 'function') { + return edit({ + draft, + onChange: this.handleDraftChange, + inputRef: this.inputRef, + }); + } + return edit; } return display; } @@ -212,8 +215,8 @@ class EditablePanelTileBase extends Component { renderOverlayNode() { const { overlay } = this.props; const { editing, draft } = this.state; - if (!isValidElement(overlay)) return null; - return cloneElement(overlay, { + if (typeof overlay !== 'function') return null; + return overlay({ editing, draft, onChange: this.handleDraftChange,