forked from projectcaluma/ember-emeis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: extract meta fields rendering into a component (projectcaluma#277)
This also allows usage of meta fields under users Co-authored-by: Akanksh Saxena <[email protected]>
- Loading branch information
Showing
9 changed files
with
82 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{{#each @fields as |field|}} | ||
{{#if field.visible}} | ||
<EditForm::Element @label={{get field.label this.intl.primaryLocale}}> | ||
{{#if (eq field.type "choice")}} | ||
<PowerSelect | ||
@disabled={{field.readOnly}} | ||
@options={{field.options}} | ||
@selected={{find-by "value" (get @model.meta field.slug) @field.options}} | ||
@onChange={{fn this.updateMetaField field @model}} | ||
@placeholder={{concat (get field.label this.intl.primaryLocale) "..."}} | ||
as |option| | ||
> | ||
{{get option.label this.intl.primaryLocale}} | ||
</PowerSelect> | ||
{{/if}} | ||
{{#if (eq field.type "text")}} | ||
<input | ||
class="uk-input" | ||
type="text" | ||
value={{get @model.meta field.slug}} | ||
disabled={{field.readOnly}} | ||
{{on "input" (fn this.updateMetaField field @model)}} | ||
> | ||
{{/if}} | ||
</EditForm::Element> | ||
{{/if}} | ||
{{/each}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { action } from "@ember/object"; | ||
import { inject as service } from "@ember/service"; | ||
import Component from "@glimmer/component"; | ||
|
||
export default class EditFormComponent extends Component { | ||
@service intl; | ||
|
||
@action | ||
updateMetaField(field, model, optionOrEvent) { | ||
const value = optionOrEvent.target?.value ?? optionOrEvent.value; | ||
model.meta = { ...model.meta, [field.slug]: value }; | ||
model.notifyPropertyChange("meta"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "ember-emeis/components/meta-fields"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { render } from "@ember/test-helpers"; | ||
import { hbs } from "ember-cli-htmlbars"; | ||
import { setupRenderingTest } from "ember-qunit"; | ||
import { module, test } from "qunit"; | ||
|
||
module("Integration | Component | meta-fields", function (hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
test("it renders", async function (assert) { | ||
await render(hbs`<MetaFields />`); | ||
|
||
assert.dom(this.element).hasText(""); | ||
}); | ||
}); |