Skip to content

Commit

Permalink
Fix the issue #677. Check the match of rows and cols for approved key…
Browse files Browse the repository at this point in the history
…boards.
  • Loading branch information
yoichiro committed Dec 4, 2021
1 parent 0fd9218 commit 09555a3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
SchemaValidateError,
validateIds,
validateKeyboardDefinitionSchema,
validateRowsAndCols,
} from '../../../services/storage/Validator';
import {
Accordion,
Expand All @@ -18,6 +19,7 @@ import {
import { Alert, AlertTitle } from '@material-ui/lab';
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
import './KeyboardDefinitionFormPart.scss';
import { IKeyboardDefinitionDocument } from '../../../services/storage/Storage';

// eslint-disable-next-line no-undef
const loadDefinitionFile = async (file: File): Promise<string> => {
Expand Down Expand Up @@ -48,6 +50,8 @@ export type KeyboardDefinitionFormPartProps = {
fileName: string,
jsonStr: string
) => void;
keyboardDefinitionDocument?: IKeyboardDefinitionDocument | null;
keyboardDefinitionSchema?: KeyboardDefinitionSchema | null;
};
/* eslint-enable no-unused-vars */

Expand Down Expand Up @@ -133,6 +137,22 @@ export class KeyboardDefinitionFormPart extends React.Component<
}
}

if (
this.props.keyboardDefinitionDocument &&
this.props.keyboardDefinitionSchema &&
this.props.keyboardDefinitionDocument.status === 'approved'
) {
const msg = validateRowsAndCols(
keyboardDefinition,
this.props.keyboardDefinitionSchema
);
if (msg) {
this.stopLoading();
this.showErrorMessage('INVALID Row and Col', msg);
return Promise.reject(msg);
}
}

this.stopLoading();
this.props.onLoadFile(keyboardDefinition, file.name, jsonStr);
return keyboardDefinition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { KeyboardDefinitionSchema } from '../../../gen/types/KeyboardDefinition'

// eslint-disable-next-line no-unused-vars
const mapStateToProps = (state: RootState) => {
return {};
return {
keyboardDefinitionDocument: state.entities.keyboardDefinitionDocument,
keyboardDefinitionSchema: state.entities.keyboardDefinition,
};
};
export type ConfigurationDialogStateType = ReturnType<typeof mapStateToProps>;

Expand Down
2 changes: 2 additions & 0 deletions src/components/configure/importDef/ImportDefDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ export default class ConfigurationDialog extends React.Component<
this.onLoadFile(kd, name);
}}
size="small"
keyboardDefinitionDocument={this.props.keyboardDefinitionDocument}
keyboardDefinitionSchema={this.props.keyboardDefinitionSchema}
/>

{this.state.keyboardDefinition && (
Expand Down
13 changes: 13 additions & 0 deletions src/services/storage/Validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ export const validateIds = (
return null;
};

export const validateRowsAndCols = (
source: KeyboardDefinitionSchema,
target: KeyboardDefinitionSchema
): string | null => {
if (source.matrix.rows !== target.matrix.rows) {
return `Not match the Rows: Server:${target.matrix.rows}, Local:${source.matrix.rows}`;
}
if (source.matrix.cols !== target.matrix.cols) {
return `Not match the Cols: Server:${target.matrix.cols}, Local:${source.matrix.cols}`;
}
return null;
};

export const validateKeyboardDefinitionSchema = (
json: Object,
schemaObject: Object = schema
Expand Down

0 comments on commit 09555a3

Please sign in to comment.