Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.2.7 #36

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions addon/utils/apply-context-component-arguments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import getModelName from '@fleetbase/ember-core/utils/get-model-name';
import isModel from '@fleetbase/ember-core/utils/is-model';
import { camelize } from '@ember/string';

/**
* Applies context and dynamic arguments to a given component.
*
* @param {Component} component - The component to which context and arguments will be applied.
*/
export default function applyContextComponentArguments(component) {
const { context, dynamicArgs = {} } = component.args;

// Apply context model if available
if (context && isModel(context)) {
const contextModelName = camelize(getModelName(context));
if (contextModelName) {
component[contextModelName] = context;
}
}

// Execute any apply callback present in dynamic arguments
const { applyCallback } = dynamicArgs;
if (typeof applyCallback === 'function') {
applyCallback(component);
}

// Apply other dynamic arguments to the component
for (const [key, value] of Object.entries(dynamicArgs)) {
if (key !== 'applyCallback') {
component[key] = value;
}
}
}
16 changes: 16 additions & 0 deletions addon/utils/context-component-callback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default function contextComponentCallback(component, name, ...params) {
let callbackInvoked = false;

if (typeof component.args[name] === 'function') {
component.args[name](...params);
callbackInvoked = true;
}

// now do for context options
if (typeof component.args.options === 'object' && typeof component.args.options[name] === 'function') {
component.args.options[name](...params);
callbackInvoked = true;
}

return callbackInvoked;
}
1 change: 1 addition & 0 deletions app/utils/apply-context-component-arguments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@fleetbase/ember-core/utils/apply-context-component-arguments';
1 change: 1 addition & 0 deletions app/utils/context-component-callback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@fleetbase/ember-core/utils/context-component-callback';
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fleetbase/ember-core",
"version": "0.2.6",
"version": "0.2.7",
"description": "Provides all the core services, decorators and utilities for building a Fleetbase extension for the Console.",
"keywords": [
"fleetbase-core",
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/utils/apply-context-component-arguments-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import applyContextComponentArguments from 'dummy/utils/apply-context-component-arguments';
import { module, test } from 'qunit';

module('Unit | Utility | apply-context-component-arguments', function () {
// TODO: Replace this with your real tests.
test('it works', function (assert) {
let result = applyContextComponentArguments();
assert.ok(result);
});
});
10 changes: 10 additions & 0 deletions tests/unit/utils/context-component-callback-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import contextComponentCallback from 'dummy/utils/context-component-callback';
import { module, test } from 'qunit';

module('Unit | Utility | context-component-callback', function () {
// TODO: Replace this with your real tests.
test('it works', function (assert) {
let result = contextComponentCallback();
assert.ok(result);
});
});
Loading