Skip to content

Commit 5b62522

Browse files
authored
fix: filter block nesting (#364)
* fix: filter block nesting * fix: make CardLayout title not required
1 parent b29c87a commit 5b62522

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

src/blocks/CardLayout/CardLayout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const CardLayout: React.FC<CardLayoutBlockProps> = ({
2424
children,
2525
}) => (
2626
<AnimateBlock className={b()} animate={animated}>
27-
<BlockHeader title={title} description={description} />
27+
{(title || description) && <BlockHeader title={title} description={description} />}
2828
<Row>
2929
{React.Children.map(children, (child, index) => (
3030
<Col key={index} sizes={colSizes} className={b('item')}>

src/blocks/CardLayout/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88

99
export const CardLayoutProps = {
1010
additionalProperties: false,
11-
required: ['title'],
11+
required: [],
1212
properties: {
1313
...BlockBaseProps,
1414
...AnimatableProps,

src/blocks/FilterBlock/FilterBlock.tsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import React, {useMemo, useState} from 'react';
22

3+
import {CardLayoutBlock} from '..';
34
import {AnimateBlock, BlockHeader} from '../../components';
45
import ButtonTabs, {ButtonTabsItemProps} from '../../components/ButtonTabs/ButtonTabs';
5-
import {ConstructorBlocks} from '../../containers/PageConstructor/components/ConstructorBlocks';
6+
import {ConstructorItem} from '../../containers/PageConstructor/components/ConstructorItem';
67
import {Col, Row} from '../../grid';
7-
import {BlockType, ConstructorItem, FilterBlockProps, FilterItem} from '../../models';
8-
import {block} from '../../utils';
8+
import {FilterBlockProps, FilterItem} from '../../models';
9+
import {block, getBlockKey} from '../../utils';
910

1011
import i18n from './i18n';
1112

@@ -41,19 +42,13 @@ const FilterBlock: React.FC<FilterBlockProps> = ({
4142
: selectedTag;
4243
}, [tabButtons, selectedTag]);
4344

44-
const container: ConstructorItem[] = useMemo(() => {
45+
const cards = useMemo(() => {
4546
const itemsToShow: FilterItem[] = actualTag
4647
? items.filter((item) => item.tags.includes(actualTag))
4748
: items;
48-
return [
49-
{
50-
type: BlockType.CardLayoutBlock,
51-
title: '',
52-
colSizes: colSizes,
53-
children: itemsToShow.map((item) => item.card),
54-
},
55-
];
56-
}, [actualTag, items, colSizes]);
49+
50+
return itemsToShow.map((item) => item.card);
51+
}, [actualTag, items]);
5752

5853
return (
5954
<AnimateBlock className={b()} animate={animated}>
@@ -78,7 +73,13 @@ const FilterBlock: React.FC<FilterBlockProps> = ({
7873
</Row>
7974
)}
8075
<Row className={b('block-container')}>
81-
<ConstructorBlocks items={container} />
76+
<CardLayoutBlock title="" colSizes={colSizes}>
77+
{cards.map((card, index) => {
78+
const key = getBlockKey(card, index);
79+
80+
return <ConstructorItem data={card} blockKey={key} key={key} />;
81+
})}
82+
</CardLayoutBlock>
8283
</Row>
8384
</AnimateBlock>
8485
);

src/models/constructor-items/blocks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ export interface LinkTableBlockProps extends BlockHeaderProps {
320320
}
321321

322322
export interface CardLayoutBlockProps extends Childable, Animatable, LoadableChildren {
323-
title: TitleProps | string;
323+
title?: TitleProps | string;
324324
description?: string;
325325
colSizes?: GridColumnSizesType;
326326
}

0 commit comments

Comments
 (0)