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

Add app config tab #1577

Merged
merged 6 commits into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
22 changes: 22 additions & 0 deletions app/controllers/app-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { computed } from '@ember/object';
import Controller from '@ember/controller';

export default class AppConfigController extends Controller {
get columns() {
return [
{ name: 'Key', valuePath: 'key' },
{ name: 'Value', valuePath: 'value' },
];
}

@computed('model')
get rows() {
return Object.entries(this.get('model')).map(([key, value]) => {
const obj = { key, value };
if (typeof obj.value === 'object') {
obj.value = JSON.stringify(obj.value, null, 2);
}
return obj;
});
}
}
1 change: 1 addition & 0 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Router.map(function () {
this.route('info', { resetNamespace: true }, function () {
this.route('info-index', { path: '/', resetNamespace: true });
this.route('libraries', { resetNamespace: true });
this.route('app-config', { resetNamespace: true });
this.route('whats-new', { resetNamespace: true });
});

Expand Down
15 changes: 15 additions & 0 deletions app/routes/app-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import TabRoute from 'ember-inspector/routes/tab';
import { readOnly } from '@ember/object/computed';
RobbieTheWagner marked this conversation as resolved.
Show resolved Hide resolved

export default TabRoute.extend({

RobbieTheWagner marked this conversation as resolved.
Show resolved Hide resolved
model() {
const port = this.port;
return new Promise((resolve) => {
port.one('general:emberCliConfig', (message) => {
resolve(message.emberCliConfig);
});
port.send('general:getEmberCliConfig');
});
},
});
15 changes: 15 additions & 0 deletions app/templates/app-config.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<EmberTable as |t|>
<t.head @columns={{columns}} @enableReorder={{false}} />

<t.body @rows={{rows}} as |b|>
<b.row
class={{
concat "js-config-row" (if (mod b.rowMeta.index 2) " striped")
}} as |r|
>
<r.cell class={{concat "js-config-" r.columnValue.valuePath}} as |value|>
{{value}}
</r.cell>
</b.row>
</t.body>
</EmberTable>
5 changes: 5 additions & 0 deletions app/templates/info.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
<LinkTo @route="libraries" class="nav__item">
<span class="nav__item-label">Libraries</span>
</LinkTo>
</li>
<li>
<LinkTo @route="app-config" class="nav__item">
<span class="nav__item-label">App Config</span>
</LinkTo>
</li>
<li>
<LinkTo @route="whats-new" class="nav__item">
Expand Down
6 changes: 6 additions & 0 deletions ember_debug/general-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ export default EmberObject.extend(PortMixin, {
this.sendMessage('libraries', { libraries: libraries._registry });
},

getEmberCliConfig() {
this.sendMessage('emberCliConfig', {
emberCliConfig: this.emberCliConfig,
});
},

/**
* Called from the inspector to refresh the inspected app.
* Used in case the inspector was opened late and therefore missed capturing
Expand Down
31 changes: 31 additions & 0 deletions tests/acceptance/info-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,35 @@ module('Info Tab', function (hooks) {
.hasText('Handlebars');
assert.dom(libraries[2].querySelector('.js-lib-version')).hasText('2.1');
});

test('App config is displayed correctly', async function (assert) {
respondWith('general:getEmberCliConfig', {
type: 'general:emberCliConfig',
emberCliConfig: {
modulePrefix: 'extended',
environment: 'production',
},
});

await visit('/info/app-config');

let configs = findAll('.js-config-row');
assert.equal(
configs.length,
2,
'The correct number of configurations is displayed'
);
assert
.dom(configs[0].querySelector('.js-config-key'))
.hasText('modulePrefix');
assert
.dom(configs[0].querySelector('.js-config-value'))
.hasText('extended');
assert
.dom(configs[1].querySelector('.js-config-key'))
.hasText('environment');
assert
.dom(configs[1].querySelector('.js-config-value'))
.hasText('production');
});
});