Skip to content

Commit d32965f

Browse files
committed
Merge branch 'release/v1.3.5'
2 parents 247ae0d + 7f1c025 commit d32965f

File tree

17 files changed

+2919
-2514
lines changed

17 files changed

+2919
-2514
lines changed

.babelrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"presets": ["next/babel"],
2+
"presets": ["@babel/env", "next/babel", "@babel/preset-flow"],
33
"plugins": [
44
[
55
"module-resolver",
@@ -20,7 +20,6 @@
2020
"extensions": ["less$"]
2121
}
2222
],
23-
["import", { "libraryName": "antd" }],
2423
["styled-components", { "ssr": true, "displayName": true, "preprocess": false } ]
2524
]
2625
}

.rancher-pipeline.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ notification:
1919
recipients:
2020
- recipient: '#pipeline'
2121
notifier: c-qzkvv:n-qqrqq
22-
- recipient: ab@caesar.team
23-
notifier: c-qzkvv:n-z4jfb
2422
condition:
2523
- Success
2624
- Changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# docker run -it node:8.12-alpine /bin/bash
22
# ---- Base Node ----
3-
FROM node:8.12-alpine AS base
3+
FROM node:10.16-alpine AS base
44
# Preparing
55
RUN mkdir -p /var/app && chown -R node /var/app
66
# Set working directory

common/utils/clipboard.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,13 @@ export const copyToClipboard = str => {
77
document.execCommand('copy');
88
document.body.removeChild(el);
99
};
10+
11+
export const pastFromClipboard = e => {
12+
// Get pasted data via clipboard API
13+
const clipboardData = e.clipboardData || window.clipboardData;
14+
const pastedData = clipboardData.getData('Text');
15+
if (pastedData != null && pastedData.length > 0) {
16+
return pastedData;
17+
}
18+
return null;
19+
};

common/utils/download.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
export function downloadElement(elementId) {
22
const a = document.body.appendChild(document.createElement('a'));
33

4-
a.download = 'export.txt';
4+
a.download = '2fa_backup_codes.txt';
55
a.href = `data:text/plain;charset=utf-8,${
66
document.getElementById(elementId).innerText
77
}`;
88

99
a.click();
1010
}
11+
12+
export function downloadTextData(data) {
13+
const a = document.body.appendChild(document.createElement('a'));
14+
15+
a.download = '2fa_backup_codes.txt';
16+
a.href = `data:text/plain;charset=utf-8,${data}`;
17+
18+
a.click();
19+
}

common/utils/format.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export function formatNumbersByColumns(numbers, columns) {
2+
const printCodes = numbers.map((number, index) => {
3+
const position = index + 1;
4+
if (position % columns === 0) return `${number}\n`;
5+
return `${number} `;
6+
});
7+
8+
return printCodes.join('');
9+
}

common/utils/print.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,10 @@ export function printElement(elementId) {
88

99
document.body.innerHTML = originalContents;
1010
}
11+
12+
export function printData(data) {
13+
const win = window.open();
14+
win.document.write(data);
15+
win.print();
16+
win.close();
17+
}

components/CodeInput/CodeInput.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { CodeItem } from './CodeItem';
55
const Wrapper = styled.div`
66
display: flex;
77
`;
8+
const isCodeValidated = (v, length) => v.match(`^[0-9]{${length}}$`) !== null;
89

910
class CodeInput extends Component {
1011
values = this.generateValues();
@@ -19,6 +20,16 @@ class CodeInput extends Component {
1920
this.elements[index] = ref;
2021
};
2122

23+
onPaste = v => {
24+
const { length } = this.props;
25+
26+
if (!isCodeValidated(v, length)) {
27+
return;
28+
}
29+
30+
v.split('').map((ev, ei) => this.onItemChange(ev, ei)); // Simulate user input.
31+
};
32+
2233
onItemChange = (value, index) => {
2334
const {
2435
length,
@@ -61,11 +72,13 @@ class CodeInput extends Component {
6172
{this.values.map((e, i) => (
6273
<CodeItem
6374
createRef={ref => this.createElementsRefs(ref, i)}
75+
value={e}
6476
key={i}
6577
index={i}
6678
onBackspace={() => this.onBackspace(i)}
6779
resetFormOnBackspace={onCompleteWithErrors}
6880
onChange={v => this.onItemChange(v, i)}
81+
onPaste={v => this.onPaste(v)}
6982
disabled={disabled}
7083
errors={errors}
7184
/>

components/CodeInput/CodeItem.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { Component } from 'react';
22
import styled from 'styled-components';
33
import { KEY_CODES } from 'common/constants';
4+
import { pastFromClipboard } from 'common/utils/clipboard';
45

56
const StyledInput = styled.input`
67
width: 40px;
@@ -24,6 +25,24 @@ export class CodeItem extends Component {
2425
value: '',
2526
};
2627

28+
static getDerivedStateFromProps(nextProps) {
29+
// The state without cache is a reasonable solution for this place.
30+
return {
31+
value: nextProps.value,
32+
};
33+
}
34+
35+
onPaste = e => {
36+
// Stop the data being pasted into the element.
37+
e.stopPropagation();
38+
e.preventDefault();
39+
40+
const pastedData = pastFromClipboard(e);
41+
if (pastedData != null && pastedData.length > 0) {
42+
this.props.onPaste(pastedData);
43+
}
44+
};
45+
2746
onKeyDown = e => {
2847
const {
2948
onBackspace,
@@ -48,17 +67,12 @@ export class CodeItem extends Component {
4867
onChange = e => {
4968
const value = this.validate(e.target.value);
5069
if (this.state.value === value) return;
51-
if (value.length < 2) {
52-
this.setState({ value });
53-
this.props.onChange(value);
54-
}
70+
this.setState({ value });
71+
this.props.onChange(value);
5572
};
5673

5774
validate = value => {
58-
const numCode = value.charCodeAt(0);
59-
const isInteger =
60-
numCode >= '0'.charCodeAt(0) && numCode <= '9'.charCodeAt(0);
61-
return isInteger ? value : '';
75+
return /^[0-9]$/.test(value) ? value : '';
6276
};
6377

6478
render() {
@@ -69,6 +83,7 @@ export class CodeItem extends Component {
6983
<StyledInput
7084
onChange={this.onChange}
7185
onKeyDown={this.onKeyDown}
86+
onPaste={this.onPaste}
7287
maxLength="1"
7388
autoComplete="off"
7489
ref={createRef}

components/Item/Types/schema/schema.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ const checkFileSize = raw =>
2121
convertSizeNameToNumber(MAX_UPLOADING_FILE_SIZE);
2222

2323
const checkAllFileSizes = files =>
24-
files.reduce((acc, { raw }) => acc + raw.length, 0) *
25-
BASE_64_LENGTH_BYTE_RATE <=
26-
convertSizeNameToNumber(TOTAL_MAX_UPLOADING_FILES_SIZES);
24+
files
25+
? files.reduce((acc, { raw }) => acc + raw.length, 0) *
26+
BASE_64_LENGTH_BYTE_RATE <=
27+
convertSizeNameToNumber(TOTAL_MAX_UPLOADING_FILES_SIZES)
28+
: true;
2729

2830
export const attachmentsSchema = yup
2931
.array(

0 commit comments

Comments
 (0)