@startinblox/components-ds4go 3.3.6 → 3.3.7

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.
@@ -8,8 +8,8 @@ import type {
8
8
  NegotiationState,
9
9
  OrbitComponent as OrbitComponentConfig,
10
10
  PolicyDefinition,
11
- Resource,
12
11
  } from "@src/component";
12
+ import type { Customer, FactBundle } from "@src/ds4go";
13
13
 
14
14
  import ModalStyle from "@styles/modal/ds4go-customer-modal.scss?inline";
15
15
  import { css, html, nothing, unsafeCSS } from "lit";
@@ -17,7 +17,7 @@ import { customElement, state } from "lit/decorators.js";
17
17
 
18
18
  type ExtendedContractNegotiation = ContractNegotiation & {
19
19
  agreement?: ContractAgreement;
20
- relatedBundle?: Resource;
20
+ relatedBundle?: FactBundle;
21
21
  };
22
22
 
23
23
  @customElement("ds4go-customer-modal")
@@ -41,7 +41,7 @@ export class Ds4goCustomerModal extends OrbitComponent {
41
41
  policies: PolicyDefinition[] = [];
42
42
 
43
43
  @state()
44
- bundles: Resource[] = [];
44
+ bundles: FactBundle[] = [];
45
45
 
46
46
  @state()
47
47
  negotiations: ExtendedContractNegotiation[] = [];
@@ -130,7 +130,7 @@ export class Ds4goCustomerModal extends OrbitComponent {
130
130
 
131
131
  // Get all fact bundles from the connector's datas
132
132
  const allDatas = this.dspConnector.instance.datas || [];
133
- this.bundles = allDatas.filter((data: Resource) => {
133
+ this.bundles = allDatas.filter((data: FactBundle) => {
134
134
  const type = data["@type"];
135
135
  if (Array.isArray(type)) {
136
136
  return type.includes("ds4go:FactBundle");
@@ -264,7 +264,7 @@ export class Ds4goCustomerModal extends OrbitComponent {
264
264
  render() {
265
265
  return this._getResource.render({
266
266
  pending: () => html`<solid-loader></solid-loader>`,
267
- complete: (obj?: Resource) => {
267
+ complete: (obj?: Customer) => {
268
268
  if (!obj) {
269
269
  this._closeModal();
270
270
  return nothing;
@@ -8,8 +8,8 @@ import type {
8
8
  ContractNegotiation,
9
9
  OrbitComponent as OrbitComponentConfig,
10
10
  PolicyDefinition,
11
- Resource,
12
11
  } from "@src/component";
12
+ import type { Category, Fact, FactBundle } from "@src/ds4go";
13
13
 
14
14
  import ModalStyle from "@styles/modal/ds4go-fact-bundle-modal.scss?inline";
15
15
  import { css, html, nothing, unsafeCSS } from "lit";
@@ -132,7 +132,7 @@ export class Ds4goFactBundleModal extends OrbitComponent {
132
132
  render() {
133
133
  return this._getResource.render({
134
134
  pending: () => html`<solid-loader></solid-loader>`,
135
- complete: (obj?: Resource) => {
135
+ complete: (obj?: FactBundle) => {
136
136
  if (!obj) {
137
137
  this._closeModal();
138
138
  return nothing;
@@ -159,8 +159,8 @@ export class Ds4goFactBundleModal extends OrbitComponent {
159
159
  ><div>${msg("All facts in this bundle")}</div></tems-division
160
160
  >
161
161
  <div class="card-grid card-grid-vertical">
162
- ${obj.facts.map((fact: Resource) => {
163
- const tags = fact.categories.map((c: Resource) => ({
162
+ ${(obj.facts || []).map((fact: Fact) => {
163
+ const tags = (fact.categories || []).map((c: Category) => ({
164
164
  name: c.name,
165
165
  type: "information",
166
166
  }));
@@ -9,14 +9,17 @@ import { Task } from "@lit/task";
9
9
  import type {
10
10
  OrbitComponent as OrbitComponentConfig,
11
11
  PropertiesPicker,
12
- Resource,
13
12
  SearchObject,
14
13
  } from "@src/component";
14
+ import type { Customer } from "@src/ds4go";
15
15
  import { css, html, nothing } from "lit";
16
16
  import { customElement, property, state } from "lit/decorators.js";
17
17
 
18
18
  @customElement("solid-customer-list")
19
19
  export class SolidCustomerList extends OrbitComponent {
20
+ @property({ attribute: false })
21
+ objects?: Customer[] = [];
22
+
20
23
  static styles = css`
21
24
  .modal {
22
25
  position: fixed;
@@ -82,7 +85,7 @@ export class SolidCustomerList extends OrbitComponent {
82
85
  if (!this.hasCachedDatas || this.oldDataSrc !== dataSrc) {
83
86
  if (!dataSrc) return;
84
87
 
85
- this.objects = (await this._getProxyValue(dataSrc)) as Resource[];
88
+ this.objects = (await this._getProxyValue(dataSrc)) as Customer[];
86
89
  this.hasCachedDatas = true;
87
90
  }
88
91
 
@@ -96,7 +99,7 @@ export class SolidCustomerList extends OrbitComponent {
96
99
 
97
100
  if (objSrc) {
98
101
  this.object = this.objects.find(
99
- (obj: Resource) => obj["@id"] === objSrc,
102
+ (obj: Customer) => obj["@id"] === objSrc,
100
103
  );
101
104
  } else {
102
105
  this.dataSrc = dataSrc;
@@ -14,14 +14,17 @@ import type {
14
14
  PolicyDefinition,
15
15
  PolicyTemplate,
16
16
  PropertiesPicker,
17
- Resource,
18
17
  } from "@src/component";
18
+ import type { Category, Fact } from "@src/ds4go";
19
19
  import ComponentStyles from "@styles/fact-bundle-creation.scss?inline";
20
20
  import { html, nothing, unsafeCSS } from "lit";
21
21
  import { customElement, property, state } from "lit/decorators.js";
22
22
 
23
23
  @customElement("solid-fact-bundle-creation")
24
24
  export class SolidFactBundle extends OrbitComponent {
25
+ @property({ attribute: false })
26
+ objects?: Fact[] = [];
27
+
25
28
  static styles = [unsafeCSS(ComponentStyles)];
26
29
 
27
30
  @property({ attribute: "header", type: String })
@@ -31,7 +34,7 @@ export class SolidFactBundle extends OrbitComponent {
31
34
  factsSrc?: string;
32
35
 
33
36
  @state()
34
- selectedFacts: Resource[] = [];
37
+ selectedFacts: Fact[] = [];
35
38
 
36
39
  @state()
37
40
  bundleName = "";
@@ -92,7 +95,7 @@ export class SolidFactBundle extends OrbitComponent {
92
95
  key: "categories",
93
96
  value: "categories",
94
97
  expand: true,
95
- cast: (c: Resource[]) => sort(c, "name"),
98
+ cast: (c: Category[]) => sort(c, "name"),
96
99
  },
97
100
  ];
98
101
 
@@ -111,7 +114,7 @@ export class SolidFactBundle extends OrbitComponent {
111
114
  if (!this.hasCachedDatas || this.oldDataSrc !== factsSrc) {
112
115
  if (!factsSrc) return;
113
116
 
114
- this.facts = (await this._getProxyValue(factsSrc)) as Resource[];
117
+ this.facts = (await this._getProxyValue(factsSrc)) as Fact[];
115
118
  this.hasCachedDatas = true;
116
119
  }
117
120
 
@@ -124,7 +127,7 @@ export class SolidFactBundle extends OrbitComponent {
124
127
  }
125
128
 
126
129
  const factsWithoutSelected = this.facts.filter(
127
- (fact: Resource) => !selectedFacts.includes(fact),
130
+ (fact: Fact) => !selectedFacts.includes(fact),
128
131
  );
129
132
 
130
133
  if (filterText) {
@@ -209,7 +212,7 @@ export class SolidFactBundle extends OrbitComponent {
209
212
  name: this.bundleName,
210
213
  category: this.bundleCategory,
211
214
  description: this.bundleDescription || "",
212
- "ldp:contains": this.selectedFacts.map((fact: Resource) => ({
215
+ "ldp:contains": this.selectedFacts.map((fact: Fact) => ({
213
216
  "@id": fact["@id"],
214
217
  })),
215
218
  };
@@ -442,7 +445,7 @@ export class SolidFactBundle extends OrbitComponent {
442
445
  }
443
446
  }
444
447
 
445
- _toggleFactSelection(fact: Resource) {
448
+ _toggleFactSelection(fact: Fact) {
446
449
  if (this.selectedFacts.includes(fact)) {
447
450
  this.selectedFacts = this.selectedFacts.filter((f) => f !== fact);
448
451
  } else {
@@ -512,8 +515,8 @@ export class SolidFactBundle extends OrbitComponent {
512
515
  </div></tems-division
513
516
  >
514
517
  <div class="card-grid card-grid-vertical">
515
- ${this.selectedFacts.map((fact: Resource) => {
516
- const tags = fact.categories.map((c: Resource) => ({
518
+ ${this.selectedFacts.map((fact: Fact) => {
519
+ const tags = (fact.categories || []).map((c: Category) => ({
517
520
  name: c.name,
518
521
  type: "information",
519
522
  }));
@@ -556,9 +559,9 @@ export class SolidFactBundle extends OrbitComponent {
556
559
  </div>
557
560
  ${splicedDatas.length > 0
558
561
  ? html` <div class="card-grid card-grid-vertical">
559
- ${splicedDatas.map((fact: Resource) => {
560
- const tags = fact.categories.map(
561
- (c: Resource) => ({
562
+ ${splicedDatas.map((fact: Fact) => {
563
+ const tags = (fact.categories || []).map(
564
+ (c: Category) => ({
562
565
  name: c.name,
563
566
  type: "information",
564
567
  }),
@@ -653,9 +656,9 @@ export class SolidFactBundle extends OrbitComponent {
653
656
  </option>
654
657
  ${Array.from(
655
658
  new Set(
656
- this.selectedFacts.flatMap((fact) =>
657
- fact.categories.map((category: Resource) =>
658
- formatCase(category.name),
659
+ this.selectedFacts.flatMap((fact: Fact) =>
660
+ (fact.categories || []).map((category: Category) =>
661
+ formatCase(category.name || ""),
659
662
  ),
660
663
  ),
661
664
  ),
@@ -10,14 +10,17 @@ import { Task } from "@lit/task";
10
10
  import type {
11
11
  OrbitComponent as OrbitComponentConfig,
12
12
  PropertiesPicker,
13
- Resource,
14
13
  SearchObject,
15
14
  } from "@src/component";
15
+ import type { Category, Fact, FactBundle } from "@src/ds4go";
16
16
  import { css, html, nothing } from "lit";
17
17
  import { customElement, property, state } from "lit/decorators.js";
18
18
 
19
19
  @customElement("solid-fact-bundle")
20
20
  export class SolidFactBundle extends OrbitComponent {
21
+ @property({ attribute: false })
22
+ objects?: FactBundle[] = [];
23
+
21
24
  static styles = css`
22
25
  .modal {
23
26
  position: fixed;
@@ -53,11 +56,11 @@ export class SolidFactBundle extends OrbitComponent {
53
56
  { key: "description", value: "description" },
54
57
  ];
55
58
 
56
- async _responseAdaptator(response: Resource): Promise<Resource> {
59
+ async _responseAdaptator(response: FactBundle): Promise<FactBundle> {
57
60
  if (response?._originalResource?.hasType("ds4go:FactBundle")) {
58
61
  response.facts = await Promise.all(
59
62
  (await response._originalResource["ldp:contains"]).map(
60
- (fact: Resource) => {
63
+ (fact: Fact) => {
61
64
  return this._getProxyValue(fact["@id"], false, [
62
65
  { key: "updated_at", value: "updated_at", cast: formatDate },
63
66
  { key: "name", value: "name" },
@@ -66,7 +69,7 @@ export class SolidFactBundle extends OrbitComponent {
66
69
  key: "categories",
67
70
  value: "categories",
68
71
  expand: true,
69
- cast: (c: Resource[]) => sort(c, "name"),
72
+ cast: (c: Category[]) => sort(c, "name"),
70
73
  },
71
74
  { key: "author", value: "author" },
72
75
  { key: "link", value: "link" },
@@ -128,7 +131,7 @@ export class SolidFactBundle extends OrbitComponent {
128
131
  if (!this.hasCachedDatas || this.oldDataSrc !== dataSrc) {
129
132
  if (!dataSrc) return;
130
133
 
131
- this.objects = (await this._getProxyValue(dataSrc)) as Resource[];
134
+ this.objects = (await this._getProxyValue(dataSrc)) as FactBundle[];
132
135
  this.hasCachedDatas = true;
133
136
  }
134
137
 
@@ -142,7 +145,7 @@ export class SolidFactBundle extends OrbitComponent {
142
145
 
143
146
  if (objSrc) {
144
147
  this.object = this.objects.find(
145
- (obj: Resource) => obj["@id"] === objSrc,
148
+ (obj: FactBundle) => obj["@id"] === objSrc,
146
149
  );
147
150
  } else {
148
151
  this.dataSrc = dataSrc;
package/src/ds4go.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ import type { LimitedResource } from "@src/component";
2
+
3
+ export interface FactBundle extends LimitedResource {
4
+ "@type"?: "ds4go:FactBundle" | "ldp:Container" | ["ldp:Container", "ds4go:FactBundle"];
5
+ name?: string;
6
+ category?: string;
7
+ description?: string;
8
+ facts?: Fact[];
9
+ }
10
+
11
+ export interface Customer extends LimitedResource {
12
+ "@type"?: "ds4go:Customer";
13
+ name?: string;
14
+ participant_id?: string;
15
+ balance?: number;
16
+ }
17
+
18
+ export interface Category extends LimitedResource {
19
+ "@type"?: "ds4go:Category";
20
+ name?: string;
21
+ parent_category?: Category | null;
22
+ }
23
+
24
+ export interface Fact extends LimitedResource {
25
+ "@type"?: "ds4go:Fact";
26
+ name?: string;
27
+ link?: string;
28
+ description?: string;
29
+ content?: string;
30
+ author?: string;
31
+ categories?: Category[];
32
+ enclosure?: string;
33
+ medias?: Media[];
34
+ review?: Record<string, any>;
35
+ }
36
+
37
+ export interface Media extends LimitedResource {
38
+ "@type"?: "ds4go:Media";
39
+ url?: string;
40
+ file_size?: number;
41
+ width?: number;
42
+ height?: number;
43
+ file_type?: string;
44
+ description?: string;
45
+ }