Skip to content

Commit

Permalink
chore: prettier --write
Browse files Browse the repository at this point in the history
  • Loading branch information
snorrees committed Nov 17, 2022
1 parent 6e93d7d commit f80245e
Show file tree
Hide file tree
Showing 27 changed files with 202 additions and 295 deletions.
75 changes: 24 additions & 51 deletions src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,34 @@
import { AddIcon } from '@sanity/icons'
import {
Box,
Button,
Card,
Flex,
Text,
ToastProvider,
Tooltip,
} from '@sanity/ui'
import { useMachine } from '@xstate/react'
import {AddIcon} from '@sanity/icons'
import {Box, Button, Card, Flex, Text, ToastProvider, Tooltip} from '@sanity/ui'
import {useMachine} from '@xstate/react'
import groq from 'groq'
import React from 'react'
import { QueryClient, QueryClientProvider } from 'react-query'
import {QueryClient, QueryClientProvider} from 'react-query'

import StateDebug from './components/StateDebug'
import {
DEPLOYMENT_TARGET_DOCUMENT_TYPE,
Z_INDEX_TOAST_PROVIDER,
} from './constants'
import {DEPLOYMENT_TARGET_DOCUMENT_TYPE, Z_INDEX_TOAST_PROVIDER} from './constants'
import deploymentTargetListMachine from './machines/deploymentTargetList'
import DeploymentTargets from './components/DeploymentTargets'
import DialogForm from './components/DialogForm'
import dialogMachine from './machines/dialog'
import { Sanity } from './types'
import { useSanityClient } from './client'
import {Sanity} from './types'
import {useSanityClient} from './client'

const Widget = () => {
const client = useSanityClient()
// xstate
const [deploymentTargetListState, deploymentTargetListStateTransition] =
useMachine(deploymentTargetListMachine, {
const [deploymentTargetListState, deploymentTargetListStateTransition] = useMachine(
deploymentTargetListMachine,
{
services: {
fetchDataService: () => {
return client
.fetch(
groq`*[_type == "${DEPLOYMENT_TARGET_DOCUMENT_TYPE}"] | order(name asc)`
)
.fetch(groq`*[_type == "${DEPLOYMENT_TARGET_DOCUMENT_TYPE}"] | order(name asc)`)
.then((result: any) => result)
},
},
})
}
)
const [dialogState, dialogStateTransition] = useMachine(dialogMachine)

const queryClient = new QueryClient({
Expand All @@ -59,32 +48,27 @@ const Widget = () => {
dialogStateTransition('CREATE')
}
const handleDialogShowEdit = (deploymentTarget: Sanity.DeploymentTarget) => {
dialogStateTransition('EDIT', { deploymentTarget })
dialogStateTransition('EDIT', {deploymentTarget})
}
const handleTargetCreate = (deploymentTarget: Sanity.DeploymentTarget) => {
deploymentTargetListStateTransition('CREATE', { deploymentTarget })
deploymentTargetListStateTransition('CREATE', {deploymentTarget})
}
const handleTargetDelete = (id: string) => {
deploymentTargetListStateTransition('DELETE', { id })
deploymentTargetListStateTransition('DELETE', {id})
}
const handleTargetUpdate = (deploymentTarget: Sanity.DeploymentTarget) => {
deploymentTargetListStateTransition('UPDATE', { deploymentTarget })
deploymentTargetListStateTransition('UPDATE', {deploymentTarget})
}

return (
<ToastProvider zOffset={Z_INDEX_TOAST_PROVIDER}>
<QueryClientProvider client={queryClient}>
<Card radius={2} style={{ overflow: 'hidden ' }}>
<Card radius={2} style={{overflow: 'hidden '}}>
{/* xstate debug */}
<StateDebug name="List" state={deploymentTargetListState} />

{/* Header */}
<Flex
align="center"
justify="space-between"
paddingX={3}
paddingY={2}
>
<Flex align="center" justify="space-between" paddingX={3} paddingY={2}>
<Text size={5} weight="semibold">
Vercel deployments
</Text>
Expand All @@ -99,12 +83,7 @@ const Widget = () => {
}
placement="left"
>
<Button
fontSize={1}
icon={AddIcon}
onClick={handleDialogShowCreate}
mode="bleed"
/>
<Button fontSize={1} icon={AddIcon} onClick={handleDialogShowCreate} mode="bleed" />
</Tooltip>
</Flex>

Expand All @@ -119,10 +98,7 @@ const Widget = () => {
<Box paddingX={3} paddingY={4}>
<Text>
No deployment targets found.{' '}
<a
onClick={handleDialogShowCreate}
style={{ cursor: 'pointer' }}
>
<a onClick={handleDialogShowCreate} style={{cursor: 'pointer'}}>
Create a new target?
</a>
</Text>
Expand All @@ -139,8 +115,8 @@ const Widget = () => {
{deploymentTargetListState.matches('failed') && (
<Box paddingX={3} paddingY={4}>
<Text>
Failed to retrieve deployment targets. Please check the
developer console log for more information.
Failed to retrieve deployment targets. Please check the developer console log for
more information.
</Text>
</Box>
)}
Expand All @@ -149,10 +125,7 @@ const Widget = () => {

{/* Dialogs */}
{dialogState.matches('create') && (
<DialogForm
onClose={handleDialogClose}
onCreate={handleTargetCreate}
/>
<DialogForm onClose={handleDialogClose} onCreate={handleTargetCreate} />
)}

{dialogState.matches('edit') && (
Expand Down
8 changes: 4 additions & 4 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { SanityClient } from '@sanity/client'
import { API_VERSION } from './constants'
import { useClient } from 'sanity'
import type {SanityClient} from '@sanity/client'
import {API_VERSION} from './constants'
import {useClient} from 'sanity'

export function useSanityClient(): SanityClient {
return useClient({ apiVersion: API_VERSION })
return useClient({apiVersion: API_VERSION})
}
21 changes: 10 additions & 11 deletions src/components/DeployButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { UploadIcon } from '@sanity/icons'
import { Box, Button, useToast } from '@sanity/ui'
import { useMachine } from '@xstate/react'
import React, { useEffect, useMemo } from 'react'
import {UploadIcon} from '@sanity/icons'
import {Box, Button, useToast} from '@sanity/ui'
import {useMachine} from '@xstate/react'
import React, {useEffect, useMemo} from 'react'

import { WIDGET_NAME } from '../../constants'
import {WIDGET_NAME} from '../../constants'
import deployMachine from '../../machines/deploy'
import StateDebug from '../StateDebug'

Expand All @@ -14,12 +14,11 @@ type Props = {
}

const DeployButton = (props: Props) => {
const { deployHook, onDeploySuccess, targetName } = props
const {deployHook, onDeploySuccess, targetName} = props

const machine = useMemo(() => deployMachine(deployHook), [deployHook])

const [deployState, deployStateTransition, deployStateInterpreter] =
useMachine(machine)
const [deployState, deployStateTransition, deployStateInterpreter] = useMachine(machine)

const toast = useToast()

Expand All @@ -28,7 +27,7 @@ const DeployButton = (props: Props) => {

// Callbacks
const handleDeploy = () => {
deployStateTransition({ type: 'DEPLOY' })
deployStateTransition({type: 'DEPLOY'})
}

// Effects
Expand All @@ -55,7 +54,7 @@ const DeployButton = (props: Props) => {
}, [isError, isSuccess, toast, targetName, deployState.context.error])

useEffect(() => {
deployStateInterpreter.onTransition(state => {
deployStateInterpreter.onTransition((state) => {
if (state.value === 'success') {
if (onDeploySuccess) {
onDeploySuccess()
Expand All @@ -65,7 +64,7 @@ const DeployButton = (props: Props) => {
}, [deployStateInterpreter, onDeploySuccess])

return (
<Box padding={3} style={{ position: 'relative' }}>
<Box padding={3} style={{position: 'relative'}}>
{/* xstate debug */}
<StateDebug name="Deploy" state={deployState} />

Expand Down
23 changes: 9 additions & 14 deletions src/components/Deployment/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Box, Flex, Stack, Text } from '@sanity/ui'
import React, { useRef } from 'react'
import {Box, Flex, Stack, Text} from '@sanity/ui'
import React, {useRef} from 'react'
import ReactTimeAgo from 'react-time-ago'

import TableCell from '../TableCell'
import StatusDot from '../StatusDot'
import { LinkIcon } from '@sanity/icons'
import { Vercel } from '../../types'
import {LinkIcon} from '@sanity/icons'
import {Vercel} from '../../types'

type Props = {
deployment: Vercel.DeploymentWithAlias
}

const Deployment = (props: Props) => {
const { deployment } = props
const {deployment} = props

const date = useRef(new Date(deployment.created))

Expand All @@ -29,7 +29,7 @@ const Deployment = (props: Props) => {
<Box
display={['block', 'block', 'block', 'block', 'none']}
marginRight={3}
style={{ flexShrink: 0 }}
style={{flexShrink: 0}}
>
<StatusDot state={deployment.state} />
</Box>
Expand All @@ -45,19 +45,14 @@ const Deployment = (props: Props) => {
size={1}
style={{
textDecoration:
deployment.state === 'CANCELED' ||
deployment.state === 'ERROR'
deployment.state === 'CANCELED' || deployment.state === 'ERROR'
? 'line-through'
: 'normal',
}}
textOverflow="ellipsis"
>
{deployment.state === 'READY' ? (
<a
href={`https://${targetUrl}`}
rel="noopener noreferrer"
target="_blank"
>
<a href={`https://${targetUrl}`} rel="noopener noreferrer" target="_blank">
{targetUrl}
</a>
) : (
Expand All @@ -81,7 +76,7 @@ const Deployment = (props: Props) => {
{deployment.state
.trim()
.toLowerCase()
.replace(/^[a-z]/i, t => t.toUpperCase())}
.replace(/^[a-z]/i, (t) => t.toUpperCase())}
</Text>
</Box>
</Flex>
Expand Down
2 changes: 1 addition & 1 deletion src/components/DeploymentPlaceholder/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Flex } from '@sanity/ui'
import {Flex} from '@sanity/ui'
import React from 'react'

import PlaceholderAvatar from '../PlaceholderAvatar'
Expand Down
19 changes: 7 additions & 12 deletions src/components/DeploymentTarget/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { EditIcon } from '@sanity/icons'
import { Box, Button, Flex, Text, Tooltip } from '@sanity/ui'
import React, { FC } from 'react'
import {EditIcon} from '@sanity/icons'
import {Box, Button, Flex, Text, Tooltip} from '@sanity/ui'
import React, {FC} from 'react'

import Deployments from '../Deployments'
import { Sanity } from '../../types'
import {Sanity} from '../../types'

type Props = {
item: Sanity.DeploymentTarget
onDialogEdit: (deploymentTarget: Sanity.DeploymentTarget) => void
}

const DeploymentTarget: FC<Props> = (props: Props) => {
const { item, onDialogEdit } = props
const {item, onDialogEdit} = props

const deploymentTarget = {
deployHook: item.deployHook,
Expand All @@ -23,7 +23,7 @@ const DeploymentTarget: FC<Props> = (props: Props) => {
} as Sanity.DeploymentTarget

return (
<Box style={{ position: 'relative' }}>
<Box style={{position: 'relative'}}>
{/* Header */}
<Flex align="center" justify="space-between" marginTop={2} paddingX={3}>
<Text size={2}>{item.name}</Text>
Expand All @@ -38,12 +38,7 @@ const DeploymentTarget: FC<Props> = (props: Props) => {
}
placement="left"
>
<Button
fontSize={1}
icon={EditIcon}
mode="bleed"
onClick={() => onDialogEdit(item)}
/>
<Button fontSize={1} icon={EditIcon} mode="bleed" onClick={() => onDialogEdit(item)} />
</Tooltip>
</Flex>

Expand Down
14 changes: 5 additions & 9 deletions src/components/DeploymentTargets/index.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
import React from 'react'
import { Stack } from '@sanity/ui'
import {Stack} from '@sanity/ui'

import DeploymentTarget from '../DeploymentTarget'
import { Sanity } from '../../types'
import {Sanity} from '../../types'

type Props = {
items: Sanity.DeploymentTarget[]
onDialogEdit: (deploymentTarget: Sanity.DeploymentTarget) => void
}

const DeploymentTargets = (props: Props) => {
const { items, onDialogEdit } = props
const {items, onDialogEdit} = props

return (
<Stack space={5}>
{items?.map(item => (
<DeploymentTarget
item={item}
key={item._id}
onDialogEdit={onDialogEdit}
/>
{items?.map((item) => (
<DeploymentTarget item={item} key={item._id} onDialogEdit={onDialogEdit} />
))}
</Stack>
)
Expand Down
Loading

0 comments on commit f80245e

Please sign in to comment.