Add validation
This commit is contained in:
parent
8fdd973a00
commit
cc252f0ebc
10 changed files with 124 additions and 20 deletions
|
|
@ -12,6 +12,7 @@
|
|||
@schema={{@setting}}
|
||||
@sendValue={{this.save}}
|
||||
@invoker={{this.invoker}}
|
||||
@onDidValidation={{set this 'errors'}}
|
||||
class='h-40'
|
||||
/>
|
||||
</Form::Element>
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ import { action } from '@ember/object';
|
|||
import { tracked } from '@glimmer/tracking';
|
||||
import ActionInvoker from '../lib/action-invoker';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { editor } from 'monaco-editor/esm/vs/editor/editor.api.js';
|
||||
import { registerDestructor } from '@ember/destroyable';
|
||||
|
||||
export default class FormIndexSettingComponent extends Component {
|
||||
@service toaster;
|
||||
|
|
@ -16,12 +14,6 @@ export default class FormIndexSettingComponent extends Component {
|
|||
super(...arguments);
|
||||
|
||||
this.invoker = new ActionInvoker();
|
||||
|
||||
// Checking errors
|
||||
const onDidChangeMarkersHandler = editor.onDidChangeMarkers(() => {
|
||||
this.errors = editor.getModelMarkers().map((item) => item.message);
|
||||
});
|
||||
registerDestructor(this, onDidChangeMarkersHandler.dispose);
|
||||
}
|
||||
|
||||
@action
|
||||
|
|
@ -40,12 +32,12 @@ export default class FormIndexSettingComponent extends Component {
|
|||
@action
|
||||
async setValue() {
|
||||
this.value = await this.args.index.getSetting(this.args.setting.name);
|
||||
this.error = [];
|
||||
this.errors = [];
|
||||
}
|
||||
|
||||
@action
|
||||
reset() {
|
||||
this.error = [];
|
||||
this.errors = [];
|
||||
|
||||
try {
|
||||
return this.args.index
|
||||
|
|
|
|||
|
|
@ -82,6 +82,14 @@ export default class MonacoEditorComponent extends Component {
|
|||
}
|
||||
);
|
||||
registerDestructor(this, onDidContentSizeChangeHandler.dispose);
|
||||
|
||||
// Validation
|
||||
const onDidChangeMarkersHandler = editor.onDidChangeMarkers(() => {
|
||||
this.args.onDidValidation?.(
|
||||
editor.getModelMarkers().map((item) => item.message)
|
||||
);
|
||||
});
|
||||
registerDestructor(this, onDidChangeMarkersHandler.dispose);
|
||||
}
|
||||
|
||||
@action
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ export default class AdminIndexesItemDocumentsDocumentEditController extends Con
|
|||
@service router;
|
||||
@service toaster;
|
||||
|
||||
@tracked error;
|
||||
@tracked errors = [];
|
||||
@tracked isSaving;
|
||||
|
||||
constructor() {
|
||||
|
|
@ -19,7 +19,7 @@ export default class AdminIndexesItemDocumentsDocumentEditController extends Con
|
|||
|
||||
@action
|
||||
async save(value) {
|
||||
this.error = null;
|
||||
this.errors = [];
|
||||
|
||||
this.isSaving = true;
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ export default class AdminIndexesItemDocumentsDocumentEditController extends Con
|
|||
|
||||
this.toaster.taskToast(task);
|
||||
} catch (error) {
|
||||
this.error = error.error || error;
|
||||
this.errors = [error.error || error];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ export default class AdminKeysKeyEditController extends Controller {
|
|||
@service router;
|
||||
@service toaster;
|
||||
|
||||
@tracked error;
|
||||
@tracked errors;
|
||||
@tracked isSaving;
|
||||
|
||||
constructor() {
|
||||
|
|
@ -21,7 +21,7 @@ export default class AdminKeysKeyEditController extends Controller {
|
|||
async save(value) {
|
||||
const isNew = this.model.isNew;
|
||||
|
||||
this.error = null;
|
||||
this.errors = [];
|
||||
this.isSaving = true;
|
||||
|
||||
try {
|
||||
|
|
@ -37,7 +37,7 @@ export default class AdminKeysKeyEditController extends Controller {
|
|||
|
||||
await this.router.transitionTo('admin.keys.key.index', key.uid);
|
||||
} catch (error) {
|
||||
this.error = error.error || error;
|
||||
this.errors = [error.error || error];
|
||||
} finally {
|
||||
this.isSaving = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,20 @@ export default class Index {
|
|||
return Boolean(!this.uid);
|
||||
}
|
||||
|
||||
get documentSetting() {
|
||||
const uri = 'https://docs.meilisearch.com/reference/api/documents';
|
||||
|
||||
return {
|
||||
uri: uri,
|
||||
fileMatch: [uri],
|
||||
schema: {
|
||||
$id: uri,
|
||||
type: 'object',
|
||||
required: [this.primaryKey],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: replace to getSetting
|
||||
getSortableAttributes() {
|
||||
return query(`${this.path}/settings/sortable-attributes`);
|
||||
|
|
|
|||
|
|
@ -33,6 +33,90 @@ export default class Key {
|
|||
);
|
||||
}
|
||||
|
||||
get setting() {
|
||||
const uri = 'https://docs.meilisearch.com/reference/api/keys';
|
||||
const required = this.isNew ? ['actions', 'indexes', 'expiresAt'] : [];
|
||||
|
||||
return {
|
||||
uri: uri,
|
||||
fileMatch: [uri],
|
||||
schema: {
|
||||
$id: uri,
|
||||
type: 'object',
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
actions: {
|
||||
type: 'array',
|
||||
// enum: [
|
||||
// '*',
|
||||
// 'search',
|
||||
|
||||
// 'documents.*',
|
||||
// 'documents.add',
|
||||
// 'documents.get',
|
||||
// 'documents.delete',
|
||||
|
||||
// 'indexes.*',
|
||||
// 'indexes.create',
|
||||
// 'indexes.get',
|
||||
// 'indexes.update',
|
||||
// 'indexes.delete',
|
||||
|
||||
// 'tasks.*',
|
||||
// 'tasks.get',
|
||||
|
||||
// 'settings.*',
|
||||
// 'settings.get',
|
||||
// 'settings.update',
|
||||
|
||||
// 'stats.*',
|
||||
// 'stats.get',
|
||||
|
||||
// 'dumps.*',
|
||||
// 'dumps.create',
|
||||
|
||||
// 'version',
|
||||
|
||||
// 'keys.*',
|
||||
// 'keys.get',
|
||||
// 'keys.create',
|
||||
// 'keys.update',
|
||||
// 'keys.delete',
|
||||
// ],
|
||||
items: {
|
||||
type: 'string',
|
||||
},
|
||||
uniqueItems: true,
|
||||
minItems: 1,
|
||||
},
|
||||
indexes: {
|
||||
oneOf: [
|
||||
{ type: 'array', enum: ['*'] },
|
||||
{
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
},
|
||||
uniqueItems: true,
|
||||
minItems: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
expiresAt: {
|
||||
type: ['null', 'date-time'],
|
||||
},
|
||||
name: {
|
||||
type: ['null', 'string'],
|
||||
},
|
||||
description: {
|
||||
type: ['null', 'string'],
|
||||
},
|
||||
},
|
||||
required,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
save(data) {
|
||||
const path = this.isNew ? 'keys' : this.path;
|
||||
const method = this.isNew ? 'POST' : 'PATCH';
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@ import Route from '@ember/routing/route';
|
|||
import { dasherize } from '@ember/string';
|
||||
|
||||
const urlSettingsPrefix = 'https://docs.meilisearch.com/reference/api/settings';
|
||||
|
||||
export const settings = [
|
||||
const settings = [
|
||||
{
|
||||
name: 'displayedAttributes',
|
||||
schema: {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
<div class='mb-4'>
|
||||
<Form::Element @errors={{array this.error}}>
|
||||
<Form::Element @errors={{this.errors}}>
|
||||
<MonacoEditor
|
||||
@value={{json-stringify @model.document}}
|
||||
@uri={{@model.index.documentSetting.uri}}
|
||||
@language='json'
|
||||
@schema={{@model.index.documentSetting}}
|
||||
@sendValue={{this.save}}
|
||||
@invoker={{this.invoker}}
|
||||
@onDidValidation={{set this 'errors'}}
|
||||
/>
|
||||
</Form::Element>
|
||||
|
||||
|
|
|
|||
|
|
@ -3,12 +3,15 @@
|
|||
{{/if}}
|
||||
|
||||
<div class='mb-4'>
|
||||
<Form::Element @errors={{array this.error}}>
|
||||
<Form::Element @errors={{this.errors}}>
|
||||
<MonacoEditor
|
||||
@value={{json-stringify @model.editablePayload}}
|
||||
@uri={{@model.setting.uri}}
|
||||
@language='json'
|
||||
@schema={{@model.setting}}
|
||||
@sendValue={{this.save}}
|
||||
@invoker={{this.invoker}}
|
||||
@onDidValidation={{set this 'errors'}}
|
||||
/>
|
||||
</Form::Element>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue