Skip to content

Commit 7aa884f

Browse files
committed
Made description optional. Working on allowing uppercase in names.
1 parent c960403 commit 7aa884f

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

src/CodeSnippetContentsService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ContentsManager, Drive, Contents } from '@jupyterlab/services';
55

66
export interface ICodeSnippet {
77
name: string;
8-
description: string;
8+
description?: string;
99
language: string;
1010
// code separated by new line
1111
code: string[];

src/CodeSnippetEditor.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,10 @@ export class CodeSnippetEditor extends ReactWidget {
370370
message += 'Wrong format of the name\n';
371371
status = false;
372372
}
373-
if (description === '') {
374-
message += 'Description must be filled out\n';
375-
status = false;
376-
}
373+
// if (description === '') {
374+
// message += 'Description must be filled out\n';
375+
// status = false;
376+
// }
377377
if (description.match(/[^a-zA-Z0-9_ ,.?!]+/)) {
378378
message += 'Wrong format of the description\n';
379379
status = false;
@@ -589,14 +589,13 @@ export class CodeSnippetEditor extends ReactWidget {
589589
}
590590
</p>
591591
<label className={CODE_SNIPPET_EDITOR_LABEL}>
592-
Description (required)
592+
Description (optional)
593593
</label>
594594
<input
595595
className={CODE_SNIPPET_EDITOR_DESC_INPUT}
596596
defaultValue={this._codeSnippetEditorMetaData.description}
597597
placeholder={'Description'}
598598
type="text"
599-
required
600599
pattern={'[a-zA-Z0-9_ ,.?!]+'}
601600
onMouseDown={(
602601
event: React.MouseEvent<HTMLInputElement, MouseEvent>

src/CodeSnippetInputDialog.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export function showInputDialog(
110110

111111
const tags = result.value.slice(3);
112112
const newSnippet: ICodeSnippet = {
113-
name: result.value[0].replace(' ', '').toLowerCase(),
113+
name: result.value[0].replace(' ', ''),
114114
description: result.value[1],
115115
language: result.value[2],
116116
code: code,
@@ -120,13 +120,13 @@ export function showInputDialog(
120120
const contentsService = CodeSnippetContentsService.getInstance();
121121
const currSnippets = codeSnippetWidget.codeSnippetWidgetModel.snippets;
122122
for (const snippet of currSnippets) {
123-
if (snippet.name === newSnippet.name) {
123+
if (snippet.name.toLowerCase() === newSnippet.name.toLowerCase()) {
124124
const result = saveOverWriteFile(
125125
codeSnippetWidget.codeSnippetWidgetModel,
126126
snippet,
127127
newSnippet
128128
);
129-
129+
console.log('uh reached here');
130130
result
131131
.then(newSnippets => {
132132
codeSnippetWidget.renderCodeSnippetsSignal.emit(newSnippets);
@@ -156,7 +156,7 @@ function createNewSnippet(
156156
content: JSON.stringify(newSnippet)
157157
}
158158
);
159-
159+
console.log(newSnippet.name);
160160
request.then(_ => {
161161
// add the new snippet to the snippet model
162162
codeSnippet.codeSnippetWidgetModel.addSnippet(newSnippet, newSnippet.id);
@@ -178,7 +178,7 @@ async function saveOverWriteFile(
178178
oldSnippet: ICodeSnippet,
179179
newSnippet: ICodeSnippet
180180
): Promise<ICodeSnippet[] | null> {
181-
const newPath = 'snippets/' + newSnippet.name + '.json';
181+
const newPath = 'snippets/' + oldSnippet.name + '.json';
182182

183183
return await shouldOverwrite(newPath).then(value => {
184184
if (value) {
@@ -233,15 +233,13 @@ export function validateForm(
233233
message += 'Name must be filled out\n';
234234
status = false;
235235
}
236-
if (name.match(/[^a-z0-9_]+/)) {
236+
if (name.match(/[^a-zA-Z0-9_]+/)) {
237+
//allow lowercase, uppercase, alphanumeric, and underscore
237238
message += 'Wrong format of the name\n';
238239
status = false;
239240
}
240-
if (description === '') {
241-
message += 'Description must be filled out\n';
242-
status = false;
243-
}
244241
if (description.match(/[^a-zA-Z0-9_ ,.?!]+/)) {
242+
//alphanumeric but can include space or punctuation
245243
message += 'Wrong format of the description\n';
246244
status = false;
247245
}
@@ -333,10 +331,9 @@ class Private {
333331
name.onblur = Private.handleOnBlur;
334332

335333
const descriptionTitle = document.createElement('label');
336-
descriptionTitle.textContent = 'Description';
334+
descriptionTitle.textContent = 'Description (optional)';
337335
const description = document.createElement('input');
338336
description.className = CODE_SNIPPET_DIALOG_INPUT;
339-
description.required = true;
340337
description.pattern = '[a-zA-Z0-9_ ,.?!]+';
341338
description.onblur = Private.handleOnBlur;
342339

0 commit comments

Comments
 (0)