@evergis/react 4.0.29 → 4.0.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.esm.js CHANGED
@@ -4441,6 +4441,10 @@ const applyQueryFilters = ({ parameters: configParameters, filters: configFilter
4441
4441
  return result;
4442
4442
  }
4443
4443
  if (typeof configParameters[key] === "string" && configParameters[key].includes("{") && attributes?.length) {
4444
+ const exactAttr = attributes.find(({ attributeName }) => configParameters[key] === `{${attributeName}}`);
4445
+ if (exactAttr) {
4446
+ return { ...result, [key]: exactAttr.value ?? "" };
4447
+ }
4444
4448
  let interpolated = configParameters[key];
4445
4449
  attributes.forEach(({ attributeName, value: attrValue }) => {
4446
4450
  interpolated = interpolated.replace(new RegExp(`\\{${attributeName}\\}`, "g"), attrValue?.toString() ?? "");
@@ -5399,6 +5403,7 @@ const usePythonTask = () => {
5399
5403
  const [taskId, setTaskId] = useState(null);
5400
5404
  const [subscriptionId, setSubscriptionId] = useState(null);
5401
5405
  const [isLogDialogOpen, setIsLogDialogOpen] = useState(false);
5406
+ const [result, setResult] = useState(null);
5402
5407
  const logRef = useRef(null);
5403
5408
  const reset = useCallback(() => {
5404
5409
  setStatus(RemoteTaskStatus.Unknown);
@@ -5407,6 +5412,7 @@ const usePythonTask = () => {
5407
5412
  setExecutionTime(null);
5408
5413
  setTaskId(null);
5409
5414
  setSubscriptionId(null);
5415
+ setResult(null);
5410
5416
  }, []);
5411
5417
  const runTask = useCallback(async ({ resourceId, parameters, script, fileName, methodName, }) => {
5412
5418
  reset();
@@ -5446,7 +5452,7 @@ const usePythonTask = () => {
5446
5452
  });
5447
5453
  setTaskId(newTaskId);
5448
5454
  setSubscriptionId(newSubscriptionId);
5449
- const onNotification = ({ data }) => {
5455
+ const onNotification = async ({ data }) => {
5450
5456
  if (data?.taskId === newTaskId) {
5451
5457
  setStatus(data.status);
5452
5458
  setLog([logRef.current, data.log].filter(Boolean).join("\n"));
@@ -5462,10 +5468,14 @@ const usePythonTask = () => {
5462
5468
  unsubscribeById(newSubscriptionId);
5463
5469
  connection.off(SERVER_NOTIFICATION_EVENT.PythonProgressNotification, onNotification);
5464
5470
  }
5471
+ if (data.status === RemoteTaskStatus.Completed) {
5472
+ const subTasks = await api.remoteTaskManager.get(newTaskId);
5473
+ setResult(subTasks?.[0]?.results ?? null);
5474
+ }
5465
5475
  }
5466
5476
  };
5467
5477
  connection.on(SERVER_NOTIFICATION_EVENT.PythonProgressNotification, onNotification);
5468
- }, [api, connection, addSubscription, unsubscribeById, reset]);
5478
+ }, [reset, api.remoteTaskManager, addSubscription, connection, t, unsubscribeById]);
5469
5479
  const stopTask = useCallback(async () => {
5470
5480
  await api.remoteTaskManager.stop(taskId);
5471
5481
  reset();
@@ -5492,6 +5502,7 @@ const usePythonTask = () => {
5492
5502
  executionTime,
5493
5503
  isLogDialogOpen,
5494
5504
  closeLog,
5505
+ result,
5495
5506
  };
5496
5507
  };
5497
5508
 
@@ -7462,14 +7473,35 @@ const StatusWaitingButton = ({ title, icon = "play", status, statusColors, isWai
7462
7473
  return (jsx(ThemeProvider, { theme: darkTheme, children: jsxs(StyledButton, { status: status, statusColors: statusColors, disabled: isDisabled, themeName: themeName, onClick: onClick, children: [renderIcon, renderTitle] }) }));
7463
7474
  };
7464
7475
 
7476
+ const buildFiltersFromResponse = (responseFilters, result) => {
7477
+ if (!responseFilters || !result)
7478
+ return null;
7479
+ const properties = result?.result?.features?.[0]?.properties;
7480
+ if (!properties)
7481
+ return null;
7482
+ const filters = Object.entries(responseFilters).reduce((acc, [filterName, token]) => {
7483
+ const attrName = typeof token === "string" && token.startsWith("%") ? token.slice(1) : token;
7484
+ const value = properties[attrName];
7485
+ if (value === undefined)
7486
+ return acc;
7487
+ return { ...acc, [filterName]: { value: value } };
7488
+ }, {});
7489
+ return Object.keys(filters).length ? filters : null;
7490
+ };
7491
+
7465
7492
  const TaskContainer = memo(({ type, elementConfig, renderElement }) => {
7466
7493
  const { t, ewktGeometry } = useGlobalContext();
7467
- const { dataSources, filters: selectedFilters, attributes, layerInfo } = useWidgetContext(type);
7494
+ const { dataSources, filters: selectedFilters, attributes, layerInfo, changeFilters, } = useWidgetContext(type);
7468
7495
  const { dataSources: projectDataSources } = useWidgetContext(WidgetType.Dashboard);
7469
7496
  const { currentPage } = useWidgetPage(type);
7470
- const { taskId, runTask, stopTask, status, openLog, loading, isLogDialogOpen, closeLog, log } = usePythonTask();
7497
+ const { taskId, runTask, stopTask, status, openLog, loading, isLogDialogOpen, closeLog, log, result, } = usePythonTask();
7471
7498
  const { options } = elementConfig || {};
7472
- const { title, relatedResources, center, icon, statusColors } = options || {};
7499
+ const { title, relatedResources, center, icon, statusColors, responseFilters } = options || {};
7500
+ useEffect(() => {
7501
+ const filtersToApply = buildFiltersFromResponse(responseFilters, result);
7502
+ if (filtersToApply)
7503
+ changeFilters(filtersToApply);
7504
+ }, [result, responseFilters, changeFilters]);
7473
7505
  const onClick = useCallback(async () => {
7474
7506
  if (taskId) {
7475
7507
  await stopTask();
@@ -7516,6 +7548,12 @@ const EditGroupContainer = memo(({ type, elementConfig, renderElement }) => {
7516
7548
  const getRenderContainerItem = useRenderContainerItem(type, renderElement);
7517
7549
  const { options } = elementConfig || {};
7518
7550
  const { controls } = options || {};
7551
+ const filteredAttributes = useMemo(() => {
7552
+ const { idAttribute } = layerInfo?.configuration?.attributesConfiguration || {};
7553
+ if (!idAttribute)
7554
+ return attributes;
7555
+ return attributes.filter(({ attributeName }) => attributeName !== idAttribute);
7556
+ }, [attributes, layerInfo?.configuration]);
7519
7557
  const renderContainer = useCallback((attributeName) => {
7520
7558
  const control = controls?.find(({ targetAttributeName }) => targetAttributeName === attributeName);
7521
7559
  const itemAttribute = attributes.find(item => item.attributeName === attributeName);
@@ -7548,7 +7586,7 @@ const EditGroupContainer = memo(({ type, elementConfig, renderElement }) => {
7548
7586
  expandedContainers,
7549
7587
  ]);
7550
7588
  if (!controls?.length) {
7551
- return (jsx(Fragment$1, { children: attributes.map(({ attributeName }) => renderContainer(attributeName)) }));
7589
+ return (jsx(Fragment$1, { children: filteredAttributes.map(({ attributeName }) => renderContainer(attributeName)) }));
7552
7590
  }
7553
7591
  return (jsx(Fragment$1, { children: controls.map(({ targetAttributeName }) => renderContainer(targetAttributeName)) }));
7554
7592
  });
@@ -7579,6 +7617,16 @@ const useEditControl = (type, elementConfig) => {
7579
7617
  [attributeName]: newValue,
7580
7618
  });
7581
7619
  }, [changeControls, attributeName]);
7620
+ useEffect(() => {
7621
+ if (control?.defaultValue === undefined)
7622
+ return;
7623
+ if (controls[attributeName] !== undefined)
7624
+ return;
7625
+ const hasAttributeValue = attributes.some(({ attributeName: name, value: attrValue }) => name === attributeName && attrValue !== undefined && attrValue !== null);
7626
+ if (hasAttributeValue)
7627
+ return;
7628
+ changeControls({ [attributeName]: control.defaultValue });
7629
+ }, [attributeName, attributes, changeControls, control?.defaultValue, controls]);
7582
7630
  return useMemo(() => ({ control, value, dataSource, items, onChange }), [control, value, dataSource, items, onChange]);
7583
7631
  };
7584
7632
 
@@ -7714,7 +7762,7 @@ const DefaultHeaderContainer = styled(Flex) `
7714
7762
  position: relative;
7715
7763
  flex-shrink: 0;
7716
7764
  min-height: 8.175rem;
7717
- margin-bottom: -1.5rem;
7765
+ margin-bottom: -0.75rem;
7718
7766
  padding: 1.5rem 1.5rem 0;
7719
7767
  border-top-left-radius: 0.5rem;
7720
7768
  border-top-right-radius: 0.5rem;
@@ -9264,19 +9312,15 @@ const ElementUploader = memo(({ elementConfig, type }) => {
9264
9312
  return (jsx(UploaderContainer, { id: id, style: style, children: jsx("div", { children: jsx(Uploader, { currentRef: refInput, title: renderTitle, accept: fileExtensions, width: "100%", fileItems: files, isMultiple: multiSelect, onUpload: onUpload, onDelete: onDelete }) }) }));
9265
9313
  });
9266
9314
 
9267
- const ModalIcon = styled(Icon) `
9268
- &&& {
9269
- cursor: pointer;
9270
-
9271
- :after {
9272
- font-size: 0.75rem;
9273
- color: ${({ theme: { palette } }) => palette.iconDisabled};
9274
- transition: color ${transition.hover};
9275
- }
9315
+ const ModalIcon = styled(IconButton) `
9316
+ :after {
9317
+ font-size: 0.75rem;
9318
+ color: ${({ theme: { palette } }) => palette.iconDisabled};
9319
+ transition: color ${transition.hover};
9320
+ }
9276
9321
 
9277
- :hover:after {
9278
- color: ${({ theme: { palette } }) => palette.icon};
9279
- }
9322
+ :hover:after {
9323
+ color: ${({ theme: { palette } }) => palette.icon};
9280
9324
  }
9281
9325
  `;
9282
9326
 
@@ -9386,7 +9430,7 @@ const ElementModal = memo(({ type = WidgetType.Dashboard, elementConfig }) => {
9386
9430
  return null;
9387
9431
  const { options: modalOptions } = modalConfig;
9388
9432
  const { title, maxWidth, minWidth, minHeight } = modalOptions || {};
9389
- return (jsxs(Fragment$1, { children: [jsx(ModalIcon, { kind: icon || "new_window", onClick: handleOpen }), jsxs(Dialog, { isOpen: isOpen, onCloseRequest: handleClose, modal: true, maxWidth: maxWidth, minWidth: minWidth, minHeight: minHeight, style: { paddingBottom: "2rem" }, children: [jsx(DialogTitle, { children: jsxs(Flex, { justifyContent: "space-between", alignItems: "center", children: [!!title && jsx("span", { children: title }), jsx(IconButton, { kind: "close", onClick: handleClose })] }) }), jsx(DialogContent, { children: isLoading ? (jsx(DashboardLoading, {})) : (jsx(Container, { isColumn: true, noBorders: true, children: jsx(ContainerChildren, { type: type, items: modalContent, isMain: true, renderElement: renderElement }) })) })] })] }));
9433
+ return (jsxs(Fragment$1, { children: [jsx(ModalIcon, { kind: icon || "new_window", onClick: handleOpen, children: title }), jsxs(Dialog, { maxWidth: maxWidth, minWidth: minWidth, minHeight: minHeight, isOpen: isOpen, modal: true, onCloseRequest: handleClose, style: { paddingBottom: "2rem" }, children: [jsx(DialogTitle, { children: jsxs(Flex, { justifyContent: "space-between", alignItems: "center", children: [!!title && jsx("span", { children: title }), jsx(IconButton, { kind: "close", onClick: handleClose })] }) }), jsx(DialogContent, { children: isLoading ? (jsx(DashboardLoading, {})) : (jsx(Container, { isColumn: true, noBorders: true, children: jsx(ContainerChildren, { type: type, items: modalContent, isMain: true, renderElement: renderElement }) })) })] })] }));
9390
9434
  });
9391
9435
 
9392
9436
  const ElementLayerName = memo(({ type }) => {
@@ -9474,7 +9518,7 @@ function getFeatureAttributes(feature = {}, layer, dataSource) {
9474
9518
  const isIdAttribute = attributeName === idAttribute;
9475
9519
  const additionalProps = isIdAttribute
9476
9520
  ? {
9477
- value: idValue,
9521
+ value: currentAttributes?.[attributeName] ?? idValue,
9478
9522
  readOnly: true,
9479
9523
  }
9480
9524
  : {