Add editing index

This commit is contained in:
Stanislav Romanov 2022-08-30 12:48:13 +03:00
parent 105d8617f5
commit cff4a195ba
10 changed files with 102 additions and 0 deletions

View file

@ -0,0 +1,7 @@
<h1 class='text-3xl mb-4'>
{{#if (has-block)}}
{{yield}}
{{else}}
{{@title}}
{{/if}}
</h1>

View file

@ -0,0 +1,14 @@
import Controller from '@ember/controller';
import { action } from '@ember/object';
export default class AdminIndexesItemEditController extends Controller {
@action
save(event) {
event.preventDefault();
const formData = new FormData(event.currentTarget);
const data = Object.fromEntries(formData.entries());
this.model.save(data);
}
}

View file

@ -88,4 +88,11 @@ export default class Index {
// ? Object.keys(this.stats.value.fieldDistribution)
// : [];
// }
save(data) {
return query(this.indexPath, {
method: 'PATCH',
body: JSON.stringify(data),
});
}
}

View file

@ -13,6 +13,7 @@ Router.map(function () {
this.route('settings');
this.route('data');
this.route('info');
this.route('edit');
});
});
this.route('keys', function () {

View file

@ -0,0 +1,7 @@
import Route from '@ember/routing/route';
export default class AdminIndexesItemEditRoute extends Route {
async model() {
return this.modelFor('admin.indexes.item');
}
}

View file

@ -5,6 +5,7 @@
<div class="flex mb-4">
<Tab @route="admin.indexes.item.data" @text="Data" @model={{@model}} />
<Tab @route="admin.indexes.item.info" @text="Info" @model={{@model}} />
<Tab @route="admin.indexes.item.edit" @text="Edit" @model={{@model}} />
{{!-- <Tab @route="admin.indexes.item.settings" @text="Settings" @model={{@model}} /> --}}
</div>

View file

@ -0,0 +1,16 @@
<Headers::H1>Edit {{@model.uid}}</Headers::H1>
<form {{on 'submit' this.save}}>
<InputText
@label='Primary key'
@name='primaryKey'
@value={{@model.primaryKey}}
@required={{true}}
/>
<Button
type='submit'
@text='Save'
@style='primary'
/>
</form>

View file

@ -0,0 +1,26 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'meiliadmin/tests/helpers';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
module('Integration | Component | headers/h1', function (hooks) {
setupRenderingTest(hooks);
test('it renders', async function (assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.set('myAction', function(val) { ... });
await render(hbs`<Headers::H1 />`);
assert.dom(this.element).hasText('');
// Template block usage:
await render(hbs`
<Headers::H1>
template block text
</Headers::H1>
`);
assert.dom(this.element).hasText('template block text');
});
});

View file

@ -0,0 +1,12 @@
import { module, test } from 'qunit';
import { setupTest } from 'meiliadmin/tests/helpers';
module('Unit | Controller | admin/indexes/item/edit', function (hooks) {
setupTest(hooks);
// TODO: Replace this with your real tests.
test('it exists', function (assert) {
let controller = this.owner.lookup('controller:admin/indexes/item/edit');
assert.ok(controller);
});
});

View file

@ -0,0 +1,11 @@
import { module, test } from 'qunit';
import { setupTest } from 'meiliadmin/tests/helpers';
module('Unit | Route | admin/indexes/item/edit', function (hooks) {
setupTest(hooks);
test('it exists', function (assert) {
let route = this.owner.lookup('route:admin/indexes/item/edit');
assert.ok(route);
});
});