Skip to content

Commit

Permalink
feat: adding in env the limit of verticeis
Browse files Browse the repository at this point in the history
  • Loading branch information
Eliav-Maimon committed Dec 30, 2024
1 parent b052c0a commit 6f20621
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 4 deletions.
3 changes: 2 additions & 1 deletion confd/production.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ window._env_ = {
SITES_CONFIG: '{{ getv "/configuration/sites/config" "{\"masters\": [{ \"dns\": \"http://localhost:3000\", \"isAlias\": false }], \"slaves\": [{ \"dns\": \"http://localhost:8090\", \"isAlias\": false }], \"generics\": [{ \"dns\": \"https://catalog.mapcolonies.net\", \"isAlias\": false }]}"}}',
BFF_PATH: '{{getv "/configuration/bff/path" "/graphql"}}',
POLYGON_PARTS_FEATURE_TYPE_PREFIX: '{{getv "/configuration/polygon/parts/feature/type/prefix" "polygonParts:"}}',
POLYGON_PARTS_MAX_PER_SHAPE: {{getv "/configuration/polygon/parts/maxpershape" "300"}}
POLYGON_PARTS_MAX_PER_SHAPE: {{getv "/configuration/polygon/parts/maxpershape" "300"}},
POLYGON_PARTS_MAX_VERTICES: {{getv "/configuration/polygon/parts/max/vertices" "300000"}}
};
3 changes: 2 additions & 1 deletion confd/production.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ keys = [
"/configuration/sites/config",
"/configuration/bff/path",
"/configuration/polygon/parts/feature/type/prefix",
"/configuration/polygon/parts/maxpershape"
"/configuration/polygon/parts/maxpershape",
"/configuration/polygon/parts/max/vertices"
]
1 change: 1 addition & 0 deletions helm/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
CONFIGURATION_BFF_PATH: {{ quote .Values.env.bffPath }}
CONFIGURATION_POLYGON_PARTS_FEATURE_TYPE_PREFIX: {{ quote .Values.env.polygonPartsFeatureTypePrefix }}
CONFIGURATION_POLYGON_PARTS_MAXPERSHAPE: {{ quote .Values.env.polygonPartsMaxPerShape }}
CONFIGURATION_POLYGON_PARTS_MAX_VERTICES: {{ quote .Values.env.polygonPartsMaxVertices }}
{{- end -}}

{{ include "mc-chart.configmap" (dict "MAIN_OBJECT_BLOCK" $MAIN_OBJECT_BLOCK "COMPONENT_NAME" $COMPONENT_NAME "DATA" $DATA "WITH_TELEMETRY_TRACING" false "WITH_TELEMETRY_METRICS" false "context" .)}}
1 change: 1 addition & 0 deletions helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ env:
bffPath: ''
polygonPartsFeatureTypePrefix: ''
polygonPartsMaxPerShape: 300
polygonPartsMaxVertices: 300000
route:
enabled: true
annotations:
Expand Down
2 changes: 2 additions & 0 deletions src/common/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const SITES_CONFIG = JSON.parse((window as any)._env_.SITES_CONFIG);
const BFF_PATH = (window as any)._env_.BFF_PATH;
const POLYGON_PARTS_FEATURE_TYPE_PREFIX = (window as any)._env_.POLYGON_PARTS_FEATURE_TYPE_PREFIX;
const POLYGON_PARTS_MAX_PER_SHAPE = (window as any)._env_.POLYGON_PARTS_MAX_PER_SHAPE;
const POLYGON_PARTS_MAX_VERTICES = (window as any)._env_.POLYGON_PARTS_MAX_VERTICES;

const enrichBaseMaps = (baseMaps: IBaseMaps): IBaseMaps => {
return {
Expand Down Expand Up @@ -197,6 +198,7 @@ const APP_CONFIG = {
BFF_PATH: BFF_PATH,
POLYGON_PARTS_FEATURE_TYPE_PREFIX: POLYGON_PARTS_FEATURE_TYPE_PREFIX,
POLYGON_PARTS_MAX_PER_SHAPE: POLYGON_PARTS_MAX_PER_SHAPE,
POLYGON_PARTS_MAX_VERTICES: POLYGON_PARTS_MAX_VERTICES,
};

export default APP_CONFIG;
1 change: 1 addition & 0 deletions src/common/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@
"validation-general.number": "{fieldName} is required and numeric",
"validation-general.date.future": "{fieldName} cannot be future date",
"validation-general.shapeFile.too-many-features": "Number of features exceeds {maxPPNumber}",
"validation-general.shapeFile.too-many-vertices": "Vertices number exceeds the limit of {maxVerticesPP}. Number defined polygons: {ppNumber}, total vertices {verticesNumber}",
"validation-general.shapeFile.generic": "Please select zip file with only shape or related files, or a single shape file",
"validation-general.shapeFile.polygonParts.not-in-gpkg-extent": "Polygon Parts from shape file are not in GPKG extent",
"validation-general.polygonParts.hasErrors": "Marked {numErrorParts} Plygon Parts has errors. Complete missing data or fix the SHAPE file.",
Expand Down
1 change: 1 addition & 0 deletions src/common/i18n/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@
"validation-general.number": "{fieldName} הוא שדה חובה ומספרי",
"validation-general.date.future": "{fieldName} לא יכול להיות תאריך עתידי",
"validation-general.shapeFile.too-many-features": "מס' חלקי תיחום חורג מ {maxPPNumber}",
"validation-general.shapeFile.too-many-vertices": "מספר נקודות חורג מ {maxVerticesPP}. {ppNumber} פוליגונים מורכבים מ {verticesNumber} נקודות",
"validation-general.shapeFile.generic": "יש לוודא שבחרת בקובץ zip המכיל קבצי shape ונלווים בלבד, או קובץ shape בודד",
"validation-general.shapeFile.polygonParts.not-in-gpkg-extent": "חלקי תיחום מחוץ לGPKG",
"validation-general.polygonParts.hasErrors": "{numErrorParts} חלקי תיחום שגויים, נדרש להשלים מידע על חלקי תיחום או לתקן קובץ shape",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,26 @@ export const InnerRasterForm = (
// }
// }, [sourceExtent, outlinedPerimeter]);

const excidedFeaturesNumberError = useMemo(() => new Error(
const exceededFeaturesNumberError = useMemo(() => new Error(
intl.formatMessage(
{ id: 'validation-general.shapeFile.too-many-features'},
{ maxPPNumber: emphasizeByHTML(`${CONFIG.POLYGON_PARTS_MAX_PER_SHAPE}`)}
)
), []);

const exceededVertexNumberError = useCallback((numberOfPP: number, numberOfVertexes: number) => {
return new Error(
intl.formatMessage(
{ id: 'validation-general.shapeFile.too-many-vertices' },
{
maxVerticesPP: emphasizeByHTML(`${CONFIG.POLYGON_PARTS_MAX_VERTICES}`),
ppNumber: emphasizeByHTML(`${numberOfPP}`),
verticesNumber: emphasizeByHTML(`${numberOfVertexes}`)
}
)
);
}, []);

const shapeFileGenericError = useMemo(() => new Error(`validation-general.shapeFile.generic`), []);
// const shapeFilePerimeterVSGpkgExtentError = useMemo(() => new Error(`validation-general.shapeFile.polygonParts.not-in-gpkg-extent`), []);

Expand Down Expand Up @@ -533,11 +547,19 @@ export const InnerRasterForm = (
};

const isShapeFileValid = (featuresArr: unknown[] | undefined): boolean | Error => {
let verticesNum = 0;
featuresArr?.forEach(f => {
//@ts-ignore
verticesNum += f.geometry.coordinates.length;
});
if (typeof featuresArr === 'undefined') {
return shapeFileGenericError;
}
if (featuresArr && featuresArr.length > CONFIG.POLYGON_PARTS_MAX_PER_SHAPE) {
return excidedFeaturesNumberError;
return exceededFeaturesNumberError;
}
if(verticesNum > CONFIG.POLYGON_PARTS_MAX_VERTICES){
return exceededVertexNumberError(featuresArr.length, verticesNum)
}
return true;
}
Expand Down

0 comments on commit 6f20621

Please sign in to comment.