From c3d3f83c495ffe6a5b1d93ea5fdab35dbfe09962 Mon Sep 17 00:00:00 2001 From: Michael Matloka Date: Wed, 14 Oct 2020 10:42:06 +0200 Subject: [PATCH] Destroy lodash (#1864) * Convert utils to TS and add missing lodash-like functions * Purge lodash, using utils and ES features instead * Remove lodash as a dependency * Fix Annotation.created_at default value (was null) * Convert all of utils to TypeScript * Update ESLint rule @typescript-eslint/explicit-module-boundary-types * Put all @types/* into devDependencies * Lower @typescript-eslint/explicit-function-return-type severity * Fix Annotation.created_at in a better way * Don't copy item on push in groupBy * Use `Set.has()` instead of `in Set` * Update .eslintrc.js * Update .eslintrc.js --- .eslintrc.js | 7 +- .../Annotations/AnnotationMarker.js | 65 ++-- .../Annotations/annotationsLogic.js | 11 +- .../CommandPalette/commandPaletteLogic.ts | 9 +- .../PropertyFilters/PropertyFilters.js | 3 +- frontend/src/lib/{utils.js => utils.tsx} | 289 +++++++++++------- frontend/src/scenes/users/Cohort.js | 3 +- frontend/src/scenes/users/CohortGroup.js | 7 +- latest_migrations.manifest | 2 +- package.json | 6 +- .../0087_fix_annotation_created_at.py | 19 ++ posthog/models/annotation.py | 3 +- yarn.lock | 5 - 13 files changed, 253 insertions(+), 176 deletions(-) rename frontend/src/lib/{utils.js => utils.tsx} (56%) create mode 100644 posthog/migrations/0087_fix_annotation_created_at.py diff --git a/.eslintrc.js b/.eslintrc.js index d0903916f59..f55b74b0a17 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -56,7 +56,12 @@ module.exports = { allowExpressions: true, }, ], - '@typescript-eslint/explicit-module-boundary-types': ['error'], + '@typescript-eslint/explicit-module-boundary-types': [ + 'error', + { + allowArgumentsExplicitlyTypedAsAny: true, + }, + ], }, }, { diff --git a/frontend/src/lib/components/Annotations/AnnotationMarker.js b/frontend/src/lib/components/Annotations/AnnotationMarker.js index 375d8b6c633..b801784d252 100644 --- a/frontend/src/lib/components/Annotations/AnnotationMarker.js +++ b/frontend/src/lib/components/Annotations/AnnotationMarker.js @@ -4,7 +4,6 @@ import { userLogic } from 'scenes/userLogic' import { Button, Popover, Row, Input, Checkbox, Tooltip } from 'antd' import { humanFriendlyDetailedTime } from '~/lib/utils' import { DeleteOutlined, PlusOutlined, GlobalOutlined, CloseOutlined } from '@ant-design/icons' -import _ from 'lodash' import { annotationsLogic } from './annotationsLogic' import moment from 'moment' import { useEscapeKey } from 'lib/hooks/useEscapeKey' @@ -138,37 +137,41 @@ export function AnnotationMarker({ ) : (
- {_.orderBy(annotations, ['created_at'], ['asc']).map((data) => ( -
- -
- - {data.created_by === 'local' - ? name || email - : data.created_by && - (data.created_by.first_name || data.created_by.email)} - - - {humanFriendlyDetailedTime(data.created_at)} - - {data.scope !== 'dashboard_item' && ( - - - + {[...annotations] + .sort((annotationA, annotationB) => annotationA.created_at - annotationB.created_at) + .map((data) => ( +
+ +
+ + {data.created_by === 'local' + ? name || email + : data.created_by && + (data.created_by.first_name || data.created_by.email)} + + + {humanFriendlyDetailedTime(data.created_at)} + + {data.scope !== 'dashboard_item' && ( + + + + )} +
+ {(!data.created_by || + data.created_by.id === id || + data.created_by === 'local') && ( + { + onDelete(data) + }} + > )} -
- {(!data.created_by || data.created_by.id === id || data.created_by === 'local') && ( - { - onDelete(data) - }} - > - )} - - {data.content} -
- ))} +
+ {data.content} +
+ ))} {textAreaVisible && (