Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
536 changes: 514 additions & 22 deletions src/CodeSnippetDisplay.tsx

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions src/CodeSnippetEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import React from 'react';

import { CodeSnippetContentsService } from './CodeSnippetContentsService';
import { CodeSnippetWidget } from './CodeSnippetWidget';
import { SUPPORTED_LANGUAGES } from './index';
import { SUPPORTED_LANGUAGES } from './CodeSnippetLanguages';
import { CodeSnippetEditorTags } from './CodeSnippetEditorTags';

/**
Expand Down Expand Up @@ -323,10 +323,18 @@ export class CodeSnippetEditor extends ReactWidget {
message += 'Name must be filled out\n';
status = false;
}
if (name.match(/[^a-z0-9_]+/)) {
message += 'Wrong format of the name\n';
status = false;
}
if (description === '') {
message += 'Description must be filled out\n';
status = false;
}
if (description.match(/[^a-zA-Z0-9_ ,.?!]+/)) {
message += 'Wrong format of the description\n';
status = false;
}
if (language === '') {
message += 'Language must be filled out';
status = false;
Expand Down Expand Up @@ -457,6 +465,13 @@ export class CodeSnippetEditor extends ReactWidget {
this.saved = false;
}

handleOnBlur(event: React.FocusEvent<HTMLInputElement>): void {
const target = event.target as HTMLElement;
if (!target.classList.contains('touched')) {
target.classList.add('touched');
}
}

/**
* TODO: clean CSS style class - "Use constant"
*/
Expand Down Expand Up @@ -527,6 +542,7 @@ export class CodeSnippetEditor extends ReactWidget {
onChange={(event: React.ChangeEvent<HTMLInputElement>): void => {
this.handleInputFieldChange(event);
}}
onBlur={this.handleOnBlur}
></input>
<p className={CODE_SNIPPET_EDITOR_INPUTNAME_VALIDITY}>
{
Expand All @@ -549,6 +565,7 @@ export class CodeSnippetEditor extends ReactWidget {
onChange={(event: React.ChangeEvent<HTMLInputElement>): void => {
this.handleInputFieldChange(event);
}}
onBlur={this.handleOnBlur}
></input>
<p className={CODE_SNIPPET_EDITOR_INPUTDESC_VALIDITY}>
{
Expand All @@ -569,7 +586,7 @@ export class CodeSnippetEditor extends ReactWidget {
<span className={CODE_SNIPPET_EDITOR_LABEL}>Code</span>
{this.renderCodeInput()}
<Button className="saveBtn" onClick={this.saveChange}>
{fromScratch ? 'Create' : 'Save'}
{fromScratch ? 'Create & Close' : 'Save'}
</Button>
</div>
);
Expand Down
23 changes: 21 additions & 2 deletions src/CodeSnippetInputDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {

import { CodeSnippetWidget } from './CodeSnippetWidget';
import { CodeSnippetWidgetModel } from './CodeSnippetWidgetModel';
import { SUPPORTED_LANGUAGES } from './index';
import { SUPPORTED_LANGUAGES } from './CodeSnippetLanguages';
import { showMessage } from './ConfirmMessage';
import { showCodeSnippetForm, CodeSnippetForm } from './CodeSnippetForm';

Expand Down Expand Up @@ -214,20 +214,29 @@ export function validateForm(
const name = input.value[0];
const description = input.value[1];
const language = input.value[2];

if (name === '') {
message += 'Name must be filled out\n';
status = false;
}
if (name.match(/[^a-z0-9_]+/)) {
message += 'Wrong format of the name\n';
status = false;
}
if (description === '') {
message += 'Description must be filled out\n';
status = false;
}
if (description.match(/[^a-zA-Z0-9_ ,.?!]+/)) {
message += 'Wrong format of the description\n';
status = false;
}
if (language === '') {
message += 'Language must be filled out';
status = false;
}
if (!SUPPORTED_LANGUAGES.includes(language)) {
message += '\nLanguage must be one of the options';
message += 'Language must be one of the options';
status = false;
}
if (status === false) {
Expand Down Expand Up @@ -278,6 +287,13 @@ class Private {
static selectedTags: string[] = [];
static allTags: string[];

static handleOnBlur(event: Event): void {
const target = event.target as HTMLElement;
if (!target.classList.contains('touched')) {
target.classList.add('touched');
}
}

/**
* Create the node for a rename handler. This is what's creating all of the elements to be displayed.
*/
Expand All @@ -300,13 +316,15 @@ class Private {
name.className = CODE_SNIPPET_DIALOG_INPUT;
name.required = true;
name.pattern = '[a-zA-Z0-9_]+';
name.onblur = Private.handleOnBlur;

const descriptionTitle = document.createElement('label');
descriptionTitle.textContent = 'Description*';
const description = document.createElement('input');
description.className = CODE_SNIPPET_DIALOG_INPUT;
description.required = true;
description.pattern = '[a-zA-Z0-9_ ,.?!]+';
description.onblur = Private.handleOnBlur;

const languageTitle = document.createElement('label');
languageTitle.textContent = 'Language*';
Expand All @@ -316,6 +334,7 @@ class Private {
languageInput.required = true;
const languageOption = document.createElement('datalist');
languageOption.id = 'languages';
languageOption.onblur = Private.handleOnBlur;

SUPPORTED_LANGUAGES.sort();
for (const language of SUPPORTED_LANGUAGES) {
Expand Down
Loading