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

mendersoftware / gui / 963002358

pending completion
963002358

Pull #3870

gitlab-ci

mzedel
chore: cleaned up left over onboarding tooltips & aligned with updated design

Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #3870: MEN-5413

4348 of 6319 branches covered (68.81%)

95 of 122 new or added lines in 24 files covered. (77.87%)

1734 existing lines in 160 files now uncovered.

8174 of 9951 relevant lines covered (82.14%)

178.12 hits per line

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

76.14
/src/js/components/settings/artifactgeneration.js
1
// Copyright 2022 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, useMemo, useRef, useState } from 'react';
15
import { useDispatch, useSelector } from 'react-redux';
16

17
// material ui
18
import { InfoOutlined as InfoOutlinedIcon } from '@mui/icons-material';
19
import { Checkbox, FormControlLabel, TextField, Typography, formControlLabelClasses, textFieldClasses } from '@mui/material';
20
import { makeStyles } from 'tss-react/mui';
21

22
import DeltaIcon from '../../../assets/img/deltaicon.svg';
23
import { getDeploymentsConfig, saveDeltaDeploymentsConfig } from '../../actions/deploymentActions';
24
import { TIMEOUTS } from '../../constants/appConstants';
25
import { getIsEnterprise } from '../../selectors';
26
import { useDebounce } from '../../utils/debouncehook';
27
import EnterpriseNotification from '../common/enterpriseNotification';
28
import InfoText from '../common/infotext';
29

30
const useStyles = makeStyles()(theme => ({
6✔
31
  deviceLimitBar: { backgroundColor: theme.palette.grey[500], margin: '15px 0' },
32
  wrapper: {
33
    backgroundColor: theme.palette.background.lightgrey,
34
    display: 'flex',
35
    flexDirection: 'column',
36
    marginTop: theme.spacing(6),
37
    padding: theme.spacing(2),
38
    paddingTop: 0,
39
    '&>h5': { marginTop: 0, marginBottom: 0 },
40
    '.flexbox>span': { alignSelf: 'flex-end' },
41
    [`.${textFieldClasses.root}`]: { maxWidth: 200, minWidth: 100 },
42
    [`.${formControlLabelClasses.root}`]: { marginTop: theme.spacing() }
43
  }
44
}));
45

46
const numberFields = {
6✔
47
  compressionLevel: { key: 'compressionLevel', title: 'Compression level' },
48
  sourceWindow: { key: 'sourceWindow', title: 'Source window size' },
49
  inputWindow: { key: 'inputWindow', title: 'Input window size' },
50
  duplicatesWindow: { key: 'duplicatesWindow', title: 'Compression duplicates window' },
51
  instructionBuffer: { key: 'instructionBuffer', title: 'Instruction buffer size' }
52
};
53

54
const NumberInputLimited = ({ limit, onChange, value: propsValue, ...remainder }) => {
6✔
55
  const [value, setValue] = useState(propsValue);
12✔
56
  const debouncedValue = useDebounce(value, TIMEOUTS.oneSecond);
12✔
57
  const { default: defaultValue, max, min } = limit;
12✔
58

59
  useEffect(() => {
12✔
60
    const minimum = Math.max(min, debouncedValue);
6✔
61
    const allowedValue = Math.min(max ?? minimum, minimum);
6✔
62
    if (allowedValue !== debouncedValue) {
6!
63
      setValue(allowedValue);
6✔
64
      return;
6✔
65
    }
UNCOV
66
    onChange(allowedValue);
×
67
  }, [debouncedValue, max, min, onChange]);
68

69
  return (
12✔
70
    <TextField
71
      inputProps={{ step: 1, type: 'numeric', pattern: '[0-9]*', autoComplete: 'off' }}
72
      InputLabelProps={{ shrink: true }}
73
      error={min || max ? min > value || value > max : false}
41✔
74
      value={value}
UNCOV
75
      onChange={({ target: { value } }) => setValue(Number(value) || 0)}
×
76
      helperText={defaultValue !== undefined ? `Defaults to: ${defaultValue}` : null}
12✔
77
      {...remainder}
78
    />
79
  );
80
};
81

82
export const ArtifactGenerationSettings = () => {
6✔
83
  const { binaryDelta: deltaConfig = {}, binaryDeltaLimits: deltaLimits = {}, hasDelta: deltaEnabled } = useSelector(state => state.deployments.config) ?? {};
3!
84
  const isEnterprise = useSelector(getIsEnterprise);
2✔
85
  const dispatch = useDispatch();
2✔
86
  const [timeoutValue, setTimeoutValue] = useState(deltaConfig.timeout);
2✔
87
  const [disableChecksum, setDisableChecksum] = useState(deltaConfig.disableChecksum);
2✔
88
  const [disableDecompression, setDisableDecompression] = useState(deltaConfig.disableChecksum);
2✔
89
  const [compressionLevel, setCompressionLevel] = useState(deltaConfig.compressionLevel);
2✔
90
  const [sourceWindow, setSourceWindow] = useState(deltaConfig.sourceWindow);
2✔
91
  const [inputWindow, setInputWindow] = useState(deltaConfig.inputWindow);
2✔
92
  const [duplicatesWindow, setDuplicatesWindow] = useState(deltaConfig.duplicatesWindow);
2✔
93
  const [instructionBuffer, setInstructionBuffer] = useState(deltaConfig.instructionBuffer);
2✔
94
  const timer = useRef(null);
2✔
95
  const isInitialized = useRef(false);
2✔
96

97
  const { classes } = useStyles();
2✔
98

99
  useEffect(() => {
2✔
100
    if (deltaConfig.timeout === -1) {
1!
UNCOV
101
      return;
×
102
    }
103
    const { timeout, duplicatesWindow, compressionLevel, disableChecksum, disableDecompression, inputWindow, instructionBuffer, sourceWindow } = deltaConfig;
1✔
104
    setDisableChecksum(disableChecksum);
1✔
105
    setDisableDecompression(disableDecompression);
1✔
106
    setCompressionLevel(compressionLevel);
1✔
107
    setTimeoutValue(timeout);
1✔
108
    setSourceWindow(sourceWindow);
1✔
109
    setInputWindow(inputWindow);
1✔
110
    setDuplicatesWindow(duplicatesWindow);
1✔
111
    setInstructionBuffer(instructionBuffer);
1✔
112
    setTimeout(() => (isInitialized.current = true), TIMEOUTS.debounceShort);
1✔
113
    // eslint-disable-next-line react-hooks/exhaustive-deps
114
  }, [JSON.stringify(deltaConfig), JSON.stringify(deltaLimits)]);
115

116
  useEffect(() => {
2✔
117
    dispatch(getDeploymentsConfig());
1✔
118
  }, [dispatch]);
119

120
  useEffect(() => {
2✔
121
    if (!isInitialized.current) {
1!
122
      return;
1✔
123
    }
UNCOV
124
    clearTimeout(timer.current);
×
UNCOV
125
    timer.current = setTimeout(
×
126
      () =>
UNCOV
127
        dispatch(
×
128
          saveDeltaDeploymentsConfig({
129
            timeout: timeoutValue,
130
            duplicatesWindow,
131
            compressionLevel,
132
            disableChecksum,
133
            disableDecompression,
134
            inputWindow,
135
            instructionBuffer,
136
            sourceWindow
137
          })
138
        ),
139
      TIMEOUTS.twoSeconds
140
    );
UNCOV
141
    return () => {
×
UNCOV
142
      clearTimeout(timer.current);
×
143
    };
144
  }, [compressionLevel, disableChecksum, disableDecompression, dispatch, duplicatesWindow, inputWindow, instructionBuffer, sourceWindow, timeoutValue]);
145

146
  const numberInputs = useMemo(() => {
2✔
147
    return [
1✔
148
      { ...numberFields.compressionLevel, setter: setCompressionLevel, value: compressionLevel, ...deltaLimits.compressionLevel },
149
      { ...numberFields.sourceWindow, setter: setSourceWindow, value: sourceWindow, ...deltaLimits.sourceWindow },
150
      { ...numberFields.inputWindow, setter: setInputWindow, value: inputWindow, ...deltaLimits.inputWindow },
151
      { ...numberFields.duplicatesWindow, setter: setDuplicatesWindow, value: duplicatesWindow, ...deltaLimits.duplicatesWindow },
152
      { ...numberFields.instructionBuffer, setter: setInstructionBuffer, value: instructionBuffer, ...deltaLimits.instructionBuffer }
153
    ];
154
    // eslint-disable-next-line react-hooks/exhaustive-deps
155
  }, [
156
    compressionLevel,
157
    setCompressionLevel,
158
    setSourceWindow,
159
    sourceWindow,
160
    inputWindow,
161
    setInputWindow,
162
    setDuplicatesWindow,
163
    duplicatesWindow,
164
    setInstructionBuffer,
165
    instructionBuffer,
166
    // eslint-disable-next-line react-hooks/exhaustive-deps
167
    JSON.stringify(deltaLimits)
168
  ]);
169

170
  return (
2✔
171
    <div className={`flexbox column ${classes.wrapper}`}>
172
      <div className="flexbox center-aligned">
173
        <DeltaIcon />
174
        <h5 className="margin-left-small">Delta artifacts generation configuration</h5>
175
      </div>
176
      {deltaEnabled && isInitialized ? (
6!
177
        <div className="margin-small margin-top-none">
178
          <div className="flexbox">
179
            <NumberInputLimited
180
              limit={{ default: deltaLimits.timeout.default, min: deltaLimits.timeout.min, max: deltaLimits.timeout.max }}
181
              label="Timeout"
182
              onChange={setTimeoutValue}
183
              value={timeoutValue}
184
            />
185
            <span className="margin-left-small muted slightly-smaller">seconds</span>
186
          </div>
187
          <Typography className="margin-top-small" display="block" variant="caption">
188
            xDelta3 arguments
189
          </Typography>
190
          <div className="flexbox column margin-left">
191
            <FormControlLabel
UNCOV
192
              control={<Checkbox color="primary" checked={disableChecksum} onChange={({ target: { checked } }) => setDisableChecksum(checked)} size="small" />}
×
193
              label="Disable checksum"
194
            />
195
            <FormControlLabel
196
              control={
197
                <Checkbox
198
                  color="primary"
199
                  checked={disableDecompression}
UNCOV
200
                  onChange={({ target: { checked } }) => setDisableDecompression(checked)}
×
201
                  size="small"
202
                />
203
              }
204
              label="Disable external decompression"
205
            />
206
            {numberInputs.map(({ default: defaultValue, key, setter, title, value, min = 0, max }) => (
2✔
207
              <NumberInputLimited key={key} limit={{ default: defaultValue, max, min }} label={title} value={value} onChange={setter} />
10✔
208
            ))}
209
          </div>
210
        </div>
211
      ) : isEnterprise ? (
×
212
        <InfoText>
213
          <InfoOutlinedIcon style={{ fontSize: '14px', margin: '0 4px 4px 0', verticalAlign: 'middle' }} />
214
          Automatic delta artifacts generation is not enabled in your account. If you want to start using this feature,{' '}
215
          <a href="mailto:contact@mender.io" target="_blank" rel="noopener noreferrer">
216
            contact our team
217
          </a>
218
          .
219
        </InfoText>
220
      ) : (
221
        <EnterpriseNotification
222
          isEnterprise={isEnterprise}
223
          benefit="automatic delta artifacts generation to minimize data transfer and improve the update delivery"
224
        />
225
      )}
226
    </div>
227
  );
228
};
229

230
export default ArtifactGenerationSettings;
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