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

terrestris / react-geo / 16910231513

12 Aug 2025 01:24PM UTC coverage: 57.289% (-0.3%) from 57.562%
16910231513

push

github

web-flow
Merge pull request #4368 from terrestris/searchfield-without-autocomplete

allow SearchField with external data display

532 of 1040 branches covered (51.15%)

Branch coverage included in aggregate %.

0 of 5 new or added lines in 1 file covered. (0.0%)

1036 of 1697 relevant lines covered (61.05%)

10.8 hits per line

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

4.35
/src/FeatureLabelModal/FeatureLabelModal.tsx
1
import React, { FC , useEffect, useState } from 'react';
2

3

4
import { Modal, ModalProps } from 'antd';
5
import TextArea from 'antd/lib/input/TextArea';
6
import Feature from 'ol/Feature';
7
import Geometry from 'ol/geom/Geometry';
8

9
import StringUtil from '@terrestris/base-util/dist/StringUtil/StringUtil';
10

11
interface OwnProps {
12
  feature: Feature<Geometry>;
13
  onOk: () => void;
14
  onCancel: () => void;
15
  /**
16
   * Maximal length of feature label.
17
   * If exceeded label will be divided into multiple lines. Optional.
18
   */
19
  maxLabelLineLength?: number;
20
}
21

22
export type FeatureLabelModalProps = OwnProps & Omit<ModalProps, 'closable'|'visible'|'onOk'|'onCancel'>;
23

24
export const FeatureLabelModal: FC<FeatureLabelModalProps> = ({
3✔
25
  feature,
26
  onOk,
27
  onCancel,
28
  maxLabelLineLength,
29
  ...passThroughProps
30
}) => {
31
  const [label, setLabel] = useState<string>('');
×
32
  const [showPrompt, setShowPrompt] = useState<boolean>(false);
×
33

34
  useEffect(() => {
×
35
    if (feature) {
×
36
      setLabel(feature.get('label') ?? '');
×
37
      setShowPrompt(true);
×
38
    } else {
39
      setShowPrompt(false);
×
40
    }
41
  }, [feature]);
42

43
  const onOkInternal = () => {
×
44
    feature.set('label', maxLabelLineLength !== undefined ?
×
45
      StringUtil.stringDivider(label, maxLabelLineLength, '\n') :
46
      label
47
    );
48
    onOk();
×
49
  };
50

51
  const onLabelChange = (e: any) => setLabel(e.target.value);
×
52

53
  if (!showPrompt) {
×
54
    return null;
×
55
  }
56

57
  return (
×
58
    <Modal
59
      open={showPrompt}
60
      closable={false}
61
      onOk={onOkInternal}
62
      onCancel={onCancel}
63
      {...passThroughProps}
64
    >
65
      <TextArea
66
        value={label}
67
        onChange={onLabelChange}
68
        autoSize
69
      />
70
    </Modal>
71
  );
72
};
73

74
export default FeatureLabelModal;
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