diff --git a/app/common.js b/app/common.js deleted file mode 100644 index 56c8faa..0000000 --- a/app/common.js +++ /dev/null @@ -1,177 +0,0 @@ -// import { dasherize } from '@ember/string'; -// // import { languages } from 'monaco-editor/esm/vs/editor/editor.api.js'; - -// const urlSettingsPrefix = 'https://docs.meilisearch.com/reference/api/settings'; - -// export const indexSettings = [ -// { -// name: 'displayedAttributes', -// schema: { -// type: 'array', -// items: { -// type: 'string', -// }, -// uniqueItems: true, -// }, -// }, -// { -// name: 'distinctAttribute', -// schema: { -// type: ['string', 'null'], -// }, -// }, -// { -// name: 'faceting', -// schema: { -// type: 'object', -// properties: { -// maxValuesPerFacet: { -// type: 'integer', -// }, -// }, -// required: ['maxValuesPerFacet'], -// additionalProperties: false, -// }, -// }, -// { -// name: 'filterableAttributes', -// schema: { -// type: 'array', -// items: { -// type: 'string', -// }, -// uniqueItems: true, -// }, -// }, -// { -// name: 'pagination', -// schema: { -// type: 'object', -// properties: { -// maxTotalHits: { -// type: 'integer', -// }, -// }, -// required: ['maxTotalHits'], -// additionalProperties: false, -// }, -// }, -// { -// name: 'rankingRules', -// schema: { -// type: 'array', -// items: { -// type: 'string', -// }, -// uniqueItems: true, -// }, -// }, -// { -// name: 'searchableAttributes', -// schema: { -// type: 'array', -// items: { -// type: 'string', -// }, -// uniqueItems: true, -// }, -// }, -// { -// name: 'sortableAttributes', -// schema: { -// type: 'array', -// items: { -// type: 'string', -// }, -// uniqueItems: true, -// }, -// }, -// { -// name: 'stopWords', -// schema: { -// type: 'array', -// items: { -// type: 'string', -// }, -// uniqueItems: true, -// }, -// }, -// { -// name: 'synonyms', -// schema: { -// type: 'object', -// additionalProperties: { -// type: 'array', -// items: { -// type: 'string', -// }, -// uniqueItems: true, -// }, -// }, -// }, -// { -// name: 'typoTolerance', -// schema: { -// type: 'object', -// properties: { -// enabled: { -// type: 'boolean', -// }, -// minWordSizeForTypos: { -// type: 'object', -// properties: { -// oneTypo: { type: 'integer' }, -// twoTypos: { type: 'integer' }, -// }, -// additionalProperties: false, -// }, -// disableOnWords: { -// type: 'array', -// items: { -// type: 'string', -// }, -// uniqueItems: true, -// }, -// disableOnAttributes: { -// type: 'array', -// items: { -// type: 'string', -// }, -// uniqueItems: true, -// }, -// }, -// additionalProperties: false, -// }, -// }, -// ].map((item) => { -// item.uri = item.schema.$id = `${urlSettingsPrefix}/${dasherize(item.name)}`; -// item.fileMatch = [item.uri]; - -// return item; -// }); - -// const allSettings = { -// name: 'allSettings', -// uri: urlSettingsPrefix, -// fileMatch: [urlSettingsPrefix], -// schema: { -// $id: urlSettingsPrefix, -// type: 'object', -// properties: indexSettings.reduce((properties, item) => { -// properties[item.name] = { -// $ref: item.schema.$id, -// }; - -// return properties; -// }, {}), -// additionalProperties: false, -// }, -// }; - -// indexSettings.unshift(allSettings); - -// // TODO: do it async, not in main stream -// // languages.json.jsonDefaults.setDiagnosticsOptions({ -// // validate: true, -// // schemas: indexSettings, -// // }); diff --git a/app/components/index-setting.hbs b/app/components/index-setting.hbs index bada591..a4f235c 100644 --- a/app/components/index-setting.hbs +++ b/app/components/index-setting.hbs @@ -4,7 +4,7 @@ {{did-update this.setValue @setting}} > {{! TODO: add link to meilisearch's documentation }} - + diff --git a/app/components/index-setting.js b/app/components/index-setting.js index e555e38..c7c1134 100644 --- a/app/components/index-setting.js +++ b/app/components/index-setting.js @@ -3,53 +3,56 @@ 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; @tracked value; - @tracked error; + @tracked errors = []; constructor() { 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 save(newValue) { - this.error = null; + this.errors = []; try { return this.args.index .updateSetting(JSON.parse(newValue), this.args.setting.name) .then(this.toaster.taskToast); } catch (error) { - this.error = error.error || error; + this.errors = [error.error || error]; } } @action async setValue() { this.value = await this.args.index.getSetting(this.args.setting.name); - this.error = null; + this.error = []; } @action reset() { - this.error = null; + this.error = []; try { return this.args.index .resetSetting(this.args.setting.name) .then(this.toaster.taskToast); } catch (error) { - this.error = error.error || error; + this.errors = [error.error || error]; } } - - @action - onDidChangeValidation(error) { - this.error = error; - } } diff --git a/app/components/monaco-editor.js b/app/components/monaco-editor.js index ac61fa0..d4950e3 100644 --- a/app/components/monaco-editor.js +++ b/app/components/monaco-editor.js @@ -82,15 +82,6 @@ export default class MonacoEditorComponent extends Component { } ); registerDestructor(this, onDidContentSizeChangeHandler.dispose); - - // const onDidChangeMarkersHandler = editor.onDidChangeMarkers((uris) => { - // const error = uris.find((item) => item.toString() === this.args.uri); - - // this.args.onDidChangeValidation?.( - // error ? 'Error: the value is invalid' : false - // ); - // }); - // registerDestructor(this, onDidChangeMarkersHandler.dispose); } @action diff --git a/app/models/index.js b/app/models/index.js index 83d6e9d..048f3a4 100644 --- a/app/models/index.js +++ b/app/models/index.js @@ -1,12 +1,8 @@ import query from '../utils/query'; import Document from './document'; import { dasherize } from '@ember/string'; -import { indexSettings, allIndexSettings } from '../common'; export default class Index { - settings = indexSettings; - allSettings = allIndexSettings; - constructor(data = {}) { for (const key in data) { this[key] = data[key]; diff --git a/app/routes/admin/indexes/item/settings.js b/app/routes/admin/indexes/item/settings.js index e90e73c..6597900 100644 --- a/app/routes/admin/indexes/item/settings.js +++ b/app/routes/admin/indexes/item/settings.js @@ -143,18 +143,11 @@ export const settings = [ additionalProperties: false, }, }, -].map((item) => { - item.uri = item.schema.$id = `${urlSettingsPrefix}/${dasherize(item.name)}`; - item.fileMatch = [item.uri]; - - return item; -}); +]; +// All settings settings.unshift({ - uri: urlSettingsPrefix, - fileMatch: [urlSettingsPrefix], schema: { - $id: urlSettingsPrefix, type: 'object', properties: settings.reduce((properties, item) => { properties[item.name] = item.schema; @@ -165,6 +158,19 @@ settings.unshift({ }, }); +settings.forEach((item) => { + let uri = urlSettingsPrefix; + + if (item.name) { + uri += `/${dasherize(item.name)}`; + } + + item.uri = item.schema.$id = uri; + item.fileMatch = [uri]; + + return item; +}); + export default class AdminIndexesItemSettingsRoute extends Route { model() { const index = this.modelFor('admin.indexes.item');