kempo-products 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/kempo-config.json +16 -0
- package/package.json +4 -2
- package/public/components/ProductsWidget.js +55 -0
package/README.md
CHANGED
|
@@ -264,3 +264,7 @@ DATABASE_URL=postgresql://kempo:kempo@localhost:5443/kempo_products_test npm tes
|
|
|
264
264
|
```
|
|
265
265
|
|
|
266
266
|
The database tests skip themselves when no database is reachable, and refuse to run unless its name ends in `_test`, because they empty the tables. **A green run with `SKIPPED` did not test the database.**
|
|
267
|
+
|
|
268
|
+
## Dashboard widget
|
|
269
|
+
|
|
270
|
+
Adds a **Products** widget to the kempo admin dashboard showing catalog size, recorded purchases and the latest products, with a **New product** button. It is declared in `widgets` in `kempo-config.json` and registered when the extension is installed or updated; people only see it if they hold its permission, and can hide, reorder or resize it from the dashboard's Customize dialog. Needs a kempo with the dashboard (see kempo's `docs/dashboard.md`); on an older kempo the entry is ignored.
|
package/kempo-config.json
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
3
3
|
"git": "https://github.com/dustinpoissant/kempo-products",
|
|
4
4
|
"public-scope": "products",
|
|
5
5
|
"schema": "./server/db/schema.js",
|
|
6
|
+
"widgets": [
|
|
7
|
+
{
|
|
8
|
+
"key": "catalog",
|
|
9
|
+
"title": "Products",
|
|
10
|
+
"description": "How many products there are, how many purchases were recorded, and the latest products.",
|
|
11
|
+
"icon": "label",
|
|
12
|
+
"element": "k-prod-widget",
|
|
13
|
+
"module": "/products/components/ProductsWidget.js",
|
|
14
|
+
"defaultWidth": 2,
|
|
15
|
+
"defaultHeight": 2,
|
|
16
|
+
"minWidth": 1,
|
|
17
|
+
"minHeight": 2,
|
|
18
|
+
"permission": "products:read",
|
|
19
|
+
"priority": 101
|
|
20
|
+
}
|
|
21
|
+
],
|
|
6
22
|
"permissions": [
|
|
7
23
|
{
|
|
8
24
|
"name": "products:read",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kempo-products",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "A product catalog for kempo cms: browse, filter and inquire about products, with no checkout required",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Dustin Poissant",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"type": "module",
|
|
16
16
|
"main": "sdk.js",
|
|
17
17
|
"scripts": {
|
|
18
|
-
"test": "node --test --test-concurrency=1",
|
|
18
|
+
"test": "node scripts/run-tests.js unit node --test --test-concurrency=1",
|
|
19
|
+
"test:integration": "node scripts/run-tests.js integration node --test --test-concurrency=1",
|
|
19
20
|
"link:local": "npm install ../kempo ../kempo-server ../kempo-ui --no-save --no-legacy-peer-deps --force",
|
|
20
21
|
"docs:build": "node scripts/build-docs.js",
|
|
21
22
|
"docs:dev": "npx kempo-server --root docs --port 4049"
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
}
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
56
|
+
"@electric-sql/pglite": "^0.5.9",
|
|
55
57
|
"drizzle-kit": "^0.31.10",
|
|
56
58
|
"postgres": "^3.4.9",
|
|
57
59
|
"highlight.js": "^11.11.1"
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import DashboardWidget from '/kempo/components/DashboardWidget.js';
|
|
2
|
+
import { html, nothing } from '/kempo-ui/lit-all.min.js';
|
|
3
|
+
import { getProducts, getPurchases } from '/products/sdk.js';
|
|
4
|
+
const stat = (value, label, classes = '') => html`<div class="flex"><div class="h2 m0 ${classes}">${value}</div><div class="small tc-muted">${label}</div></div>`;
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
The catalog size, recorded purchases and the latest products.
|
|
8
|
+
*/
|
|
9
|
+
export default class ProductsWidget extends DashboardWidget {
|
|
10
|
+
static properties = {
|
|
11
|
+
...DashboardWidget.properties,
|
|
12
|
+
total: { state: true },
|
|
13
|
+
purchases: { state: true },
|
|
14
|
+
recent: { state: true }
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
constructor(){
|
|
18
|
+
super();
|
|
19
|
+
this.total = 0;
|
|
20
|
+
this.purchases = 0;
|
|
21
|
+
this.recent = [];
|
|
22
|
+
this.cta = { label: 'New product', icon: 'add', href: '/admin/extension/kempo-products/new', permission: 'products:create' };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/*
|
|
26
|
+
Public Methods
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
load = async () => {
|
|
30
|
+
const [products, purchases] = await Promise.all([
|
|
31
|
+
this.unwrap(getProducts({ limit: 9 })),
|
|
32
|
+
this.unwrap(getPurchases({ limit: 1 }))
|
|
33
|
+
]);
|
|
34
|
+
this.total = products.total;
|
|
35
|
+
this.recent = products.items;
|
|
36
|
+
this.purchases = purchases.total;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/*
|
|
40
|
+
Rendering
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
renderContent(){
|
|
44
|
+
if(!this.total && !this.purchases) return html`<p class="tc-muted">No products yet.</p>`;
|
|
45
|
+
return html`
|
|
46
|
+
<div class="d-f mb">${stat(this.total, 'Products')}${stat(this.purchases, 'Purchases')}</div>
|
|
47
|
+
${this.recent.length ? html`<div class="small tc-muted mbq">Latest</div>` : nothing}
|
|
48
|
+
${this.recent.slice(0, this.height * 2).map(product => html`
|
|
49
|
+
<div class="d-f pyq bb"><span class="flex">${product.name}</span><span class="small tc-muted">${product.status}</span></div>
|
|
50
|
+
`)}
|
|
51
|
+
`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
customElements.define('k-prod-widget', ProductsWidget);
|