Show category pills in article name view, delay new article button until loaded
- Display category breadcrumb chips below article name in ArticleViewName - Only show NewArticleTile when articles are successfully loaded
This commit is contained in:
@@ -69,6 +69,8 @@ export default function ArticleView({
|
|||||||
<PanelTileGrid>
|
<PanelTileGrid>
|
||||||
<ArticleViewName
|
<ArticleViewName
|
||||||
article={articleData}
|
article={articleData}
|
||||||
|
categories={categories}
|
||||||
|
rootCategoryId={rootCategoryId}
|
||||||
onArticleUpdated={onArticleUpdated}
|
onArticleUpdated={onArticleUpdated}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import SingleLineTextEdit from '../../SingleLineTextEdit';
|
|||||||
import { article } from '../../../api';
|
import { article } from '../../../api';
|
||||||
import { requireObject } from '../../../utils/apiShape';
|
import { requireObject } from '../../../utils/apiShape';
|
||||||
import { PANEL_TILE_KEYS } from '../../../theme';
|
import { PANEL_TILE_KEYS } from '../../../theme';
|
||||||
|
import { getCategoryBreadcrumbs } from '../../../store/categorySlice';
|
||||||
|
import { Box, Chip } from '@mui/material';
|
||||||
|
|
||||||
const articleNameTextSx = {
|
const articleNameTextSx = {
|
||||||
fontWeight: 700,
|
fontWeight: 700,
|
||||||
@@ -33,6 +35,13 @@ const articleNameFieldHiddenSx = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const pillsContainerSx = {
|
||||||
|
display: 'flex',
|
||||||
|
flexWrap: 'wrap',
|
||||||
|
gap: 0.5,
|
||||||
|
mt: 'auto',
|
||||||
|
};
|
||||||
|
|
||||||
function nameDraftDirty(draft, saved) {
|
function nameDraftDirty(draft, saved) {
|
||||||
return draft.name.trim() !== String(saved.name ?? '').trim();
|
return draft.name.trim() !== String(saved.name ?? '').trim();
|
||||||
}
|
}
|
||||||
@@ -45,7 +54,14 @@ const headerTileSx = {
|
|||||||
minHeight: 0,
|
minHeight: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function ArticleViewName({ article: articleData, onArticleUpdated }) {
|
function buildCategoryLabel(categories, categoryId, rootCategoryId) {
|
||||||
|
if (!categories || categoryId == null) return '';
|
||||||
|
const crumbs = getCategoryBreadcrumbs(categories, categoryId, rootCategoryId);
|
||||||
|
if (crumbs.length === 0) return '';
|
||||||
|
return crumbs.map((c) => c.name).join(' | ');
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ArticleViewName({ article: articleData, categories, rootCategoryId, onArticleUpdated }) {
|
||||||
const handleSave = async (draft) => {
|
const handleSave = async (draft) => {
|
||||||
const name = draft.name.trim();
|
const name = draft.name.trim();
|
||||||
const res = await article.update(articleData.sku, { name });
|
const res = await article.update(articleData.sku, { name });
|
||||||
@@ -54,6 +70,11 @@ export default function ArticleViewName({ article: articleData, onArticleUpdated
|
|||||||
onArticleUpdated?.(res.article);
|
onArticleUpdated?.(res.article);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const categoryIds = articleData.categoryIds ?? [];
|
||||||
|
const categoryLabels = categoryIds
|
||||||
|
.map((id) => ({ id, label: buildCategoryLabel(categories, id, rootCategoryId) }))
|
||||||
|
.filter((c) => c.label);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<EditablePanelTile
|
<EditablePanelTile
|
||||||
wide={3}
|
wide={3}
|
||||||
@@ -65,13 +86,24 @@ export default function ArticleViewName({ article: articleData, onArticleUpdated
|
|||||||
isDirty={nameDraftDirty}
|
isDirty={nameDraftDirty}
|
||||||
canSave={nameDraftValid}
|
canSave={nameDraftValid}
|
||||||
renderDisplay={({ name }) => (
|
renderDisplay={({ name }) => (
|
||||||
<SingleLineTextEdit
|
<Box sx={{ display: 'flex', flexDirection: 'column', flex: 1, alignSelf: 'stretch' }}>
|
||||||
label="Name"
|
<Box sx={{ flex: 1, display: 'flex', alignItems: 'center' }}>
|
||||||
value={name}
|
<SingleLineTextEdit
|
||||||
readOnly
|
label="Name"
|
||||||
onChange={() => {}}
|
value={name}
|
||||||
sx={articleNameFieldHiddenSx}
|
readOnly
|
||||||
/>
|
onChange={() => {}}
|
||||||
|
sx={articleNameFieldHiddenSx}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
{categoryLabels.length > 0 && (
|
||||||
|
<Box sx={pillsContainerSx}>
|
||||||
|
{categoryLabels.map(({ id, label }) => (
|
||||||
|
<Chip key={id} label={label} size="small" variant="outlined" />
|
||||||
|
))}
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
)}
|
)}
|
||||||
renderEdit={(draft, onChange, inputRef) => (
|
renderEdit={(draft, onChange, inputRef) => (
|
||||||
<SingleLineTextEdit
|
<SingleLineTextEdit
|
||||||
|
|||||||
@@ -462,7 +462,7 @@ class ArtikelKategorienPage extends Component {
|
|||||||
))}
|
))}
|
||||||
|
|
||||||
{renameMode && <NewCategoryTile parentId={currentCategoryId} />}
|
{renameMode && <NewCategoryTile parentId={currentCategoryId} />}
|
||||||
{!renameMode && (
|
{!renameMode && articlesStatus === 'succeeded' && (
|
||||||
<NewArticleTile
|
<NewArticleTile
|
||||||
parentId={currentCategoryId}
|
parentId={currentCategoryId}
|
||||||
onOpenArticle={this.handleArticleClick}
|
onOpenArticle={this.handleArticleClick}
|
||||||
|
|||||||
Reference in New Issue
Block a user