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

ui-manchette : integration get manchette #86

Merged
merged 1 commit into from
Jul 9, 2024
Merged

ui-manchette : integration get manchette #86

merged 1 commit into from
Jul 9, 2024

Conversation

Math-R
Copy link
Contributor

@Math-R Math-R commented Jul 5, 2024

No description provided.

@Math-R Math-R force-pushed the mrd/ui-manchette branch 2 times, most recently from 28fa47c to 0916d3d Compare July 9, 2024 07:47
@Math-R Math-R marked this pull request as ready for review July 9, 2024 07:48
@Math-R Math-R self-assigned this Jul 9, 2024
@Math-R Math-R requested review from kmer2016, Yohh and Uriel-Sautron July 9, 2024 07:49
@Math-R Math-R force-pushed the mrd/ui-manchette branch from 0916d3d to 13b37f8 Compare July 9, 2024 07:57
Copy link
Contributor

@Yohh Yohh left a comment

Choose a reason for hiding this comment

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

💪

ui-manchette/src/components/Manchette.tsx Outdated Show resolved Hide resolved
ui-manchette/src/components/helpers.ts Outdated Show resolved Hide resolved
@Math-R Math-R force-pushed the mrd/ui-manchette branch 2 times, most recently from 9acd20c to 6d3d07a Compare July 9, 2024 10:48
Copy link
Contributor

@kmer2016 kmer2016 left a comment

Choose a reason for hiding this comment

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

Great work ! Add some small refacto. suggestions. I noticed that there are no unit tests included for helpers. This can be done in a separate PR if needed

ui-manchette/src/components/Manchette.tsx Outdated Show resolved Hide resolved
ui-manchette/src/hooks/isOverFlowed.ts Outdated Show resolved Hide resolved
ui-manchette/src/hooks/isOverFlowed.ts Outdated Show resolved Hide resolved
ui-manchette/src/hooks/isOverFlowed.ts Outdated Show resolved Hide resolved
ui-manchette/src/components/Manchette.tsx Outdated Show resolved Hide resolved
ui-manchette/src/components/Manchette.tsx Outdated Show resolved Hide resolved
ui-manchette/src/components/Manchette.tsx Show resolved Hide resolved
@Math-R Math-R force-pushed the mrd/ui-manchette branch from 8592dc4 to 85e9d5e Compare July 9, 2024 11:22
@Math-R Math-R requested review from kmer2016 and Yohh July 9, 2024 12:02
Copy link
Contributor

@kmer2016 kmer2016 left a comment

Choose a reason for hiding this comment

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

LGTM and tested ! Well done !

Copy link
Contributor

@Yohh Yohh left a comment

Choose a reason for hiding this comment

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

nice! don't forget to add type prefix when you import a Type

@Math-R Math-R force-pushed the mrd/ui-manchette branch 6 times, most recently from 52ce002 to f355fb8 Compare July 9, 2024 13:07
@Math-R Math-R force-pushed the mrd/ui-manchette branch from f355fb8 to da0da75 Compare July 9, 2024 13:09
@Math-R Math-R merged commit fde6e26 into dev Jul 9, 2024
1 check passed
@Math-R Math-R deleted the mrd/ui-manchette branch July 9, 2024 13:12
@@ -36,7 +36,8 @@
"dependencies": {
"classnames": "^2.5.1",
"lodash.isequal": "^4.5.0",
"tailwindcss": "^3.4.1"
"tailwindcss": "^3.4.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this @osrd-project/ui-manchette module exports its own built CSS code, why is TailWind in the dependencies? Can I use it without Tailwind? And if I use Tailwind in my project that depends on @osrd-project/ui-manchette, what is the benefit?


const zoomIn = () => {
if (zoom < 10) setZoom(zoom + 0.5);
const zoomYIn = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to have those three constants (min, max, step) stored and named somewhere, like in a consts.ts file somewhere. I would even argue to make them overridable through props.


export const calcOperationalPointsToDisplay = (
operationalPoints: OperationalPointType[],
isProportionnal: boolean,
Copy link
Contributor

Choose a reason for hiding this comment

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

I only point it here, but there are a lot of typos with proportionnal that should be proportional with one single N in the manchette codebase.

}
};

export const operationalPointsHeight = (
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that in this function, you mutate existing styles attributes for the input operationalPoints.

I think this pattern is dangerous: When I see this function that takes a StyledOperationalPointType[] and returns another StyledOperationalPointType[], I would expect it not to mutate what's inside the input value:

  • Either you return something totally new
  • Either you mutate, and name and type the function accordingly (like const setOperationalPointsHeight: (...) => void for instance)

I know JavaScript itself does not respect this convention (like with Array#reverse for instance), but it has been widely criticized, and it is now quite standard to have no side effects on functions that return something new.

Anyway, a common way to avoid mutating the input would be to replace the op.styles = {...}; return op; by return {...op, styles: {...}};.

@@ -1,3 +1,5 @@
import React from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

Only import { CSSProperties } instead would be better I think

positions: number[];
times: number[];
}[];
} & {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are there two types that are combined with { ... } & { ... } instead of one single type?

const Manchette: React.FC<ManchetteProps> = ({ operationalPoints, projectPathTrainResult }) => {
const manchette = useRef<HTMLDivElement>(null);

const [zoomY, setZoomY] = useState(1);
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 you use so many separate setState instead of one single "larger" setState such as something like this for instance?

const [state, setState] = useState({
  zoomX: 1,
  zoomY: 1,
  offsetX: 0,
  offsetY: 0,
  // ...
});

The "more compact" version seems easier to read for me (it's easy to have a full overview of what's in the state). Do you see any pros on your "split" version?

jacomyal added a commit that referenced this pull request Jul 9, 2024
This commit fixes various comments from my review for PR #86. The PR has
been merged while I was reviewing it, so we decided I can directly
submit a new one with my fixes.

Details:
- Fixes all typos from proportionnal to proportional
- Fixes React.XXX as import { XXX } from 'react'
- Refactors Manchette.tsx code to have a single, more readable setState
- Removes magic zoom boundaries and replace them with proper consts
- Fixes operationalPointsHeight so that it does not mutate things
  anymore
- Rewrites calcOperationalPointsToDisplay with simpler code and some
  comment, to help make it maintainable
- Actually stops displaying OperationalPoint with display: false
github-merge-queue bot pushed a commit that referenced this pull request Jul 10, 2024
This commit fixes various comments from my review for PR #86. The PR has
been merged while I was reviewing it, so we decided I can directly
submit a new one with my fixes.

Details:
- Fixes all typos from proportionnal to proportional
- Fixes React.XXX as import { XXX } from 'react'
- Refactors Manchette.tsx code to have a single, more readable setState
- Removes magic zoom boundaries and replace them with proper consts
- Fixes operationalPointsHeight so that it does not mutate things
  anymore
- Rewrites calcOperationalPointsToDisplay with simpler code and some
  comment, to help make it maintainable
- Actually stops displaying OperationalPoint with display: false
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