Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
underbluewaters committed Jan 2, 2024
1 parent 225ba56 commit c05937f
Show file tree
Hide file tree
Showing 17 changed files with 538 additions and 304 deletions.
38 changes: 28 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/api/generated-schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -6535,6 +6535,7 @@ type InteractivitySetting implements Node {
"""
nodeId: ID!
shortTemplate: String
title: String!
type: InteractivityType!
}

Expand All @@ -6550,6 +6551,7 @@ input InteractivitySettingInput {
layers: [String]
longTemplate: String
shortTemplate: String
title: String
type: InteractivityType
}

Expand All @@ -6567,6 +6569,7 @@ input InteractivitySettingPatch {
layers: [String]
longTemplate: String
shortTemplate: String
title: String
type: InteractivityType
}

Expand All @@ -6576,6 +6579,7 @@ enum InteractivityType {
FIXED_BLOCK
NONE
POPUP
SIDEBAR_OVERLAY
TOOLTIP
}

Expand Down
3 changes: 3 additions & 0 deletions packages/api/migrations/current.sql
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
-- Enter migration here
ALTER TYPE interactivity_type ADD VALUE IF NOT EXISTS 'SIDEBAR_OVERLAY';

alter table interactivity_settings add column if not exists title text not null default '';
192 changes: 116 additions & 76 deletions packages/client/src/admin/data/InteractivitySettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default function InteractivitySettings({
const attributeNames = useSourcePropertyNames(dataSourceId || 0, sublayer);
const [shortTemplate, setShortTemplate] = useState(settings?.shortTemplate);
const [longTemplate, setLongTemplate] = useState(settings?.longTemplate);
const [title, setTitle] = useState(settings?.title);
const [pickLayersOpen, setPickLayersOpen] = useState(false);

useEffect(() => {
Expand All @@ -59,6 +60,9 @@ export default function InteractivitySettings({
if (settings && settings.longTemplate && longTemplate === undefined) {
setLongTemplate(settings.longTemplate);
}
if (settings && settings.title && title === undefined) {
setTitle(settings.title);
}
if (settings && type === undefined) {
setType(settings.type);
}
Expand All @@ -72,6 +76,7 @@ export default function InteractivitySettings({
type,
longTemplate,
shortTemplate,
title
},
});
}
Expand All @@ -90,7 +95,11 @@ export default function InteractivitySettings({
return input;
}

const sanitizeTemplate = (propName: "longTemplate" | "shortTemplate") => {
const sanitizeTemplate = (propName: "longTemplate" | "shortTemplate" | "title") => {
console.log('sanitize', propName);
if (propName === "title") {
setTitle(title || "");
}
if (propName === "longTemplate") {
setLongTemplate(sanitizeInput(longTemplate || ""));
} else {
Expand Down Expand Up @@ -134,82 +143,82 @@ export default function InteractivitySettings({
},
...(!sublayer
? [
{
label: t("Banner"),
description: basemap
? t(
"Short text can be displayed towards the top of the map when the user hovers over features in the selected basemap layers."
)
: t(
"Short text can be displayed towards the top of the map when the user hovers over features."
),
value: InteractivityType.Banner,
children: (
<>
<TemplateEditor
type={InteractivityType.Banner}
selectedType={selectedType}
propName={"shortTemplate"}
templateValue={shortTemplate || undefined}
onSave={sanitizeTemplate}
onChange={(value) => setShortTemplate(value)}
attributeNames={attributeNames}
basemap={basemap}
layers={data.interactivitySetting?.layers as string[]}
onSelectLayers={() => setPickLayersOpen(true)}
/>
</>
),
},
{
label: t("Tooltip"),
description:
"Short text is displayed next to the mouse cursor.",
value: InteractivityType.Tooltip,
children: (
<>
<TemplateEditor
type={InteractivityType.Tooltip}
selectedType={selectedType}
propName={"shortTemplate"}
templateValue={shortTemplate || undefined}
onSave={sanitizeTemplate}
onChange={(value) => setShortTemplate(value)}
attributeNames={attributeNames}
basemap={basemap}
layers={data.interactivitySetting?.layers as string[]}
onSelectLayers={() => setPickLayersOpen(true)}
/>
</>
{
label: t("Banner"),
description: basemap
? t(
"Short text can be displayed towards the top of the map when the user hovers over features in the selected basemap layers."
)
: t(
"Short text can be displayed towards the top of the map when the user hovers over features."
),
},
]
value: InteractivityType.Banner,
children: (
<>
<TemplateEditor
type={InteractivityType.Banner}
selectedType={selectedType}
propName={"shortTemplate"}
templateValue={shortTemplate || undefined}
onSave={sanitizeTemplate}
onChange={(value) => setShortTemplate(value)}
attributeNames={attributeNames}
basemap={basemap}
layers={data.interactivitySetting?.layers as string[]}
onSelectLayers={() => setPickLayersOpen(true)}
/>
</>
),
},
{
label: t("Tooltip"),
description:
"Short text is displayed next to the mouse cursor.",
value: InteractivityType.Tooltip,
children: (
<>
<TemplateEditor
type={InteractivityType.Tooltip}
selectedType={selectedType}
propName={"shortTemplate"}
templateValue={shortTemplate || undefined}
onSave={sanitizeTemplate}
onChange={(value) => setShortTemplate(value)}
attributeNames={attributeNames}
basemap={basemap}
layers={data.interactivitySetting?.layers as string[]}
onSelectLayers={() => setPickLayersOpen(true)}
/>
</>
),
},
]
: []),
...(!sublayer
? [
{
label: "Custom Popup",
description:
"Popup windows can be opened and closed to show detailed information.",
value: InteractivityType.Popup,
children: (
<>
<TemplateEditor
type={InteractivityType.Popup}
selectedType={selectedType}
propName={"longTemplate"}
templateValue={longTemplate || undefined}
onSave={sanitizeTemplate}
onChange={(value) => setLongTemplate(value)}
attributeNames={attributeNames}
basemap={basemap}
layers={data.interactivitySetting?.layers as string[]}
onSelectLayers={() => setPickLayersOpen(true)}
/>
</>
),
},
]
{
label: "Custom Popup",
description:
"Popup windows can be opened and closed to show detailed information.",
value: InteractivityType.Popup,
children: (
<>
<TemplateEditor
type={InteractivityType.Popup}
selectedType={selectedType}
propName={"longTemplate"}
templateValue={longTemplate || undefined}
onSave={sanitizeTemplate}
onChange={(value) => setLongTemplate(value)}
attributeNames={attributeNames}
basemap={basemap}
layers={data.interactivitySetting?.layers as string[]}
onSelectLayers={() => setPickLayersOpen(true)}
/>
</>
),
},
]
: []),
{
label: "Popup with all columns",
Expand All @@ -233,6 +242,37 @@ export default function InteractivitySettings({
// />
// ),
// },
{
label: "Sidebar",
description:
"Similar to a popup, but the content is displayed in a sidebar.",
value: InteractivityType.SidebarOverlay,
children: <div className="mt-4">
<h4 className="text-sm font-normal">{t("Sidebar title")}</h4><p className="text-sm text-gray-500">{t("You may reference feature properties in the title but html tags will not be rendered")}</p>
<TemplateEditor
type={InteractivityType.SidebarOverlay}
selectedType={selectedType}
propName={"title"}
templateValue={title || undefined}
onSave={sanitizeTemplate}
onChange={(value) => setTitle(value)}
attributeNames={attributeNames}
basemap={basemap}
layers={data.interactivitySetting?.layers as string[]}
onSelectLayers={() => setPickLayersOpen(true)}
/>
<h4 className="mt-4 text-sm font-normal">{t("Sidebar content")}</h4><p className="text-sm text-gray-500">{t("Content can reference feature properties and include html content.")}</p>
<TemplateEditor
type={InteractivityType.SidebarOverlay}
selectedType={selectedType}
propName={"longTemplate"}
templateValue={longTemplate || undefined}
onSave={sanitizeTemplate}
onChange={(value) => setLongTemplate(value)}
attributeNames={attributeNames}
/>
</div>,
},
]}
value={selectedType}
onChange={(type) => {
Expand All @@ -247,9 +287,9 @@ export default function InteractivitySettings({
function TemplateEditor(props: {
type: InteractivityType;
selectedType: InteractivityType;
propName: "shortTemplate" | "longTemplate";
propName: "shortTemplate" | "longTemplate" | "title";
templateValue: string | undefined;
onSave: (propName: "shortTemplate" | "longTemplate") => void;
onSave: (propName: "shortTemplate" | "longTemplate" | "title") => void;
onChange: (value: string) => void;
attributeNames: string[];
layers?: string[];
Expand All @@ -274,7 +314,7 @@ function TemplateEditor(props: {
onBeforeChange={(editor, data, value) => {
props.onChange(value);
}}
onChange={(editor, data, value) => {}}
onChange={(editor, data, value) => { }}
/>
<Button small label={t("save")} onClick={onSave} />
{props.basemap && (
Expand Down
Loading

0 comments on commit c05937f

Please sign in to comment.