Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6dc7f70

Browse files
committed
chore: remove unnecessary lodash
1 parente6f320f commit6dc7f70

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

‎site/src/pages/AIBridgePage/RequestLogsPage/RequestLogsRow/RequestLogsRow.tsx‎

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ import {
77
TooltipProvider,
88
TooltipTrigger,
99
}from"components/Tooltip/Tooltip";
10-
importeveryfrom"lodash/every";
11-
importkeysfrom"lodash/keys";
12-
importmapValuesfrom"lodash/mapValues";
13-
importsomefrom"lodash/some";
14-
importsumfrom"lodash/sum";
15-
importuniqfrom"lodash/uniq";
1610
import{
1711
ArrowDownIcon,
1812
ArrowUpIcon,
@@ -37,35 +31,43 @@ type RequestLogsRowProps = {
3731
functiontokenUsageMetadataMerge(
3832
...objects:Array<AIBridgeInterception["token_usages"][number]["metadata"]>
3933
):unknown{
40-
// TODO: Where possible, use native JS functions instead of lodash functions
41-
4234
// Filter out empty objects
43-
constnonEmptyObjects=objects.filter((obj)=>keys(obj).length>0);
35+
constnonEmptyObjects=objects.filter((obj)=>Object.keys(obj).length>0);
4436

4537
// If all objects were empty, return null
4638
if(nonEmptyObjects.length===0)returnnull;
4739

4840
// Check if all objects have the same keys
49-
constkeySets=nonEmptyObjects.map((obj)=>keys(obj).sort().join(","));
41+
constkeySets=nonEmptyObjects.map((obj)=>
42+
Object.keys(obj).sort().join(","),
43+
);
5044
// If the keys are different, just instantly return the objects
51-
if(uniq(keySets).length>1)returnnonEmptyObjects;
45+
if(newSet(keySets).size>1)returnnonEmptyObjects;
5246

5347
// Group the objects by key
54-
constgrouped=mapValues(nonEmptyObjects[0],(_,key)=>
55-
nonEmptyObjects.map((obj)=>obj[key]),
48+
constgrouped=Object.fromEntries(
49+
Object.keys(nonEmptyObjects[0]).map((key)=>[
50+
key,
51+
nonEmptyObjects.map((obj)=>obj[key]),
52+
]),
5653
);
5754

5855
// Map the grouped values to a new object
59-
constresult=mapValues(grouped,(values:unknown[])=>{
60-
constallNumeric=every(values,(v:unknown)=>typeofv==="number");
61-
constallSame=uniq(values).length===1;
56+
constresult=Object.fromEntries(
57+
Object.entries(grouped).map(([key,values]:[string,unknown[]])=>{
58+
constallNumeric=values.every((v:unknown)=>typeofv==="number");
59+
constallSame=newSet(values).size===1;
6260

63-
if(allNumeric)returnsum(values);
64-
if(allSame)returnvalues[0];
65-
returnnull;// Mark conflict
66-
});
61+
if(allNumeric)
62+
return[key,values.reduce((acc,v)=>acc+(vasnumber),0)];
63+
if(allSame)return[key,values[0]];
64+
return[key,null];// Mark conflict
65+
}),
66+
);
6767

68-
returnsome(result,(v:unknown)=>v===null) ?nonEmptyObjects :result;
68+
returnObject.values(result).some((v:unknown)=>v===null)
69+
?nonEmptyObjects
70+
:result;
6971
}
7072

7173
exportconstRequestLogsRow:FC<RequestLogsRowProps>=({ interception})=>{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp