Skip to content

Commit

Permalink
fix(ProjectListItemCollapsable): icorrect children state
Browse files Browse the repository at this point in the history
  • Loading branch information
asabotovich committed Aug 7, 2023
1 parent 43e574b commit f589b65
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { MouseEvent, ReactNode, useMemo } from 'react';
import React, { MouseEvent, ReactNode } from 'react';
import styled from 'styled-components';
import NextLink from 'next/link';
import { gapXs, gray4, radiusM } from '@taskany/colors';
Expand Down Expand Up @@ -26,6 +26,7 @@ const StyledProjectIcons = styled.div`
interface ProjectListItemCollapsableProps {
href?: string;
project: NonNullable<ProjectByIdReturnType>;
childShown?: number;
goals?: ReactNode;
children?: ReactNode;
collapsed: boolean;
Expand All @@ -49,11 +50,10 @@ export const ProjectListItemCollapsable: React.FC<ProjectListItemCollapsableProp
children,
goals,
loading = false,
childShown = 0,
deep = 0,
href,
}) => {
const childs = useMemo(() => project.children.map(({ id }) => id), [project]);

const contentHidden = collapsed || loading;

const offset = collapseOffset * (deep > 0 && contentHidden ? deep - 1 : deep);
Expand All @@ -69,7 +69,7 @@ export const ProjectListItemCollapsable: React.FC<ProjectListItemCollapsableProp
averageScore={project.averageScore}
onClick={onProjectClickHandler}
>
{nullable(childs.length, (c) => (
{nullable(childShown, (c) => (
<StyledProjectIcons>
<IconServersOutline size="xs" />
<Text size="xs">{c}</Text>
Expand All @@ -82,7 +82,7 @@ export const ProjectListItemCollapsable: React.FC<ProjectListItemCollapsableProp
<CollapsableItem
collapsed={contentHidden}
onClick={onClick}
hasChild={!!childs.length}
hasChild={!!childShown}
header={
<ProjectListContainer offset={offset}>
{href ? (
Expand Down
8 changes: 8 additions & 0 deletions src/components/ProjectListItemConnected.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ export const ProjectListItemConnected: FC<{
setIsCollapsed((value) => !value);
}, []);

const childrenNodeShown = childrenProjects.reduce((acum, p) => {
if (p._count.goals) {
return acum + 1;
}
return acum;
}, 0);

// hide projects without goals

if (!project._count.goals) {
Expand Down Expand Up @@ -88,6 +95,7 @@ export const ProjectListItemConnected: FC<{
onTagClick={onTagClick}
/>
))}
childShown={childrenNodeShown}
project={project}
collapsed={collapsed}
onClick={onClick}
Expand Down

0 comments on commit f589b65

Please sign in to comment.