Skip to content

Commit

Permalink
Merge pull request #998 from digma-ai/filters-unify
Browse files Browse the repository at this point in the history
Filters unify
  • Loading branch information
opoliarush committed Aug 23, 2024
2 parents aa9d42b + 5255892 commit b827cc8
Show file tree
Hide file tree
Showing 17 changed files with 460 additions and 233 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"digma",
"digmathon",
"digmo",
"Hotspot",
"leaderboard",
"undismiss",
"zustand"
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"build:prod": "webpack --config webpack.prod.ts",
"build:prod:web": "webpack --config webpack.prod.ts --env platform=Web",
"precommit": "lint-staged",
"prepare": "husky"
"prepare": "husky",
"start": "npm run storybook"
},
"lint-staged": {
"*.{js,ts,tsx}": [
Expand Down
120 changes: 61 additions & 59 deletions src/components/Assets/AssetsFilter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@ import { isNull } from "../../../typeGuards/isNull";
import { isUndefined } from "../../../typeGuards/isUndefined";
import { InsightType } from "../../../types";
import { sendTrackingEvent } from "../../../utils/actions/sendTrackingEvent";
import { sendUserActionTrackingEvent } from "../../../utils/actions/sendUserActionTrackingEvent";
import { getInsightTypeInfo } from "../../../utils/getInsightTypeInfo";
import { FilterButton } from "../../common/FilterButton";
import { NewButton } from "../../common/NewButton";
import { NewPopover } from "../../common/NewPopover";
import { Select } from "../../common/Select";
import { FilterPopup } from "../../common/FilterPopup";
import { WrenchIcon } from "../../common/icons/12px/WrenchIcon";
import { EndpointIcon } from "../../common/icons/EndpointIcon";
import { SparkleIcon } from "../../common/icons/SparkleIcon";
import { IconProps } from "../../common/icons/types";
import { AssetScopeOption } from "../AssetsViewScopeConfiguration/types";
import { actions } from "../actions";
import { trackingEvents } from "../tracking";
import * as s from "./styles";
import {
AssetFilterCategory,
AssetFilterQuery,
Expand All @@ -29,6 +26,8 @@ import {
GetAssetFiltersDataPayload
} from "./types";

import * as s from "./styles";

const PERSISTENCE_KEY = "assetsFilters";

const getData = ({
Expand All @@ -53,7 +52,7 @@ const getData = ({
insights,
directOnly: Boolean(assetScopeOption?.isDirect),
scopedSpanCodeObjectId: assetScopeOption?.scopedSpanCodeObjectId,
...(searchQuery.length > 0 ? { displayName: searchQuery } : {})
...(searchQuery?.length > 0 ? { displayName: searchQuery } : {})
}
}
});
Expand All @@ -76,7 +75,7 @@ const renderFilterCategory = (
})) ?? [];

return (
<Select
<s.StyledSelect
searchable={true}
key={category.categoryName}
items={items}
Expand Down Expand Up @@ -462,25 +461,20 @@ export const AssetsFilter = ({
...selectedInsights
];

return (
<NewPopover
width={"calc(100% - 16px)"}
content={
<s.Container>
<s.Header>Filters</s.Header>
{isServicesFilterEnabled && (
<>
<s.FilterCategoryName>Services</s.FilterCategoryName>
{renderFilterCategory(
servicesCategory,
WrenchIcon,
selectedServices.length > 0 ? "Services" : "All",
selectedServices,
handleSelectedItemsChange
)}
</>
)}
<s.FilterCategoryName>Operations</s.FilterCategoryName>
const handleCloseButtonClick = () => {
sendUserActionTrackingEvent(
trackingEvents.FILTERS_POPUP_CLOSE_BUTTON_CLICKED
);
};
const handleOnStateChange = (state: boolean) => {
setIsOpen(state);
};

const filterComponents = [
{
title: "Operations",
component: (
<>
{renderFilterCategory(
endpointsCategory,
EndpointIcon,
Expand All @@ -502,38 +496,46 @@ export const AssetsFilter = ({
selectedInternals,
handleSelectedItemsChange
)}
<s.FilterCategoryName>Insights</s.FilterCategoryName>
{insightsCategory &&
renderFilterCategory(
insightsCategory,
SparkleIcon,
"Insights",
selectedInsights,
handleSelectedItemsChange,
(value) => getInsightTypeInfo(value)?.label ?? value
)}
<s.Footer>
<NewButton
buttonType={"tertiary"}
label={"Clear filters"}
disabled={selectedFilters.length === 0}
onClick={handleClearFiltersButtonClick}
/>
</s.Footer>
</s.Container>
}
onOpenChange={setIsOpen}
isOpen={isOpen}
placement={"bottom-end"}
>
<div>
<FilterButton
title={"Filters"}
showCount={true}
selectedCount={selectedFilters.length}
isActive={isOpen}
/>
</div>
</NewPopover>
</>
)
}
];

if (insightsCategory) {
filterComponents.push({
title: "Insights",
component: renderFilterCategory(
insightsCategory,
SparkleIcon,
"Insights",
selectedInsights,
handleSelectedItemsChange,
(value) => getInsightTypeInfo(value)?.label ?? value
)
});
}

if (isServicesFilterEnabled) {
filterComponents.unshift({
title: "Services",
component: renderFilterCategory(
servicesCategory,
WrenchIcon,
selectedServices.length > 0 ? "Services" : "All",
selectedServices,
handleSelectedItemsChange
)
});
}

return (
<FilterPopup
onClose={handleCloseButtonClick}
onClearAll={handleClearFiltersButtonClick}
title="Filters"
filters={filterComponents}
selectedFiltersCount={selectedFilters.length}
onStateChange={handleOnStateChange}
/>
);
};
5 changes: 5 additions & 0 deletions src/components/Assets/AssetsFilter/styles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import styled from "styled-components";
import { grayScale } from "../../common/App/v2colors";
import { Select } from "../../common/v3/Select";

export const Container = styled.div`
display: flex;
Expand Down Expand Up @@ -47,3 +48,7 @@ export const Footer = styled.div`
justify-content: space-between;
align-items: center;
`;

export const StyledSelect = styled(Select)`
background: ${({ theme }) => theme.colors.surface.brandDark};
`;
3 changes: 2 additions & 1 deletion src/components/Assets/tracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export const trackingEvents = addPrefix(
TRACKING_PREFIX,
{
FILTER_APPLIED: "filter applied",
REFRESH_BUTTON_CLICKED: "refresh button clicked"
REFRESH_BUTTON_CLICKED: "refresh button clicked",
FILTERS_POPUP_CLOSE_BUTTON_CLICKED: "filter popup close button clicked"
},
" "
);
1 change: 0 additions & 1 deletion src/components/Dashboard/Report/ReportHeader/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,4 @@ export const Background = styled.div`
export const FilterSelector = styled(Select)`
width: 180px;
height: 28px;
color: ${({ theme }) => theme.colors.v3.text.secondary};
`;
Loading

0 comments on commit b827cc8

Please sign in to comment.