2
0

📦 Update cuid to cuid2

This commit is contained in:
Baptiste Arnaud
2023-02-10 15:06:02 +01:00
parent 2dbf0fb848
commit 51f76700b2
77 changed files with 254 additions and 250 deletions

View File

@ -1,6 +1,6 @@
import test, { expect } from '@playwright/test'
import { defaultTextInputOptions, InputBlockType } from 'models'
import cuid from 'cuid'
import { createId } from '@paralleldrive/cuid2'
import {
createTypebots,
importTypebotInDatabase,
@ -17,7 +17,7 @@ import { getTestAsset } from '@/test/utils/playwright'
test.describe.configure({ mode: 'parallel' })
test('Edges connection should work', async ({ page }) => {
const typebotId = cuid()
const typebotId = createId()
await createTypebots([
{
id: typebotId,
@ -68,7 +68,7 @@ test('Edges connection should work', async ({ page }) => {
expect(total).toBe(1)
})
test('Drag and drop blocks and items should work', async ({ page }) => {
const typebotId = cuid()
const typebotId = createId()
await importTypebotInDatabase(
getTestAsset('typebots/editor/buttonsDnd.json'),
{
@ -120,7 +120,7 @@ test('Drag and drop blocks and items should work', async ({ page }) => {
)
})
test('Undo / Redo and Zoom buttons should work', async ({ page }) => {
const typebotId = cuid()
const typebotId = createId()
await createTypebots([
{
id: typebotId,
@ -162,7 +162,7 @@ test('Undo / Redo and Zoom buttons should work', async ({ page }) => {
})
test('Rename and icon change should work', async ({ page }) => {
const typebotId = cuid()
const typebotId = createId()
await createTypebots([
{
id: typebotId,
@ -189,7 +189,7 @@ test('Rename and icon change should work', async ({ page }) => {
})
test('Preview from group should work', async ({ page }) => {
const typebotId = cuid()
const typebotId = createId()
await importTypebotInDatabase(
getTestAsset('typebots/editor/previewFromGroup.json'),
{
@ -214,7 +214,7 @@ test('Preview from group should work', async ({ page }) => {
})
test('Published typebot menu should work', async ({ page }) => {
const typebotId = cuid()
const typebotId = createId()
await createTypebots([
{
id: typebotId,

View File

@ -9,7 +9,7 @@ import { WritableDraft } from 'immer/dist/types/types-external'
import { SetTypebot } from '../TypebotProvider'
import produce from 'immer'
import { cleanUpEdgeDraft, deleteEdgeDraft } from './edges'
import cuid from 'cuid'
import { createId } from '@paralleldrive/cuid2'
import { byId, isWebhookBlock, blockHasItems } from 'utils'
import { duplicateItemDraft } from './items'
import { parseNewBlock } from '@/features/graph/utils'
@ -141,7 +141,7 @@ const moveBlockToGroup = (
export const duplicateBlockDraft =
(groupId: string) =>
(block: Block): Block => {
const blockId = cuid()
const blockId = createId()
if (blockHasItems(block))
return {
...block,
@ -155,7 +155,7 @@ export const duplicateBlockDraft =
...block,
groupId,
id: blockId,
webhookId: cuid(),
webhookId: createId(),
outgoingEdgeId: undefined,
}
return {

View File

@ -10,7 +10,7 @@ import { WritableDraft } from 'immer/dist/types/types-external'
import { SetTypebot } from '../TypebotProvider'
import { produce } from 'immer'
import { byId, isDefined, blockHasItems } from 'utils'
import cuid from 'cuid'
import { createId } from '@paralleldrive/cuid2'
export type EdgesActions = {
createEdge: (edge: Omit<Edge, 'id'>) => void
@ -24,7 +24,7 @@ export const edgesAction = (setTypebot: SetTypebot): EdgesActions => ({
produce(typebot, (typebot) => {
const newEdge = {
...edge,
id: cuid(),
id: createId(),
}
removeExistingEdge(typebot, edge)
typebot.edges.push(newEdge)

View File

@ -1,4 +1,4 @@
import cuid from 'cuid'
import { createId } from '@paralleldrive/cuid2'
import { produce } from 'immer'
import { Group, DraggableBlock, DraggableBlockType, BlockIndices } from 'models'
import { SetTypebot } from '../TypebotProvider'
@ -56,7 +56,7 @@ const groupsActions = (setTypebot: SetTypebot): GroupsActions => ({
setTypebot((typebot) =>
produce(typebot, (typebot) => {
const group = typebot.groups[groupIndex]
const id = cuid()
const id = createId()
const newGroup: Group = {
...group,
title: `${group.title} copy`,

View File

@ -12,7 +12,7 @@ import { SetTypebot } from '../TypebotProvider'
import produce from 'immer'
import { cleanUpEdgeDraft } from './edges'
import { byId, blockHasItems } from 'utils'
import cuid from 'cuid'
import { createId } from '@paralleldrive/cuid2'
import { WritableDraft } from 'immer/dist/types/types-external'
type NewItem = Pick<Item, 'blockId' | 'outgoingEdgeId' | 'type'> & Partial<Item>
@ -34,7 +34,7 @@ const createItem = (
if (item.type === ItemType.CONDITION) {
const newItem = {
...item,
id: 'id' in item && item.id ? item.id : cuid(),
id: 'id' in item && item.id ? item.id : createId(),
content: item.content ?? defaultConditionContent,
}
block.items.splice(itemIndex, 0, newItem)
@ -46,7 +46,7 @@ const createItem = (
if (item.type === ItemType.BUTTON) {
const newItem = {
...item,
id: 'id' in item && item.id ? item.id : cuid(),
id: 'id' in item && item.id ? item.id : createId(),
content: item.content,
}
block.items.splice(itemIndex, 0, newItem)
@ -122,7 +122,7 @@ const itemsAction = (setTypebot: SetTypebot): ItemsActions => ({
const duplicateItemDraft = (blockId: string) => (item: Item) => ({
...item,
id: cuid(),
id: createId(),
blockId,
outgoingEdgeId: undefined,
})