Renamed snippet.title to snippet.name for consistency

no issue

- all of our models which allow users to name something use `name` as the field descriptor rather than `title` so `snippet.title` was renamed for consistency
- also fixes typo in the plus-menu component that stopped clicking on snippets from working
This commit is contained in:
Kevin Ansfield 2020-10-16 10:15:07 +01:00
parent 5606b9c068
commit 5ecf3872f5
7 changed files with 24 additions and 24 deletions

View File

@ -296,7 +296,7 @@ export default Controller.extend({
return snippetRecord.save().then(() => {
this.notifications.closeAlerts('snippet.save');
this.notifications.showNotification(
`Snippet saved as "${snippet.title}"`,
`Snippet saved as "${snippet.name}"`,
{type: 'success'}
);
return snippetRecord;

View File

@ -4,7 +4,7 @@ import ValidationEngine from 'ghost-admin/mixins/validation-engine';
export default Model.extend(ValidationEngine, {
validationType: 'snippet',
title: attr('string'),
name: attr('string'),
mobiledoc: attr('json-string'),
createdAtUTC: attr('moment-utc'),
updatedAtUTC: attr('moment-utc')

View File

@ -2,14 +2,14 @@ import BaseValidator from './base';
import {isBlank} from '@ember/utils';
export default BaseValidator.create({
properties: ['title', 'mobiledoc'],
properties: ['name', 'mobiledoc'],
title(model) {
if (isBlank(model.get('title'))) {
model.errors.add('title', 'Title cannot be blank');
name(model) {
if (isBlank(model.get('name'))) {
model.errors.add('name', 'Name cannot be blank');
this.invalidate();
}
model.get('hasValidated').addObject('title');
model.get('hasValidated').addObject('name');
},
mobiledoc(model) {

View File

@ -49,10 +49,10 @@ export default Component.extend({
snippets.forEach((snippet) => {
snippetsSection.items.push({
label: snippet.title,
label: snippet.name,
icon: 'koenig/kg-card-type-bookmark',
type: 'snippet',
matches: [snippet.title.toLowerCase()]
matches: [snippet.name.toLowerCase()]
});
});
@ -127,8 +127,8 @@ export default Component.extend({
this.replaceWithCardSection(item.replaceArg, range, item.payload);
}
if (item.tpye === 'snippet') {
let clickedSnippet = this.snippets.find(snippet => snippet.title === item.label);
if (item.type === 'snippet') {
let clickedSnippet = this.snippets.find(snippet => snippet.name === item.label);
if (clickedSnippet) {
let post = mobiledocParsers.parse(this.editor.builder, clickedSnippet.mobiledoc);
this.replaceWithPost(range, post);

View File

@ -68,10 +68,10 @@ export default class KoenigSlashMenuComponent extends Component {
snippets.forEach((snippet) => {
snippetsSection.items.push({
label: snippet.title,
label: snippet.name,
icon: 'koenig/kg-card-type-bookmark',
type: 'snippet',
matches: [snippet.title.toLowerCase()]
matches: [snippet.name.toLowerCase()]
});
});
@ -178,9 +178,9 @@ export default class KoenigSlashMenuComponent extends Component {
}
if (item.type === 'snippet') {
const clickedSnippet = this.args.snippets.find(snippet => snippet.title === item.label);
let clickedSnippet = this.args.snippets.find(snippet => snippet.name === item.label);
if (clickedSnippet) {
const post = mobiledocParsers.parse(this.args.editor.builder, clickedSnippet.mobiledoc);
let post = mobiledocParsers.parse(this.args.editor.builder, clickedSnippet.mobiledoc);
this.args.replaceWithPost(range, post);
}
}

View File

@ -1,10 +1,10 @@
<div class="kg-input-bar absolute z-999" style={{this.style}} {{did-insert this.registerAndPositionElement}} ...attributes>
<input
placeholder="Snippet title"
value={{this.title}}
placeholder="Snippet name"
value={{this.name}}
class="kg-link-input pa2 pr6 mih-100 ba br3 shadow-2 f8 lh-heading tracked-2 outline-0 b--blue h10 nudge-top--8"
{{on "input" this.titleInput}}
{{on "keydown" this.titleKeydown}}
{{on "input" this.nameInput}}
{{on "keydown" this.nameKeydown}}
{{did-insert this.focusInput}}
/>
</div>

View File

@ -11,7 +11,7 @@ import {tracked} from '@glimmer/tracking';
const TICK_ADJUSTMENT = 8;
export default class KoenigSnippetInputComponent extends Component {
@tracked title = '';
@tracked name = '';
@tracked style = ''.htmlSafe();
constructor() {
@ -64,7 +64,7 @@ export default class KoenigSnippetInputComponent extends Component {
}
@action
titleKeydown(event) {
nameKeydown(event) {
if (event.key === 'Enter') {
// prevent Enter from triggering in the editor and removing text
event.preventDefault();
@ -74,7 +74,7 @@ export default class KoenigSnippetInputComponent extends Component {
let mobiledoc = editor.serializePost(editor.post.trimTo(snippetRange), 'mobiledoc');
this.args.save({
title: event.target.value,
name: event.target.value,
mobiledoc
}).then(() => {
this.args.cancel();
@ -83,8 +83,8 @@ export default class KoenigSnippetInputComponent extends Component {
}
@action
titleInput(event) {
this.title = event.target.value;
nameInput(event) {
this.name = event.target.value;
}
// TODO: largely shared with {{koenig-toolbar}} and {{koenig-link-input}} - extract to a shared util?