diff --git a/ui/jsconfig.json b/ui/jsconfig.json index 735e8c7..244a67f 100644 --- a/ui/jsconfig.json +++ b/ui/jsconfig.json @@ -32,6 +32,9 @@ ], "styles/*": [ "styles/*" + ], + "fragments/*": [ + "fragments/*" ] } }, diff --git a/ui/src/components/internal/forms/ProjectSearchForm.js b/ui/src/components/internal/forms/ProjectSearchForm.js new file mode 100644 index 0000000..4198170 --- /dev/null +++ b/ui/src/components/internal/forms/ProjectSearchForm.js @@ -0,0 +1,24 @@ +import React from 'react' +import { Field, Form } from 'react-final-form' + +import FilledButton from 'components/buttons/FilledButton' +import FormFooter from 'components/internal/FormFooter' +import TextInput from 'components/inputs/TextInput' + +function ProjectSearchForm(props) { + return ( +
+ )} + {...props} + /> + ) +} + +export default ProjectSearchForm diff --git a/ui/src/components/internal/forms/RecordForm.js b/ui/src/components/internal/forms/RecordForm.js index 6c967aa..ffdde87 100644 --- a/ui/src/components/internal/forms/RecordForm.js +++ b/ui/src/components/internal/forms/RecordForm.js @@ -2,12 +2,14 @@ /* eslint-disable no-use-before-define */ import _ from 'lodash' import arrayMutators from 'final-form-arrays' +import gql from 'graphql-tag' import flat from 'flat' import injectSheet from 'react-jss' import React, { Fragment, useState, useRef, useEffect } from 'react' import { Field, Form } from 'react-final-form' import { FieldArray } from 'react-final-form-arrays' import { ReactSortable } from 'react-sortablejs' +import { withApollo } from 'react-apollo' import * as mixins from 'styles/mixins' import ButtonGroupInput from 'components/internal/inputs/ButtonGroupInput' @@ -29,6 +31,8 @@ import UploadInput from 'components/inputs/UploadInput' import { LoaderText } from 'components/internal/typography' import { SidePaneFormFooter } from 'components/internal/sidePane' +import RECORD_FRAGMENTS from 'fragments/record' + const REFERENCE_OPTIONS = [ { value: 'new', label: 'New Record' }, { value: 'edit', label: 'Existing Record' } @@ -575,9 +579,54 @@ const toggleFormVisibilityMutator = ([ name, selectedRecord, fields ], state, { }) } -function RecordForm({ initialValues, entities, fields, ...other }) { +function RecordForm({ initialValues, fields, client, ...other }) { const newRecord = !initialValues.id + const [ entities, setEntities ] = useState([]) + const [ entitiesLoading, setEntitiesLoading ] = useState(false) + const [ recordLoading, setRecordLoading ] = useState(false) + + const getEntities = async (entityId) => { + setEntitiesLoading(true) + const { data } = await client.query({ + query: RecordForm.ENTITIES_QUERY, + variables: { + entityId + }, + fetchPolicy: 'network-only' + }) + + const newEntities = [ ...entities, ...data.referencedEntities ] + + setEntities(newEntities) + setEntitiesLoading(false) + return newEntities + } + + const getRecord = async (recordId) => { + setRecordLoading(true) + const { data: { record } } = await client.query({ + query: RecordForm.RECORD_QUERY, + variables: { + recordId + }, + fetchPolicy: 'network-only' + }) + + const newEntities = entities + .map((entity) => { + if (entity.id === record.entityId) { + entity.records.push(record) + } + + return entity + }) + + setEntities(newEntities) + setRecordLoading(false) + return newEntities + } + return (