Skip to content

Commit

Permalink
Merge pull request #175 from Foxy/beta
Browse files Browse the repository at this point in the history
chore: release 1.31.0
  • Loading branch information
brettflorio authored Sep 3, 2024
2 parents 2323b1d + a1c907e commit 65852df
Show file tree
Hide file tree
Showing 27 changed files with 3,385 additions and 3,164 deletions.
88 changes: 72 additions & 16 deletions custom-elements.json
Original file line number Diff line number Diff line change
Expand Up @@ -16812,23 +16812,24 @@
"attributes": [
{
"name": "customer-addresses",
"type": "string",
"deprecatedMessage": "Link to the collection of customer addresses that can be used with this item."
},
{
"name": "item-categories",
"description": "Link to the collection of item categories that can be used with this item.",
"type": "string"
"description": "Link to the collection of item categories that can be used with this item."
},
{
"name": "locale-codes",
"description": "Link to the `fx:locale_codes` property helper for currency formatting."
},
{
"name": "coupons",
"type": "string",
"deprecatedMessage": "Link to the collection of coupons that can be used with this item."
},
{
"name": "store",
"description": "Link to `fx:store` this item belongs to."
},
{
"name": "simplify-ns-loading",
"type": "boolean",
Expand Down Expand Up @@ -16919,14 +16920,12 @@
{
"name": "customerAddresses",
"attribute": "customer-addresses",
"type": "string",
"deprecatedMessage": "Link to the collection of customer addresses that can be used with this item."
},
{
"name": "itemCategories",
"attribute": "item-categories",
"description": "Link to the collection of item categories that can be used with this item.",
"type": "string"
"description": "Link to the collection of item categories that can be used with this item."
},
{
"name": "localeCodes",
Expand All @@ -16936,9 +16935,13 @@
{
"name": "coupons",
"attribute": "coupons",
"type": "string",
"deprecatedMessage": "Link to the collection of coupons that can be used with this item."
},
{
"name": "store",
"attribute": "store",
"description": "Link to `fx:store` this item belongs to."
},
{
"name": "simplifyNsLoading",
"attribute": "simplify-ns-loading",
Expand Down Expand Up @@ -21153,6 +21156,14 @@
"path": "./src/elements/public/PaymentsApiPaymentMethodForm/index.ts",
"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._",
"attributes": [
{
"name": "payment-preset",
"description": "URL of the linked `fx:payment_preset` resource from the virtual Payments API."
},
{
"name": "store",
"description": "URL of the linked `fx:store` resource."
},
{
"name": "simplify-ns-loading",
"type": "boolean",
Expand Down Expand Up @@ -21240,10 +21251,20 @@
}
],
"properties": [
{
"name": "paymentPreset",
"attribute": "payment-preset",
"description": "URL of the linked `fx:payment_preset` resource from the virtual Payments API."
},
{
"name": "getImageSrc",
"description": "A function that returns a URL of a payment method icon based on the given type."
},
{
"name": "store",
"attribute": "store",
"description": "URL of the linked `fx:store` resource."
},
{
"name": "simplifyNsLoading",
"attribute": "simplify-ns-loading",
Expand Down Expand Up @@ -24519,19 +24540,23 @@
},
{
"name": "store-versions",
"description": "URL of the `fx:store_versions` property helper resource."
"description": "URL of the `fx:store_versions` property helper resource.",
"deprecatedMessage": "All elements in this library are designed to work with store version 2.0."
},
{
"name": "checkout-types",
"description": "URL of the `fx:checkout_types` property helper resource."
"description": "URL of the `fx:checkout_types` property helper resource.",
"deprecatedMessage": "Checkout type is effectively controlled by the default template config."
},
{
"name": "locale-codes",
"description": "URL of the `fx:locale_codes` property helper resource."
"description": "URL of the `fx:locale_codes` property helper resource.",
"deprecatedMessage": "Default locale code is effectively controlled by the active template set."
},
{
"name": "languages",
"description": "URL of the `fx:languages` property helper resource."
"description": "URL of the `fx:languages` property helper resource.",
"deprecatedMessage": "Default language is effectively controlled by the active template set."
},
{
"name": "timezones",
Expand Down Expand Up @@ -24645,22 +24670,26 @@
{
"name": "storeVersions",
"attribute": "store-versions",
"description": "URL of the `fx:store_versions` property helper resource."
"description": "URL of the `fx:store_versions` property helper resource.",
"deprecatedMessage": "All elements in this library are designed to work with store version 2.0."
},
{
"name": "checkoutTypes",
"attribute": "checkout-types",
"description": "URL of the `fx:checkout_types` property helper resource."
"description": "URL of the `fx:checkout_types` property helper resource.",
"deprecatedMessage": "Checkout type is effectively controlled by the default template config."
},
{
"name": "localeCodes",
"attribute": "locale-codes",
"description": "URL of the `fx:locale_codes` property helper resource."
"description": "URL of the `fx:locale_codes` property helper resource.",
"deprecatedMessage": "Default locale code is effectively controlled by the active template set."
},
{
"name": "languages",
"attribute": "languages",
"description": "URL of the `fx:languages` property helper resource."
"description": "URL of the `fx:languages` property helper resource.",
"deprecatedMessage": "Default language is effectively controlled by the active template set."
},
{
"name": "timezones",
Expand Down Expand Up @@ -28290,6 +28319,10 @@
"name": "payment-gateways-helper",
"description": "URL of the `fx:payment_gateways` property helper resource."
},
{
"name": "locale-codes",
"description": "Link to the `fx:locale_codes` property helper for currency formatting."
},
{
"name": "simplify-ns-loading",
"type": "boolean",
Expand Down Expand Up @@ -28387,6 +28420,11 @@
"attribute": "payment-gateways-helper",
"description": "URL of the `fx:payment_gateways` property helper resource."
},
{
"name": "localeCodes",
"attribute": "locale-codes",
"description": "Link to the `fx:locale_codes` property helper for currency formatting."
},
{
"name": "getSubscriptionPageHref"
},
Expand Down Expand Up @@ -30292,6 +30330,10 @@
"path": "./src/elements/public/WebhookCard/index.ts",
"description": "Basic card displaying webhook (`fx:webhook`) info.",
"attributes": [
{
"name": "resource-uri",
"description": "Optional URI of a transaction, customer or subscription. When provided,\nthe form will display logs and statuses for that particular resource only."
},
{
"name": "simplify-ns-loading",
"type": "boolean",
Expand Down Expand Up @@ -30342,6 +30384,11 @@
}
],
"properties": [
{
"name": "resourceUri",
"attribute": "resource-uri",
"description": "Optional URI of a transaction, customer or subscription. When provided,\nthe form will display logs and statuses for that particular resource only."
},
{
"name": "simplifyNsLoading",
"attribute": "simplify-ns-loading",
Expand Down Expand Up @@ -30463,6 +30510,10 @@
"path": "./src/elements/public/WebhookForm/index.ts",
"description": "Form element for creating or editing webhooks (`fx:webhook`).",
"attributes": [
{
"name": "resource-uri",
"description": "Optional URI of a transaction, customer or subscription. When provided,\nthe form will display logs and statuses for that particular resource only."
},
{
"name": "simplify-ns-loading",
"type": "boolean",
Expand Down Expand Up @@ -30550,6 +30601,11 @@
}
],
"properties": [
{
"name": "resourceUri",
"attribute": "resource-uri",
"description": "Optional URI of a transaction, customer or subscription. When provided,\nthe form will display logs and statuses for that particular resource only."
},
{
"name": "simplifyNsLoading",
"attribute": "simplify-ns-loading",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ export class InternalAsyncListControl extends InternalEditableControl {
>
</foxy-internal-confirm-dialog>
`}
<div class="flex gap-m items-center justify-between mb-xs text-s font-medium">
<span class="text-secondary mr-auto">
<div class="flex gap-m items-center justify-between mb-s text-l font-medium">
<span class="text-body mr-auto">
${this.label && this.label !== 'label' ? this.label : ''}
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import type { CSSResultArray, PropertyDeclarations } from 'lit-element';
import type { CheckboxElement } from '@vaadin/vaadin-checkbox';
import type { TemplateResult } from 'lit-html';
import type { ItemRenderer } from '../../public/CollectionPage/types';
import type { Collection } from './types';

import { InternalEditableControl } from '../InternalEditableControl/InternalEditableControl';
import { NucleonElement } from '../../public/NucleonElement/NucleonElement';
import { getResourceId } from '@foxy.io/sdk/core';
import { ifDefined } from 'lit-html/directives/if-defined';
import { classMap } from '../../../utils/class-map';
import { html } from 'lit-html';
Expand Down Expand Up @@ -85,53 +85,31 @@ export class InternalAsyncResourceLinkListControl extends InternalEditableContro
`;

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

try {
const url = new URL(this.linksHref ?? '');
url.searchParams.set(this.foreignKeyForId ?? '', String(id ?? ''));
url.searchParams.set('limit', '1');
linkHref = url.toString();
} catch {
linkHref = undefined;
}

const content = html`
<foxy-nucleon
infer=""
href=${ifDefined(linkHref)}
id="link-${id}"
@update=${() => this.requestUpdate()}
>
${render(ctx)}
</foxy-nucleon>
`;

if (this.readonly) return wrap(content);
const foreignKeyForUri = this.foreignKeyForUri;
const linkResource = foreignKeyForUri
? this.__allLinks?.find(link => link[foreignKeyForUri] === ctx.href)
: undefined;

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

return wrap(html`
<vaadin-checkbox
class="block"
?disabled=${isDisabled}
?checked=${checked}
?checked=${!!linkResource}
@change=${(evt: CustomEvent) => {
const target = evt.currentTarget as CheckboxElement;
if (target.checked) {
this.__insertLink(ctx.data?._links.self.href ?? '');
} else {
this.__deleteLink(
nucleon?.data?._embedded?.[this.embedKey ?? '']?.[0]?._links.self.href ?? ''
);
this.__deleteLink(linkResource?._links.self.href ?? '');
}
}}
>
<div class="transition-opacity ${isDisabled ? 'opacity-50' : 'opacity-100'}">
${content}
${render(ctx)}
</div>
</vaadin-checkbox>
`);
Expand All @@ -150,11 +128,7 @@ export class InternalAsyncResourceLinkListControl extends InternalEditableContro
firstHref = undefined;
}

const nucleons = [
...(this.renderRoot.querySelectorAll('foxy-nucleon') as NodeListOf<NucleonElement<any>>),
];

const isStatusVisible = this.__isFetching || nucleons.some(n => !n.in('idle'));
const isStatusVisible = this.__isFetching || !this.__allLinks;

return html`
<div class="group">
Expand Down Expand Up @@ -203,6 +177,8 @@ export class InternalAsyncResourceLinkListControl extends InternalEditableContro
>
${this._errorMessage}
</div>
${this.__renderLinkResourceLoaders()}
</div>
`;
}
Expand Down Expand Up @@ -256,4 +232,52 @@ export class InternalAsyncResourceLinkListControl extends InternalEditableContro

this.__isFetching = false;
}

private __renderLinkResourceLoaders() {
const maxApiLimit = 200;
const firstPage = this.renderRoot.querySelector<NucleonElement<Collection>>('[data-link-page]');
const totalItems = Number(firstPage?.data?.total_items ?? maxApiLimit); // sometimes total_items is a string in hAPI
const links: string[] = [];

try {
for (let i = 0; i < Math.max(1, Math.ceil(totalItems / maxApiLimit)); i++) {
const url = new URL(this.linksHref ?? '');
url.searchParams.set('offset', String(i * maxApiLimit));
url.searchParams.set('limit', String(maxApiLimit));
links.push(url.toString());
}
} catch {
// Do nothing.
}

return links.map(
href => html`
<foxy-nucleon
class="hidden"
data-link-page
infer=""
href=${href}
@update=${() => this.requestUpdate()}
>
</foxy-nucleon>
`
);
}

private get __allLinks() {
const embedKey = this.embedKey;
if (!embedKey) return null;

type Loader = NucleonElement<Collection>;
const loaders = this.renderRoot.querySelectorAll<Loader>('[data-link-page]');
const allLinks: any[] = [];

for (const loader of loaders) {
const embedded = loader.data?._embedded?.[embedKey];
if (!embedded) return null;
allLinks.push(...embedded);
}

return allLinks;
}
}
Loading

0 comments on commit 65852df

Please sign in to comment.