-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1633 from SeedCompany/add-default-field-region
- Loading branch information
Showing
17 changed files
with
175 additions
and
70 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
src/components/form/Lookup/FieldRegion/FieldRegionField.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { action } from '@storybook/addon-actions'; | ||
import { boolean } from '@storybook/addon-knobs'; | ||
import { Form } from 'react-final-form'; | ||
import { ChildrenProp } from '~/common'; | ||
import { FieldSpy } from '../../FieldSpy'; | ||
import { | ||
FieldRegionField, | ||
FieldZoneField, | ||
LocationField, | ||
} from './FieldRegionField'; | ||
|
||
export default { title: 'Components/Forms/Fields/Lookup/Location' }; | ||
|
||
const FF = ({ children }: ChildrenProp) => ( | ||
<Form | ||
onSubmit={action('submit')} | ||
initialValues={{ | ||
location: { | ||
id: 'locationId', | ||
name: { | ||
value: 'Ethiopia', | ||
}, | ||
}, | ||
region: { | ||
id: 'regionid', | ||
name: { | ||
value: 'Africa - Anglophone East', | ||
}, | ||
}, | ||
zone: { | ||
id: 'zoneid', | ||
name: { | ||
value: 'Africa', | ||
}, | ||
}, | ||
}} | ||
> | ||
{({ handleSubmit }) => <form onSubmit={handleSubmit}>{children}</form>} | ||
</Form> | ||
); | ||
|
||
export const Location = () => ( | ||
<FF> | ||
<LocationField | ||
name="location" | ||
label="Location" | ||
multiple={boolean('Multiple', false)} | ||
/> | ||
<FieldSpy name="location" /> | ||
</FF> | ||
); | ||
|
||
export const FieldRegion = () => ( | ||
<FF> | ||
<FieldRegionField | ||
name="fieldRegion" | ||
label="Field Regions" | ||
multiple={boolean('Multiple', false)} | ||
/> | ||
<FieldSpy name="fieldRegion" /> | ||
</FF> | ||
); | ||
|
||
export const FieldZone = () => ( | ||
<FF> | ||
<FieldZoneField | ||
name="fieldZone" | ||
label="Field Zones" | ||
multiple={boolean('Multiple', false)} | ||
/> | ||
<FieldSpy name="fieldZone" /> | ||
</FF> | ||
); |
10 changes: 10 additions & 0 deletions
10
src/components/form/Lookup/FieldRegion/FieldRegionField.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { DisplayFieldRegionFragment as FieldRegionLookupItem } from '~/common'; | ||
import { LookupField } from '../LookupField'; | ||
import { FieldRegionLookupDocument } from './FieldRegionLookup.graphql'; | ||
|
||
export const FieldRegionField = LookupField.createFor<FieldRegionLookupItem>({ | ||
resource: 'FieldRegion', | ||
lookupDocument: FieldRegionLookupDocument, | ||
label: 'Field Region', | ||
placeholder: 'Search for a field region by name', | ||
}); |
7 changes: 7 additions & 0 deletions
7
src/components/form/Lookup/FieldRegion/FieldRegionLookup.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
query FieldRegionLookup($query: String!) { | ||
search(input: { query: $query, type: [FieldRegion] }) { | ||
items { | ||
...DisplayFieldRegion | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './FieldRegionField'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { DisplayFieldZoneFragment as FieldZoneLookupItem } from '~/common'; | ||
import { LookupField } from '../LookupField'; | ||
import { FieldZoneLookupDocument } from './FieldZoneLookup.graphql'; | ||
|
||
export const FieldZoneField = LookupField.createFor<FieldZoneLookupItem>({ | ||
resource: 'FieldZone', | ||
lookupDocument: FieldZoneLookupDocument, | ||
label: 'Field Zone', | ||
placeholder: 'Search for a field zone by name', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
query FieldZoneLookup($query: String!) { | ||
search(input: { query: $query, type: [FieldZone] }) { | ||
items { | ||
...DisplayFieldZone | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './FieldZoneField'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { CreateLocation as CreateLocationType } from '~/api/schema.graphql'; | ||
import { DisplayLocationFragment as LocationLookupItem } from '~/common'; | ||
import { CreateLocation } from '../../../../scenes/Locations/Create'; | ||
import { LocationFormValues } from '../../../../scenes/Locations/LocationForm'; | ||
import { LookupField } from '../LookupField'; | ||
import { LocationLookupDocument } from './LocationLookup.graphql'; | ||
|
||
export const LocationField = LookupField.createFor< | ||
LocationLookupItem, | ||
LocationFormValues<CreateLocationType> | ||
>({ | ||
resource: 'Location', | ||
lookupDocument: LocationLookupDocument, | ||
label: 'Location', | ||
placeholder: 'Search for a location by name', | ||
CreateDialogForm: CreateLocation, | ||
// @ts-expect-error don't need to pass through entire initialValues | ||
getInitialValues: (val) => ({ | ||
location: { | ||
name: val, | ||
}, | ||
}), | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from './LocationFields'; | ||
export * from './LocationField'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters