From 4180ddd61daa01bc679a882dffb5ff19782e08f9 Mon Sep 17 00:00:00 2001 From: Illia Hreben Date: Thu, 10 Nov 2022 21:58:16 +0200 Subject: [PATCH 1/4] fix: dont slide matches when one of the wasnt presented --- src/bracket-single/connectors.tsx | 20 ++++++++------------ src/bracket-single/single-elim-bracket.tsx | 20 ++++++++++++-------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/bracket-single/connectors.tsx b/src/bracket-single/connectors.tsx index 48933b9..b63ae52 100644 --- a/src/bracket-single/connectors.tsx +++ b/src/bracket-single/connectors.tsx @@ -25,26 +25,22 @@ const Connectors = ({ offsetY, }); const previousBottomPosition = (rowIndex + 1) * 2 - 1; - const previousTopMatchPosition = calculatePositionOfMatch( - previousBottomPosition - 1, - columnIndex - 1, - { + const previousTopMatchPosition = + bracketSnippet.match && + calculatePositionOfMatch(previousBottomPosition - 1, columnIndex - 1, { canvasPadding, rowHeight, columnWidth, offsetY, - } - ); - const previousBottomMatchPosition = calculatePositionOfMatch( - previousBottomPosition, - columnIndex - 1, - { + }); + const previousBottomMatchPosition = + bracketSnippet.match && + calculatePositionOfMatch(previousBottomPosition, columnIndex - 1, { canvasPadding, rowHeight, columnWidth, offsetY, - } - ); + }); return ( { const previousMatchesColumn = matchesColumn.reduce((result, match) => { + const previousMatches = matches + .filter(m => m.nextMatchId === match.id) + .sort((a, b) => sortAlphanumerically(a.name, b.name)) + + if (previousMatches.length === 1) previousMatches.unshift(null); + if (previousMatches.length === 2) previousMatches.unshift(null, null); return [ ...result, - ...matches - .filter(m => m.nextMatchId === match.id) - .sort((a, b) => sortAlphanumerically(a.name, b.name)), + ...previousMatches, ]; }, []); - if (previousMatchesColumn.length > 0) { + if (previousMatchesColumn.length > 0 && previousMatchesColumn.every(Boolean)) { return [...generateColumn(previousMatchesColumn), previousMatchesColumn]; } - return [previousMatchesColumn]; + return [previousMatchesColumn.some(Boolean)? previousMatchesColumn : []]; }; const generate2DBracketArray = final => { return final @@ -123,7 +127,7 @@ const SingleEliminationBracket = ({ canvasPadding={canvasPadding} width={width} numOfRounds={columns.length} - tournamentRoundText={match.tournamentRoundText} + tournamentRoundText={match?.tournamentRoundText} columnIndex={columnIndex} /> )} @@ -143,7 +147,7 @@ const SingleEliminationBracket = ({ }} /> )} - + {match && - + } ); }) From 7b6c14cdb580473e54315190582c090e48a37359 Mon Sep 17 00:00:00 2001 From: Illia Hreben Date: Fri, 11 Nov 2022 11:36:42 +0200 Subject: [PATCH 2/4] chore --- package.json | 3 ++- src/bracket-single/single-elim-bracket.tsx | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d4f293e..dc67684 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "build-storybook": "build-storybook -o devapp-build", "test": "jest --verbose false", "lint": "eslint \"src/**/*.js\" \"src/**/*.jsx\"", - "format": "eslint --fix \"src/**/*.js\" \"src/**/*.jsx\"" + "format": "eslint --fix \"src/**/*.js\" \"src/**/*.jsx\"", + "prepare": "npm run build" }, "author": "Omar ElGaml", "license": "ISC", diff --git a/src/bracket-single/single-elim-bracket.tsx b/src/bracket-single/single-elim-bracket.tsx index dace6be..f8af43b 100644 --- a/src/bracket-single/single-elim-bracket.tsx +++ b/src/bracket-single/single-elim-bracket.tsx @@ -50,7 +50,7 @@ const SingleEliminationBracket = ({ .sort((a, b) => sortAlphanumerically(a.name, b.name)) if (previousMatches.length === 1) previousMatches.unshift(null); - if (previousMatches.length === 2) previousMatches.unshift(null, null); + if (previousMatches.length === 0) previousMatches.unshift(null, null); return [ ...result, ...previousMatches, From 7acf63f45f9058fe677171e0a0426de5b3fa6130 Mon Sep 17 00:00:00 2001 From: Illia Hreben Date: Thu, 1 Dec 2022 17:08:58 +0200 Subject: [PATCH 3/4] fix: disable line to child party if it not there --- package.json | 1 - src/bracket-single/connectors.tsx | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index dc67684..4f60328 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,6 @@ "@storybook/addon-links": "^6.5.9", "@storybook/addon-storysource": "^6.5.9", "@storybook/react": "^6.5.9", - "@types/jest": "^29.0.2", "@types/styled-components": "^5.1.10", "@typescript-eslint/parser": "^4.28.1", "babel-eslint": "^10.1.0", diff --git a/src/bracket-single/connectors.tsx b/src/bracket-single/connectors.tsx index b63ae52..ebdcec3 100644 --- a/src/bracket-single/connectors.tsx +++ b/src/bracket-single/connectors.tsx @@ -26,7 +26,7 @@ const Connectors = ({ }); const previousBottomPosition = (rowIndex + 1) * 2 - 1; const previousTopMatchPosition = - bracketSnippet.match && + bracketSnippet.previousTopMatch && calculatePositionOfMatch(previousBottomPosition - 1, columnIndex - 1, { canvasPadding, rowHeight, @@ -34,7 +34,7 @@ const Connectors = ({ offsetY, }); const previousBottomMatchPosition = - bracketSnippet.match && + bracketSnippet.previousBottomMatch && calculatePositionOfMatch(previousBottomPosition, columnIndex - 1, { canvasPadding, rowHeight, From 6b0743ad34430dccfef36de2fb0b21a6f60fc261 Mon Sep 17 00:00:00 2001 From: Illia Hreben Date: Thu, 1 Dec 2022 17:15:41 +0200 Subject: [PATCH 4/4] chore: revert package.json --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4f60328..d4f293e 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,7 @@ "build-storybook": "build-storybook -o devapp-build", "test": "jest --verbose false", "lint": "eslint \"src/**/*.js\" \"src/**/*.jsx\"", - "format": "eslint --fix \"src/**/*.js\" \"src/**/*.jsx\"", - "prepare": "npm run build" + "format": "eslint --fix \"src/**/*.js\" \"src/**/*.jsx\"" }, "author": "Omar ElGaml", "license": "ISC", @@ -34,6 +33,7 @@ "@storybook/addon-links": "^6.5.9", "@storybook/addon-storysource": "^6.5.9", "@storybook/react": "^6.5.9", + "@types/jest": "^29.0.2", "@types/styled-components": "^5.1.10", "@typescript-eslint/parser": "^4.28.1", "babel-eslint": "^10.1.0",