Skip to content

Commit

Permalink
fn type as generic string
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak committed Aug 19, 2024
1 parent a129d35 commit aa42644
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
9 changes: 5 additions & 4 deletions editor.planx.uk/src/@planx/components/List/Public/Fields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export const MapFieldInput: React.FC<Props<MapField>> = (props) => {
const { formik, activeIndex, schema } = useListContext();
const {
id,
data: { title, fn, drawType, drawColor, drawMany },
data: { title, fn, mapOptions },
} = props;

const teamSettings = useStore.getState().teamSettings;
Expand Down Expand Up @@ -308,10 +308,11 @@ export const MapFieldInput: React.FC<Props<MapField>> = (props) => {
id={id}
ariaLabelOlFixedOverlay={`An interactive map for plotting and describing ${schema.type.toLocaleLowerCase()}`}
height={400}
basemap={mapOptions?.basemap}
drawMode
drawMany={drawMany}
drawColor={drawColor}
drawType={drawType}
drawMany={mapOptions?.drawMany}
drawColor={mapOptions?.drawColor}
drawType={mapOptions?.drawType}
drawPointer="crosshair"
zoom={20}
maxZoom={23}
Expand Down
17 changes: 11 additions & 6 deletions editor.planx.uk/src/@planx/components/List/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ export type MapField = {
type: "map";
data: {
title: string;
fn: "features";
drawType?: "Point" | "Polygon";
drawColor?: string;
drawMany?: boolean;
fn: string;
mapOptions?: {
basemap?: "OSVectorTile" | "OSRaster" | "MapboxSatellite" | "OSM";
drawType?: "Point" | "Polygon";
drawColor?: string;
drawMany?: boolean;
};
};
};

Expand Down Expand Up @@ -120,12 +123,14 @@ export const parseContent = (data: Record<string, any> | undefined): List => ({
...parseMoreInformation(data),
});

const mapValidationSchema = ({ drawType }: MapField["data"]) =>
const mapValidationSchema = ({ mapOptions }: MapField["data"]) =>
array()
.required()
.test({
name: "atLeastOneFeature",
message: `Draw at least one ${drawType?.toLocaleLowerCase()} on the map`,
message: `Draw at least one ${
mapOptions?.drawType?.toLocaleLowerCase() || "feature"
} on the map`,
test: (features?: Array<Feature>) => {
return Boolean(features && features?.length > 0);
},
Expand Down
9 changes: 6 additions & 3 deletions editor.planx.uk/src/@planx/components/List/schemas/Trees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ export const Trees: Schema = {
data: {
title: "Where is it?",
fn: "features",
drawType: "Point",
drawColor: "#ff0000",
drawMany: true,
mapOptions: {
basemap: "OSVectorTile",
drawType: "Point",
drawColor: "#ff0000",
drawMany: true,
},
},
},
],
Expand Down

0 comments on commit aa42644

Please sign in to comment.