Skip to content

Commit

Permalink
Remove unused create and delete chain code (now static from config)
Browse files Browse the repository at this point in the history
  • Loading branch information
archseer committed Dec 11, 2024
1 parent 0b3b5d6 commit dfc0cd7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 165 deletions.
32 changes: 0 additions & 32 deletions src/actionCreators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,45 +333,13 @@ const RECEIVE_CREATE_SUCCESS_ACTION = {
type: ResourceActionType.RECEIVE_CREATE_SUCCESS,
}

const receiveDeleteSuccess = (id: string) =>
({
type: ResourceActionType.RECEIVE_DELETE_SUCCESS,
id,
} as const)

export const submitSignIn = (data: Parameter<Sessions['createSession']>) =>
sendSignIn(data)

export const submitSignOut = () => sendSignOut

export const beginRegistration = () => sendBeginRegistration()

export const deleteChain = (
id: string,
successCallback: React.ReactNode,
errorCallback: React.ReactNode,
) => {
return (dispatch: Dispatch) => {
dispatch({ type: ResourceActionType.REQUEST_DELETE })

const endpoint = api.v2.chains

return endpoint
.destroyChain(id)
.then((doc) => {
dispatch(receiveDeleteSuccess(id))
dispatch(notifySuccess(successCallback, doc))
})
.catch((error: Errors) => {
curryErrorHandler(
dispatch,
ResourceActionType.RECEIVE_DELETE_ERROR,
)(error)
dispatch(notifyError(errorCallback, error))
})
}
}

export const createJobRunV2 = (
id: string,
pipelineInput: string,
Expand Down
42 changes: 1 addition & 41 deletions src/api/v2/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,13 @@ import * as jsonapi from 'utils/json-api-client'
import * as models from 'core/store/models'

export const ENDPOINT = '/v2/chains/:network'
const UPDATE_ENDPOINT = `${ENDPOINT}/:id`

export class Chains {
constructor(private api: jsonapi.Api) {}

public getChains = (network: string): Promise<jsonapi.ApiResponse<models.Chain[]>> => {
return this.index(undefined, { network })
}

public createChain = (
request: models.CreateChainRequest,
): Promise<jsonapi.ApiResponse<models.Chain>> => {
return this.create(request)
}

public destroyChain = (id: string): Promise<jsonapi.ApiResponse<null>> => {
return this.destroy(undefined, { id })
}

public updateChain = (
id: string,
req: models.UpdateChainRequest,
): Promise<jsonapi.ApiResponse<models.Chain>> => {
return this.update(req, { id })
}

private index = this.api.fetchResource<object, models.Chain[], { network: string }>(ENDPOINT)

private create = this.api.createResource<
models.CreateChainRequest,
models.Chain
>(ENDPOINT)

private destroy = this.api.deleteResource<
undefined,
null,
{
id: string
network: string
}
>(UPDATE_ENDPOINT)

private update = this.api.updateResource<
models.UpdateChainRequest,
models.Chain,
{
id: string
network: string
}
>(UPDATE_ENDPOINT)
}
95 changes: 3 additions & 92 deletions src/pages/Chains/RegionalNav.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import React, { useState } from 'react'
import React from 'react'
import { connect } from 'react-redux'
import { Chain, Resource } from 'core/store/models'
import { localizedTimestamp, TimeAgo } from 'components/TimeAgo'
import { Redirect, useLocation } from 'react-router-dom'
import Button from 'components/Button'
import Close from 'components/Icons/Close'
import Dialog from '@material-ui/core/Dialog'
import { useLocation } from 'react-router-dom'
import Card from '@material-ui/core/Card'
import Grid from '@material-ui/core/Grid'
import List from '@material-ui/core/List'
Expand All @@ -19,8 +16,6 @@ import {
import Typography from '@material-ui/core/Typography'
import classNames from 'classnames'
import Link from 'components/Link'
import ErrorMessage from 'components/Notifications/DefaultError'
import { deleteChain } from 'actionCreators'

const styles = (theme: Theme) =>
createStyles({
Expand Down Expand Up @@ -101,9 +96,6 @@ const styles = (theme: Theme) =>
modalContent: {
width: 'inherit',
},
deleteButton: {
marginTop: theme.spacing.unit * 4,
},
runJobButton: {
marginBottom: theme.spacing.unit * 3,
},
Expand All @@ -117,99 +109,20 @@ export type ChainResource = Resource<Chain>
interface Props extends WithStyles<typeof styles> {
chainId: string
chain?: ChainResource
deleteChain: (...args: any[]) => any
}

const DeleteSuccessNotification = ({ id }: any) => (
<React.Fragment>Successfully deleted chain {id}</React.Fragment>
)

const RegionalNavComponent = ({
classes,
chainId,
chain,
deleteChain,
}: Props) => {
const [modalOpen, setModalOpen] = useState(false)
const [deleted, setDeleted] = useState(false)
const location = useLocation()
const navOverridesActive = location.pathname.endsWith('/config-overrides')
const editActive = location.pathname.endsWith('/edit')
const navNodesActive = !navOverridesActive && !editActive

const handleDelete = (id: string) => {
deleteChain(id, () => DeleteSuccessNotification({ id }), ErrorMessage)
setDeleted(true)
}

return (
<>
<Dialog
open={modalOpen}
classes={{ paper: classes.dialogPaper }}
onClose={() => setModalOpen(false)}
>
<Grid container spacing={0}>
<Grid item className={classes.modalContent}>
<Grid container alignItems="baseline" justify="space-between">
<Grid item>
<Typography
variant="h5"
color="secondary"
className={classes.warningText}
>
Warning: This Action Cannot Be Undone
</Typography>
</Grid>
<Grid item>
<Close
className={classes.closeButton}
onClick={() => setModalOpen(false)}
/>
</Grid>
</Grid>
<Grid container direction="column">
<Grid item>
<Grid item>
<Typography
className={classes.infoText}
variant="h5"
color="secondary"
>
- Disabling the chain may be a safer option
</Typography>
<Typography
className={classes.infoText}
variant="h5"
color="secondary"
>
- All associated RPC Nodes will be permanently deleted
</Typography>
<Typography
className={classes.infoText}
variant="h5"
color="secondary"
>
- Access to this page will be lost
</Typography>
</Grid>
</Grid>
<Grid container spacing={0} alignItems="center" justify="center">
<Grid item className={classes.deleteButton}>
<Button
variant="danger"
onClick={() => handleDelete(chainId)}
>
Delete {chainId}
{deleted && <Redirect to="/" />}
</Button>
</Grid>
</Grid>
</Grid>
</Grid>
</Grid>
</Dialog>

<Card className={classes.container}>
<Grid container spacing={0}>
<Grid item xs={12}>
Expand Down Expand Up @@ -262,8 +175,6 @@ const RegionalNavComponent = ({
)
}

export const ConnectedRegionalNav = connect(null, {
deleteChain,
})(RegionalNavComponent)
export const ConnectedRegionalNav = connect(null, {})(RegionalNavComponent)

export default withStyles(styles)(ConnectedRegionalNav)

0 comments on commit dfc0cd7

Please sign in to comment.