Fix CascadeStudio integration #99

Merged
Irev-Dev merged 11 commits from kurt/issue-95 into main 2020-11-16 19:33:35 +01:00
7 changed files with 82 additions and 24 deletions
Showing only changes of commit 955f4c9e83 - Show all commits

View File

@@ -1,6 +1,6 @@
import { createUserInsecure } from 'src/services/users/users.js'
import { db } from 'src/lib/db'
import { enforceAlphaNumeric } from 'src/services/helpers'
import { enforceAlphaNumeric, generateUniqueString } from 'src/services/helpers'
export const handler = async (req, _context) => {
const body = JSON.parse(req.body)
@@ -58,26 +58,12 @@ export const handler = async (req, _context) => {
if (eventType === 'signup') {
roles.push('user')
// const hi = {
// email: 'kurt.hutten@gmail.com',
// image: '',
// bio: ''
// }
const generateUniqueUserName = async (seed, count = 0) => {
const isUnique = !(await db.user.findOne({
const isUniqueCallback = async (seed) =>
db.user.findOne({
where: { userName: seed },
}))
if (isUnique) {
return seed
}
count += 1
const newSeed =
count === 1 ? `${seed}_${count}` : seed.slice(0, -1) + count
return generateUniqueUserName(newSeed, count)
}
})
const userNameSeed = enforceAlphaNumeric(email.split('@')[0])
const userName = await generateUniqueUserName(userNameSeed) // TODO maybe come up with a better default userName?
const userName = await generateUniqueString(userNameSeed, isUniqueCallback) // TODO maybe come up with a better default userName?
const input = {
email,
userName,

View File

@@ -37,6 +37,7 @@ export const schema = gql`
type Mutation {
createPart(input: CreatePartInput!): Part!
forkPart(input: CreatePartInput!): Part!
updatePart(id: String!, input: UpdatePartInput!): Part!
deletePart(id: String!): Part!
}

View File

@@ -14,3 +14,17 @@ export const foreignKeyReplacement = (input) => {
export const enforceAlphaNumeric = (string) =>
string.replace(/([^a-zA-Z\d_:])/g, '-')
export const generateUniqueString = async (
seed,
isUniqueCallback,
count = 0
) => {
const isUnique = !(await isUniqueCallback(seed))
if (isUnique) {
return seed
}
count += 1
const newSeed = count === 1 ? `${seed}_${count}` : seed.slice(0, -1) + count
return generateUniqueString(newSeed, isUniqueCallback, count)
}

View File

@@ -2,6 +2,7 @@ import { db } from 'src/lib/db'
import {
foreignKeyReplacement,
enforceAlphaNumeric,
generateUniqueString,
} from 'src/services/helpers'
import { requireAuth } from 'src/lib/auth'
import { requireOwnership } from 'src/lib/owner'
@@ -38,6 +39,25 @@ export const createPart = async ({ input }) => {
})
}
export const forkPart = async ({ input }) => {
// Only difference between create nda clone part is that clone part will generate a unique title
// (for the user) if there is a conflict
const isUniqueCallback = async (seed) =>
db.part.findOne({
where: {
title_userId: {
title: seed,
userId: input.userId,
},
},
})
const title = await generateUniqueString(input.title, isUniqueCallback)
// TODO change the description to `forked from userName/partName ${rest of description}`
return db.part.create({
data: foreignKeyReplacement({ ...input, title }),
})
}
export const updatePart = async ({ id, input }) => {
requireAuth()
await requireOwnership({ partId: id })

View File

@@ -60,7 +60,18 @@ const IdeCascadeStudio = ({ part, saveCode, loading, error }) => {
Irev-Dev commented 2020-11-16 10:57:13 +01:00 (Migrated from github.com)
Review

clean up

clean up
Irev-Dev commented 2020-11-16 10:57:13 +01:00 (Migrated from github.com)
Review

clean up

clean up
Irev-Dev commented 2020-11-16 11:00:25 +01:00 (Migrated from github.com)
Review

delete this nav element. I added hidden class but intended to remove it entirely.

delete this nav element. I added hidden class but intended to remove it entirely.
Irev-Dev commented 2020-11-16 11:00:25 +01:00 (Migrated from github.com)
Review

delete this nav element. I added hidden class but intended to remove it entirely.

delete this nav element. I added hidden class but intended to remove it entirely.
Irev-Dev commented 2020-11-16 11:00:47 +01:00 (Migrated from github.com)
Review

Likewise has a hidden class. This div should be removed.

Likewise has a hidden class. This div should be removed.
Irev-Dev commented 2020-11-16 11:00:47 +01:00 (Migrated from github.com)
Review

Likewise has a hidden class. This div should be removed.

Likewise has a hidden class. This div should be removed.
<IdeToolbar
canEdit={canEdit}
isChanges={isChanges && !loading}
onSave={() => {}}
Irev-Dev commented 2020-11-16 10:57:13 +01:00 (Migrated from github.com)
Review

clean up

clean up
Irev-Dev commented 2020-11-16 11:00:25 +01:00 (Migrated from github.com)
Review

delete this nav element. I added hidden class but intended to remove it entirely.

delete this nav element. I added hidden class but intended to remove it entirely.
Irev-Dev commented 2020-11-16 11:00:47 +01:00 (Migrated from github.com)
Review

Likewise has a hidden class. This div should be removed.

Likewise has a hidden class. This div should be removed.
onSave={() => {
Irev-Dev commented 2020-11-16 10:57:13 +01:00 (Migrated from github.com)
Review

clean up

clean up
Irev-Dev commented 2020-11-16 11:00:25 +01:00 (Migrated from github.com)
Review

delete this nav element. I added hidden class but intended to remove it entirely.

delete this nav element. I added hidden class but intended to remove it entirely.
Irev-Dev commented 2020-11-16 11:00:47 +01:00 (Migrated from github.com)
Review

Likewise has a hidden class. This div should be removed.

Likewise has a hidden class. This div should be removed.
saveCode({
Irev-Dev commented 2020-11-16 10:57:13 +01:00 (Migrated from github.com)
Review

clean up

clean up
Irev-Dev commented 2020-11-16 11:00:25 +01:00 (Migrated from github.com)
Review

delete this nav element. I added hidden class but intended to remove it entirely.

delete this nav element. I added hidden class but intended to remove it entirely.
Irev-Dev commented 2020-11-16 11:00:47 +01:00 (Migrated from github.com)
Review

Likewise has a hidden class. This div should be removed.

Likewise has a hidden class. This div should be removed.
input: {
Irev-Dev commented 2020-11-16 10:57:13 +01:00 (Migrated from github.com)
Review

clean up

clean up
Irev-Dev commented 2020-11-16 11:00:25 +01:00 (Migrated from github.com)
Review

delete this nav element. I added hidden class but intended to remove it entirely.

delete this nav element. I added hidden class but intended to remove it entirely.
Irev-Dev commented 2020-11-16 11:00:47 +01:00 (Migrated from github.com)
Review

Likewise has a hidden class. This div should be removed.

Likewise has a hidden class. This div should be removed.
code,
Irev-Dev commented 2020-11-16 10:57:13 +01:00 (Migrated from github.com)
Review

clean up

clean up
Irev-Dev commented 2020-11-16 11:00:25 +01:00 (Migrated from github.com)
Review

delete this nav element. I added hidden class but intended to remove it entirely.

delete this nav element. I added hidden class but intended to remove it entirely.
Irev-Dev commented 2020-11-16 11:00:47 +01:00 (Migrated from github.com)
Review

Likewise has a hidden class. This div should be removed.

Likewise has a hidden class. This div should be removed.
title: part?.title,
Irev-Dev commented 2020-11-16 10:57:13 +01:00 (Migrated from github.com)
Review

clean up

clean up
Irev-Dev commented 2020-11-16 11:00:25 +01:00 (Migrated from github.com)
Review

delete this nav element. I added hidden class but intended to remove it entirely.

delete this nav element. I added hidden class but intended to remove it entirely.
Irev-Dev commented 2020-11-16 11:00:47 +01:00 (Migrated from github.com)
Review

Likewise has a hidden class. This div should be removed.

Likewise has a hidden class. This div should be removed.
userId: currentUser?.sub,
Irev-Dev commented 2020-11-16 10:57:13 +01:00 (Migrated from github.com)
Review

clean up

clean up
Irev-Dev commented 2020-11-16 11:00:25 +01:00 (Migrated from github.com)
Review

delete this nav element. I added hidden class but intended to remove it entirely.

delete this nav element. I added hidden class but intended to remove it entirely.
Irev-Dev commented 2020-11-16 11:00:47 +01:00 (Migrated from github.com)
Review

Likewise has a hidden class. This div should be removed.

Likewise has a hidden class. This div should be removed.
description: part?.description,
Irev-Dev commented 2020-11-16 10:57:13 +01:00 (Migrated from github.com)
Review

clean up

clean up
Irev-Dev commented 2020-11-16 11:00:25 +01:00 (Migrated from github.com)
Review

delete this nav element. I added hidden class but intended to remove it entirely.

delete this nav element. I added hidden class but intended to remove it entirely.
Irev-Dev commented 2020-11-16 11:00:47 +01:00 (Migrated from github.com)
Review

Likewise has a hidden class. This div should be removed.

Likewise has a hidden class. This div should be removed.
},
Irev-Dev commented 2020-11-16 10:57:13 +01:00 (Migrated from github.com)
Review

clean up

clean up
Irev-Dev commented 2020-11-16 11:00:25 +01:00 (Migrated from github.com)
Review

delete this nav element. I added hidden class but intended to remove it entirely.

delete this nav element. I added hidden class but intended to remove it entirely.
Irev-Dev commented 2020-11-16 11:00:47 +01:00 (Migrated from github.com)
Review

Likewise has a hidden class. This div should be removed.

Likewise has a hidden class. This div should be removed.
id: part.id,
Irev-Dev commented 2020-11-16 10:57:13 +01:00 (Migrated from github.com)
Review

clean up

clean up
Irev-Dev commented 2020-11-16 11:00:25 +01:00 (Migrated from github.com)
Review

delete this nav element. I added hidden class but intended to remove it entirely.

delete this nav element. I added hidden class but intended to remove it entirely.
Irev-Dev commented 2020-11-16 11:00:47 +01:00 (Migrated from github.com)
Review

Likewise has a hidden class. This div should be removed.

Likewise has a hidden class. This div should be removed.
isFork: !canEdit,
Irev-Dev commented 2020-11-16 10:57:13 +01:00 (Migrated from github.com)
Review

clean up

clean up
Irev-Dev commented 2020-11-16 11:00:25 +01:00 (Migrated from github.com)
Review

delete this nav element. I added hidden class but intended to remove it entirely.

delete this nav element. I added hidden class but intended to remove it entirely.
Irev-Dev commented 2020-11-16 11:00:47 +01:00 (Migrated from github.com)
Review

Likewise has a hidden class. This div should be removed.

Likewise has a hidden class. This div should be removed.
})
Irev-Dev commented 2020-11-16 10:57:13 +01:00 (Migrated from github.com)
Review

clean up

clean up
Irev-Dev commented 2020-11-16 11:00:25 +01:00 (Migrated from github.com)
Review

delete this nav element. I added hidden class but intended to remove it entirely.

delete this nav element. I added hidden class but intended to remove it entirely.
Irev-Dev commented 2020-11-16 11:00:47 +01:00 (Migrated from github.com)
Review

Likewise has a hidden class. This div should be removed.

Likewise has a hidden class. This div should be removed.
}}
Irev-Dev commented 2020-11-16 10:57:13 +01:00 (Migrated from github.com)
Review

clean up

clean up
Irev-Dev commented 2020-11-16 11:00:25 +01:00 (Migrated from github.com)
Review

delete this nav element. I added hidden class but intended to remove it entirely.

delete this nav element. I added hidden class but intended to remove it entirely.
Irev-Dev commented 2020-11-16 11:00:47 +01:00 (Migrated from github.com)
Review

Likewise has a hidden class. This div should be removed.

Likewise has a hidden class. This div should be removed.
onExport={(type) => threejsViewport[`saveShape${type}`]()}
/>
<div id="topnav" className="topnav hidden">
Irev-Dev commented 2020-11-16 10:57:13 +01:00 (Migrated from github.com)
Review

clean up

clean up
Irev-Dev commented 2020-11-16 10:57:13 +01:00 (Migrated from github.com)
Review

clean up

clean up
Irev-Dev commented 2020-11-16 11:00:25 +01:00 (Migrated from github.com)
Review

delete this nav element. I added hidden class but intended to remove it entirely.

delete this nav element. I added hidden class but intended to remove it entirely.
Irev-Dev commented 2020-11-16 11:00:25 +01:00 (Migrated from github.com)
Review

delete this nav element. I added hidden class but intended to remove it entirely.

delete this nav element. I added hidden class but intended to remove it entirely.
Irev-Dev commented 2020-11-16 11:00:47 +01:00 (Migrated from github.com)
Review

Likewise has a hidden class. This div should be removed.

Likewise has a hidden class. This div should be removed.
Irev-Dev commented 2020-11-16 11:00:47 +01:00 (Migrated from github.com)
Review

Likewise has a hidden class. This div should be removed.

Likewise has a hidden class. This div should be removed.

View File

@@ -26,6 +26,17 @@ const UPDATE_PART_MUTATION = gql`
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
}
}
`
const FORK_PART_MUTATION = gql`
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
mutation ForkPartMutation($input: CreatePartInput!) {
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
forkPart(input: $input) {
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
id
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
title
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
user {
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
userName
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
}
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
}
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
}
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
`
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
export const Loading = () => <div>Loading...</div>
@@ -39,10 +50,25 @@ export const Success = ({ part, refetch }) => {
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
addMessage('Part updated.', { classes: 'rw-flash-success' })
},
})
const [forkPart] = useMutation(FORK_PART_MUTATION, {
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
onCompleted: ({ forkPart }) => {
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
navigate(
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
routes.ide({
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
userName: forkPart?.user?.userName,
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
partTitle: forkPart?.title,
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
})
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
)
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
addMessage('Part Forked.', { classes: 'rw-flash-success' })
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
},
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
})
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
const saveCode = (input, id) => {
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
updatePart({ variables: { id, input } })
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
refetch()
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
const saveCode = ({ input, id, isFork }) => {
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
if (!isFork) {
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
updatePart({ variables: { id, input } })
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
refetch()
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
return
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
}
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
forkPart({ variables: { input } })
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
}
return (
<IdeCascadeStudio
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.
Irev-Dev commented 2020-11-16 11:01:05 +01:00 (Migrated from github.com)
Review

remove commented code.

remove commented code.