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

mendersoftware / gui / 944676341

pending completion
944676341

Pull #3875

gitlab-ci

mzedel
chore: aligned snapshots with updated design

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

4469 of 6446 branches covered (69.33%)

230 of 266 new or added lines in 43 files covered. (86.47%)

1712 existing lines in 161 files now uncovered.

8406 of 10170 relevant lines covered (82.65%)

196.7 hits per line

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

78.82
/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 { BENEFITS, TIMEOUTS } from '../../constants/appConstants';
25
import { useDebounce } from '../../utils/debouncehook';
26
import EnterpriseNotification from '../common/enterpriseNotification';
27
import InfoText from '../common/infotext';
28

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

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

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

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

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

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

95
  const { classes } = useStyles();
3✔
96

97
  useEffect(() => {
3✔
98
    if (deltaConfig.timeout === -1) {
1!
UNCOV
99
      return;
×
100
    }
101
    const { timeout, duplicatesWindow, compressionLevel, disableChecksum, disableDecompression, inputWindow, instructionBuffer, sourceWindow } = deltaConfig;
1✔
102
    setDisableChecksum(disableChecksum);
1✔
103
    setDisableDecompression(disableDecompression);
1✔
104
    setCompressionLevel(compressionLevel);
1✔
105
    setTimeoutValue(timeout);
1✔
106
    setSourceWindow(sourceWindow);
1✔
107
    setInputWindow(inputWindow);
1✔
108
    setDuplicatesWindow(duplicatesWindow);
1✔
109
    setInstructionBuffer(instructionBuffer);
1✔
110
    setTimeout(() => setIsInitialized(true), 0);
1✔
111
  }, [JSON.stringify(deltaConfig), JSON.stringify(deltaLimits)]);
112

113
  useEffect(() => {
3✔
114
    dispatch(getDeploymentsConfig());
1✔
115
  }, []);
116

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

143
  const numberInputs = useMemo(() => {
3✔
144
    return [
1✔
145
      { ...numberFields.compressionLevel, setter: setCompressionLevel, value: compressionLevel, ...deltaLimits.compressionLevel },
146
      { ...numberFields.sourceWindow, setter: setSourceWindow, value: sourceWindow, ...deltaLimits.sourceWindow },
147
      { ...numberFields.inputWindow, setter: setInputWindow, value: inputWindow, ...deltaLimits.inputWindow },
148
      { ...numberFields.duplicatesWindow, setter: setDuplicatesWindow, value: duplicatesWindow, ...deltaLimits.duplicatesWindow },
149
      { ...numberFields.instructionBuffer, setter: setInstructionBuffer, value: instructionBuffer, ...deltaLimits.instructionBuffer }
150
    ];
151
  }, [
152
    compressionLevel,
153
    setCompressionLevel,
154
    setSourceWindow,
155
    sourceWindow,
156
    inputWindow,
157
    setInputWindow,
158
    setDuplicatesWindow,
159
    duplicatesWindow,
160
    setInstructionBuffer,
161
    instructionBuffer,
162
    JSON.stringify(deltaLimits)
163
  ]);
164

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

221
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