Skip to content

Commit

Permalink
chore: Replace lodash with ES6 funcs
Browse files Browse the repository at this point in the history
Summary:
lodash isn't heavily used in our codebase and ES6 should cover everthing
we need anyway so this is just a step towards getting rid of lodash.

Test Plan: result-data-utils-test still passes

Reviewers: nlanam, zasgar

Reviewed By: zasgar

Signed-off-by: Vihang Mehta <vihang@pixielabs.ai>

Differential Revision: https://phab.corp.pixielabs.ai/D12348

GitOrigin-RevId: 7be88685d8441b73594fc275653a0ba4240de6c3
  • Loading branch information
vihangm authored and copybaranaut committed Oct 6, 2022
1 parent b6b2ec4 commit fecd0c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
9 changes: 4 additions & 5 deletions src/ui/src/containers/legend/legend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
import { IconButton, Tooltip } from '@mui/material';
import { Theme } from '@mui/material/styles';
import { createStyles, makeStyles } from '@mui/styles';
import * as _ from 'lodash';

import { LegendData, LegendEntry } from './legend-data';

Expand Down Expand Up @@ -144,7 +143,7 @@ const Legend = React.memo((props: LegendProps) => {

const handleRowLeftClick = React.useCallback((key: string) => {
// Toggle selected series.
if (_.includes(interactState.selectedSeries, key)) {
if (interactState.selectedSeries.includes(key)) {
setInteractState({
...interactState,
selectedSeries: interactState.selectedSeries.filter((s: string) => s !== key),
Expand Down Expand Up @@ -205,10 +204,10 @@ const Legend = React.memo((props: LegendProps) => {
let dataEntries: LegendEntry[];
if (interactState.selectedSeries.length > 0) {
// Put selected series first.
dataEntries = data.entries.filter((entry) => _.includes(interactState.selectedSeries, entry.key));
dataEntries = data.entries.filter((entry) => interactState.selectedSeries.includes(entry.key));
dataEntries = [
...dataEntries,
...data.entries.filter((entry) => !_.includes(interactState.selectedSeries, entry.key)),
...data.entries.filter((entry) => !interactState.selectedSeries.includes(entry.key)),
];
} else {
dataEntries = data.entries;
Expand Down Expand Up @@ -251,7 +250,7 @@ const Legend = React.memo((props: LegendProps) => {
const styles: CSSProperties = {
opacity: '1.0',
};
if (interactState.selectedSeries.length > 0 && !_.includes(interactState.selectedSeries, entry.key)) {
if (interactState.selectedSeries.length > 0 && !interactState.selectedSeries.includes(entry.key)) {
styles.opacity = '0.3';
}
if (interactState.hoveredSeries === entry.key) {
Expand Down
8 changes: 4 additions & 4 deletions src/ui/src/utils/result-data-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/

import * as jspb from 'google-protobuf';
import * as _ from 'lodash';

import {
Column, Relation, RowBatchData,
Expand All @@ -31,8 +30,9 @@ export function ResultsToCsv(results: string): string {
const jsonResults = JSON.parse(results);
let csvStr = '';

csvStr += `${_.map(jsonResults.relation.columns, 'columnName').join()}\n`;
_.each(jsonResults.rowBatches, (rowBatch) => {
const colNames = jsonResults.relation.columns.map((column) => (column.columnName));
csvStr += `${colNames.join()}\n`;
for (const rowBatch of jsonResults.rowBatches) {
const numRows = parseInt(rowBatch.numRows, 10);
const numCols = rowBatch.cols.length;
for (let i = 0; i < numRows; i++) {
Expand All @@ -51,7 +51,7 @@ export function ResultsToCsv(results: string): string {
}
csvStr += `${rowData.join()}\n`;
}
});
}

return csvStr;
}
Expand Down

0 comments on commit fecd0c5

Please sign in to comment.