• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

terrestris / react-geo / 16338835141

17 Jul 2025 07:22AM CUT coverage: 57.562%. Remained the same
16338835141

push

github

web-flow
Merge pull request #4344 from terrestris/dependabot/npm_and_yarn/typescript-eslint-8.37.0

build(deps-dev): bump typescript-eslint from 8.35.0 to 8.37.0

532 of 1032 branches covered (51.55%)

Branch coverage included in aggregate %.

1036 of 1692 relevant lines covered (61.23%)

10.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

45.16
/src/Button/ModifyButton/ModifyButton.tsx
1
import * as React from 'react';
2

3
import {ReactNode, useCallback, useState} from 'react';
4

5
import OlFeature from 'ol/Feature';
6
import OlGeometry from 'ol/geom/Geometry';
7
import { SelectEvent as OlSelectEvent } from 'ol/interaction/Select';
8

9
import { useModify, UseModifyProps } from '@terrestris/react-util/dist/Hooks/useModify/useModify';
10

11
import { CSS_PREFIX } from '../../constants';
12
import { FeatureLabelModal } from '../../FeatureLabelModal/FeatureLabelModal';
13
import ToggleButton, {ToggleButtonProps} from '../ToggleButton/ToggleButton';
14

15
interface OwnProps {
16
  /**
17
   * The className which should be added.
18
   */
19
  className?: string;
20
  /**
21
   * Callback function that will be called when the ok-button of the modal was clicked
22
   */
23
  onModalLabelOk?: (feature: OlFeature<OlGeometry>) => void;
24
  /**
25
   * Callback function that will be called
26
   * when the cancel-button of the modal was clicked
27
   */
28
  onModalLabelCancel?: () => void;
29
  /**
30
   * Maximal length of feature label.
31
   * If exceeded label will be divided into multiple lines. Optional.
32
   */
33
  maxLabelLineLength?: number;
34
  /**
35
   * Title for modal used for input of labels for digitize features.
36
   */
37
  modalPromptTitle?: string;
38
  /**
39
   * Text string for `OK` button of the modal.
40
   */
41
  modalPromptOkButtonText?: string;
42
  /**
43
   * Text string for `Cancel` button of the modal.
44
   */
45
  modalPromptCancelButtonText?: string;
46
  /**
47
   * Enable label editing via modal. Will open before being able to modify/translate feature. Default: `true`.
48
   */
49
  editLabel?: boolean;
50
}
51

52
export type ModifyButtonProps = OwnProps & Omit<UseModifyProps, 'active'> &
53
  Partial<ToggleButtonProps>;
54

55
/**
56
 * The className added to this component.
57
 */
58
const defaultClassName = `${CSS_PREFIX}modifybutton`;
1✔
59

60
export const ModifyButton: React.FC<ModifyButtonProps> = ({
1✔
61
  className,
62
  hitTolerance = 5,
3✔
63
  onFeatureSelect,
64
  onModifyStart,
65
  onModifyEnd,
66
  onTranslateStart,
67
  onTranslateEnd,
68
  onTranslating,
69
  digitizeLayer,
70
  selectStyle,
71
  selectInteractionConfig,
72
  modifyInteractionConfig,
73
  translateInteractionConfig,
74
  onModalLabelOk,
75
  onModalLabelCancel,
76
  maxLabelLineLength,
77
  modalPromptTitle,
78
  modalPromptOkButtonText,
79
  modalPromptCancelButtonText,
80
  editLabel = true,
3✔
81
  pressed,
82
  ...passThroughProps
83
}) => {
84
  const [editLabelFeature, setEditLabelFeature] = useState<OlFeature<OlGeometry>|null>(null);
3✔
85

86
  const onFeatureSelectInternal = useCallback((event: OlSelectEvent) => {
3✔
87
    if (editLabel) {
×
88
      const labeled = event.selected.find(f => f.get('isLabel'));
×
89
      setEditLabelFeature(labeled || null);
×
90
    }
91
    onFeatureSelect?.(event);
×
92
  }, [editLabel, onFeatureSelect]);
93

94
  useModify({
3✔
95
    selectStyle,
96
    selectInteractionConfig,
97
    digitizeLayer,
98
    onModifyStart,
99
    onModifyEnd,
100
    onTranslateStart,
101
    onTranslateEnd,
102
    onTranslating,
103
    active: !!pressed,
104
    modifyInteractionConfig,
105
    translateInteractionConfig,
106
    onFeatureSelect: onFeatureSelectInternal,
107
    hitTolerance
108
  });
109

110
  const finalClassName = className
3!
111
    ? `${defaultClassName} ${className}`
112
    : defaultClassName;
113

114
  const btnWrapperClass = `${CSS_PREFIX}digitize-button-wrapper`;
3✔
115

116
  let modal: ReactNode = null;
3✔
117
  if (editLabelFeature) {
3!
118
    const onModalLabelOkInternal = () => {
×
119
      onModalLabelOk?.(editLabelFeature);
×
120
      setEditLabelFeature(null);
×
121
    };
122

123
    const onModalLabelCancelInternal = () => {
×
124
      onModalLabelCancel?.();
×
125
      setEditLabelFeature(null);
×
126
    };
127

128
    modal = (
×
129
      <FeatureLabelModal
130
        feature={editLabelFeature}
131
        onOk={onModalLabelOkInternal}
132
        onCancel={onModalLabelCancelInternal}
133
        title={modalPromptTitle}
134
        okText={modalPromptOkButtonText}
135
        cancelText={modalPromptCancelButtonText}
136
        maxLabelLineLength={maxLabelLineLength}
137
      />
138
    );
139
  }
140

141
  return (
3✔
142
    <span className={btnWrapperClass}>
143
      <ToggleButton
144
        pressed={pressed}
145
        className={finalClassName}
146
        {...passThroughProps}
147
      />
148
      {
149
        modal
150
      }
151
    </span>
152
  );
153
};
154

155
export default ModifyButton;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc