Skip to content

Commit 9410048

Browse files
committed
Created duplicate alert for language tags in editor.
1 parent ff6e5a5 commit 9410048

File tree

5 files changed

+27
-13
lines changed

5 files changed

+27
-13
lines changed

src/CodeSnippetDisplay.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,15 +1504,17 @@ export class CodeSnippetDisplay extends React.Component<
15041504
editSnip.className = CODE_SNIPPET_MORE_OTPIONS_EDIT;
15051505
editSnip.textContent = 'Edit snippet';
15061506
editSnip.onclick = (): void => {
1507-
const allTags = this.getActiveTags()[0];
1507+
const allSnippetTags = this.getActiveTags()[0]; // snippet tags only
1508+
const allLangTags = this.getActiveTags()[1];
15081509
this.props.openCodeSnippetEditor({
15091510
name: codeSnippet.name,
15101511
description: codeSnippet.description,
15111512
language: codeSnippet.language,
15121513
code: codeSnippet.code,
15131514
id: codeSnippet.id,
1514-
selectedTags: codeSnippet.tags,
1515-
allTags: allTags,
1515+
selectedTags: codeSnippet.tags, // snippet tags
1516+
allSnippetTags: allSnippetTags,
1517+
allLangTags: allLangTags,
15161518
fromScratch: false,
15171519
});
15181520
this.removeOptionsNode();
@@ -1563,7 +1565,8 @@ export class CodeSnippetDisplay extends React.Component<
15631565
code: [],
15641566
id: this.state.codeSnippets.length,
15651567
selectedTags: [],
1566-
allTags: this.getActiveTags()[0],
1568+
allSnippetTags: this.getActiveTags()[0],
1569+
allLangTags: this.getActiveTags()[1],
15671570
fromScratch: true,
15681571
});
15691572
}}

src/CodeSnippetEditor.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ export interface ICodeSnippetEditorMetadata {
5858
code: string[];
5959
id: number;
6060
selectedTags: string[];
61-
allTags: string[];
61+
allSnippetTags: string[];
62+
allLangTags: string[];
6263
fromScratch: boolean;
6364
}
6465

@@ -489,7 +490,7 @@ export class CodeSnippetEditor extends ReactWidget {
489490
}
490491

491492
this._codeSnippetEditorMetaData.selectedTags = selectedTags;
492-
this._codeSnippetEditorMetaData.allTags = allTags;
493+
this._codeSnippetEditorMetaData.allSnippetTags = allTags;
493494

494495
this.saved = false;
495496
}
@@ -595,7 +596,8 @@ export class CodeSnippetEditor extends ReactWidget {
595596
<label className={CODE_SNIPPET_EDITOR_LABEL}>Tags</label>
596597
<CodeSnippetEditorTags
597598
selectedTags={this.codeSnippetEditorMetadata.selectedTags}
598-
tags={this.codeSnippetEditorMetadata.allTags}
599+
snippetTags={this.codeSnippetEditorMetadata.allSnippetTags}
600+
langTags={this.codeSnippetEditorMetadata.allLangTags}
599601
handleChange={this.handleChangeOnTag}
600602
/>
601603
</section>

src/CodeSnippetEditorTags.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import { checkIcon, addIcon } from '@jupyterlab/ui-components';
66
import React from 'react';
77

88
interface ICodeSnippetEditorTagProps {
9-
selectedTags: string[];
10-
tags: string[];
9+
selectedTags: string[]; // selected snippet tags only
10+
snippetTags: string[]; // snippet tags only
11+
langTags: string[];
1112
handleChange: (selectedTags: string[], allTags: string[]) => void;
1213
}
1314

@@ -44,7 +45,7 @@ export class CodeSnippetEditorTags extends React.Component<
4445
componentDidMount(): void {
4546
this.setState({
4647
selectedTags: this.props.selectedTags ? this.props.selectedTags : [],
47-
tags: this.props.tags ? this.props.tags : [],
48+
tags: this.props.snippetTags ? this.props.snippetTags : [],
4849
plusIconShouldHide: false,
4950
addingNewTag: false,
5051
});
@@ -54,7 +55,7 @@ export class CodeSnippetEditorTags extends React.Component<
5455
if (prevProps !== this.props) {
5556
this.setState({
5657
selectedTags: this.props.selectedTags ? this.props.selectedTags : [],
57-
tags: this.props.tags ? this.props.tags : [],
58+
tags: this.props.snippetTags ? this.props.snippetTags : [],
5859
});
5960
}
6061
}
@@ -117,6 +118,13 @@ export class CodeSnippetEditorTags extends React.Component<
117118
return;
118119
}
119120

121+
if (this.props.langTags.includes(inputElement.value)) {
122+
alert(
123+
'This tag already exists in language tags!\nIf you want to create this tag, lowercase the first letter.'
124+
);
125+
return;
126+
}
127+
120128
const newTag = inputElement.value;
121129

122130
// update state all tag and selected tag

src/FilterTools.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import React from 'react';
88

99
interface IFilterSnippetProps {
1010
languages: string[];
11-
allTags: string[][]; // change to [[snip], lang]]
11+
allTags: string[][]; // change to [[snip], [lang]]
1212
onFilter: (searchValue: string, filterTags: string[]) => void;
1313
}
1414

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ function activateCodeSnippet(
281281
code: editorMetadata.code,
282282
id: editorMetadata.id,
283283
selectedTags: editorMetadata.selectedTags,
284-
allTags: editorMetadata.allTags,
284+
allSnippetTags: editorMetadata.allSnippetTags,
285+
allLangTags: editorMetadata.allLangTags,
285286
fromScratch: editorMetadata.fromScratch,
286287
};
287288
},

0 commit comments

Comments
 (0)