Skip to content

Commit

Permalink
feat: add vertices limit to env configuration (#579)
Browse files Browse the repository at this point in the history
* feat: adding in env the limit of verticeis

* fix: pr, correct config hierarchy

* fix: config error

* fix: error

* fix: error

* fix: pr
  • Loading branch information
Eliav-Maimon authored Jan 1, 2025
1 parent b052c0a commit e015eb7
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 19 deletions.
9 changes: 7 additions & 2 deletions confd/production.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ window._env_ = {
WHATSNEW_URL: '{{getv "/configuration/whatsnew/url" "http://whatsnew-URL"}}',
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: {
featureTypePrefix: '{{getv "/configuration/polygonparts/featuretypeprefix" "polygonParts:"}}',
max: {
perShape: {{getv "/configuration/polygonparts/max/pershape" "300"}},
vertices: {{getv "/configuration/polygonparts/max/vertices" "300000"}}
}
}
};
5 changes: 3 additions & 2 deletions confd/production.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ keys = [
"/configuration/whatsnew/url",
"/configuration/sites/config",
"/configuration/bff/path",
"/configuration/polygon/parts/feature/type/prefix",
"/configuration/polygon/parts/maxpershape"
"/configuration/polygonparts/featuretypeprefix",
"/configuration/polygonparts/max/pershape",
"/configuration/polygonparts/max/vertices"
]
5 changes: 3 additions & 2 deletions helm/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@
CONFIGURATION_WHATSNEW_URL: {{ quote .Values.env.whatsnewUrl }}
CONFIGURATION_SITES_CONFIG: {{ quote .Values.env.sitesConfig }}
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_POLYGONPARTS_FEATURETYPEPREFIX: {{ quote .Values.env.polygonParts.featureTypePrefix }}
CONFIGURATION_POLYGONPARTS_MAX_PERSHAPE: {{ quote .Values.env.polygonParts.max.perShape }}
CONFIGURATION_POLYGONPARTS_MAX_VERTICES: {{ quote .Values.env.polygonParts.max.vertices }}
{{- 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" .)}}
7 changes: 5 additions & 2 deletions helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,11 @@ env:
projection: ''
sitesConfig: '{"masters": [{ "dns": "http://localhost:3000", "isAlias": "false" }], "slaves": [{ "dns": "http://localhost:8090", "isAlias": "false" }], "generics": []}'
bffPath: ''
polygonPartsFeatureTypePrefix: ''
polygonPartsMaxPerShape: 300
polygonParts:
featureTypePrefix: ''
max:
perShape: 300
vertices: 300000
route:
enabled: true
annotations:
Expand Down
9 changes: 7 additions & 2 deletions src/__mocks__/confEnvShim.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ if (!window._env_) {
WHATSNEW_URL: 'http://whatsnew-URL',
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: '/graphql',
POLYGON_PARTS_FEATURE_TYPE_PREFIX: 'polygonParts:',
POLYGON_PARTS_MAX_PER_SHAPE: 300
POLYGON_PARTS: {
featureTypePrefix: 'polygonParts:',
max: {
perShape: 300,
vertices: 3,
}
}
};
})(void 0);
}
12 changes: 8 additions & 4 deletions src/common/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ const PROJECT_VERSION = (window as any)._env_.PROJECT_VERSION;
const WHATSNEW_URL = (window as any)._env_.WHATSNEW_URL;
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 = (window as any)._env_.POLYGON_PARTS;

const enrichBaseMaps = (baseMaps: IBaseMaps): IBaseMaps => {
return {
Expand Down Expand Up @@ -195,8 +194,13 @@ const APP_CONFIG = {
WHATSNEW_URL: WHATSNEW_URL,
SITES_CONFIG: SITES_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: {
FEATURE_TYPE_PREFIX: POLYGON_PARTS.featureTypePrefix,
MAX: {
PER_SHAPE: POLYGON_PARTS.max.perShape,
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 @@ -143,6 +143,7 @@ export const InnerRasterForm = (
type POLYGON_PARTS_MODE = 'FROM_SHAPE' | 'MANUAL';

const POLYGON_PARTS_STATUS_ERROR = 'pp_status_errors';
const ppConfig = CONFIG.POLYGON_PARTS;

const intl = useIntl();
const ZOOM_LEVELS = useZoomLevels();
Expand Down Expand Up @@ -373,12 +374,27 @@ 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}`)}
{ maxPPNumber: emphasizeByHTML(`${ppConfig.MAX.PER_SHAPE}`)}
)
), []);

const exceededVertexNumberError = useCallback((numberOfPP: number, numberOfVertexes: number) => {
return new Error(
intl.formatMessage(
{ id: 'validation-general.shapeFile.too-many-vertices' },
{
maxVerticesPP: emphasizeByHTML(`${ppConfig.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 +549,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;
if (featuresArr && featuresArr.length > ppConfig.MAX.PER_SHAPE) {
return exceededFeaturesNumberError;
}
if(verticesNum > ppConfig.MAX.VERTICES){
return exceededVertexNumberError(featuresArr.length, verticesNum)
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const getWFSFeatureTypeName = (layerRecord: LayerRasterRecordModelType |
// Naming convension of polygon parts feature typeName
// polygonParts:{productId}-{productType}
return layerRecord ?
`${CONFIG.POLYGON_PARTS_FEATURE_TYPE_PREFIX}${layerRecord.productId}-${enums[layerRecord.productType as string].realValue}` :
`${CONFIG.POLYGON_PARTS.FEATURE_TYPE_PREFIX}${layerRecord.productId}-${enums[layerRecord.productType as string].realValue}` :
'SHOULD_BE_CALCULATED_FROM_UPDATED_LAYER';
}

Expand Down

0 comments on commit e015eb7

Please sign in to comment.