-
-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement dialog to input board user fields
- Loading branch information
1 parent
2024b7f
commit e9dd2fe
Showing
5 changed files
with
235 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
arduino-ide-extension/src/browser/dialogs/user-fields/user-fields-component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import * as React from 'react'; | ||
import { BoardUserField } from '../../../common/protocol'; | ||
|
||
export const UserFieldsComponent = ({ | ||
initialBoardUserFields, | ||
updateUserFields, | ||
}: { | ||
initialBoardUserFields: BoardUserField[]; | ||
updateUserFields: (userFields: BoardUserField[]) => void; | ||
}): React.ReactElement => { | ||
const [boardUserFields, setBoardUserFields] = React.useState< | ||
BoardUserField[] | ||
>(initialBoardUserFields); | ||
React.useEffect(() => { | ||
setBoardUserFields(initialBoardUserFields); | ||
}, [initialBoardUserFields]); | ||
|
||
const updateUserField = | ||
(index: number) => (e: React.ChangeEvent<HTMLInputElement>) => { | ||
let newBoardUserFields = [...boardUserFields]; | ||
newBoardUserFields[index].value = e.target.value; | ||
setBoardUserFields(newBoardUserFields); | ||
}; | ||
|
||
React.useEffect(() => { | ||
updateUserFields(boardUserFields); | ||
}, [boardUserFields]); | ||
|
||
return ( | ||
<div> | ||
{boardUserFields.map((field, index) => { | ||
return ( | ||
<div className="dialogSection" key={index}> | ||
<div className="dialogRow"> | ||
<label className="field-label">{field.label}</label> | ||
</div> | ||
<div className="dialogRow"> | ||
<input | ||
type={field.secret ? 'password' : 'text'} | ||
value={field.value} | ||
className="theia-input" | ||
placeholder={'Enter ' + field.label} | ||
onChange={updateUserField(index)} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
); | ||
}; |
106 changes: 106 additions & 0 deletions
106
arduino-ide-extension/src/browser/dialogs/user-fields/user-fields-dialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import * as React from 'react'; | ||
import { inject, injectable } from 'inversify'; | ||
import { | ||
AbstractDialog, | ||
DialogProps, | ||
ReactWidget, | ||
} from '@theia/core/lib/browser'; | ||
import { Widget } from '@phosphor/widgets'; | ||
import { Message } from '@phosphor/messaging'; | ||
import { UploadSketch } from '../../contributions/upload-sketch'; | ||
import { UserFieldsComponent } from './user-fields-component'; | ||
import { BoardUserField } from '../../../common/protocol'; | ||
|
||
@injectable() | ||
export class UserFieldsDialogWidget extends ReactWidget { | ||
protected _currentUserFields: BoardUserField[] = []; | ||
|
||
constructor() { | ||
super(); | ||
} | ||
|
||
set currentUserFields(userFields: BoardUserField[]) { | ||
this.setUserFields(userFields); | ||
} | ||
|
||
get currentUserFields(): BoardUserField[] { | ||
return this._currentUserFields; | ||
} | ||
|
||
resetUserFieldsValue(): void { | ||
this._currentUserFields = this._currentUserFields.map((field) => { | ||
field.value = ''; | ||
return field; | ||
}); | ||
} | ||
|
||
protected setUserFields(userFields: BoardUserField[]): void { | ||
this._currentUserFields = userFields; | ||
} | ||
|
||
protected render(): React.ReactNode { | ||
return ( | ||
<form> | ||
<UserFieldsComponent | ||
initialBoardUserFields={this._currentUserFields} | ||
updateUserFields={this.setUserFields.bind(this)} | ||
/> | ||
</form> | ||
); | ||
} | ||
} | ||
|
||
@injectable() | ||
export class UserFieldsDialogProps extends DialogProps {} | ||
|
||
@injectable() | ||
export class UserFieldsDialog extends AbstractDialog<BoardUserField[]> { | ||
@inject(UserFieldsDialogWidget) | ||
protected readonly widget: UserFieldsDialogWidget; | ||
|
||
constructor( | ||
@inject(UserFieldsDialogProps) | ||
protected readonly props: UserFieldsDialogProps | ||
) { | ||
super({ | ||
title: UploadSketch.Commands.UPLOAD_WITH_CONFIGURATION.label || '', | ||
}); | ||
this.titleNode.classList.add('user-fields-dialog-title'); | ||
this.contentNode.classList.add('user-fields-dialog-content'); | ||
this.appendCloseButton('CANCEL'); | ||
this.appendAcceptButton('UPLOAD'); | ||
} | ||
|
||
set value(userFields: BoardUserField[]) { | ||
this.widget.currentUserFields = userFields; | ||
} | ||
|
||
get value(): BoardUserField[] { | ||
return this.widget.currentUserFields; | ||
} | ||
|
||
protected onAfterAttach(msg: Message): void { | ||
if (this.widget.isAttached) { | ||
Widget.detach(this.widget); | ||
} | ||
Widget.attach(this.widget, this.contentNode); | ||
super.onAfterAttach(msg); | ||
this.update(); | ||
} | ||
|
||
protected onUpdateRequest(msg: Message): void { | ||
super.onUpdateRequest(msg); | ||
this.widget.update(); | ||
} | ||
|
||
protected onActivateRequest(msg: Message): void { | ||
super.onActivateRequest(msg); | ||
this.widget.activate(); | ||
} | ||
|
||
close(): void { | ||
this.widget.resetUserFieldsValue(); | ||
this.widget.close(); | ||
super.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
arduino-ide-extension/src/browser/style/user-fields-dialog.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
.user-fields-dialog-title { | ||
font-family: Open Sans; | ||
font-size: 16px; | ||
font-style: normal; | ||
font-weight: 700; | ||
line-height: 27px; | ||
letter-spacing: 0.01em; | ||
text-align: left; | ||
} | ||
|
||
.user-fields-dialog-content { | ||
width: 408px; | ||
} | ||
|
||
.user-fields-dialog-content .field-label { | ||
color: #2c353a; | ||
font-family: Open Sans; | ||
font-size: 14px; | ||
font-style: normal; | ||
font-weight: 400; | ||
line-height: 21px; | ||
letter-spacing: 0.01em; | ||
text-align: left; | ||
} | ||
|
||
.user-fields-dialog-content .theia-input { | ||
flex-grow: 1; | ||
} |