-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathInfoDialog.tsx
More file actions
293 lines (280 loc) · 9.06 KB
/
InfoDialog.tsx
File metadata and controls
293 lines (280 loc) · 9.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/* eslint-disable no-undef */
import React from 'react';
import './InfoDialog.scss';
import {
Dialog,
DialogContent,
DialogTitle,
Grid,
Paper,
PaperProps,
} from '@mui/material';
import CloseIcon from '@mui/icons-material/Close';
import Draggable from 'react-draggable';
import {
InfoDialogActionsType,
InfoDialogStateType,
} from './InfoDialog.container';
import { hexadecimal } from '../../../utils/StringUtils';
import {
IKeyboardDefinitionDocument,
IOrganization,
KeyboardDefinitionStatus,
} from '../../../services/storage/Storage';
import { KeyboardDefinitionSchema } from '../../../gen/types/KeyboardDefinition';
import firebase from 'firebase/app';
import { t } from 'i18next';
const GOOGLE_FORM_URL =
'https://docs.google.com/forms/d/e/1FAIpQLScZPhiXEG2VETCGZ2dYp4YbzzMlU62Crh1cNxPpFBkN4cCPbA/viewform?usp=pp_url&entry.661359702=${keyboard_name}&entry.135453541=${keyboard_id}';
type OwnState = {
deviceInfo: {
productName: string;
vendorId: number;
productId: number;
viaProtocolVersion: number;
};
keyboardDef: {
name: string;
vendorId: string;
productId: string;
matrix: {
rows: number;
cols: number;
};
};
};
type OwnProps = {
open: boolean;
onClose: () => void;
};
type InfoStateProps = OwnProps &
Partial<InfoDialogActionsType> &
Partial<InfoDialogStateType>;
export default class InfoDialog extends React.Component<
InfoStateProps,
OwnState
> {
private googleFormUrl: string = '';
private githubUrl: string = '';
private githubDisplayName: string = '';
constructor(props: InfoStateProps | Readonly<InfoStateProps>) {
super(props);
this.state = {
deviceInfo: {
productName: '',
vendorId: NaN,
productId: NaN,
viaProtocolVersion: NaN,
},
keyboardDef: {
name: '',
vendorId: '',
productId: '',
matrix: {
rows: NaN,
cols: NaN,
},
},
};
}
private onEnter() {
if (this.props.keyboardDefinitionDocument) {
this.googleFormUrl = GOOGLE_FORM_URL.replace(
'${keyboard_name}',
this.props.keyboardDefinitionDocument.name
).replace('${keyboard_id}', this.props.keyboardDefinitionDocument.id);
this.githubUrl = this.props.keyboardDefinitionDocument.githubUrl;
this.githubDisplayName =
this.props.keyboardDefinitionDocument.githubDisplayName;
}
const deviceInfo = {
...this.props.keyboard!.getInformation(),
viaProtocolVersion: this.props.viaProtocolVersion!,
};
const keyboardDef = this.props.keyboardDefinition!;
this.setState({ deviceInfo, keyboardDef });
}
render() {
return (
<Dialog
open={this.props.open}
maxWidth={'sm'}
PaperComponent={PaperComponent}
className="info-dialog"
TransitionProps={{
onEnter: () => {
this.onEnter();
},
}}
>
<DialogTitle id="info-dialog-title" style={{ cursor: 'move' }}>
{t('Keyboard Info')}
<div className="close-dialog">
<CloseIcon onClick={this.props.onClose} />
</div>
</DialogTitle>
<DialogContent dividers className="info-dialog-content">
<Grid container spacing={1}>
<Grid item xs={12} className="option-info-label">
<h4>{t('CONNECTED DEVICE')}</h4>
</Grid>
<InfoRow
label="Product Name"
value={this.state.deviceInfo.productName}
/>
<InfoRow
label="Vendor ID"
value={hexadecimal(this.state.deviceInfo.vendorId, 4)}
/>
<InfoRow
label="Product ID"
value={hexadecimal(this.state.deviceInfo.productId, 4)}
/>
<InfoRow
label="VIA Protocol Version"
value={hexadecimal(this.state.deviceInfo.viaProtocolVersion, 4)}
/>
<KeyboardDefinitionSection
keyboardDefinitionDocument={this.props.keyboardDefinitionDocument}
keyboardDefinition={this.props.keyboardDefinition}
googleFormUrl={this.googleFormUrl}
authenticatedUser={
this.props.auth
? this.props.auth.getCurrentAuthenticatedUserIgnoreNull()
: undefined
}
organization={this.props.organization}
/>
</Grid>
</DialogContent>
</Dialog>
);
}
}
type IKeyboardDefinitionSectionProps = {
keyboardDefinitionDocument: IKeyboardDefinitionDocument | null | undefined;
keyboardDefinition: KeyboardDefinitionSchema | null | undefined;
googleFormUrl: string;
authenticatedUser: firebase.User | undefined;
organization: IOrganization | null | undefined;
};
function KeyboardDefinitionSection(props: IKeyboardDefinitionSectionProps) {
if (props.keyboardDefinition) {
const designerName =
!props.keyboardDefinitionDocument?.authorType ||
props.keyboardDefinitionDocument.authorType === 'individual'
? props.keyboardDefinitionDocument?.githubDisplayName
: props.organization?.name;
const designerWebsite =
!props.keyboardDefinitionDocument?.authorType ||
props.keyboardDefinitionDocument.authorType === 'individual'
? props.keyboardDefinitionDocument?.githubUrl
: props.organization?.website_url;
return (
<React.Fragment>
<Grid item xs={12} className="option-info-label">
<h4>{t('KEYBOARD DEFINITION')}</h4>
</Grid>
<InfoRow label={t('Name')} value={props.keyboardDefinition.name} />
<InfoRow label="Vendor ID" value={props.keyboardDefinition.vendorId} />
<InfoRow
label="Product ID"
value={props.keyboardDefinition.productId}
/>
<InfoRow
label={t('Col x Row')}
value={`${props.keyboardDefinition.matrix.cols} x ${props.keyboardDefinition.matrix.rows}`}
/>
{props.keyboardDefinitionDocument ? (
<React.Fragment>
<InfoRow
label={t('Registered by')}
value={
<a href={designerWebsite} target="_blank" rel="noreferrer">
{designerName}
</a>
}
/>
<InfoRow
label={t('Status')}
value={props.keyboardDefinitionDocument.status}
/>
{props.keyboardDefinitionDocument.authorUid ===
props.authenticatedUser?.uid ? (
[
KeyboardDefinitionStatus.draft,
KeyboardDefinitionStatus.rejected,
].includes(props.keyboardDefinitionDocument.status) ? (
<Grid item xs={12} className="option-info-label">
<div className="info-dialog-warning-message">
{t(
'The keyboard definition is currently applied for only you. Please submit a review request of this keyboard definition for all users from'
)}{' '}
<a
href={`/keyboards/${props.keyboardDefinitionDocument.id}`}
target="_blank"
rel="noreferrer"
>
here
</a>
.
</div>
</Grid>
) : null
) : (
<Grid item xs={12} className="option-info-label">
<div className="info-dialog-information-message">
{t(
'If you think that the person above does not have any rights for the keyboard and the keyboard definition (in the case of the person is not original keyboard designer or etc.), please report it to the Remap team from this form:'
)}
<a
href={props.googleFormUrl}
target="_blank"
rel="noreferrer"
>
{t('Here')}
</a>
</div>
</Grid>
)}
</React.Fragment>
) : (
<Grid item xs={12} className="option-info-label">
<div className="info-dialog-information-message">
Are you a designer of this keyboard? If yes, please register your
keyboard to Remap from{' '}
<a href={'/keyboards'} target="_blank" rel="noreferrer">
here
</a>
.
</div>
</Grid>
)}
</React.Fragment>
);
} else {
return null;
}
}
function InfoRow(props: { label: string; value: string | React.ReactNode }) {
return (
<React.Fragment>
<Grid item xs={6} className="option-info-label">
{props.label}
</Grid>
<Grid item xs={6} className="option-info-value">
{props.value}
</Grid>
</React.Fragment>
);
}
function PaperComponent(props: PaperProps) {
return (
<Draggable
handle="#info-dialog-title"
cancel={'[class*="MuiDialogContent-root"]'}
>
<Paper {...props} />
</Draggable>
);
}