From fa6d910723835a8eab333c62307d71cd4eac4cda Mon Sep 17 00:00:00 2001 From: seb Date: Thu, 8 Oct 2026 20:12:37 +0200 Subject: [PATCH] u --- .../article/boxes/ArticleViewName.jsx | 80 +++++++++++++++---- src/components/article/tabs/ArticleSeoTab.jsx | 38 +-------- 2 files changed, 65 insertions(+), 53 deletions(-) diff --git a/src/components/article/boxes/ArticleViewName.jsx b/src/components/article/boxes/ArticleViewName.jsx index 6273266..1abd021 100644 --- a/src/components/article/boxes/ArticleViewName.jsx +++ b/src/components/article/boxes/ArticleViewName.jsx @@ -4,7 +4,7 @@ import SingleLineTextEdit from 'dashgui/SingleLineTextEdit'; import { getCategoryState } from '../../../automats/categoryAutomat'; import artikelAutomat from '../../../automats/artikelAutomat'; import { getCategoryBreadcrumbs, categoryDisplayName } from '../../../utils/categoryUtils'; -import { Box, Chip, IconButton } from '@mui/material'; +import { Box, Chip, IconButton, Typography } from '@mui/material'; import AddIcon from '@mui/icons-material/Add'; import CategoryPickerDialog from '../CategoryPickerDialog'; import { notifyError } from '../../../utils/notify'; @@ -66,8 +66,9 @@ function categoryIdsChanged(a, b) { function draftDirty(draft, saved) { const nameDiff = draft.name.trim() !== String(saved.name ?? '').trim(); + const seoDiff = String(draft.seo ?? '').trim() !== String(saved.seo ?? '').trim(); const catDiff = categoryIdsChanged(draft.categoryIds, saved.categoryIds); - return nameDiff || catDiff; + return nameDiff || seoDiff || catDiff; } function draftValid(draft) { @@ -207,10 +208,10 @@ class CategoryPills extends Component { class NameDisplay extends Component { render() { - const { name, categoryIds } = this.props; + const { name, seo, categoryIds } = this.props; return ( - + {}} sx={articleNameFieldHiddenSx} /> + {seo ? ( + + + {seo} + + + ) : null} {(categoryIds?.length ?? 0) > 0 ? ( @@ -232,13 +240,15 @@ class NameEdit extends Component { super(props); this.state = { name: props.name, + seo: props.seo ?? '', categoryIds: [...(props.categoryIds ?? [])], }; } componentDidMount() { - const { onNameDraftChange, onCategoryIdsDraftChange } = this.props; + const { onNameDraftChange, onSeoDraftChange, onCategoryIdsDraftChange } = this.props; onNameDraftChange?.(this.state.name); + onSeoDraftChange?.(this.state.seo); onCategoryIdsDraftChange?.(this.state.categoryIds); } @@ -247,22 +257,35 @@ class NameEdit extends Component { this.props.onNameDraftChange?.(name); }; + handleSeoChange = (seo) => { + this.setState({ seo }); + this.props.onSeoDraftChange?.(seo); + }; + handleCategoryIdsChange = (categoryIds) => { this.setState({ categoryIds }); this.props.onCategoryIdsDraftChange?.(categoryIds); }; render() { - const { name, categoryIds } = this.state; + const { name, seo, categoryIds } = this.state; return ( - + + + + { + this.setState({ seoDraft: seo }); + }; + handleCategoryIdsDraftChange = (categoryIds) => { this.setState({ categoryIdsDraft: categoryIds }); }; handleSave = async () => { const { article: articleData, onArticleUpdated } = this.props; - const { nameDraft, categoryIdsDraft } = this.state; - const name = nameDraft.trim(); - const categoryIds = categoryIdsDraft; + const { nameDraft, seoDraft, categoryIdsDraft } = this.state; + const name = nameDraft != null ? nameDraft.trim() : String(articleData.name ?? '').trim(); + const seo = seoDraft != null ? seoDraft.trim() : String(articleData.seo ?? articleData.seoDescription ?? '').trim(); + const categoryIds = categoryIdsDraft ?? (articleData.categoryIds ?? []); + const nameChanged = name !== String(articleData.name ?? '').trim(); + const seoChanged = seo !== String(articleData.seo ?? articleData.seoDescription ?? '').trim(); const categoriesChanged = categoryIdsChanged(categoryIds, articleData.categoryIds); let article = null; - if (nameChanged) { - const nameRes = await artikelAutomat.actions.update(articleData.sku, { name }); - article = nameRes.article; + if (nameChanged || seoChanged) { + const updateBody = {}; + if (nameChanged) updateBody.name = name; + if (seoChanged) updateBody.seo = seo; + const res = await artikelAutomat.actions.update(articleData.sku, updateBody); + article = res.article; } if (categoriesChanged) { @@ -312,17 +346,26 @@ export default class ArticleViewName extends PureComponent { } if (article) onArticleUpdated?.(article); - this.setState({ nameDraft: null, categoryIdsDraft: null }); + this.setState({ nameDraft: null, seoDraft: null, categoryIdsDraft: null }); }; render() { const { article: articleData } = this.props; - const { nameDraft, categoryIdsDraft } = this.state; + const { nameDraft, seoDraft, categoryIdsDraft } = this.state; const savedCategoryIds = articleData.categoryIds ?? []; - const value = { name: articleData.name ?? '', categoryIds: [...savedCategoryIds] }; + const savedSeo = articleData.seo ?? articleData.seoDescription ?? ''; + const value = { + name: articleData.name ?? '', + seo: savedSeo, + categoryIds: [...savedCategoryIds], + }; const draft = nameDraft != null && categoryIdsDraft != null - ? { name: nameDraft, categoryIds: categoryIdsDraft } + ? { + name: nameDraft, + seo: seoDraft ?? savedSeo, + categoryIds: categoryIdsDraft, + } : null; return ( @@ -339,14 +382,17 @@ export default class ArticleViewName extends PureComponent { display={ } edit={ } diff --git a/src/components/article/tabs/ArticleSeoTab.jsx b/src/components/article/tabs/ArticleSeoTab.jsx index 825de36..6e1dfcc 100644 --- a/src/components/article/tabs/ArticleSeoTab.jsx +++ b/src/components/article/tabs/ArticleSeoTab.jsx @@ -1,37 +1,10 @@ import { Component } from 'react'; import Box from '@mui/material/Box'; -import Typography from '@mui/material/Typography'; -function PanelValue({ label, children }) { - if (children == null || children === '') return null; - return ( - - {label ? ( - - {label} - - ) : null} - - {children} - - - ); -} - -function PanelHtmlValue({ label, html }) { +function PanelHtmlValue({ html }) { if (html == null || html === '') return null; return ( - {label ? ( - - {label} - - ) : null} ({ p: 1.5, @@ -83,14 +56,7 @@ function PanelHtmlValue({ label, html }) { export default class ArticleSeoTab extends Component { render() { const { article: articleData } = this.props; - const seo = articleData.seo ?? articleData.seoDescription; const desc = articleData.desc ?? articleData.description; - return ( - <> - {articleData.slug} - {seo} - - - ); + return ; } }