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

mendersoftware / gui / 951400782

pending completion
951400782

Pull #3900

gitlab-ci

web-flow
chore: bump @testing-library/jest-dom from 5.16.5 to 5.17.0

Bumps [@testing-library/jest-dom](https://github.com/testing-library/jest-dom) from 5.16.5 to 5.17.0.
- [Release notes](https://github.com/testing-library/jest-dom/releases)
- [Changelog](https://github.com/testing-library/jest-dom/blob/main/CHANGELOG.md)
- [Commits](https://github.com/testing-library/jest-dom/compare/v5.16.5...v5.17.0)

---
updated-dependencies:
- dependency-name: "@testing-library/jest-dom"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #3900: chore: bump @testing-library/jest-dom from 5.16.5 to 5.17.0

4446 of 6414 branches covered (69.32%)

8342 of 10084 relevant lines covered (82.73%)

186.0 hits per line

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

71.43
/src/js/components/devices/device-details/devicetags.js
1
// Copyright 2021 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14
import React, { useEffect, useState } from 'react';
15

16
import { Edit as EditIcon } from '@mui/icons-material';
17
import { Button } from '@mui/material';
18
import { useTheme } from '@mui/material/styles';
19

20
import { toggle } from '../../../helpers';
21
import Tracking from '../../../tracking';
22
import ConfigurationObject from '../../common/configurationobject';
23
import KeyValueEditor from '../../common/forms/keyvalueeditor';
24
import { NameTagTip } from '../../helptips/helptooltips';
25
import DeviceDataCollapse from './devicedatacollapse';
26

27
const configHelpTipsMap = {
11✔
28
  name: {
29
    position: 'right',
30
    component: NameTagTip
31
  }
32
};
33

34
export const DeviceTags = ({ device, setDeviceTags, setSnackbar, showHelptips, userCapabilities }) => {
11✔
35
  const { canWriteDevices } = userCapabilities;
6✔
36
  const theme = useTheme();
6✔
37
  const [changedTags, setChangedTags] = useState({});
6✔
38
  const [isEditDisabled, setIsEditDisabled] = useState(!canWriteDevices);
6✔
39
  const [isEditing, setIsEditing] = useState(false);
6✔
40
  const [shouldUpdateEditor, setShouldUpdateEditor] = useState(false);
6✔
41

42
  const { tags = {} } = device;
6✔
43
  const hasTags = !!Object.keys(tags).length;
6✔
44

45
  useEffect(() => {
6✔
46
    setShouldUpdateEditor(toggle);
4✔
47
  }, [isEditing]);
48

49
  useEffect(() => {
6✔
50
    if (canWriteDevices) {
2!
51
      setIsEditing(!hasTags);
2✔
52
    }
53
  }, [hasTags, canWriteDevices]);
54

55
  const onCancel = () => {
6✔
56
    setIsEditing(false);
×
57
    setChangedTags(tags);
×
58
  };
59

60
  const onStartEdit = e => {
6✔
61
    e.stopPropagation();
×
62
    setChangedTags(tags);
×
63
    setIsEditing(true);
×
64
  };
65

66
  const onSubmit = () => {
6✔
67
    Tracking.event({ category: 'devices', action: 'modify_tags' });
×
68
    setIsEditDisabled(true);
×
69
    return setDeviceTags(device.id, changedTags)
×
70
      .then(() => setIsEditing(false))
×
71
      .finally(() => setIsEditDisabled(false));
×
72
  };
73

74
  const helpTipsMap = Object.entries(configHelpTipsMap).reduce((accu, [key, value]) => {
6✔
75
    accu[key] = {
6✔
76
      ...value,
77
      props: { deviceId: device.id }
78
    };
79
    return accu;
6✔
80
  }, {});
81
  return (
6✔
82
    <DeviceDataCollapse
83
      title={
84
        <div className="two-columns">
85
          <div className="flexbox center-aligned">
86
            <h4 className="margin-right">Tags</h4>
87
            {!isEditing && canWriteDevices && (
10✔
88
              <Button onClick={onStartEdit} startIcon={<EditIcon />} size="small">
89
                Edit
90
              </Button>
91
            )}
92
          </div>
93
        </div>
94
      }
95
    >
96
      <div className="relative" style={{ maxWidth: 700 }}>
97
        {isEditing ? (
6✔
98
          <>
99
            <KeyValueEditor
100
              disabled={isEditDisabled}
101
              errortext=""
102
              input={changedTags}
103
              inputHelpTipsMap={helpTipsMap}
104
              onInputChange={setChangedTags}
105
              reset={shouldUpdateEditor}
106
              showHelptips={showHelptips}
107
            />
108
            <div className="flexbox center-aligned margin-bottom-small" style={{ justifyContent: 'flex-end' }}>
109
              <Button color="primary" onClick={onSubmit} variant="contained" style={{ marginRight: theme.spacing(2) }}>
110
                Save
111
              </Button>
112
              <Button onClick={onCancel}>Cancel</Button>
113
            </div>
114
          </>
115
        ) : (
116
          hasTags && <ConfigurationObject config={tags} setSnackbar={setSnackbar} />
2!
117
        )}
118
      </div>
119
    </DeviceDataCollapse>
120
  );
121
};
122

123
export default DeviceTags;
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