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

LF-4627 [Nice to have] Implement Add to Map redesign #3715

Open
wants to merge 18 commits into
base: integration
Choose a base branch
from

Conversation

kathyavini
Copy link
Collaborator

@kathyavini kathyavini commented Mar 14, 2025

Description

This PR updates the <Drawer /> component to allow a side drawer opening from the left, and uses this variant in the "Add to Map" and "Filter Map" modals.

Changes to <Drawer />

  • Adds the property (sideDrawerDirection) and styles that control the left side drawer variant. Storybook here.
  • Renders all off-screen drawers inert. I was horrified to realize the other week when looking at our keyboard navigation that the feedback drawer components are gaining focus even when off screen! The same was true for the hamburger menu when un-opened at mobile widths.
    • TypeScript React required a type for this which I added (source documented in the file)
  • slight reconfiguration of styles so that view-specific properties like min-width are passed by the component of that view and not in the base Drawer
    • this also required a new styling class since some styles (e.g. distance from the top of screen) should not be shared between bottom and side drawers

Changes to <MapDrawer />

In addition to making it a left-opening side drawer with no backdrop:

  • Updated the + icon to the new (+ Add) style
  • Added a hover state
  • Updated the section headers

Changes not implemented (I think these warrant a different ticket)

  • Updates to "Filter Map" not shared with "Add to Map", e.g. the icons -- I think this was designed in conjunction with the "add custom filters to map" ilot project
  • Making map filters draggable/re-arrangeable. As above, and also a sizeable task in itself that deserves its own scope + ticket

Jira link: https://lite-farm.atlassian.net/browse/LF-4627

Side note: sorry for the lack of Jira numbers on the the commit messages. I committed for a whole day and a half (!) to integration before realizing my mistake, and then cherry-picked them over. This was not before I tried to git rebase them over though, and instead completely trashed my local integration (and never successfully moved the commits) 😝 I am really not good with rebase!

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Passes test case
  • UI components visually reviewed on desktop view
  • UI components visually reviewed on mobile view
  • Other (please explain)

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • The precommit and linting ran successfully
  • I have added or updated language tags for text that's part of the UI
  • I have added "MISSING" for all new language tags to languages I don't speak
  • I have added the GNU General Public License to all new files

Sorry, something went wrong.

@kathyavini kathyavini added the enhancement New feature or request label Mar 14, 2025
@kathyavini kathyavini self-assigned this Mar 14, 2025
@kathyavini kathyavini requested review from a team as code owners March 14, 2025 23:04
@kathyavini kathyavini requested review from antsgar and SayakaOno and removed request for a team March 14, 2025 23:04
@@ -27,7 +27,7 @@ export function CancelButton({ onCancel, showConfirmCancelModal, setShowConfirmC
);
}

CancelButton.PropTypes = {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Completely unrelated but this was my typo from #3710 in two files that was causing a console warning:

Screenshot 2025-03-14 at 3 50 19 PM

@@ -111,6 +111,7 @@ export default function Map({ history, isCompactSideMenu }) {
}
return () => {
dispatch(canShowSuccessHeader(false));
dispatch(setMapAddDrawerHide(farm_id));
Copy link
Collaborator Author

@kathyavini kathyavini Mar 14, 2025

Choose a reason for hiding this comment

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

This hides the Add to Map Drawer when unmounting Map (i.e. when navigating away). There was no previous need to do so since the backdrop of the modal was basically a click away listener that would close if you clicked on, e.g., the side menu.

Actually -- and I think this is a lowkey bug -- you can see on beta that if you start the "add area" action, which hides the backdrop and modal, and then navigate to a different part of app, the modal is re-opened when you return to Map because the 'showModal' redux state was never touched. I think resetting that state when leaving Map makes more sense!

SayakaOno
SayakaOno previously approved these changes Mar 17, 2025
Copy link
Collaborator

@SayakaOno SayakaOno left a comment

Choose a reason for hiding this comment

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

Looks great!

…e overrideable

Maintained higher specificity for placement properties (drawer open-close)
@kathyavini
Copy link
Collaborator Author

I would like to discuss the header shadow on scroll tomorrow (on Figma here) and will draft until that is decided on 🙏

@kathyavini kathyavini marked this pull request as draft March 19, 2025 02:19
This was Loic's preference from dev-design meeting today
@kathyavini
Copy link
Collaborator Author

kathyavini commented Mar 19, 2025

I have reverted the shadow-on-scroll commit from this branch, and noted that commit down in a new ticket for that feature if someone with more frontend skills than me wants to take it up in the future.

For now, on this branch I have just changed all the border radiuses to 4px as Loïc requested today, and I previously rearranged the SCSS a little so that only drawer directional properties (the slide in/up) are over-specified, to fix the issue above where the passed classes were not overriding default styles.

Thank you in advance for re-review 🙏

@kathyavini kathyavini marked this pull request as ready for review March 19, 2025 18:20
@kathyavini kathyavini requested a review from SayakaOno March 19, 2025 18:20
SayakaOno
SayakaOno previously approved these changes Mar 20, 2025
antsgar
antsgar previously approved these changes Mar 21, 2025
Copy link
Collaborator

@antsgar antsgar left a comment

Choose a reason for hiding this comment

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

It looks so beautiful! Thank you for thinking about accessibility ❤️

@@ -33,13 +33,16 @@ interface DrawerProps {
buttonGroup?: React.ReactNode;
fullHeight?: boolean;
desktopVariant?: DesktopDrawerVariants;
sideDrawerDirection?: 'left' | 'right';
Copy link
Collaborator

Choose a reason for hiding this comment

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

This only affects the styles applied in desktop, right? Should this be desktopSideDrawerDirection instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@antsgar Correct, because mobile has no variants! I'm definitely on board with rename but I just want to make sure it's not suggesting there is something like a mobileSideDrawer -- do you think that's clear enough from the props if this change is made?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe sideDrawerDesktopVariantDirection would be clearer? Although perhaps too long 🤔

It might also be good to make the typing more explicit so that setting the direction to left or right is only applicable if the right desktop variant is selected. Something like this could work

type CommonDrawerProps = {
  title: NonNullable<string | React.ReactNode>;
  isOpen: boolean;
  onClose: () => void;
  children: React.ReactNode;
  buttonGroup?: React.ReactNode;
  fullHeight?: boolean;
  isCompactSideMenu?: boolean; // only needed for left side drawer placement
  addBackdrop?: boolean;
  classes?: {
    modal?: string;
    drawerBackdrop?: string;
    drawerHeader?: string;
    drawerContent?: string;
    drawerContainer?: string; // applied to all drawers
    sideDrawerContainer?: string; // side drawer only
  };
}

type DrawerProps = CommonDrawerProps & ({
  desktopVariant?: DesktopDrawerVariants.DRAWER | DesktopDrawerVariants.MODAL;
  sideDrawerDirection: never;
} | {
  desktopVariant: DesktopDrawerVariants.SIDE_DRAWER;
  sideDrawerDirection: 'left' | 'right';
});

and then a TS error would show up if you try to set up the direction but forgot to set up the right variant.

Copy link
Collaborator Author

@kathyavini kathyavini Mar 24, 2025

Choose a reason for hiding this comment

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

Ah I really did want to split up types (for isCompactSideMenu actually) but I removed it because I thought the union type was so much harder to read and the import was in a JS file anyway. This union syntax I like more though!

But the code above isn't working for me like this (even in .tsx files):

and then a TS error would show up if you try to set up the direction but forgot to set up the right variant.

Did it work for you? Instead I only get an error in the valid case of passing neither desktopVariant nor sideDrawer, and I haven't been able to resolve this... 😓 (or actually that one can be resolved by sideDrawerDirection?: never; but then for sure I don't think it would be possible to flag supplying a direction but not a variant)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it work like this?

type DrawerProps = CommonDrawerProps & ({
  desktopVariant?: DesktopDrawerVariants.DRAWER | DesktopDrawerVariants.MODAL;
  sideDrawerDirection?: never;
} | {
  desktopVariant: DesktopDrawerVariants.SIDE_DRAWER;
  sideDrawerDirection?: 'left' | 'right';
})

I'm getting an error if I try to pass a direction without a variant, and no error if I pass neither.

addBackdrop = true,
}: DrawerProps) => {
const theme = useTheme();
const isDesktop = useMediaQuery(theme.breakpoints.up('sm'));

const isSideDrawer = isDesktop && desktopVariant === DesktopDrawerVariants.SIDE_DRAWER;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, maybe it'd be more explicit as isDesktopSideDrawer?

Copy link
Collaborator Author

@kathyavini kathyavini Mar 24, 2025

Choose a reason for hiding this comment

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

I guess my original question was a bit unclear here -- I was worried if the need to add desktop to the sideDrawer props and booleans means something is fundamentally unclear that variants (DesktopDrawerVariants) cannot apply to mobile (and if so, I would worry this also needs fixing). But maybe the prop name is fix enough? I'll add those first regardless of whether the types can be fixed up!

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure, perhaps in the future every desktop variant can have its own props and we can pass them in an object that's called something like desktopVariantProps or such? I think that'd be clearer and more flexible, but probably overkill at this point

@kathyavini kathyavini dismissed stale reviews from antsgar and SayakaOno via f59ab3b March 24, 2025 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants