@@ -5,13 +5,16 @@ import {
55 Button , CircularProgress ,
66 Paper , Typography ,
77} from '@material-ui/core' ;
8+ import FileCopyIcon from '@material-ui/icons/FileCopy' ;
89import LocalLibraryIcon from '@material-ui/icons/LocalLibrary' ;
910import { Alert } from '@material-ui/lab' ;
11+ import isempty from 'lodash.isempty' ;
1012import { useSnackbar } from 'notistack' ;
1113import React , {
1214 useCallback , useEffect , useState ,
1315} from 'react' ;
1416import { useMutation , useQuery } from 'react-query' ;
17+ import { Link , useNavigate , useParams } from 'react-router-dom' ;
1518
1619import ActionButton from '@/components/ActionButton' ;
1720import { useAuth } from '@/components/Auth' ;
@@ -54,6 +57,9 @@ const StatementForm = ({
5457 variant,
5558 ...rest
5659} : StatementFormProps ) => {
60+ const params = useParams ( ) ;
61+ const navigate = useNavigate ( ) ;
62+
5763 const { data : diagnosticData } = useQuery (
5864 tuple (
5965 '/query' ,
@@ -102,6 +108,30 @@ const StatementForm = ({
102108 async ( { queryKey : [ , body ] } ) => api . query ( body ) ,
103109 ) ;
104110
111+ // Fetch and populate the fields for quick copy of record
112+ useQuery (
113+ `/statements/${ params . rid } ?neighbors=1` ,
114+ async ( { queryKey : [ route ] } ) => api . get ( route ) ,
115+ {
116+ enabled : ( isempty ( initialValue ) && Boolean ( params . rid ) ) ,
117+ onSuccess : ( data ) => {
118+ navigate ( '/new/statement' , { replace : true } ) ;
119+ const keysToIgnore = [
120+ '@rid' , '@class' ,
121+ 'createdAt' , 'createdBy' ,
122+ 'updatedAt' , 'updatedBy' ,
123+ 'deletedAt' , 'deletedBy' ,
124+ 'uuid' , 'reviews' ,
125+ ] ;
126+ Object . entries ( data ) . forEach ( ( [ key , value ] ) => {
127+ if ( ! keysToIgnore . includes ( key ) ) {
128+ updateField ( key , value ) ;
129+ }
130+ } ) ;
131+ } ,
132+ } ,
133+ ) ;
134+
105135 const snackbar = useSnackbar ( ) ;
106136 const auth = useAuth ( ) ;
107137 const model = schemaDefn . get ( 'Statement' ) ;
@@ -324,6 +354,17 @@ const StatementForm = ({
324354 Add Review
325355 </ Button >
326356 ) }
357+ { variant === FORM_VARIANT . VIEW && (
358+ < Button
359+ className = "header__review-action"
360+ component = { Link }
361+ target = "_blank"
362+ to = { ! isempty ( initialValue ) ? `/new/${ initialValue [ '@class' ] . toLowerCase ( ) } /${ initialValue [ '@rid' ] . replace ( / ^ # / , '' ) } /` : '' }
363+ variant = "outlined"
364+ >
365+ < FileCopyIcon classes = { { root : 'review-icon' } } /> Create As Copy
366+ </ Button >
367+ ) }
327368 { civicEvidenceId && < CivicEvidenceLink evidenceId = { civicEvidenceId } /> }
328369 { onToggleState && ( variant === FORM_VARIANT . VIEW || variant === FORM_VARIANT . EDIT ) && (
329370 < RecordFormStateToggle
0 commit comments