Skip to content

Commit

Permalink
Merge pull request #974 from openmsupply/#285-delete-application-in-d…
Browse files Browse the repository at this point in the history
…raft

#285 delete application in draft
  • Loading branch information
nmadruga authored Sep 27, 2021
2 parents a4b825b + 4b07077 commit 43373f2
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 16 deletions.
5 changes: 5 additions & 0 deletions semantic/src/site/globals/site.overrides
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,11 @@ a:hover {

.list-row {
padding-bottom: 30px;

.delete-icon {
.clickable();
padding-left: 10px;
}
}

.flex-grow-1 {
Expand Down
26 changes: 21 additions & 5 deletions src/components/List/ApplicationsList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { Fragment } from 'react'
import { Table, Message } from 'semantic-ui-react'
import { useDeleteApplicationMutation } from '../../utils/generated/graphql'
import messages from '../../utils/messages'
import strings from '../../utils/constants'
import { ApplicationListRow, ColumnDetails, SortQuery } from '../../utils/types'
import Loading from '../Loading'

Expand All @@ -10,6 +12,7 @@ interface ApplicationsListProps {
sortQuery: SortQuery
handleSort: Function
loading: boolean
refetch: Function
}

const ApplicationsList: React.FC<ApplicationsListProps> = ({
Expand All @@ -18,6 +21,7 @@ const ApplicationsList: React.FC<ApplicationsListProps> = ({
sortQuery: { sortColumn, sortDirection },
handleSort,
loading,
refetch,
}) => {
return (
<>
Expand Down Expand Up @@ -46,7 +50,7 @@ const ApplicationsList: React.FC<ApplicationsListProps> = ({
) : (
applications.map((application, index) => {
const rowProps = {
index,
refetch,
columns,
application,
}
Expand All @@ -68,17 +72,29 @@ const ApplicationsList: React.FC<ApplicationsListProps> = ({
}

interface ApplicationRowProps {
index: number
refetch: Function
columns: Array<ColumnDetails>
application: ApplicationListRow
}

const ApplicationRow: React.FC<ApplicationRowProps> = ({ columns, application }) => {
const ApplicationRow: React.FC<ApplicationRowProps> = ({ refetch, columns, application }) => {
const [deleteApplication, { loading, error }] = useDeleteApplicationMutation({
variables: { id: application.id || 0 },
onCompleted: () => refetch(),
})
const props = {
application,
loading,
deleteApplication,
}

if (error) return <Message error header={strings.ERROR_APPLICATION_DELETE} list={[error]} />

return (
<Table.Row key={`ApplicationList-application-${application.id}`} className="list-row">
{columns.map(({ headerName, ColumnComponent }, index) => (
{columns.map(({ ColumnComponent }, index) => (
<Table.Cell key={`ApplicationList-row-${application.id}-${index}`}>
<ColumnComponent application={application} />
<ColumnComponent {...props} />
</Table.Cell>
))}
</Table.Row>
Expand Down
9 changes: 4 additions & 5 deletions src/components/List/Cells/ApplicationNameCells.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import React from 'react'
import { Link } from 'react-router-dom'
import { ApplicationListShape } from '../../../utils/generated/graphql'
import { CellProps } from '../../../utils/types'

const ApplicationNameCell: React.FC<CellProps> = ({ application }) => (
<div className="application-name-cell">
<Link to={`/application/${application.serial || 0}`}>{application.name as string}</Link>
<ApplicationNameCellDetails application={application} />
<ApplicationNameCellDetails {...application} />
</div>
)

const ApplicationNameReviewLinkCell: React.FC<CellProps> = ({ application }) => (
<div>
<Link to={`/application/${application.serial || 0}/review`}>{application.name as string}</Link>
<ApplicationNameCellDetails application={application} />
<ApplicationNameCellDetails {...application} />
</div>
)

const ApplicationNameCellDetails: React.FC<CellProps> = ({
application: { applicant, orgName },
}) => (
const ApplicationNameCellDetails: React.FC<ApplicationListShape> = ({ applicant, orgName }) => (
<p className="application-name-cell-name">{`${applicant}${orgName ? ' • ' + orgName : ''}`}</p>
)

Expand Down
38 changes: 33 additions & 5 deletions src/components/List/Cells/StatusCell.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
import React from 'react'
import React, { useState } from 'react'
import { Link } from 'react-router-dom'
import { Icon, Progress } from 'semantic-ui-react'
import { Icon, ModalProps, Progress } from 'semantic-ui-react'
import { ApplicationStatus } from '../../../utils/generated/graphql'
import { CellProps } from '../../../utils/types'
import enumsToLocalStrings from '../../../utils/data/enumsToLocalisedStrings'
import strings from '../../../utils/constants'
import messages from '../../../utils/messages'
import ModalConfirmation from '../../Main/ModalConfirmation'

const StatusCell: React.FC<CellProps> = ({ application, loading, deleteApplication }) => {
const [showModalDeletion, setShowModalDeletion] = useState<ModalProps>({ open: false })

const showConfirmation = () => {
const { title, message, option } = messages.APPLICATION_DELETION_CONFIRM
setShowModalDeletion({
open: true,
title,
message,
option,
onClick: () => {
deleteApplication()
setShowModalDeletion({ open: false })
},
onClose: () => setShowModalDeletion({ open: false }),
})
}

const deleteDraft = () => {
showConfirmation()
}

const StatusCell: React.FC<CellProps> = ({ application }) => {
const { serial, status } = application
switch (status) {
case ApplicationStatus.ChangesRequired:
Expand All @@ -23,8 +46,13 @@ const StatusCell: React.FC<CellProps> = ({ application }) => {
<Link to={`/application/${serial}`} className="user-action">
{strings.ACTION_EDIT_DRAFT}
</Link>
{/* TO DO: Trash icon should link to application delete */}
<Icon name="trash alternate outline" />
<Icon
className="delete-icon"
name="trash alternate outline"
loading={loading}
onClick={deleteDraft}
/>
<ModalConfirmation {...showModalDeletion} />
</>
)
case ApplicationStatus.Completed:
Expand Down
3 changes: 2 additions & 1 deletion src/containers/List/ListWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const ListWrapper: React.FC = () => {
return null
}

const { error, loading, applications, applicationCount } = useListApplications(query)
const { error, loading, refetch, applications, applicationCount } = useListApplications(query)

useEffect(() => {
if (!templatePermissions) return
Expand Down Expand Up @@ -133,6 +133,7 @@ const ListWrapper: React.FC = () => {
sortQuery={sortQuery}
handleSort={handleSort}
loading={loading}
refetch={refetch}
/>
)}
<PaginationBar totalCount={applicationCount} />
Expand Down
1 change: 1 addition & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export default {
PLACEHOLDER_SEARCH: 'Search Applications...',
DATE_APPLICATION_PLACEHOLDER: '31/12/2020',
ERROR_APPLICATION_CREATE: 'Problem loading application creation page',
ERROR_APPLICATION_DELETE: 'Problem deleting application',
ERROR_APPLICATION_PAGE: 'Problem loading application',
ERROR_APPLICATION_SUBMIT: 'Problem submitting application',
ERROR_APPLICATIONS_LIST: 'Problem loading applications list',
Expand Down
45 changes: 45 additions & 0 deletions src/utils/generated/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29639,6 +29639,19 @@ export type CreateReviewMutation = (
)> }
);

export type DeleteApplicationMutationVariables = Exact<{
id: Scalars['Int'];
}>;


export type DeleteApplicationMutation = (
{ __typename?: 'Mutation' }
& { deleteApplication?: Maybe<(
{ __typename?: 'DeleteApplicationPayload' }
& Pick<DeleteApplicationPayload, 'clientMutationId'>
)> }
);

export type RestartApplicationMutationVariables = Exact<{
serial: Scalars['String'];
applicationPatch: ApplicationPatch;
Expand Down Expand Up @@ -30990,6 +31003,38 @@ export function useCreateReviewMutation(baseOptions?: Apollo.MutationHookOptions
export type CreateReviewMutationHookResult = ReturnType<typeof useCreateReviewMutation>;
export type CreateReviewMutationResult = Apollo.MutationResult<CreateReviewMutation>;
export type CreateReviewMutationOptions = Apollo.BaseMutationOptions<CreateReviewMutation, CreateReviewMutationVariables>;
export const DeleteApplicationDocument = gql`
mutation deleteApplication($id: Int!) {
deleteApplication(input: {id: $id}) {
clientMutationId
}
}
`;
export type DeleteApplicationMutationFn = Apollo.MutationFunction<DeleteApplicationMutation, DeleteApplicationMutationVariables>;

/**
* __useDeleteApplicationMutation__
*
* To run a mutation, you first call `useDeleteApplicationMutation` within a React component and pass it any options that fit your needs.
* When your component renders, `useDeleteApplicationMutation` returns a tuple that includes:
* - A mutate function that you can call at any time to execute the mutation
* - An object with fields that represent the current status of the mutation's execution
*
* @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2;
*
* @example
* const [deleteApplicationMutation, { data, loading, error }] = useDeleteApplicationMutation({
* variables: {
* id: // value for 'id'
* },
* });
*/
export function useDeleteApplicationMutation(baseOptions?: Apollo.MutationHookOptions<DeleteApplicationMutation, DeleteApplicationMutationVariables>) {
return Apollo.useMutation<DeleteApplicationMutation, DeleteApplicationMutationVariables>(DeleteApplicationDocument, baseOptions);
}
export type DeleteApplicationMutationHookResult = ReturnType<typeof useDeleteApplicationMutation>;
export type DeleteApplicationMutationResult = Apollo.MutationResult<DeleteApplicationMutation>;
export type DeleteApplicationMutationOptions = Apollo.BaseMutationOptions<DeleteApplicationMutation, DeleteApplicationMutationVariables>;
export const RestartApplicationDocument = gql`
mutation restartApplication($serial: String!, $applicationPatch: ApplicationPatch!) {
updateApplicationBySerial(input: {serial: $serial, patch: $applicationPatch}) {
Expand Down
9 changes: 9 additions & 0 deletions src/utils/graphql/mutations/deleteApplication.mutation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { gql } from '@apollo/client'

export default gql`
mutation deleteApplication($id: Int!) {
deleteApplication(input: { id: $id }) {
clientMutationId
}
}
`
2 changes: 2 additions & 0 deletions src/utils/hooks/useListApplications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const useListApplications = ({ sortBy, page, perPage, ...queryFilters }: BasicSt
const {
data,
loading,
refetch,
error: applicationsError,
} = useGetApplicationListQuery({
variables: {
Expand Down Expand Up @@ -60,6 +61,7 @@ const useListApplications = ({ sortBy, page, perPage, ...queryFilters }: BasicSt
return {
error,
loading,
refetch,
applications,
applicationCount,
}
Expand Down
5 changes: 5 additions & 0 deletions src/utils/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ export default {
APPLICATIONS_LIST_EMPTY: 'No applications found',
APPLICATION_MISSING_TEMPLATE: '',
APPLICATION_OTHER_CHANGES_MADE: 'This is a new submission and will require a review.',
APPLICATION_DELETION_CONFIRM: {
title: 'Delete application',
message: 'Please confirm you would like to delete a draft application',
option: 'OK',
},
LOGIN_WELCOME: 'Welcome, %1',
LOGIN_ORG_SELECT: 'Please select an organisation',
VALIDATION_FAIL: {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ interface BasicStringObject {

interface CellProps {
application: ApplicationListShape
loading: boolean
deleteApplication: Function
}

interface ColumnDetails {
Expand Down

0 comments on commit 43373f2

Please sign in to comment.