This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
DEVPROD-1647 Add animation to details button when details menu items are changed. #424
Merged
Merged
Changes from 7 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fb9390c
Refactor details menu to contain button logic
khelif96 3cb7f70
Details menu should animate when field is toggled
khelif96 b91bfe2
Add animation for details button
khelif96 838461e
Merge branch 'main' into DEVPROD-1647
khelif96 c9ae626
Tests
khelif96 2f06bda
Snapshots
khelif96 0bbc1b8
Types
khelif96 6dfb5b6
Merge branch 'main' into DEVPROD-1647
khelif96 948bb9d
Don't animate if details menu is open
khelif96 50a4819
Merge branch 'main' into DEVPROD-1647
khelif96 9f2c04f
Dont animate on first render
khelif96 9537118
Merge branch 'main' into DEVPROD-1647
khelif96 b7f5733
Address changes
khelif96 5487ee9
Wait for 2 updates
khelif96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { act, waitFor } from "@testing-library/react"; | ||
import { QueryParams } from "constants/queryParams"; | ||
import { LogContextProvider, useLogContext } from "context/LogContext"; | ||
import { RenderFakeToastContext } from "context/toast/__mocks__"; | ||
import { useQueryParam } from "hooks/useQueryParam"; | ||
import { renderWithRouterMatch as render, screen, userEvent } from "test_utils"; | ||
import { renderComponentWithHook } from "test_utils/TestHooks"; | ||
import DetailsMenu from "."; | ||
|
||
const wrapper = ({ children }: { children: React.ReactNode }) => ( | ||
<LogContextProvider initialLogLines={logs}>{children}</LogContextProvider> | ||
); | ||
|
||
const logs = [ | ||
"line 1", | ||
"line 2", | ||
"line 3", | ||
"line 4", | ||
"line 5", | ||
"line 6", | ||
"line 7", | ||
]; | ||
/** | ||
* `renderSharingMenu` renders the sharing menu with the default open prop | ||
* @returns - hook and utils | ||
*/ | ||
const renderDetailsMenu = () => { | ||
const useCombinedHook = () => ({ | ||
useLogContext: useLogContext(), | ||
useQueryParam: useQueryParam<number | undefined>( | ||
QueryParams.UpperRange, | ||
undefined | ||
), | ||
}); | ||
const { Component: MenuComponent, hook } = renderComponentWithHook( | ||
useCombinedHook, | ||
<DetailsMenu disabled={false} /> | ||
); | ||
const { Component } = RenderFakeToastContext(<MenuComponent />); | ||
const utils = render(<Component />, { wrapper }); | ||
return { | ||
hook, | ||
utils, | ||
}; | ||
}; | ||
|
||
describe("detailsMenu", () => { | ||
it("should render a details menu button", () => { | ||
renderDetailsMenu(); | ||
expect(screen.getByText("Details")).toBeInTheDocument(); | ||
}); | ||
it("clicking on the details menu button should open the details menu", async () => { | ||
const user = userEvent.setup(); | ||
|
||
renderDetailsMenu(); | ||
expect(screen.queryByDataCy("details-menu")).not.toBeInTheDocument(); | ||
const detailsButton = screen.getByRole("button", { | ||
name: "Details", | ||
}); | ||
expect(detailsButton).toBeEnabled(); | ||
await user.click(detailsButton); | ||
expect(screen.getByDataCy("details-menu")).toBeInTheDocument(); | ||
}); | ||
it("updating search range should flash the details button", async () => { | ||
jest.useFakeTimers(); | ||
|
||
const { hook } = renderDetailsMenu(); | ||
expect(screen.queryByDataCy("details-menu")).not.toBeInTheDocument(); | ||
const detailsButton = screen.getByRole("button", { | ||
name: "Details", | ||
}); | ||
expect(detailsButton).toBeEnabled(); | ||
act(() => { | ||
hook.current.useQueryParam[1](1); | ||
}); | ||
expect(detailsButton).toHaveAttribute("data-variant", "primary"); | ||
jest.runAllTimers(); | ||
await waitFor(() => { | ||
expect(detailsButton).toHaveAttribute("data-variant", "default"); | ||
}); | ||
}); | ||
}); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,53 @@ | ||||||
import styled from "@emotion/styled"; | ||||||
import { size } from "constants/tokens"; | ||||||
import ButtonRow from "./ButtonRow"; | ||||||
import CLIInstructions from "./CLIInstructions"; | ||||||
import SearchRangeInput from "./SearchRangeInput"; | ||||||
import { | ||||||
CaseSensitiveToggle, | ||||||
ExpandableRowsToggle, | ||||||
FilterLogicToggle, | ||||||
PrettyPrintToggle, | ||||||
WrapToggle, | ||||||
} from "./Toggles"; | ||||||
|
||||||
interface DetailsMenuProps { | ||||||
["data-cy"]?: string; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
const DetailsMenuCard: React.FC<DetailsMenuProps> = ({ "data-cy": dataCy }) => ( | ||||||
<Container data-cy={dataCy}> | ||||||
<Row> | ||||||
<Column> | ||||||
<SearchRangeInput /> | ||||||
<WrapToggle /> | ||||||
<CaseSensitiveToggle /> | ||||||
</Column> | ||||||
<Column> | ||||||
<FilterLogicToggle /> | ||||||
<ExpandableRowsToggle /> | ||||||
<PrettyPrintToggle /> | ||||||
</Column> | ||||||
</Row> | ||||||
<ButtonRow /> | ||||||
<CLIInstructions /> | ||||||
</Container> | ||||||
); | ||||||
|
||||||
const Container = styled.div` | ||||||
width: 700px; | ||||||
padding: ${size.xs}; | ||||||
display: flex; | ||||||
flex-direction: column; | ||||||
`; | ||||||
|
||||||
const Row = styled.div` | ||||||
display: flex; | ||||||
flex-direction: row; | ||||||
justify-content: space-between; | ||||||
`; | ||||||
const Column = styled.div` | ||||||
width: 300px; | ||||||
`; | ||||||
|
||||||
export default DetailsMenuCard; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,53 +1,58 @@ | ||||||
import { useEffect, useState } from "react"; | ||||||
import styled from "@emotion/styled"; | ||||||
import { size } from "constants/tokens"; | ||||||
import ButtonRow from "./ButtonRow"; | ||||||
import CLIInstructions from "./CLIInstructions"; | ||||||
import SearchRangeInput from "./SearchRangeInput"; | ||||||
import { | ||||||
CaseSensitiveToggle, | ||||||
ExpandableRowsToggle, | ||||||
FilterLogicToggle, | ||||||
PrettyPrintToggle, | ||||||
WrapToggle, | ||||||
} from "./Toggles"; | ||||||
import { palette } from "@leafygreen-ui/palette"; | ||||||
import PopoverButton from "components/PopoverButton"; | ||||||
import { QueryParams } from "constants/queryParams"; | ||||||
import { useQueryParam } from "hooks/useQueryParam"; | ||||||
import DetailsMenuCard from "./DetailsMenuCard"; | ||||||
|
||||||
const { green } = palette; | ||||||
|
||||||
interface DetailsMenuProps { | ||||||
["data-cy"]?: string; | ||||||
disabled?: boolean; | ||||||
} | ||||||
const DetailsMenu: React.FC<DetailsMenuProps> = ({ disabled, ...rest }) => { | ||||||
const [lowerRange] = useQueryParam(QueryParams.LowerRange, 0); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const [upperRange] = useQueryParam<undefined | number>( | ||||||
QueryParams.UpperRange, | ||||||
undefined | ||||||
); | ||||||
const [changeVisible, setChangeVisible] = useState(false); | ||||||
|
||||||
const DetailsMenu: React.FC<DetailsMenuProps> = ({ "data-cy": dataCy }) => ( | ||||||
<DetailsMenuCard data-cy={dataCy}> | ||||||
<Row> | ||||||
<Column> | ||||||
<SearchRangeInput /> | ||||||
<WrapToggle /> | ||||||
<CaseSensitiveToggle /> | ||||||
</Column> | ||||||
<Column> | ||||||
<FilterLogicToggle /> | ||||||
<ExpandableRowsToggle /> | ||||||
<PrettyPrintToggle /> | ||||||
</Column> | ||||||
</Row> | ||||||
<ButtonRow /> | ||||||
<CLIInstructions /> | ||||||
</DetailsMenuCard> | ||||||
); | ||||||
useEffect(() => { | ||||||
setChangeVisible(true); | ||||||
const timer = setTimeout(() => { | ||||||
setChangeVisible(false); | ||||||
}, 2000); | ||||||
return () => clearTimeout(timer); | ||||||
}, [lowerRange, upperRange]); | ||||||
|
||||||
const DetailsMenuCard = styled.div` | ||||||
width: 700px; | ||||||
padding: ${size.xs}; | ||||||
display: flex; | ||||||
flex-direction: column; | ||||||
`; | ||||||
return ( | ||||||
<AnimatedPopoverButton | ||||||
buttonText="Details" | ||||||
disabled={disabled} | ||||||
variant={changeVisible ? "primary" : "default"} | ||||||
{...rest} | ||||||
> | ||||||
<DetailsMenuCard data-cy="details-menu" /> | ||||||
</AnimatedPopoverButton> | ||||||
); | ||||||
}; | ||||||
|
||||||
const Row = styled.div` | ||||||
display: flex; | ||||||
flex-direction: row; | ||||||
justify-content: space-between; | ||||||
const AnimatedPopoverButton = styled(PopoverButton)` | ||||||
/* Glow animation */ | ||||||
${({ variant }) => | ||||||
variant === "primary" && | ||||||
` | ||||||
animation: glow 1s ease-in-out infinite alternate; | ||||||
@keyframes glow { | ||||||
from { | ||||||
box-shadow: 0 0 0px ${green.base}; | ||||||
} | ||||||
to { | ||||||
box-shadow: 0 0 20px ${green.base}; | ||||||
} | ||||||
} | ||||||
`} | ||||||
`; | ||||||
const Column = styled.div` | ||||||
width: 300px; | ||||||
`; | ||||||
|
||||||
export default DetailsMenu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add assertions for all 3 states. flash off -> flash on -> flash off