Skip to content

Commit

Permalink
feat: add sort package-relation by desc (#513)
Browse files Browse the repository at this point in the history
Co-authored-by: yifancong <[email protected]>
  • Loading branch information
cairon666 and easy1090 authored Sep 14, 2024
1 parent cdaaad9 commit d219d36
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions packages/components/src/components/Alerts/common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Collapse, Space, Radio, Typography, Tooltip } from 'antd';
import React, { useMemo } from 'react';
import { AppstoreOutlined, UnorderedListOutlined } from '@ant-design/icons';
import { Rule } from '@rsdoctor/types';
import { groupBy, values } from 'lodash-es';
import { groupBy, sumBy, values } from 'lodash-es';
import { Size, ViewMode } from '../../constants';
import { Alert } from '../Alert';
import { Card } from '../Card';
Expand Down Expand Up @@ -56,10 +56,24 @@ const CommonAlertsGroup: React.FC<CommonAlertsContentProps> = ({
dataSource,
extraData,
}) => {
const _dataSource = useMemo(
() => values(groupBy(dataSource, (e) => e.code)),
[dataSource],
);
const _dataSource = useMemo(() => {
const sortedDataSource = dataSource.toSorted((a, b) => {
let sizeA = 0;
let sizeB = 0;

if (a.type === 'package-relation') {
sizeA = sumBy(a.packages, (e) => e.targetSize.sourceSize);
}

if (b.type === 'package-relation') {
sizeB = sumBy(b.packages, (e) => e.targetSize.sourceSize);
}

return sizeB - sizeA;
});
const groups = groupBy(sortedDataSource, (e) => e.code);
return values(groups);
}, [dataSource]);

return (
<Space
Expand Down

0 comments on commit d219d36

Please sign in to comment.