Skip to content

Commit 09555a3

Browse files
committed
Fix the issue #677. Check the match of rows and cols for approved keyboards.
1 parent 0fd9218 commit 09555a3

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

src/components/common/keyboarddefformpart/KeyboardDefinitionFormPart.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
SchemaValidateError,
77
validateIds,
88
validateKeyboardDefinitionSchema,
9+
validateRowsAndCols,
910
} from '../../../services/storage/Validator';
1011
import {
1112
Accordion,
@@ -18,6 +19,7 @@ import {
1819
import { Alert, AlertTitle } from '@material-ui/lab';
1920
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
2021
import './KeyboardDefinitionFormPart.scss';
22+
import { IKeyboardDefinitionDocument } from '../../../services/storage/Storage';
2123

2224
// eslint-disable-next-line no-undef
2325
const loadDefinitionFile = async (file: File): Promise<string> => {
@@ -48,6 +50,8 @@ export type KeyboardDefinitionFormPartProps = {
4850
fileName: string,
4951
jsonStr: string
5052
) => void;
53+
keyboardDefinitionDocument?: IKeyboardDefinitionDocument | null;
54+
keyboardDefinitionSchema?: KeyboardDefinitionSchema | null;
5155
};
5256
/* eslint-enable no-unused-vars */
5357

@@ -133,6 +137,22 @@ export class KeyboardDefinitionFormPart extends React.Component<
133137
}
134138
}
135139

140+
if (
141+
this.props.keyboardDefinitionDocument &&
142+
this.props.keyboardDefinitionSchema &&
143+
this.props.keyboardDefinitionDocument.status === 'approved'
144+
) {
145+
const msg = validateRowsAndCols(
146+
keyboardDefinition,
147+
this.props.keyboardDefinitionSchema
148+
);
149+
if (msg) {
150+
this.stopLoading();
151+
this.showErrorMessage('INVALID Row and Col', msg);
152+
return Promise.reject(msg);
153+
}
154+
}
155+
136156
this.stopLoading();
137157
this.props.onLoadFile(keyboardDefinition, file.name, jsonStr);
138158
return keyboardDefinition;

src/components/configure/importDef/ImportDefDialog.container.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import { KeyboardDefinitionSchema } from '../../../gen/types/KeyboardDefinition'
66

77
// eslint-disable-next-line no-unused-vars
88
const mapStateToProps = (state: RootState) => {
9-
return {};
9+
return {
10+
keyboardDefinitionDocument: state.entities.keyboardDefinitionDocument,
11+
keyboardDefinitionSchema: state.entities.keyboardDefinition,
12+
};
1013
};
1114
export type ConfigurationDialogStateType = ReturnType<typeof mapStateToProps>;
1215

src/components/configure/importDef/ImportDefDialog.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ export default class ConfigurationDialog extends React.Component<
9898
this.onLoadFile(kd, name);
9999
}}
100100
size="small"
101+
keyboardDefinitionDocument={this.props.keyboardDefinitionDocument}
102+
keyboardDefinitionSchema={this.props.keyboardDefinitionSchema}
101103
/>
102104

103105
{this.state.keyboardDefinition && (

src/services/storage/Validator.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ export const validateIds = (
5252
return null;
5353
};
5454

55+
export const validateRowsAndCols = (
56+
source: KeyboardDefinitionSchema,
57+
target: KeyboardDefinitionSchema
58+
): string | null => {
59+
if (source.matrix.rows !== target.matrix.rows) {
60+
return `Not match the Rows: Server:${target.matrix.rows}, Local:${source.matrix.rows}`;
61+
}
62+
if (source.matrix.cols !== target.matrix.cols) {
63+
return `Not match the Cols: Server:${target.matrix.cols}, Local:${source.matrix.cols}`;
64+
}
65+
return null;
66+
};
67+
5568
export const validateKeyboardDefinitionSchema = (
5669
json: Object,
5770
schemaObject: Object = schema

0 commit comments

Comments
 (0)