-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/location-search-field' into staging
- Loading branch information
Showing
27 changed files
with
5,680 additions
and
3,420 deletions.
There are no files selected for viewing
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,20 +1,10 @@ | ||
import { | ||
WktLiteralTextControlTester, | ||
WktLiteralTextControlRenderer, | ||
LocationToolSettings, | ||
} from '@formswizard/experimental-renderers' | ||
import { locationTools } from '@formswizard/experimental-renderers' | ||
import { WizardProvider, MainLayout } from '@formswizard/forms-designer' | ||
|
||
const renderers = [ | ||
{ | ||
tester: WktLiteralTextControlTester, | ||
renderer: WktLiteralTextControlRenderer, | ||
}, | ||
] | ||
export const App = () => { | ||
return ( | ||
<WizardProvider> | ||
<MainLayout additionalToolSettings={[LocationToolSettings]} renderers={renderers} /> | ||
<MainLayout additionalToolSettings={locationTools.toolSettings} renderers={locationTools.rendererRegistry} /> | ||
</WizardProvider> | ||
) | ||
} |
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
52 changes: 52 additions & 0 deletions
52
packages/experimental-renderers/WktLiteralInputControl.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,52 @@ | ||
import React, { useCallback, useMemo } from 'react' | ||
import { ControlProps } from '@jsonforms/core' | ||
import { pathToPathSegments, pathSegmentsToPath, splitLastPath, filterNullOrUndef } from '@formswizard/utils' | ||
import { NominatimResponse } from './nominatim' | ||
import { LocationSearchCombined } from './LocationSearchCombined' | ||
import { wktToLatLng } from './wktToLantLng' | ||
import { LocationSearchMapProps } from './types' | ||
|
||
type WktLiteralInputControlProps = ControlProps & { | ||
mapElement?: (props: LocationSearchMapProps) => React.ReactNode | ||
} | ||
export const WktLiteralInputControl = (props: WktLiteralInputControlProps) => { | ||
const { uischema, handleChange, path, data, mapElement } = props | ||
|
||
const position = useMemo(() => { | ||
if (data) { | ||
const parsed = wktToLatLng(data) | ||
if (parsed) return parsed | ||
} | ||
}, [data]) || { lat: 51.0833, lng: 13.73126 } | ||
|
||
const handleLocationFound = useCallback( | ||
(lat: number, lng: number, result?: NominatimResponse) => { | ||
const [first, rest] = splitLastPath(path) | ||
// @ts-ignore | ||
const buildPath = (key: string) => | ||
pathSegmentsToPath([ | ||
...filterNullOrUndef<string>(pathToPathSegments(rest || '')).filter((p) => p.length > 0), | ||
key, | ||
]) | ||
handleChange(props.path, `POINT(${lng} ${lat})`) | ||
if (!result) return | ||
if (uischema.options?.mapNominatimFields) { | ||
if ((result as any).name) { | ||
const path = buildPath('name') | ||
// @ts-ignore | ||
handleChange(path, result.name) | ||
} | ||
} | ||
}, | ||
[path, handleChange, uischema] | ||
) | ||
return ( | ||
<LocationSearchCombined | ||
readonly={props.enabled === false} | ||
label={data || props.label} | ||
markerPosition={position} | ||
onChangeMarkerPosition={handleLocationFound} | ||
mapElement={mapElement} | ||
/> | ||
) | ||
} |
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,5 +1,11 @@ | ||
export * from './LocationSearchField' | ||
export * from './LocationSearchTextFieldRenderer' | ||
export * from './LocationSearchMap' | ||
export * from './LocationToolSettings' | ||
export * from './locationTools' | ||
|
||
export * from './WktLiteralInputControl' | ||
export * from './LocationToolSettings' | ||
export * from './locationTools' | ||
export * from './wktToLantLng' | ||
export * from './types' |
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,12 @@ | ||
import { DraggableElement } from '@formswizard/types' | ||
|
||
export const locationToolElements: DraggableElement[] = [ | ||
{ | ||
name: 'Location', | ||
ToolIconName: 'LocationOn', | ||
jsonSchemaElement: { | ||
type: 'string', | ||
format: 'wktLiteral', | ||
}, | ||
}, | ||
] |
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,26 +1,27 @@ | ||
import {DraggableElement, PluggableToolDefinition} from "@formswizard/types"; | ||
import {WktLiteralTextControlRenderer, WktLiteralTextControlTester} from "./LocationSearchTextFieldRenderer"; | ||
import {LocationToolSettings} from "./LocationToolSettings"; | ||
import { DraggableElement, PluggableToolDefinition } from '@formswizard/types' | ||
import { LocationSearchTextControlRenderer, WktLiteralTextControlTester } from './LocationSearchTextFieldRenderer' | ||
import { LocationToolSettings } from './LocationToolSettings' | ||
|
||
export const locationToolElements: DraggableElement[] = [ | ||
{ | ||
name: 'Location', | ||
ToolIconName: 'LocationOn', | ||
jsonSchemaElement: { | ||
type: 'string', | ||
format: 'wktLiteral' | ||
} | ||
}] | ||
|
||
format: 'wktLiteral', | ||
}, | ||
}, | ||
] | ||
|
||
export const locationTools: PluggableToolDefinition = { | ||
dropRendererRegistry: [], | ||
rendererRegistry: [ | ||
{ | ||
tester: WktLiteralTextControlTester, | ||
renderer: WktLiteralTextControlRenderer | ||
} | ||
// renderer: WktLiteralTextControlRenderer, | ||
renderer: LocationSearchTextControlRenderer, | ||
}, | ||
], | ||
toolSettings: [LocationToolSettings], | ||
toolBoxElements: locationToolElements | ||
toolBoxElements: locationToolElements, | ||
} |
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
Oops, something went wrong.