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

💄 GC-1464 Allow users to resize the sidebar in the Content Hub #1296

Merged
merged 34 commits into from
Sep 26, 2023

Conversation

timbryandev
Copy link
Contributor

@timbryandev timbryandev commented Sep 8, 2023

💬 Description

  • A new component designed to wrap existing elements and make them resizable. In this specific instance we're keeping the sidebar menu in mind.

  • Within the vite config, It looks like most of the changes are formatting related. However, there is an actual change on line 11 were I've added tsx ((x)?) to the include list: include: ["**/.specs/**/*.+(spec).ts(x)?"],

Recording:
https://www.loom.com/share/9bd52f0c9d9248258b4f7eaa57b7efe7

🔗 Links

@timbryandev timbryandev changed the title feature/GC-1464-resizable-sidebar ✨ GC-1464 Allow users to resize the sidebar in the Content Hub Sep 8, 2023
@timbryandev timbryandev self-assigned this Sep 14, 2023
lib/helpers.ts Show resolved Hide resolved
lib/Resizeable/index.tsx Outdated Show resolved Hide resolved
@timbryandev timbryandev marked this pull request as ready for review September 14, 2023 15:50
Copy link
Contributor

@micmcgrorty micmcgrorty left a comment

Choose a reason for hiding this comment

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

Awesome stuff 🙌

@timbryandev timbryandev changed the title ✨ GC-1464 Allow users to resize the sidebar in the Content Hub 💄 GC-1464 Allow users to resize the sidebar in the Content Hub Sep 15, 2023

/**
* A wrapper for making a given child element resizable
* @param children The element to be resized
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reasoning for having types and comment blocks 🤔

They are already out of sync and like in this case shouldn't children be added to the interface but it isn't it's only described in the comment block? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

For me comment blocks are currently used to explain a complex or smelly piece of implementation, I don't see how the comment blocks add anything other than a maintenance overhead for future refactors. Some ideas to remove the need for the comment blocks...

  • maxWidth to maxResizableWidth
  • minWidth to minResizedWidth
  • defaultWidth to initialWidth
  • add type for children as I am assuming it can't be any react node (e.g. a fragment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks Kyle. I think at the time I was having a bit of trouble trying to remember what props I needed and why I needed them as I was working around new problems and iterating. I'll take them out and refactor the props & interface as advised now the solution is "complete".

Copy link
Contributor Author

@timbryandev timbryandev Sep 26, 2023

Choose a reason for hiding this comment

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

Just had a look back at the code to refresh my memory and we are actually defining the children prop via PropsWithChildren: }: PropsWithChildren<ResizableProps>) {

I still action the rest though. Thanks again for the renaming suggestions as I think the naming was where my initial confusions must have been occuring!

...rest
}: PropsWithChildren<ResizableProps>) {
const containerWidth = toPixels(
rest.containerWidth ?? document.body.offsetWidth
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is containerWidth stored in rest but other properties aren't? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah this doesn't look great. I was lazily looking for a way to dynamically set the default value for containerWidth if it was undefined but I didn't want to do it as a default param in case a falsy value such as 0 gets passed in and then overridden by my default.

I'll clean this up!


const stopDrag = () => {
document.removeEventListener("mousemove", doDrag, false);
document.removeEventListener("mouseup", stopDrag, false);
Copy link
Contributor

Choose a reason for hiding this comment

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

These events will never be removed.

This is because on re-render stopDrag and doDrag will have a different signature and removeEventListener won't work.

Talk to @micmcgrorty about this, we had a similar issue with editor server events recently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting point! I'll ask Michael about it :)

import { describe, expect, it, vi } from "vitest";
import { keepValueWithinRange, toPixels } from "../helpers";

describe("helpers: toPixels", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

vite.config.ts Show resolved Hide resolved
@kyleharper kyleharper self-requested a review September 26, 2023 11:09
@timbryandev timbryandev merged commit 3c040d7 into main Sep 26, 2023
2 checks passed
@timbryandev timbryandev deleted the feature/GC-1464-resizable-sidebar branch September 26, 2023 12:56
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.

3 participants