Skip to content

Commit

Permalink
Merge pull request #9 from fleetbase/dev-v0.2.10
Browse files Browse the repository at this point in the history
v0.2.10
  • Loading branch information
roncodes authored Feb 7, 2024
2 parents c141dfe + 6ee2b39 commit 0f072d5
Show file tree
Hide file tree
Showing 22 changed files with 692 additions and 593 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.2'
extensions: mbstring, xml, gd, zip, pdo_mysql, sockets, intl, bcmath, gmp
coverage: xdebug

Expand All @@ -28,6 +28,9 @@ jobs:
sudo apt-get update
sudo apt-get install -y libzip-dev libgd-dev libfreetype6-dev libjpeg-dev libpng-dev imagemagick libmagickwand-dev libmemcached-dev libgeos-dev libgmp-dev default-mysql-client libicu-dev
- name: Configure Composer Auth for Github
run: composer config --global github-oauth.github.com ${{ secrets._GITHUB_AUTH_TOKEN }}

- name: Validate composer.json and composer.lock
run: composer validate

Expand Down
19 changes: 19 additions & 0 deletions addon/components/widget/storefront-key-metrics.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div class="storefront-key-metrics" ...attributes>
<div class="flex flex-col">
<div class="flex flex-row items-center justify-between px-4 py-2 border dark:border-gray-700 border-gray-200 dark:bg-gray-800 bg-gray-50 rounded-lg shadow-sm">
<span class="text-base font-bold text-black dark:text-gray-100">{{t "storefront.component.widget.key-metrics.title"}}</span>
</div>

<div class="mt-4">
{{#if this.getDashboardMetrics.isRunning}}
<Spinner />
{{else}}
<div class="grid grid-cols-2 lg:grid-cols-12 gap-4">
{{#each-in this.metrics as |title options|}}
<Dashboard::Count @title={{smart-humanize title}} @options={{options}} />
{{/each-in}}
</div>
{{/if}}
</div>
</div>
</div>
73 changes: 73 additions & 0 deletions addon/components/widget/storefront-key-metrics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { task } from 'ember-concurrency-decorators';

export default class WidgetStorefrontKeyMetricsComponent extends Component {
/**
* Inject the fetch service.
*
* @memberof WidgetKeyMetricsComponent
*/
@service fetch;

/**
* Property for loading metrics to.
*
* @memberof WidgetKeyMetricsComponent
*/
@tracked metrics = {};

/**
* Creates an instance of WidgetKeyMetricsComponent.
* @memberof WidgetKeyMetricsComponent
*/
constructor() {
super(...arguments);
this.getDashboardMetrics.perform();
}

/**
* Task which fetches key metrics.
*
* @memberof WidgetKeyMetricsComponent
*/
@task *getDashboardMetrics() {
this.metrics = yield this.fetch.get('metrics', {}, { namespace: 'storefront/int/v1' }).then((response) => {
return this.createMetricsMapFromResponse(response);
});
}

/**
* Creates a map of metrics from the response data. This method organizes the metrics data into a more usable format.
*
* @param {Object} metrics - The metrics object fetched from the server.
* @returns {Object} A map of metrics where each key is a metric name and its value is an object of metric options.
* @memberof WidgetKeyMetricsComponent
*/
createMetricsMapFromResponse(metrics = {}) {
const keys = Object.keys(metrics);
const map = {};

for (let i = 0; i < keys.length; i++) {
const key = keys[i];
map[key] = this.createMetricOptionsHash(key, metrics[key]);
}

return map;
}

/**
* Creates a hash of options for a given metric. Depending on the metric key, it assigns a specific format.
*
* @param {string} key - The key representing the specific metric.
* @param {number} value - The value of the metric.
* @returns {Object} An object containing the metric value and its format.
* @memberof WidgetKeyMetricsComponent
*/
createMetricOptionsHash(key, value) {
const options = { value };

return options;
}
}
4 changes: 2 additions & 2 deletions addon/components/widget/storefront-metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export default class WidgetStorefrontMetricsComponent extends Component {
};

@tracked isLoading = true;
@tracked start = format(startOfMonth(new Date()), 'P');
@tracked end = format(endOfMonth(new Date()), 'P');
@tracked start = format(startOfMonth(new Date()), 'yyyy-MM-dd');
@tracked end = format(endOfMonth(new Date()), 'yyyy-MM-dd');

@computed('args.title') get title() {
return this.args.title || 'This Month';
Expand Down
18 changes: 18 additions & 0 deletions addon/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import loadInitializers from 'ember-load-initializers';
import Resolver from 'ember-resolver';
import config from './config/environment';
import services from '@fleetbase/ember-core/exports/services';
import StorefrontKeyMetricsWidget from './components/widget/storefront-key-metrics';

const { modulePrefix } = config;
const externalRoutes = ['console', 'extensions'];
Expand All @@ -17,6 +18,23 @@ export default class StorefrontEngine extends Engine {
setupExtension = function (app, engine, universe) {
// register menu item in header
universe.registerHeaderMenuItem('Storefront', 'console.storefront', { icon: 'store', priority: 1 });

// widgets for registry
const KeyMetricsWidgetDefinition = {
did: 'storefront-metrics',
name: 'Storefront Metrics',
description: 'Key metrics from Storefront.',
icon: 'store',
component: StorefrontKeyMetricsWidget,
grid_options: { w: 12, h: 7, minW: 8, minH: 7 },
options: {
title: 'Storefront Metrics',
},
};

// register widgets
universe.registerDefaultDashboardWidgets([KeyMetricsWidgetDefinition]);
universe.registerDashboardWidgets([KeyMetricsWidgetDefinition]);
};
}

Expand Down
1 change: 1 addition & 0 deletions addon/templates/networks/index/network.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@
</div>

<div>{{outlet}}</div>
<Spacer @height="300px" />
</Overlay::Body>
</Overlay>
1 change: 1 addition & 0 deletions addon/templates/products/index/category/new.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -296,5 +296,6 @@
</ArrayInput>
</div>
</ContentPanel>
<Spacer @height="300px" />
</Overlay::Body>
</Overlay>
1 change: 1 addition & 0 deletions app/components/widget/storefront-key-metrics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@fleetbase/storefront-engine/components/widget/storefront-key-metrics';
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fleetbase/storefront-api",
"version": "0.2.9",
"version": "0.2.10",
"description": "Headless Commerce & Marketplace Extension for Fleetbase",
"keywords": [
"fleetbase-extension",
Expand All @@ -21,22 +21,22 @@
}
],
"require": {
"php": "^7.4|^8.0",
"fleetbase/core-api": "^1.3.13",
"fleetbase/fleetops-api": "^0.4.4",
"php": "^8.0",
"fleetbase/core-api": "^1.4.0",
"fleetbase/fleetops-api": "^0.4.5",
"geocoder-php/google-maps-places-provider": "^1.4",
"laravel-notification-channels/apn": "^3.8",
"laravel-notification-channels/fcm": "^2.7",
"laravel-notification-channels/apn": "^5.0",
"laravel-notification-channels/fcm": "^4.1",
"laravel-notification-channels/twilio": "^3.3",
"milon/barcode": "^9.0",
"milon/barcode": "^10.0",
"php-http/guzzle7-adapter": "^1.0",
"psr/http-factory-implementation": "*",
"toin0u/geocoder-laravel": "^4.4"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.34.1",
"nunomaduro/collision": "^5.11.0|^6.4.0",
"pestphp/pest": "^1.22.6",
"nunomaduro/collision": "^7.0",
"pestphp/pest": "^2.33.2",
"phpstan/phpstan": "^1.10.38",
"symfony/var-dumper": "^5.4.29"
},
Expand Down
2 changes: 1 addition & 1 deletion extension.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Storefront",
"version": "0.2.9",
"version": "0.2.10",
"description": "Headless Commerce & Marketplace Extension for Fleetbase",
"repository": "https://github.com/fleetbase/storefront",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fleetbase/storefront-engine",
"version": "0.2.9",
"version": "0.2.10",
"description": "Headless Commerce & Marketplace Extension for Fleetbase",
"fleetbase": {
"route": "storefront",
Expand Down Expand Up @@ -43,7 +43,7 @@
"publish:github": "npm config set '@fleetbase:registry' https://npm.pkg.github.com/ && npm publish"
},
"dependencies": {
"@fleetbase/ember-core": "^0.2.0",
"@fleetbase/ember-core": "^0.2.3",
"@fleetbase/ember-ui": "^0.2.10",
"@fleetbase/fleetops-data": "^0.1.8",
"@babel/core": "^7.23.2",
Expand Down
Loading

0 comments on commit 0f072d5

Please sign in to comment.