Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(FilterBlock): add block that filters its subblocks #180

Merged
merged 12 commits into from
Mar 6, 2023

Conversation

DC-RomanKarpov
Copy link
Contributor

No description provided.

@gravity-ui-bot
Copy link
Contributor

Preview is ready.

src/blocks/CardLayout/CardLayout.tsx Outdated Show resolved Hide resolved
src/blocks/CardLayout/withCardLayoutItem.tsx Outdated Show resolved Hide resolved
src/blocks/FilterBlock/FilterBlock.tsx Outdated Show resolved Hide resolved
src/blocks/FilterBlock/README.md Outdated Show resolved Hide resolved
src/blocks/FilterBlock/__stories__/data.json Show resolved Hide resolved
src/components/ButtonTabs/ButtonTabs.scss Outdated Show resolved Hide resolved
src/context/innerContext/InnerContext.ts Outdated Show resolved Hide resolved
src/context/innerContext/InnerContext.ts Outdated Show resolved Hide resolved
@yuberdysheva
Copy link
Contributor

yuberdysheva commented Feb 28, 2023

Typecheck failed

&__title {
margin-bottom: $indentSM;

@include centerableTitle();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are trying to use kebab-notation for css mixins

import './FilterBlock.scss';

const b = block('filter-block');
const DEFAULT_ALL_TAG_TITLE = 'All';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to use i18n with text strings like this

: undefined;
const otherButtons: ButtonTabsItemProps[] | undefined =
filterTags && filterTags.map((tag) => ({id: tag.id, title: tag.label}));
return [...(allButton ? [allButton] : []), ...(otherButtons ? otherButtons : [])];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allButton ?? : []

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately cannot change this line as suggested, because we merge here two arrays to omit nulls in final array. Replacing ternary operator with the ?? operator because in this case type of result wont be an array.

return [...(allButton ? [allButton] : []), ...(otherButtons ? otherButtons : [])];
}, [allTag, filterTags]);

const [selectedTag, setSelectedTag] = useState(tabButtons.length ? tabButtons[0].id : null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we return null if there is no tabButtons to avoid checking it's length below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we can, but it will make the body of the memo more complex, I believe it's better to leave it as is.


const [selectedTag, setSelectedTag] = useState(tabButtons.length ? tabButtons[0].id : null);

const actualTag: string | null = useMemo(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't catch why do we need this variable? I think selectedTag is enough, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's assume that we have 3 ids, 'A', 'B', 'C'. ` We change the value of selected tag to 'C', then remove 'C' from our id list. In this case we should choose a new id to display. The actualTag is this new selected value, or the selectedTag if it still exists.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But how can we reproduce this situation? We don't have multiple tags choice or an opportunity to let no tags be selected

export interface FilterBlockProps extends Animatable, LoadableChildren {
title?: TitleProps | string;
description?: string;
filterTags: FilterTag[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could it be just tags? filterTags sounds like function name

description?: string;
filterTags: FilterTag[];
items: FilterItem[];
tagSize?: ButtonSize;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tabSize?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no entity named tabs in the block. Maybe buttonSize?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tagButtonSize =)

blockTypes: [...BlockTypes, ...getCustomBlockTypes(props.custom)],
blockTypes: [...BlockTypes, ...getCustomBlockTypes(custom)],
subBlockTypes: [...SubBlockTypes, ...getCustomSubBlockTypes(custom)],
headerBlockTypes: [...HeaderBlockTypes, ...getCustomHeaderTypes(custom)],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need subBlockTypes and headerBlockTypes in context?

Copy link
Contributor Author

@DC-RomanKarpov DC-RomanKarpov Mar 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consistency of props of the context and return values of the memo. Avoid returning of same instances differently. In context and outside it.

@@ -32,7 +32,8 @@ import {
} from './common';
import {ThemeSupporting} from '../../utils';
import {GridColumnSize, GridColumnSizesType} from '../../grid/types';
import {BannerCardProps, SubBlock} from './sub-blocks';
import {BannerCardProps, SubBlock, SubBlockModels} from './sub-blocks';
import {ButtonSize} from '@gravity-ui/uikit';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upper than internal imports

@@ -178,6 +178,7 @@ export interface ButtonProps {
metrikaGoals?: MetrikaGoal;
pixelEvents?: ButtonPixel;
target?: string;
selected?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to add this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, did not removed after testing one possible solution. Done.


const [selectedTag, setSelectedTag] = useState(tabButtons.length ? tabButtons[0].id : null);

const actualTag: string | null = useMemo(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But how can we reproduce this situation? We don't have multiple tags choice or an opportunity to let no tags be selected

description?: string;
filterTags: FilterTag[];
items: FilterItem[];
tagSize?: ButtonSize;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tagButtonSize =)

@DC-RomanKarpov DC-RomanKarpov force-pushed the roman-karpov/filter-block branch from 5e69b84 to b570dce Compare March 6, 2023 17:17
@DC-RomanKarpov DC-RomanKarpov merged commit 4b6852c into main Mar 6, 2023
@DC-RomanKarpov DC-RomanKarpov deleted the roman-karpov/filter-block branch March 6, 2023 18:08
@DC-RomanKarpov DC-RomanKarpov changed the title feat(FilterBlock): add block that filters its child's subblocks feat(FilterBlock): add block that filters its subblocks Mar 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants