Skip to content

Commit 1fbda81

Browse files
committed
Format codes with prettier
1 parent 90ca8c5 commit 1fbda81

File tree

6 files changed

+168
-166
lines changed

6 files changed

+168
-166
lines changed

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"eslint-config-prettier": "^6.10.1",
6565
"eslint-plugin-prettier": "^3.1.2",
6666
"mkdirp": "^1.0.3",
67-
"prettier": "1.16.4",
67+
"prettier": "^1.16.4",
6868
"rimraf": "^2.6.1",
6969
"typescript": "~3.7.3"
7070
},
@@ -83,5 +83,13 @@
8383
}
8484
},
8585
"extension": true
86+
},
87+
"husky": {
88+
"hooks": {
89+
"pre-commit": "lint-staged"
90+
}
91+
},
92+
"lint-staged": {
93+
"*.{js,jsx,ts,tsx}": ["eslint --cache --fix", "prettier --write"]
8694
}
8795
}

src/CodeSnippetForm.ts

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
21
import { Widget } from '@lumino/widgets';
32
import { RequestHandler } from '@elyra/application';
43

54
import checkSVGstr from '../style/check.svg';
65
import { showMessage } from './ConfirmMessage';
76

8-
import { Dialog, showDialog} from '@jupyterlab/apputils';
7+
import { Dialog, showDialog } from '@jupyterlab/apputils';
98

109
import { Contents } from '@jupyterlab/services';
1110

1211
import { JSONObject } from '@lumino/coreutils';
1312

14-
import {ICodeSnippet} from './CodeSnippetService'
13+
import { ICodeSnippet } from './CodeSnippetService';
1514

1615
import { IDocumentManager } from '@jupyterlab/docmanager';
1716
import { CodeSnippetWidget } from './CodeSnippetWidget';
@@ -41,7 +40,7 @@ export interface IFileContainer extends JSONObject {
4140
}
4241

4342
/**
44-
* Save an input with a dialog. This is what actually displays everything.
43+
* Save an input with a dialog. This is what actually displays everything.
4544
* Result.value is the value retrieved from .getValue(). ---> .getValue() returns an array of inputs.
4645
*/
4746
export function inputDialog(
@@ -58,32 +57,31 @@ export function inputDialog(
5857
console.log(result.value);
5958
if (!result.value) {
6059
return null;
61-
}
62-
else {
60+
} else {
6361
/* TODO: if name is already there call shouldOverwrite and change to a put request*/
6462
// Workaround: make a get request with result.value[0] to check... but could be slow
65-
RequestHandler.makePostRequest( //If i use their handler then I can't interrupt any error messages without editing their stuff.
66-
url,
67-
JSON.stringify({
68-
display_name: result.value[0],
69-
metadata: {
70-
code: [
71-
inputCode
72-
],
63+
RequestHandler.makePostRequest(
64+
//If i use their handler then I can't interrupt any error messages without editing their stuff.
65+
url,
66+
JSON.stringify({
67+
display_name: result.value[0],
68+
metadata: {
69+
code: [inputCode],
7370
description: result.value[1],
74-
language: result.value[2],
75-
},
76-
name: result.value[0].replace(' ','').toLowerCase(),
77-
schema_name: "code-snippet",
78-
}),
79-
false
71+
language: result.value[2]
72+
},
73+
name: result.value[0].replace(' ', '').toLowerCase(),
74+
schema_name: 'code-snippet'
75+
}),
76+
false
8077
);
8178
codeSnippet.fetchData().then((codeSnippets: ICodeSnippet[]) => {
82-
console.log("HELLLO");
83-
codeSnippet.renderCodeSnippetsSignal.emit(codeSnippets)});
79+
console.log('HELLLO');
80+
codeSnippet.renderCodeSnippetsSignal.emit(codeSnippets);
81+
});
8482
showMessage({
85-
body: /*"Saved as Snippet"*/new MessageHandler()
86-
});
83+
body: /*"Saved as Snippet"*/ new MessageHandler()
84+
});
8785
}
8886
// if (!isValidFileName(result.value)) {
8987
// void showErrorMessage(
@@ -161,19 +159,20 @@ class InputHandler extends Widget {
161159

162160
getValue(): string[] {
163161
let inputs = [];
164-
inputs.push((this.node.getElementsByTagName('input')[0] as HTMLInputElement).value,
165-
(this.node.getElementsByTagName('input')[1] as HTMLInputElement).value,
166-
(this.node.getElementsByTagName('input')[2] as HTMLInputElement).value);
162+
inputs.push(
163+
(this.node.getElementsByTagName('input')[0] as HTMLInputElement).value,
164+
(this.node.getElementsByTagName('input')[1] as HTMLInputElement).value,
165+
(this.node.getElementsByTagName('input')[2] as HTMLInputElement).value
166+
);
167167
return inputs;
168168
}
169169
}
170170

171-
172171
class MessageHandler extends Widget {
173-
constructor() {
174-
super({ node: Private.createConfirmMessageNode() });
175-
}
176-
}
172+
constructor() {
173+
super({ node: Private.createConfirmMessageNode() });
174+
}
175+
}
177176

178177
/**
179178
* A namespace for private data.
@@ -189,7 +188,7 @@ namespace Private {
189188
nameTitle.textContent = 'Snippet Name*';
190189
nameTitle.className = INPUT_NEWNAME_TITLE_CLASS;
191190
const name = document.createElement('input');
192-
191+
193192
const descriptionTitle = document.createElement('label');
194193
descriptionTitle.textContent = 'Description*';
195194
descriptionTitle.className = INPUT_NEWNAME_TITLE_CLASS;
@@ -217,8 +216,8 @@ namespace Private {
217216
messageContainer.className = 'jp-confirm-text';
218217
const message = document.createElement('text');
219218
message.textContent = 'Saved as Snippet!';
220-
messageContainer.appendChild(message)
219+
messageContainer.appendChild(message);
221220
body.append(messageContainer);
222221
return body;
223222
}
224-
}
223+
}

src/ConfirmMessage.tsx

Lines changed: 54 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { Message, MessageLoop } from '@lumino/messaging';
99
import { PromiseDelegate } from '@lumino/coreutils';
1010
import { ArrayExt } from '@lumino/algorithm';
1111

12-
1312
/**
1413
* The class name for confirmation box
1514
*/
@@ -23,40 +22,39 @@ const CONFIRM_CLASS = 'jp-confirm';
2322
* @returns A promise that resolves with whether the dialog was accepted.
2423
*/
2524
export function showMessage<T>(
26-
options: Partial<ConfirmMessage.IOptions<T>> = {}
27-
): Promise<void> {
28-
console.log(options);
29-
const confirmMessage = new ConfirmMessage(options);
30-
return confirmMessage.launch();
31-
}
25+
options: Partial<ConfirmMessage.IOptions<T>> = {}
26+
): Promise<void> {
27+
console.log(options);
28+
const confirmMessage = new ConfirmMessage(options);
29+
return confirmMessage.launch();
30+
}
3231

3332
/**
3433
* A widget used to show confirmation message.
3534
*/
3635
export class ConfirmMessage<T> extends Widget {
37-
38-
constructor(options: Partial<ConfirmMessage.IOptions<T>> = {}){
39-
super();
40-
this.addClass(CONFIRM_CLASS);
41-
const renderer = ConfirmMessage.defaultRenderer;
42-
43-
this._host = options.host || document.body;
44-
const layout = (this.layout = new PanelLayout());
45-
const content = new Panel();
46-
content.addClass('jp-Message-content');
47-
layout.addWidget(content);
48-
49-
const body = renderer.createBody(options.body || '');
50-
// body.addClass('jp-Message-body');
51-
// const icon = renderer.createIcon();
52-
// content.addWidget(icon);
53-
content.addWidget(body);
54-
55-
console.log(content);
56-
57-
void ConfirmMessage.tracker.add(this);
58-
}
59-
/**
36+
constructor(options: Partial<ConfirmMessage.IOptions<T>> = {}) {
37+
super();
38+
this.addClass(CONFIRM_CLASS);
39+
const renderer = ConfirmMessage.defaultRenderer;
40+
41+
this._host = options.host || document.body;
42+
const layout = (this.layout = new PanelLayout());
43+
const content = new Panel();
44+
content.addClass('jp-Message-content');
45+
layout.addWidget(content);
46+
47+
const body = renderer.createBody(options.body || '');
48+
// body.addClass('jp-Message-body');
49+
// const icon = renderer.createIcon();
50+
// content.addWidget(icon);
51+
content.addWidget(body);
52+
53+
console.log(content);
54+
55+
void ConfirmMessage.tracker.add(this);
56+
}
57+
/**
6058
* Launch the dialog as a modal window.
6159
*
6260
* @returns a promise that resolves with the result of the dialog.
@@ -102,7 +100,7 @@ export class ConfirmMessage<T> extends Widget {
102100
}
103101
}
104102

105-
/**
103+
/**
106104
* Handle the `'click'` event for a dialog button.
107105
*
108106
* @param event - The DOM event sent to the widget
@@ -240,11 +238,11 @@ export class ConfirmMessage<T> extends Widget {
240238
}
241239

242240
export namespace ConfirmMessage {
243-
/**
241+
/**
244242
* The body input types.
245243
*/
246-
export type Body<T> = IBodyWidget<T> | React.ReactElement<any> | string;
247-
/**
244+
export type Body<T> = IBodyWidget<T> | React.ReactElement<any> | string;
245+
/**
248246
* The options used to create a dialog.
249247
*/
250248
/**
@@ -290,7 +288,7 @@ export namespace ConfirmMessage {
290288
}
291289

292290
export interface IRenderer {
293-
/**
291+
/**
294292
* Create the body of the dialog.
295293
*
296294
* @param value - The input value for the body.
@@ -310,24 +308,24 @@ export namespace ConfirmMessage {
310308
* @returns A widget for the body.
311309
*/
312310
createBody(value: Body<any>): Widget {
313-
let body: Widget;
314-
if (typeof value === 'string') {
315-
body = new Widget({ node: document.createElement('span') });
316-
body.node.textContent = value;
317-
} else if (value instanceof Widget) {
318-
body = value;
319-
} else {
320-
body = ReactWidget.create(value);
321-
// Immediately update the body even though it has not yet attached in
322-
// order to trigger a render of the DOM nodes from the React element.
323-
MessageLoop.sendMessage(body, Widget.Msg.UpdateRequest);
324-
}
325-
// const iconNode = new Widget({ node: document.createElement('div') });
326-
// iconNode.title.icon = checkIcon;
327-
// body.
328-
body.addClass('jp-Message-body');
329-
// Styling.styleNode(body.node);
330-
return body;
311+
let body: Widget;
312+
if (typeof value === 'string') {
313+
body = new Widget({ node: document.createElement('span') });
314+
body.node.textContent = value;
315+
} else if (value instanceof Widget) {
316+
body = value;
317+
} else {
318+
body = ReactWidget.create(value);
319+
// Immediately update the body even though it has not yet attached in
320+
// order to trigger a render of the DOM nodes from the React element.
321+
MessageLoop.sendMessage(body, Widget.Msg.UpdateRequest);
322+
}
323+
// const iconNode = new Widget({ node: document.createElement('div') });
324+
// iconNode.title.icon = checkIcon;
325+
// body.
326+
body.addClass('jp-Message-body');
327+
// Styling.styleNode(body.node);
328+
return body;
331329
}
332330

333331
// createIcon(): Widget {
@@ -344,7 +342,7 @@ export namespace ConfirmMessage {
344342
// return iconWidget
345343
// }
346344
}
347-
/**
345+
/**
348346
* The default renderer instance.
349347
*/
350348
export const defaultRenderer = new Renderer();
@@ -353,7 +351,7 @@ export namespace ConfirmMessage {
353351
* The dialog widget tracker.
354352
*/
355353
export const tracker = new WidgetTracker<ConfirmMessage<any>>({
356-
namespace: '@jupyterlab/code_snippet:ConfirmWidget'
354+
namespace: '@jupyterlab/code_snippet:ConfirmWidget'
357355
});
358356
}
359357

@@ -365,4 +363,4 @@ namespace Private {
365363
* The queue for launching dialogs.
366364
*/
367365
export const launchQueue: Promise<void>[] = [];
368-
}
366+
}

0 commit comments

Comments
 (0)