-
Notifications
You must be signed in to change notification settings - Fork 2
Added days filter #1142
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
Merged
Merged
Added days filter #1142
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
25 changes: 25 additions & 0 deletions
25
src/components/Errors/GlobalErrorsList/DaysFilter/DaysFilter.stories.tsx
This file contains hidden or 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,25 @@ | ||
| import { Meta, StoryObj } from "@storybook/react"; | ||
|
|
||
| import { fn } from "@storybook/test"; | ||
| import { DaysFilter } from "."; | ||
|
|
||
| // More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction | ||
| const meta: Meta<typeof DaysFilter> = { | ||
| title: "Errors/GlobalErrorsList/DaysFilter", | ||
| component: DaysFilter, | ||
| parameters: { | ||
| // More on how to position stories at: https://storybook.js.org/docs/react/configure/story-layout | ||
| layout: "fullscreen" | ||
| } | ||
| }; | ||
|
|
||
| export default meta; | ||
|
|
||
| type Story = StoryObj<typeof meta>; | ||
|
|
||
| // More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args | ||
| export const Default: Story = { | ||
| args: { | ||
| onChanged: fn() | ||
| } | ||
| }; |
158 changes: 158 additions & 0 deletions
158
src/components/Errors/GlobalErrorsList/DaysFilter/index.tsx
This file contains hidden or 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,158 @@ | ||
| import { ChangeEvent, useCallback, useEffect, useMemo, useState } from "react"; | ||
| import { usePrevious } from "../../../../hooks/usePrevious"; | ||
| import { isUndefined } from "../../../../typeGuards/isUndefined"; | ||
| import { sendUserActionTrackingEvent } from "../../../../utils/actions/sendUserActionTrackingEvent"; | ||
| import { formatUnit } from "../../../../utils/formatUnit"; | ||
| import { CalendarIcon } from "../../../common/icons/12px/CalendarIcon"; | ||
| import { MinusIcon } from "../../../common/icons/MinusIcon"; | ||
| import { PlusIcon } from "../../../common/icons/PlusIcon"; | ||
| import { NewPopover } from "../../../common/NewPopover"; | ||
| import { NewIconButton } from "../../../common/v3/NewIconButton"; | ||
| import { MenuList } from "../../../Navigation/common/MenuList"; | ||
| import { trackingEvents } from "../../tracking"; | ||
| import * as s from "./styles"; | ||
| import { DaysFilterProps } from "./types"; | ||
|
|
||
| const MAX_VALUE = 14; | ||
| const MIN_VALUE = 1; | ||
|
|
||
| const DEFAULT_LIST_OPTIONS = [7, 14]; | ||
|
|
||
| const getOptionLabel = (days: number) => `${days} ${formatUnit(days, "Day")}`; | ||
|
|
||
| export const DaysFilter = ({ onChanged }: DaysFilterProps) => { | ||
| const [isDateMenuOpen, setIsDateMenuOpen] = useState(false); | ||
| const [selectedDays, setSelectedDays] = useState<number>(); | ||
| const [currentValue, setCurrentValue] = useState<number>(); | ||
| const previousSelectedDays = usePrevious(selectedDays); | ||
| const handleSelectionChange = useCallback( | ||
| (days: number) => { | ||
| const value = selectedDays === days ? undefined : days; | ||
| setSelectedDays(value); | ||
| setCurrentValue(value); | ||
| setIsDateMenuOpen(false); | ||
| }, | ||
| [selectedDays] | ||
| ); | ||
|
|
||
| const daysFilterMenuItems = useMemo( | ||
| () => | ||
| Object.values(DEFAULT_LIST_OPTIONS).map((x) => ({ | ||
| id: x.toString(), | ||
| label: "Last " + getOptionLabel(x), | ||
| isSelected: selectedDays === x, | ||
| onClick: () => handleSelectionChange(x) | ||
| })), | ||
| [handleSelectionChange, selectedDays] | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
| if (previousSelectedDays !== selectedDays) { | ||
| onChanged(selectedDays); | ||
| } | ||
| }, [selectedDays, previousSelectedDays, onChanged]); | ||
|
|
||
| const handleSortingMenuButtonClick = () => { | ||
| sendUserActionTrackingEvent( | ||
| trackingEvents.GLOBAL_ERRORS_VIEW_DATES_FILTERS_CHANGE | ||
| ); | ||
| setIsDateMenuOpen(!isDateMenuOpen); | ||
| setCurrentValue(selectedDays); | ||
| }; | ||
|
|
||
| const handleCounterInputChange = (e: ChangeEvent<HTMLInputElement>) => { | ||
| const newValue = e.target.value; | ||
| const intValue = parseInt(newValue); | ||
| const days = | ||
| !newValue || Number.isNaN(intValue) | ||
| ? undefined | ||
| : intValue > MAX_VALUE | ||
| ? selectedDays | ||
| : intValue; | ||
|
|
||
| sendUserActionTrackingEvent( | ||
| trackingEvents.GLOBAL_ERRORS_DAYS_FILTER_DECREMENT_CLICKED | ||
| ); | ||
| setCurrentValue(days); | ||
| }; | ||
|
|
||
| const handleDecrement = () => { | ||
| if (currentValue === MIN_VALUE) { | ||
| return; | ||
| } | ||
| sendUserActionTrackingEvent( | ||
| trackingEvents.GLOBAL_ERRORS_DAYS_FILTER_DECREMENT_CLICKED | ||
| ); | ||
| setCurrentValue(currentValue ? currentValue - 1 : 0); | ||
| }; | ||
|
|
||
| const handleIncrement = () => { | ||
| if (currentValue === MAX_VALUE) { | ||
| return; | ||
| } | ||
|
|
||
| sendUserActionTrackingEvent( | ||
| trackingEvents.GLOBAL_ERRORS_DAYS_FILTER_INCREMENT_CLICKED | ||
| ); | ||
| setCurrentValue(currentValue ? currentValue + 1 : 1); | ||
| }; | ||
|
|
||
| const handleApplyClick = () => { | ||
| sendUserActionTrackingEvent( | ||
| trackingEvents.GLOBAL_ERRORS_DAYS_FILTER_APPLY_BTN_CLICKED | ||
| ); | ||
| setSelectedDays(currentValue); | ||
| setIsDateMenuOpen(false); | ||
| }; | ||
|
|
||
| return ( | ||
| <NewPopover | ||
| isOpen={isDateMenuOpen} | ||
| onOpenChange={setIsDateMenuOpen} | ||
| content={ | ||
| <s.DatePopup> | ||
| <s.ItemsContainer> | ||
| <MenuList items={daysFilterMenuItems} highlightSelected={true} /> | ||
| <s.CustomCounterContainer> | ||
| <s.Counter> | ||
| <NewIconButton | ||
| buttonType="secondaryBorderless" | ||
| icon={() => <MinusIcon size={16} />} | ||
| onClick={handleDecrement} | ||
| /> | ||
| <s.CounterInput | ||
| onChange={handleCounterInputChange} | ||
| value={currentValue?.toString() ?? ""} | ||
| /> | ||
| <NewIconButton | ||
| buttonType="secondaryBorderless" | ||
| icon={() => <PlusIcon size={16} />} | ||
| onClick={handleIncrement} | ||
| /> | ||
| <s.Text>Last days</s.Text> | ||
| </s.Counter> | ||
| <s.ApplyButton | ||
| buttonType="primary" | ||
| label="Apply filters" | ||
| onClick={handleApplyClick} | ||
| /> | ||
| </s.CustomCounterContainer> | ||
| </s.ItemsContainer> | ||
| </s.DatePopup> | ||
| } | ||
| placement={"bottom-end"} | ||
| > | ||
| <s.DateButton | ||
| $isActive={!isUndefined(selectedDays) && selectedDays > 0} | ||
| icon={() => ( | ||
| <s.ButtonIconContainer> | ||
| <CalendarIcon size={12} color={"currentColor"} /> | ||
| </s.ButtonIconContainer> | ||
| )} | ||
| label={selectedDays ? getOptionLabel(selectedDays) : "Dates"} | ||
| buttonType={"secondary"} | ||
| onClick={handleSortingMenuButtonClick} | ||
| /> | ||
| </NewPopover> | ||
| ); | ||
| }; | ||
76 changes: 76 additions & 0 deletions
76
src/components/Errors/GlobalErrorsList/DaysFilter/styles.ts
This file contains hidden or 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,76 @@ | ||
| import styled from "styled-components"; | ||
| import { | ||
| bodyRegularTypography, | ||
| footnoteRegularTypography | ||
| } from "../../../common/App/typographies"; | ||
| import { NewButton } from "../../../common/v3/NewButton"; | ||
| import { TextField } from "../../../common/v3/TextField"; | ||
| import { Popup } from "../../../Navigation/common/Popup"; | ||
| import { DaysButtonProps } from "./types"; | ||
|
|
||
| export const ButtonIconContainer = styled.div` | ||
| color: ${({ theme }) => theme.colors.v3.icon.tertiary}; | ||
| `; | ||
|
|
||
| export const DateButton = styled(NewButton)<DaysButtonProps>` | ||
| border: 1px solid | ||
| ${({ theme, $isActive }) => { | ||
| if ($isActive) { | ||
| return theme.colors.v3.surface.brandPrimary; | ||
| } | ||
|
|
||
| return theme.colors.v3.stroke.dark; | ||
| }}; | ||
| background: ${({ theme, $isActive }) => { | ||
| if ($isActive) { | ||
| return theme.colors.v3.surface.brandDark; | ||
| } | ||
|
|
||
| return theme.colors.v3.surface.primary; | ||
| }}; | ||
| `; | ||
|
|
||
| export const DatePopup = styled(Popup)` | ||
| min-width: 164px; | ||
| display: flex; | ||
| `; | ||
|
|
||
| export const ItemsContainer = styled.div` | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 8px; | ||
| `; | ||
|
|
||
| export const CustomCounterContainer = styled.div` | ||
| flex-direction: column; | ||
| display: flex; | ||
| gap: 8px; | ||
| margin: 0 -8px -8px; | ||
| padding: 8px; | ||
| background: ${({ theme }) => theme.colors.v3.surface.highlight}; | ||
| `; | ||
|
|
||
| export const Counter = styled.div` | ||
| ${bodyRegularTypography} | ||
| display: flex; | ||
| flex-direction: row; | ||
| align-items: center; | ||
| `; | ||
|
|
||
| export const CounterInput = styled(TextField)` | ||
| ${footnoteRegularTypography} | ||
| padding: 4px; | ||
|
|
||
| input { | ||
| max-width: 16px; | ||
| } | ||
| `; | ||
|
|
||
| export const ApplyButton = styled(NewButton)` | ||
| width: 100%; | ||
| justify-content: center; | ||
| `; | ||
|
|
||
| export const Text = styled.span` | ||
| padding-right: 5px; | ||
| `; |
33 changes: 33 additions & 0 deletions
33
src/components/Errors/GlobalErrorsList/DaysFilter/types.ts
This file contains hidden or 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,33 @@ | ||
| import { ErrorFilter } from "../../../../store/errors/errorsSlice"; | ||
| import { ButtonProps } from "../../../common/v3/NewButton/types"; | ||
|
|
||
| export interface GetGlobalErrorsFiltersDataPayload { | ||
| environment: string; | ||
| filterName?: string; | ||
| filterData?: { | ||
| services?: string[]; | ||
| values: string[]; | ||
| }; | ||
| } | ||
|
|
||
| export interface FilterData<T> { | ||
| filterName: ErrorFilter; | ||
| values: T[]; | ||
| } | ||
|
|
||
| export interface EndpointFilterData { | ||
| spanCodeObjectId: string; | ||
| displayName: string; | ||
| } | ||
|
|
||
| export interface SetGlobalErrorsFiltersDataPayload { | ||
| filters: FilterData<string | EndpointFilterData>[]; | ||
| } | ||
|
|
||
| export interface DaysButtonProps extends ButtonProps { | ||
| $isActive: boolean; | ||
| } | ||
|
|
||
| export interface DaysFilterProps { | ||
| onChanged: (days?: number) => void; | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Consider to use input of
type=numberto leverage validation logic on browser:https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number