Skip to content

Commit 4670dc4

Browse files
authored
feat: move to nanonids (#3768)
1 parent e52f6c0 commit 4670dc4

File tree

17 files changed

+85
-84
lines changed

17 files changed

+85
-84
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@
9898
"@types/react-virtualized": "^9.18.3",
9999
"@types/resize-observer-browser": "^0.1.5",
100100
"@types/text-encoding": "^0.0.32",
101-
"@types/uuid": "^3.4.3",
102101
"@types/webpack": "^4.4.35",
103102
"@types/webpack-env": "^1.15.2",
104103
"@typescript-eslint/eslint-plugin": "^2.6.0",
@@ -186,6 +185,7 @@
186185
"monaco-editor-webpack-plugin": "^2.1.0",
187186
"monaco-languageclient": "^0.13.0",
188187
"monaco-textmate": "^3.0.1",
188+
"nanoid": "^3.2.0",
189189
"normalizr": "^3.4.1",
190190
"onigasm": "^2.2.4",
191191
"papaparse": "^5.2.0",
@@ -210,7 +210,6 @@
210210
"rudder-sdk-js": "^1.0.16",
211211
"s2-geometry": "^1.2.10",
212212
"use-local-storage-state": "^9.0.2",
213-
"uuid": "^3.2.1",
214213
"worker-plugin": "^5.0.1",
215214
"y-websocket": "^1.3.16",
216215
"yjs": "^13.5.13"

src/clockface/components/inputs/multipleInput/MultipleRows.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Libraries
22
import React, {SFC} from 'react'
3-
import uuid from 'uuid'
3+
import {nanoid} from 'nanoid'
44

55
// Components
66
import Row from 'src/clockface/components/inputs/multipleInput/Row'
@@ -24,7 +24,7 @@ const Rows: SFC<RowsProps> = ({tags, onDeleteTag, onChange}) => {
2424
return (
2525
<Row
2626
index={tags.indexOf(item)}
27-
key={uuid.v4()}
27+
key={nanoid()}
2828
item={item}
2929
onDelete={onDeleteTag}
3030
onChange={onChange}

src/clockface/components/inputs/multipleInput/Row.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Libraries
22
import React, {PureComponent} from 'react'
3-
import uuid from 'uuid'
3+
import {nanoid} from 'nanoid'
44
import {ErrorHandling} from 'src/shared/decorators/errors'
55

66
// Components
@@ -39,7 +39,7 @@ class Row extends PureComponent<RowProps> {
3939
return (
4040
<IndexList>
4141
<IndexList.Body emptyState={<div />} columnCount={2}>
42-
<IndexList.Row key={uuid.v4()} disabled={false}>
42+
<IndexList.Row key={nanoid()} disabled={false}>
4343
<IndexList.Cell>
4444
<EditableDescription
4545
description={item.text}

src/dashboards/utils/cellGetters.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Libraries
2-
import uuid from 'uuid'
2+
import {nanoid} from 'nanoid'
33

44
// Types
55
import {
@@ -54,7 +54,7 @@ export const getNewDashboardCell = (
5454
const isStaticLegendType = staticLegendTypes.has(viewProperties?.type)
5555

5656
const defaultCell = {
57-
id: uuid.v4(),
57+
id: nanoid(),
5858
x: 0,
5959
y: 0,
6060
h:

src/dataLoaders/components/collectorsWizard/select/StreamingSelector.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Libraries
22
import React, {PureComponent, ChangeEvent, createElement} from 'react'
3-
import uuid from 'uuid'
3+
import {nanoid} from 'nanoid'
44

55
// Components
66
import {
@@ -45,7 +45,7 @@ class StreamingSelector extends PureComponent<Props, State> {
4545
constructor(props: Props) {
4646
super(props)
4747
this.state = {
48-
gridSizerUpdateFlag: uuid.v4(),
48+
gridSizerUpdateFlag: nanoid(),
4949
searchTerm: '',
5050
}
5151
}
@@ -60,7 +60,7 @@ class StreamingSelector extends PureComponent<Props, State> {
6060
this.props.telegrafPlugins.length === 0
6161

6262
if (addFirst || removeLast) {
63-
const gridSizerUpdateFlag = uuid.v4()
63+
const gridSizerUpdateFlag = nanoid()
6464
this.setState({gridSizerUpdateFlag})
6565
}
6666
}

src/dataLoaders/components/collectorsWizard/select/TelegrafUIRefreshSelector.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Libraries
22
import React, {PureComponent, ChangeEvent} from 'react'
3-
import uuid from 'uuid'
3+
import {nanoid} from 'nanoid'
44

55
// Components
66
import {
@@ -60,7 +60,7 @@ class TelegrafUIRefreshSelector extends PureComponent<Props, State> {
6060
constructor(props: Props) {
6161
super(props)
6262
this.state = {
63-
gridSizerUpdateFlag: uuid.v4(),
63+
gridSizerUpdateFlag: nanoid(),
6464
isExistingBucket: true,
6565
searchTerm: '',
6666
selectedBucket: null,
@@ -87,7 +87,7 @@ class TelegrafUIRefreshSelector extends PureComponent<Props, State> {
8787
this.props.telegrafPlugins.length === 0
8888

8989
if (addFirst || removeLast) {
90-
const gridSizerUpdateFlag = uuid.v4()
90+
const gridSizerUpdateFlag = nanoid()
9191
this.setState({gridSizerUpdateFlag})
9292
}
9393

src/flows/context/flow.current.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ import React, {
99
import {useLocation} from 'react-router-dom'
1010
import {Flow, PipeData, PipeMeta} from 'src/types/flows'
1111
import {FlowListContext, FlowListProvider} from 'src/flows/context/flow.list'
12-
import {v4 as UUID} from 'uuid'
12+
import {customAlphabet} from 'nanoid'
1313
import {DEFAULT_PROJECT_NAME, PIPE_DEFINITIONS} from 'src/flows'
1414
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
15-
import * as Y from 'yjs'
15+
import {Doc} from 'yjs'
1616
import {WebsocketProvider} from 'y-websocket'
1717
import {serialize, hydrate} from 'src/flows/context/flow.list'
1818

19+
const prettyid = customAlphabet('abcdefghijklmnop0123456789', 12)
20+
1921
export interface FlowContextType {
2022
name: string
2123
flow: Flow | null
@@ -46,7 +48,7 @@ export const FlowProvider: FC = ({children}) => {
4648
const {flows, update, currentID} = useContext(FlowListContext)
4749
const [currentFlow, setCurrentFlow] = useState<Flow>()
4850
const provider = useRef<WebsocketProvider>()
49-
const yDoc = useRef(new Y.Doc())
51+
const yDoc = useRef(new Doc())
5052
function disconnectProvider() {
5153
if (provider.current) {
5254
provider.current.disconnect()
@@ -239,7 +241,7 @@ export const FlowProvider: FC = ({children}) => {
239241
)
240242

241243
const addPipe = (initial: PipeData, index?: number) => {
242-
const id = `local_${UUID()}`
244+
const id = prettyid()
243245
const title =
244246
initial.title ||
245247
`${PIPE_DEFINITIONS[initial.type].button || 'Panel'} ${++GENERATOR_INDEX}`

src/flows/context/flow.list.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, {FC, useCallback, useEffect, useState} from 'react'
22
import {useDispatch, useSelector} from 'react-redux'
33
import {createLocalStorageStateHook} from 'use-local-storage-state'
4-
import {v4 as UUID} from 'uuid'
4+
import {nanoid} from 'nanoid'
55
import {
66
FlowList,
77
Flow,
@@ -141,7 +141,7 @@ export function hydrate(data) {
141141
return flow
142142
}
143143
data.spec.pipes.forEach(pipe => {
144-
const id = pipe.id || `local_${UUID()}`
144+
const id = pipe.id || `local_${nanoid()}`
145145

146146
flow.data.allIDs.push(id)
147147
flow.meta.allIDs.push(id)

src/notifications/rules/components/RuleOverlay.reducer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Libraries
2-
import {v4} from 'uuid'
2+
import {nanoid} from 'nanoid'
33
import {omit} from 'lodash'
44

55
// Types
@@ -48,7 +48,7 @@ export const reducer = (state: RuleState, action: Action) => {
4848
const {tagRule} = action
4949
return {
5050
...state,
51-
tagRules: [...state.tagRules, {...tagRule, id: v4()}],
51+
tagRules: [...state.tagRules, {...tagRule, id: nanoid()}],
5252
}
5353
}
5454

src/notifications/rules/utils/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Libraries
22
import {omit} from 'lodash'
3-
import uuid from 'uuid'
3+
import {nanoid} from 'nanoid'
44

55
// Types
66
import {
@@ -109,7 +109,7 @@ export const initRuleDraft = (orgID: string): NotificationRuleDraft => ({
109109
labels: [],
110110
statusRules: [
111111
{
112-
cid: uuid.v4(),
112+
cid: nanoid(),
113113
value: {
114114
currentLevel: 'CRIT',
115115
period: '1h',
@@ -135,7 +135,7 @@ export const draftRuleToPostRule = (
135135
}
136136

137137
export const newTagRuleDraft = () => ({
138-
cid: uuid.v4(),
138+
cid: nanoid(),
139139
value: {
140140
key: '',
141141
value: '',
@@ -153,7 +153,7 @@ export const ruleToDraftRule = (rule: GenRule): NotificationRuleDraft => {
153153
status: RemoteDataState.Done,
154154
activeStatus: rule.status,
155155
offset: rule.offset || '',
156-
statusRules: statusRules.map(value => ({cid: uuid.v4(), value})),
157-
tagRules: tagRules.map(value => ({cid: uuid.v4(), value})),
156+
statusRules: statusRules.map(value => ({cid: nanoid(), value})),
157+
tagRules: tagRules.map(value => ({cid: nanoid(), value})),
158158
}
159159
}

0 commit comments

Comments
 (0)