Skip to content

Commit 65852df

Browse files
authored
Merge pull request #175 from Foxy/beta
chore: release 1.31.0
2 parents 2323b1d + a1c907e commit 65852df

File tree

27 files changed

+3385
-3164
lines changed

27 files changed

+3385
-3164
lines changed

custom-elements.json

Lines changed: 72 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16812,23 +16812,24 @@
1681216812
"attributes": [
1681316813
{
1681416814
"name": "customer-addresses",
16815-
"type": "string",
1681616815
"deprecatedMessage": "Link to the collection of customer addresses that can be used with this item."
1681716816
},
1681816817
{
1681916818
"name": "item-categories",
16820-
"description": "Link to the collection of item categories that can be used with this item.",
16821-
"type": "string"
16819+
"description": "Link to the collection of item categories that can be used with this item."
1682216820
},
1682316821
{
1682416822
"name": "locale-codes",
1682516823
"description": "Link to the `fx:locale_codes` property helper for currency formatting."
1682616824
},
1682716825
{
1682816826
"name": "coupons",
16829-
"type": "string",
1683016827
"deprecatedMessage": "Link to the collection of coupons that can be used with this item."
1683116828
},
16829+
{
16830+
"name": "store",
16831+
"description": "Link to `fx:store` this item belongs to."
16832+
},
1683216833
{
1683316834
"name": "simplify-ns-loading",
1683416835
"type": "boolean",
@@ -16919,14 +16920,12 @@
1691916920
{
1692016921
"name": "customerAddresses",
1692116922
"attribute": "customer-addresses",
16922-
"type": "string",
1692316923
"deprecatedMessage": "Link to the collection of customer addresses that can be used with this item."
1692416924
},
1692516925
{
1692616926
"name": "itemCategories",
1692716927
"attribute": "item-categories",
16928-
"description": "Link to the collection of item categories that can be used with this item.",
16929-
"type": "string"
16928+
"description": "Link to the collection of item categories that can be used with this item."
1693016929
},
1693116930
{
1693216931
"name": "localeCodes",
@@ -16936,9 +16935,13 @@
1693616935
{
1693716936
"name": "coupons",
1693816937
"attribute": "coupons",
16939-
"type": "string",
1694016938
"deprecatedMessage": "Link to the collection of coupons that can be used with this item."
1694116939
},
16940+
{
16941+
"name": "store",
16942+
"attribute": "store",
16943+
"description": "Link to `fx:store` this item belongs to."
16944+
},
1694216945
{
1694316946
"name": "simplifyNsLoading",
1694416947
"attribute": "simplify-ns-loading",
@@ -21153,6 +21156,14 @@
2115321156
"path": "./src/elements/public/PaymentsApiPaymentMethodForm/index.ts",
2115421157
"description": "Form element for the `fx:payment_method` resource of Payments API.\n\n_Payments API is a client-side virtual API layer built on top of hAPI\nin an attempt to streamline access to stores' payment method settings\nthat is currently a bit quirky due to the legacy functionality. To use\nthis element with hAPI, wrap it into a foxy-payments-api node._",
2115521158
"attributes": [
21159+
{
21160+
"name": "payment-preset",
21161+
"description": "URL of the linked `fx:payment_preset` resource from the virtual Payments API."
21162+
},
21163+
{
21164+
"name": "store",
21165+
"description": "URL of the linked `fx:store` resource."
21166+
},
2115621167
{
2115721168
"name": "simplify-ns-loading",
2115821169
"type": "boolean",
@@ -21240,10 +21251,20 @@
2124021251
}
2124121252
],
2124221253
"properties": [
21254+
{
21255+
"name": "paymentPreset",
21256+
"attribute": "payment-preset",
21257+
"description": "URL of the linked `fx:payment_preset` resource from the virtual Payments API."
21258+
},
2124321259
{
2124421260
"name": "getImageSrc",
2124521261
"description": "A function that returns a URL of a payment method icon based on the given type."
2124621262
},
21263+
{
21264+
"name": "store",
21265+
"attribute": "store",
21266+
"description": "URL of the linked `fx:store` resource."
21267+
},
2124721268
{
2124821269
"name": "simplifyNsLoading",
2124921270
"attribute": "simplify-ns-loading",
@@ -24519,19 +24540,23 @@
2451924540
},
2452024541
{
2452124542
"name": "store-versions",
24522-
"description": "URL of the `fx:store_versions` property helper resource."
24543+
"description": "URL of the `fx:store_versions` property helper resource.",
24544+
"deprecatedMessage": "All elements in this library are designed to work with store version 2.0."
2452324545
},
2452424546
{
2452524547
"name": "checkout-types",
24526-
"description": "URL of the `fx:checkout_types` property helper resource."
24548+
"description": "URL of the `fx:checkout_types` property helper resource.",
24549+
"deprecatedMessage": "Checkout type is effectively controlled by the default template config."
2452724550
},
2452824551
{
2452924552
"name": "locale-codes",
24530-
"description": "URL of the `fx:locale_codes` property helper resource."
24553+
"description": "URL of the `fx:locale_codes` property helper resource.",
24554+
"deprecatedMessage": "Default locale code is effectively controlled by the active template set."
2453124555
},
2453224556
{
2453324557
"name": "languages",
24534-
"description": "URL of the `fx:languages` property helper resource."
24558+
"description": "URL of the `fx:languages` property helper resource.",
24559+
"deprecatedMessage": "Default language is effectively controlled by the active template set."
2453524560
},
2453624561
{
2453724562
"name": "timezones",
@@ -24645,22 +24670,26 @@
2464524670
{
2464624671
"name": "storeVersions",
2464724672
"attribute": "store-versions",
24648-
"description": "URL of the `fx:store_versions` property helper resource."
24673+
"description": "URL of the `fx:store_versions` property helper resource.",
24674+
"deprecatedMessage": "All elements in this library are designed to work with store version 2.0."
2464924675
},
2465024676
{
2465124677
"name": "checkoutTypes",
2465224678
"attribute": "checkout-types",
24653-
"description": "URL of the `fx:checkout_types` property helper resource."
24679+
"description": "URL of the `fx:checkout_types` property helper resource.",
24680+
"deprecatedMessage": "Checkout type is effectively controlled by the default template config."
2465424681
},
2465524682
{
2465624683
"name": "localeCodes",
2465724684
"attribute": "locale-codes",
24658-
"description": "URL of the `fx:locale_codes` property helper resource."
24685+
"description": "URL of the `fx:locale_codes` property helper resource.",
24686+
"deprecatedMessage": "Default locale code is effectively controlled by the active template set."
2465924687
},
2466024688
{
2466124689
"name": "languages",
2466224690
"attribute": "languages",
24663-
"description": "URL of the `fx:languages` property helper resource."
24691+
"description": "URL of the `fx:languages` property helper resource.",
24692+
"deprecatedMessage": "Default language is effectively controlled by the active template set."
2466424693
},
2466524694
{
2466624695
"name": "timezones",
@@ -28290,6 +28319,10 @@
2829028319
"name": "payment-gateways-helper",
2829128320
"description": "URL of the `fx:payment_gateways` property helper resource."
2829228321
},
28322+
{
28323+
"name": "locale-codes",
28324+
"description": "Link to the `fx:locale_codes` property helper for currency formatting."
28325+
},
2829328326
{
2829428327
"name": "simplify-ns-loading",
2829528328
"type": "boolean",
@@ -28387,6 +28420,11 @@
2838728420
"attribute": "payment-gateways-helper",
2838828421
"description": "URL of the `fx:payment_gateways` property helper resource."
2838928422
},
28423+
{
28424+
"name": "localeCodes",
28425+
"attribute": "locale-codes",
28426+
"description": "Link to the `fx:locale_codes` property helper for currency formatting."
28427+
},
2839028428
{
2839128429
"name": "getSubscriptionPageHref"
2839228430
},
@@ -30292,6 +30330,10 @@
3029230330
"path": "./src/elements/public/WebhookCard/index.ts",
3029330331
"description": "Basic card displaying webhook (`fx:webhook`) info.",
3029430332
"attributes": [
30333+
{
30334+
"name": "resource-uri",
30335+
"description": "Optional URI of a transaction, customer or subscription. When provided,\nthe form will display logs and statuses for that particular resource only."
30336+
},
3029530337
{
3029630338
"name": "simplify-ns-loading",
3029730339
"type": "boolean",
@@ -30342,6 +30384,11 @@
3034230384
}
3034330385
],
3034430386
"properties": [
30387+
{
30388+
"name": "resourceUri",
30389+
"attribute": "resource-uri",
30390+
"description": "Optional URI of a transaction, customer or subscription. When provided,\nthe form will display logs and statuses for that particular resource only."
30391+
},
3034530392
{
3034630393
"name": "simplifyNsLoading",
3034730394
"attribute": "simplify-ns-loading",
@@ -30463,6 +30510,10 @@
3046330510
"path": "./src/elements/public/WebhookForm/index.ts",
3046430511
"description": "Form element for creating or editing webhooks (`fx:webhook`).",
3046530512
"attributes": [
30513+
{
30514+
"name": "resource-uri",
30515+
"description": "Optional URI of a transaction, customer or subscription. When provided,\nthe form will display logs and statuses for that particular resource only."
30516+
},
3046630517
{
3046730518
"name": "simplify-ns-loading",
3046830519
"type": "boolean",
@@ -30550,6 +30601,11 @@
3055030601
}
3055130602
],
3055230603
"properties": [
30604+
{
30605+
"name": "resourceUri",
30606+
"attribute": "resource-uri",
30607+
"description": "Optional URI of a transaction, customer or subscription. When provided,\nthe form will display logs and statuses for that particular resource only."
30608+
},
3055330609
{
3055430610
"name": "simplifyNsLoading",
3055530611
"attribute": "simplify-ns-loading",

src/elements/internal/InternalAsyncListControl/InternalAsyncListControl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ export class InternalAsyncListControl extends InternalEditableControl {
307307
>
308308
</foxy-internal-confirm-dialog>
309309
`}
310-
<div class="flex gap-m items-center justify-between mb-xs text-s font-medium">
311-
<span class="text-secondary mr-auto">
310+
<div class="flex gap-m items-center justify-between mb-s text-l font-medium">
311+
<span class="text-body mr-auto">
312312
${this.label && this.label !== 'label' ? this.label : ''}
313313
</span>
314314

src/elements/internal/InternalAsyncResourceLinkListControl/InternalAsyncResourceLinkListControl.ts

Lines changed: 61 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import type { CSSResultArray, PropertyDeclarations } from 'lit-element';
22
import type { CheckboxElement } from '@vaadin/vaadin-checkbox';
33
import type { TemplateResult } from 'lit-html';
44
import type { ItemRenderer } from '../../public/CollectionPage/types';
5+
import type { Collection } from './types';
56

67
import { InternalEditableControl } from '../InternalEditableControl/InternalEditableControl';
78
import { NucleonElement } from '../../public/NucleonElement/NucleonElement';
8-
import { getResourceId } from '@foxy.io/sdk/core';
99
import { ifDefined } from 'lit-html/directives/if-defined';
1010
import { classMap } from '../../../utils/class-map';
1111
import { html } from 'lit-html';
@@ -85,53 +85,31 @@ export class InternalAsyncResourceLinkListControl extends InternalEditableContro
8585
`;
8686

8787
if (!ctx.href || ctx.href.startsWith('foxy://')) return wrap(render(ctx));
88-
let linkHref: string | undefined;
89-
const id = getResourceId(ctx.data?._links.self.href ?? '');
88+
if (this.readonly) return wrap(render(ctx));
9089

91-
try {
92-
const url = new URL(this.linksHref ?? '');
93-
url.searchParams.set(this.foreignKeyForId ?? '', String(id ?? ''));
94-
url.searchParams.set('limit', '1');
95-
linkHref = url.toString();
96-
} catch {
97-
linkHref = undefined;
98-
}
99-
100-
const content = html`
101-
<foxy-nucleon
102-
infer=""
103-
href=${ifDefined(linkHref)}
104-
id="link-${id}"
105-
@update=${() => this.requestUpdate()}
106-
>
107-
${render(ctx)}
108-
</foxy-nucleon>
109-
`;
110-
111-
if (this.readonly) return wrap(content);
90+
const foreignKeyForUri = this.foreignKeyForUri;
91+
const linkResource = foreignKeyForUri
92+
? this.__allLinks?.find(link => link[foreignKeyForUri] === ctx.href)
93+
: undefined;
11294

113-
const nucleon = this.renderRoot.querySelector(`#link-${id}`) as NucleonElement<any> | null;
114-
const checked = !!nucleon?.data?.returned_items;
115-
const isDisabled = this.disabled || !nucleon?.in('idle') || this.__isFetching;
95+
const isDisabled = this.disabled || !this.__allLinks || this.__isFetching;
11696

11797
return wrap(html`
11898
<vaadin-checkbox
11999
class="block"
120100
?disabled=${isDisabled}
121-
?checked=${checked}
101+
?checked=${!!linkResource}
122102
@change=${(evt: CustomEvent) => {
123103
const target = evt.currentTarget as CheckboxElement;
124104
if (target.checked) {
125105
this.__insertLink(ctx.data?._links.self.href ?? '');
126106
} else {
127-
this.__deleteLink(
128-
nucleon?.data?._embedded?.[this.embedKey ?? '']?.[0]?._links.self.href ?? ''
129-
);
107+
this.__deleteLink(linkResource?._links.self.href ?? '');
130108
}
131109
}}
132110
>
133111
<div class="transition-opacity ${isDisabled ? 'opacity-50' : 'opacity-100'}">
134-
${content}
112+
${render(ctx)}
135113
</div>
136114
</vaadin-checkbox>
137115
`);
@@ -150,11 +128,7 @@ export class InternalAsyncResourceLinkListControl extends InternalEditableContro
150128
firstHref = undefined;
151129
}
152130

153-
const nucleons = [
154-
...(this.renderRoot.querySelectorAll('foxy-nucleon') as NodeListOf<NucleonElement<any>>),
155-
];
156-
157-
const isStatusVisible = this.__isFetching || nucleons.some(n => !n.in('idle'));
131+
const isStatusVisible = this.__isFetching || !this.__allLinks;
158132

159133
return html`
160134
<div class="group">
@@ -203,6 +177,8 @@ export class InternalAsyncResourceLinkListControl extends InternalEditableContro
203177
>
204178
${this._errorMessage}
205179
</div>
180+
181+
${this.__renderLinkResourceLoaders()}
206182
</div>
207183
`;
208184
}
@@ -256,4 +232,52 @@ export class InternalAsyncResourceLinkListControl extends InternalEditableContro
256232

257233
this.__isFetching = false;
258234
}
235+
236+
private __renderLinkResourceLoaders() {
237+
const maxApiLimit = 200;
238+
const firstPage = this.renderRoot.querySelector<NucleonElement<Collection>>('[data-link-page]');
239+
const totalItems = Number(firstPage?.data?.total_items ?? maxApiLimit); // sometimes total_items is a string in hAPI
240+
const links: string[] = [];
241+
242+
try {
243+
for (let i = 0; i < Math.max(1, Math.ceil(totalItems / maxApiLimit)); i++) {
244+
const url = new URL(this.linksHref ?? '');
245+
url.searchParams.set('offset', String(i * maxApiLimit));
246+
url.searchParams.set('limit', String(maxApiLimit));
247+
links.push(url.toString());
248+
}
249+
} catch {
250+
// Do nothing.
251+
}
252+
253+
return links.map(
254+
href => html`
255+
<foxy-nucleon
256+
class="hidden"
257+
data-link-page
258+
infer=""
259+
href=${href}
260+
@update=${() => this.requestUpdate()}
261+
>
262+
</foxy-nucleon>
263+
`
264+
);
265+
}
266+
267+
private get __allLinks() {
268+
const embedKey = this.embedKey;
269+
if (!embedKey) return null;
270+
271+
type Loader = NucleonElement<Collection>;
272+
const loaders = this.renderRoot.querySelectorAll<Loader>('[data-link-page]');
273+
const allLinks: any[] = [];
274+
275+
for (const loader of loaders) {
276+
const embedded = loader.data?._embedded?.[embedKey];
277+
if (!embedded) return null;
278+
allLinks.push(...embedded);
279+
}
280+
281+
return allLinks;
282+
}
259283
}

0 commit comments

Comments
 (0)