Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions src/components/Assets/AssetList/AssetEntry/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import { useTheme } from "styled-components";
import { DefaultTheme, useTheme } from "styled-components";
import { getInsightImportanceColor } from "../../../../utils/getInsightImportanceColor";
import { getInsightTypeInfo } from "../../../../utils/getInsightTypeInfo";
import { getInsightTypeOrderPriority } from "../../../../utils/getInsightTypeOrderPriority";
import { timeAgo } from "../../../../utils/timeAgo";
import { GlobeIcon } from "../../../common/icons/GlobeIcon";
import { getAssetTypeInfo } from "../../utils";
import * as s from "./styles";
import { AssetEntryProps } from "./types";

const getServiceIconColor = (theme: DefaultTheme) => {
switch (theme.mode) {
case "light":
return "#4d668a";
case "dark":
case "dark-jetbrains":
return "#dadada";
}
};

export const AssetEntry = (props: AssetEntryProps) => {
const theme = useTheme();
const serviceIconColor = getServiceIconColor(theme);

const handleLinkClick = () => {
props.onAssetLinkClick(props.entry);
Expand Down Expand Up @@ -69,10 +81,11 @@ export const AssetEntry = (props: AssetEntryProps) => {
</s.InsightIconsContainer>
</s.Header>
<s.StatsContainer>
<s.StatsColumn>
<s.StatsRow>
<s.Stats>
<span>Services</span>
<s.ServicesContainer>
<GlobeIcon color={serviceIconColor} />
<s.ServiceName title={props.entry.serviceName}>
{props.entry.serviceName}
</s.ServiceName>
Expand All @@ -83,15 +96,6 @@ export const AssetEntry = (props: AssetEntryProps) => {
)}
</s.ServicesContainer>
</s.Stats>
<s.Stats>
<span>Last</span>
<s.ValueContainer title={new Date(lastSeenDateTime).toString()}>
{timeAgo(lastSeenDateTime)}
<s.Suffix>ago</s.Suffix>
</s.ValueContainer>
</s.Stats>
</s.StatsColumn>
<s.StatsColumn>
<s.Stats>
<span>Performance</span>
<s.ValueContainer>
Expand All @@ -101,7 +105,15 @@ export const AssetEntry = (props: AssetEntryProps) => {
)}
</s.ValueContainer>
</s.Stats>

</s.StatsRow>
<s.StatsRow>
<s.Stats>
<span>Last</span>
<s.ValueContainer title={new Date(lastSeenDateTime).toString()}>
{timeAgo(lastSeenDateTime)}
<s.Suffix>ago</s.Suffix>
</s.ValueContainer>
</s.Stats>
<s.Stats>
<span>Slowest 5%</span>
<s.ValueContainer>
Expand All @@ -113,7 +125,7 @@ export const AssetEntry = (props: AssetEntryProps) => {
)}
</s.ValueContainer>
</s.Stats>
</s.StatsColumn>
</s.StatsRow>
</s.StatsContainer>
</s.Container>
);
Expand Down
27 changes: 5 additions & 22 deletions src/components/Assets/AssetList/AssetEntry/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const InsightIconContainer = styled(AssetTypeIconContainer)`

export const StatsContainer = styled.div`
display: flex;
gap: 15px 12px;
gap: 16px 12px;
flex-wrap: wrap;
font-size: 10px;
line-height: 12px;
Expand All @@ -84,20 +84,12 @@ export const Stats = styled.div`
display: flex;
flex-direction: column;
gap: 4px;
width: 120px;
`;

export const StatsColumn = styled.div`
export const StatsRow = styled.div`
display: flex;
flex-direction: column;
gap: 12px;

&:first-child {
width: 35%;
}

&:nth-child(2) {
width: 35%;
}
gap: 16px;
`;

export const ServicesContainer = styled.div`
Expand All @@ -107,7 +99,7 @@ export const ServicesContainer = styled.div`
`;

export const ServiceName = styled.div`
padding: 4px 6px;
padding: 4px 0;
border-radius: 23px;
line-height: 8px;
overflow: hidden;
Expand All @@ -122,15 +114,6 @@ export const ServiceName = styled.div`
return "#dadada";
}
}};
background: ${({ theme }) => {
switch (theme.mode) {
case "light":
return "#e9eef4";
case "dark":
case "dark-jetbrains":
return "#2e2e2e";
}
}};
`;

export const ValueContainer = styled.div`
Expand Down
105 changes: 80 additions & 25 deletions src/components/Assets/AssetList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { PopoverContent } from "../../common/Popover/PopoverContent";
import { PopoverTrigger } from "../../common/Popover/PopoverTrigger";
import { ChevronIcon } from "../../common/icons/ChevronIcon";
import { MagnifierIcon } from "../../common/icons/MagnifierIcon";
import { SortIcon } from "../../common/icons/SortIcon";
import { Direction } from "../../common/icons/types";
import { getAssetTypeInfo } from "../utils";
import { AssetEntry as AssetEntryComponent } from "./AssetEntry";
Expand All @@ -14,6 +15,7 @@ import {
AssetListProps,
ExtendedAssetEntryWithServices,
SORTING_CRITERION,
SORTING_ORDER,
Sorting
} from "./types";

Expand All @@ -23,6 +25,8 @@ const sortEntries = (
): ExtendedAssetEntryWithServices[] => {
entries = [...entries];

const isDesc = sorting.order === SORTING_ORDER.DESC;

const sortByName = (
a: ExtendedAssetEntryWithServices,
b: ExtendedAssetEntryWithServices,
Expand Down Expand Up @@ -83,39 +87,31 @@ const sortEntries = (
).length;

return (
(sorting.isDesc
(isDesc
? aHighestImportance - bHighestImportance
: bHighestImportance - aHighestImportance) ||
(sorting.isDesc
(isDesc
? bMostImportantInsightCount - aMostImportantInsightCount
: aMostImportantInsightCount - bMostImportantInsightCount) ||
sortByName(a, b, sorting.isDesc)
sortByName(a, b, isDesc)
);
});
case SORTING_CRITERION.PERFORMANCE:
return entries.sort((a, b) =>
sortByPercentile(a, b, 0.5, sorting.isDesc)
);
return entries.sort((a, b) => sortByPercentile(a, b, 0.5, isDesc));
case SORTING_CRITERION.SLOWEST_FIVE_PERCENT:
return entries.sort((a, b) =>
sortByPercentile(a, b, 0.95, sorting.isDesc)
);
return entries.sort((a, b) => sortByPercentile(a, b, 0.95, isDesc));
case SORTING_CRITERION.LATEST:
return entries.sort((a, b) => {
const aDateTime = new Date(a.lastSpanInstanceInfo.startTime).valueOf();
const bDateTime = new Date(b.lastSpanInstanceInfo.startTime).valueOf();

return (
(sorting.isDesc ? bDateTime - aDateTime : aDateTime - bDateTime) ||
sortByName(a, b, sorting.isDesc)
(isDesc ? bDateTime - aDateTime : aDateTime - bDateTime) ||
sortByName(a, b, isDesc)
);
});
case SORTING_CRITERION.NAME:
return entries.sort((a, b) =>
sorting.isDesc
? sortByName(b, a, sorting.isDesc)
: sortByName(a, b, sorting.isDesc)
);
return entries.sort((a, b) => sortByName(a, b, isDesc));
default:
return entries;
}
Expand Down Expand Up @@ -151,13 +147,44 @@ const getSortingMenuChevronColor = (theme: DefaultTheme) => {
}
};

const getSortIconColor = (theme: DefaultTheme, selected: boolean) => {
if (selected) {
switch (theme.mode) {
case "light":
return "#f1f5fa";
case "dark":
case "dark-jetbrains":
return "#dadada";
}
}
switch (theme.mode) {
case "light":
return "#828797";
case "dark":
case "dark-jetbrains":
return "#dadada";
}
};

const getDefaultSortingOrder = (
criterion: SORTING_CRITERION
): SORTING_ORDER => {
switch (criterion) {
case SORTING_CRITERION.NAME:
return SORTING_ORDER.ASC;
case SORTING_CRITERION.PERFORMANCE:
case SORTING_CRITERION.SLOWEST_FIVE_PERCENT:
case SORTING_CRITERION.CRITICAL_INSIGHTS:
case SORTING_CRITERION.LATEST:
default:
return SORTING_ORDER.DESC;
}
};

export const AssetList = (props: AssetListProps) => {
const [sorting, setSorting] = useState<{
criterion: SORTING_CRITERION;
isDesc: boolean;
}>({
const [sorting, setSorting] = useState<Sorting>({
criterion: SORTING_CRITERION.CRITICAL_INSIGHTS,
isDesc: true
order: SORTING_ORDER.DESC
});
const [isSortingMenuOpen, setIsSortingMenuOpen] = useState(false);
const [searchInputValue, setSearchInputValue] = useState("");
Expand All @@ -184,12 +211,15 @@ export const AssetList = (props: AssetListProps) => {
if (sorting.criterion === value) {
setSorting({
...sorting,
isDesc: !sorting.isDesc
order:
sorting.order === SORTING_ORDER.DESC
? SORTING_ORDER.ASC
: SORTING_ORDER.DESC
});
} else {
setSorting({
criterion: value as SORTING_CRITERION,
isDesc: false
order: getDefaultSortingOrder(value as SORTING_CRITERION)
});
}
handleSortingMenuToggle();
Expand All @@ -199,6 +229,13 @@ export const AssetList = (props: AssetListProps) => {
props.onAssetLinkClick(entry);
};

const handleSortingOrderToggleOptionButtonClick = (order: SORTING_ORDER) => {
setSorting({
...sorting,
order
});
};

const assetTypeInfo = getAssetTypeInfo(props.assetTypeId);

const entries: ExtendedAssetEntryWithServices[] = useMemo(
Expand Down Expand Up @@ -260,14 +297,14 @@ export const AssetList = (props: AssetListProps) => {
placement={"bottom-start"}
>
<PopoverTrigger onClick={handleSortingMenuToggle}>
<s.SortingMenuContainer>
<s.SortingMenuButton isOpen={isSortingMenuOpen}>
<span>Sort by</span>
<s.SortingLabel>{sorting.criterion}</s.SortingLabel>
<ChevronIcon
direction={isSortingMenuOpen ? Direction.UP : Direction.DOWN}
color={sortingMenuChevronColor}
/>
</s.SortingMenuContainer>
</s.SortingMenuButton>
</PopoverTrigger>
<PopoverContent className={"Popover"}>
<Menu
Expand All @@ -281,6 +318,24 @@ export const AssetList = (props: AssetListProps) => {
</PopoverContent>
</Popover>
</s.PopoverContainer>
<s.SortingOrderToggle>
{[SORTING_ORDER.DESC, SORTING_ORDER.ASC].map((order) => {
const isSelected = sorting.order === order;
const iconColor = getSortIconColor(theme, isSelected);

return (
<s.SortingOrderToggleOptionButton
key={order}
selected={isSelected}
onClick={() => handleSortingOrderToggleOptionButtonClick(order)}
>
<s.SortingOrderIconContainer sortingOrder={order}>
<SortIcon color={iconColor} />
</s.SortingOrderIconContainer>
</s.SortingOrderToggleOptionButton>
);
})}
</s.SortingOrderToggle>
</s.Toolbar>
{sortedEntries.length > 0 ? (
<s.List>
Expand Down
Loading