generated from eea/volto-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #78 from eea/develop
Refactor using arcgis js sdk
- Loading branch information
Showing
74 changed files
with
4,456 additions
and
2,537 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import { memo, useRef, useState, useMemo } from 'react'; | ||
import { isNil } from 'lodash'; | ||
|
||
import SidebarGroup from './SidebarGroup'; | ||
|
||
import _MapBuilder from '../Map/MapBuilder'; | ||
|
||
import { | ||
StructureBaseLayerPanel, | ||
StructureLayersPanel, | ||
StructureWidgetsPanel, | ||
SettingsGeneralPanel, | ||
SettingsLayersPanel, | ||
} from './Panels'; | ||
|
||
import EditorContext from './EditorContext'; | ||
|
||
import 'react-querybuilder/dist/query-builder.css'; | ||
import 'jsoneditor/dist/jsoneditor.min.css'; | ||
|
||
const MapBuilder = memo(_MapBuilder); | ||
|
||
const panels = { | ||
structure: [ | ||
{ | ||
title: 'Base layer', | ||
Panel: StructureBaseLayerPanel, | ||
}, | ||
{ | ||
title: 'Layers', | ||
Panel: StructureLayersPanel, | ||
}, | ||
{ | ||
title: 'Widgets', | ||
Panel: StructureWidgetsPanel, | ||
}, | ||
], | ||
settings: [ | ||
{ title: 'General', Panel: SettingsGeneralPanel }, | ||
{ title: 'Layers', Panel: SettingsLayersPanel }, | ||
], | ||
}; | ||
|
||
function useApi() { | ||
const [data, setData] = useState({}); | ||
const [loading, setLoading] = useState({}); | ||
const [loaded, setLoaded] = useState({}); | ||
const [error, setError] = useState({}); | ||
|
||
const load = async (url, opts) => { | ||
if (data[url]) return data[url]; | ||
let response, result; | ||
setLoading((prev) => ({ ...prev, [url]: true })); | ||
try { | ||
response = await fetch(`${url}?f=json`, opts); | ||
} catch { | ||
response = { ok: false, statusText: 'Unexpected error' }; | ||
} | ||
try { | ||
result = await response.json(); | ||
} catch { | ||
result = response.ok | ||
? { | ||
code: 500, | ||
message: 'Unexpected error', | ||
} | ||
: { | ||
code: response.status, | ||
message: response.statusText, | ||
}; | ||
} | ||
|
||
if (!response.ok || (!isNil(result.code) && result.code !== 200)) { | ||
setData((prev) => ({ ...prev, [url]: null })); | ||
setError((prev) => ({ ...prev, [url]: result })); | ||
setLoading((prev) => ({ ...prev, [url]: false })); | ||
setLoaded((prev) => ({ ...prev, [url]: false })); | ||
return; | ||
} | ||
setData((prev) => ({ ...prev, [url]: result })); | ||
setError((prev) => ({ ...prev, [url]: null })); | ||
setLoading((prev) => ({ ...prev, [url]: false })); | ||
setLoaded((prev) => ({ ...prev, [url]: true })); | ||
}; | ||
|
||
return { data, loading, loaded, error, load }; | ||
} | ||
|
||
export default function Editor({ value, properties, onChangeValue }) { | ||
const $map = useRef(null); | ||
const [active, setActive] = useState({ | ||
sidebar: 'structure', | ||
panel: panels.structure[0], | ||
}); | ||
const servicesApi = useApi(); | ||
const layersApi = useApi(); | ||
|
||
const Panel = useMemo(() => active.panel.Panel, [active]); | ||
|
||
return ( | ||
<EditorContext.Provider value={{ servicesApi, layersApi }}> | ||
<div className="arcgis-map__editor"> | ||
<div className="arcgis-map__controls"> | ||
<div className="arcgis-map__sidebar"> | ||
{Object.keys(panels).map((panel) => ( | ||
<SidebarGroup | ||
key={panel} | ||
title={panel} | ||
items={panels[panel]} | ||
active={active} | ||
setActive={setActive} | ||
/> | ||
))} | ||
</div> | ||
<div className="arcgis-map__panel"> | ||
<Panel | ||
$map={$map} | ||
value={value} | ||
properties={properties} | ||
onChangeValue={onChangeValue} | ||
/> | ||
</div> | ||
</div> | ||
<div className="arcgis-map__view"> | ||
<MapBuilder data={value} ref={$map} /> | ||
</div> | ||
</div> | ||
</EditorContext.Provider> | ||
); | ||
} |
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,2 @@ | ||
import { createContext } from 'react'; | ||
export default createContext(null); |
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,56 @@ | ||
import { useState } from 'react'; | ||
import cx from 'classnames'; | ||
|
||
import { Icon } from '@plone/volto/components'; | ||
|
||
import clearSVG from '@plone/volto/icons/clear.svg'; | ||
import upKeySVG from '@plone/volto/icons/up-key.svg'; | ||
|
||
export default function Fold({ | ||
children, | ||
title, | ||
icon, | ||
foldable, | ||
deletable, | ||
onDelete, | ||
}) { | ||
const [fold, setFold] = useState(false); | ||
|
||
const isfolded = foldable && fold; | ||
|
||
return ( | ||
<div className={cx('fold', { fold__open: !isfolded, foldable })}> | ||
<div | ||
className="fold--top" | ||
{...(foldable | ||
? { | ||
role: 'button', | ||
tabIndex: 0, | ||
onClick: () => setFold(!fold), | ||
onKeyDown: () => {}, | ||
} | ||
: {})} | ||
> | ||
<div className="fold--top__content"> | ||
{foldable && ( | ||
<Icon name={upKeySVG} className="fold--top__fold" size="16px" /> | ||
)} | ||
{!!icon && <Icon name={icon} size="16px" />} | ||
{!!title && <div className="fold--top__title">{title}</div>} | ||
</div> | ||
{deletable && ( | ||
<Icon | ||
name={clearSVG} | ||
className="fold--top__delete" | ||
size="16px" | ||
onClick={(e) => { | ||
onDelete(e); | ||
e.stopPropagation(); | ||
}} | ||
/> | ||
)} | ||
</div> | ||
{!isfolded && <div className="fold--content">{children}</div>} | ||
</div> | ||
); | ||
} |
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,8 @@ | ||
export default function Panel({ header, content }) { | ||
return ( | ||
<div className="panel"> | ||
{!!header && <div className="panel--header">{header}</div>} | ||
{!!content && <div className="panel--content">{content}</div>} | ||
</div> | ||
); | ||
} |
Oops, something went wrong.