@sealcode/sealgen 0.15.46 → 0.15.48
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/@types/src/page/stateful-page.d.ts +2 -0
- package/lib/forms/controls/single-reference.js +7 -4
- package/lib/forms/controls/single-reference.test.js +1 -0
- package/lib/page/stateful-page.js +6 -2
- package/package.json +1 -1
- package/src/forms/controls/single-reference.test.ts +1 -0
- package/src/forms/controls/single-reference.ts +9 -4
- package/src/page/stateful-page.ts +8 -3
|
@@ -8,6 +8,7 @@ export type StatefulPageActionDescription<ActionName> = {
|
|
|
8
8
|
action: ActionName;
|
|
9
9
|
label?: string;
|
|
10
10
|
content?: string;
|
|
11
|
+
disabled?: boolean;
|
|
11
12
|
} | ActionName;
|
|
12
13
|
export type StateAndMetadata<State, Actions> = {
|
|
13
14
|
state: State;
|
|
@@ -36,6 +37,7 @@ export declare abstract class StatefulPage<State extends Record<string, unknown>
|
|
|
36
37
|
action: string;
|
|
37
38
|
label: string;
|
|
38
39
|
content: string;
|
|
40
|
+
disabled: boolean;
|
|
39
41
|
};
|
|
40
42
|
makeActionURL<ActionName extends keyof Actions>(action_description: StatefulPageActionDescription<ActionName>, ...args: ExtractTail<ExtractTail<ExtractTail<Parameters<Actions[ActionName]>>>>): string;
|
|
41
43
|
makeActionButton<ActionName extends keyof Actions>(_state: State, action_description: StatefulPageActionDescription<ActionName>, ...args: ExtractTail<ExtractTail<ExtractTail<Parameters<Actions[ActionName]>>>>): string;
|
|
@@ -9,10 +9,13 @@ class SingleReferenceDropdown extends FreeformDropdown {
|
|
|
9
9
|
field,
|
|
10
10
|
async (ctx) => {
|
|
11
11
|
const { items } = await ctx.$app.collections[field.sealiousField.target_collection].list(ctx.$context).fetch();
|
|
12
|
-
return
|
|
13
|
-
value:
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
return [
|
|
13
|
+
{ value: "", label: "--" },
|
|
14
|
+
...items.map((item) => ({
|
|
15
|
+
value: item.id,
|
|
16
|
+
label: options.getLabel ? options.getLabel(item) : item.id
|
|
17
|
+
}))
|
|
18
|
+
];
|
|
16
19
|
},
|
|
17
20
|
options
|
|
18
21
|
);
|
|
@@ -45,6 +45,7 @@ describe("single-reference.test", () => {
|
|
|
45
45
|
await PlaywritghtExpect(page.getByLabel("article")).toBeVisible();
|
|
46
46
|
await page.getByLabel("article").selectOption({ label: "article 2" });
|
|
47
47
|
await page.getByRole("button", { name: "Wy\u015Blij" }).click();
|
|
48
|
+
await page.getByLabel("article").selectOption({ label: "--" });
|
|
48
49
|
await test_app.close();
|
|
49
50
|
}).timeout(100 * 1e3);
|
|
50
51
|
});
|
|
@@ -39,16 +39,19 @@ class StatefulPage extends Mountable {
|
|
|
39
39
|
}
|
|
40
40
|
extractActionAndLabel(action_description) {
|
|
41
41
|
let label, action, content;
|
|
42
|
+
let disabled;
|
|
42
43
|
if (is(action_description, predicates.object)) {
|
|
43
44
|
action = action_description.action.toString();
|
|
44
45
|
label = action_description.label || action;
|
|
45
46
|
content = action_description.content || label;
|
|
47
|
+
disabled = action_description.disabled || false;
|
|
46
48
|
} else {
|
|
47
49
|
action = action_description.toString();
|
|
48
50
|
label = action;
|
|
49
51
|
content = label;
|
|
52
|
+
disabled = false;
|
|
50
53
|
}
|
|
51
|
-
return { action, label, content };
|
|
54
|
+
return { action, label, content, disabled };
|
|
52
55
|
}
|
|
53
56
|
makeActionURL(action_description, ...args) {
|
|
54
57
|
const { action } = this.extractActionAndLabel(action_description);
|
|
@@ -58,7 +61,7 @@ class StatefulPage extends Mountable {
|
|
|
58
61
|
)}`;
|
|
59
62
|
}
|
|
60
63
|
makeActionButton(_state, action_description, ...args) {
|
|
61
|
-
const { label, content } = this.extractActionAndLabel(action_description);
|
|
64
|
+
const { label, content, disabled } = this.extractActionAndLabel(action_description);
|
|
62
65
|
return (
|
|
63
66
|
/* HTML */
|
|
64
67
|
`
|
|
@@ -66,6 +69,7 @@ class StatefulPage extends Mountable {
|
|
|
66
69
|
type="submit"
|
|
67
70
|
formaction="${this.makeActionURL(action_description, ...args)}"
|
|
68
71
|
title="${label}"
|
|
72
|
+
${disabled ? "disabled" : ""}
|
|
69
73
|
>
|
|
70
74
|
${content}
|
|
71
75
|
</button>
|
package/package.json
CHANGED
|
@@ -56,6 +56,7 @@ describe("single-reference.test", () => {
|
|
|
56
56
|
await PlaywritghtExpect(page.getByLabel("article")).toBeVisible();
|
|
57
57
|
await page.getByLabel("article").selectOption({ label: "article 2" });
|
|
58
58
|
await page.getByRole("button", { name: "Wyślij" }).click();
|
|
59
|
+
await page.getByLabel("article").selectOption({ label: "--" }); // "--" means empty value - it should be available, as the field is not required
|
|
59
60
|
|
|
60
61
|
await test_app.close();
|
|
61
62
|
}).timeout(100 * 1000);
|
|
@@ -25,10 +25,15 @@ export class SingleReferenceDropdown<
|
|
|
25
25
|
]
|
|
26
26
|
.list(ctx.$context)
|
|
27
27
|
.fetch();
|
|
28
|
-
return
|
|
29
|
-
value:
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
return [
|
|
29
|
+
{ value: "", label: "--" },
|
|
30
|
+
...items.map((item) => ({
|
|
31
|
+
value: item.id,
|
|
32
|
+
label: options.getLabel
|
|
33
|
+
? options.getLabel(item)
|
|
34
|
+
: item.id,
|
|
35
|
+
})),
|
|
36
|
+
];
|
|
32
37
|
},
|
|
33
38
|
options
|
|
34
39
|
);
|
|
@@ -14,6 +14,7 @@ export type StatefulPageActionDescription<ActionName> =
|
|
|
14
14
|
action: ActionName;
|
|
15
15
|
label?: string;
|
|
16
16
|
content?: string;
|
|
17
|
+
disabled?: boolean;
|
|
17
18
|
}
|
|
18
19
|
| ActionName;
|
|
19
20
|
|
|
@@ -103,18 +104,21 @@ export abstract class StatefulPage<
|
|
|
103
104
|
|
|
104
105
|
extractActionAndLabel<ActionName extends keyof Actions>(
|
|
105
106
|
action_description: StatefulPageActionDescription<ActionName>
|
|
106
|
-
): { action: string; label: string; content: string } {
|
|
107
|
+
): { action: string; label: string; content: string; disabled: boolean } {
|
|
107
108
|
let label, action, content: string;
|
|
109
|
+
let disabled: boolean;
|
|
108
110
|
if (is(action_description, predicates.object)) {
|
|
109
111
|
action = action_description.action.toString();
|
|
110
112
|
label = action_description.label || action;
|
|
111
113
|
content = action_description.content || label;
|
|
114
|
+
disabled = action_description.disabled || false;
|
|
112
115
|
} else {
|
|
113
116
|
action = action_description.toString();
|
|
114
117
|
label = action;
|
|
115
118
|
content = label;
|
|
119
|
+
disabled = false;
|
|
116
120
|
}
|
|
117
|
-
return { action, label, content };
|
|
121
|
+
return { action, label, content, disabled };
|
|
118
122
|
}
|
|
119
123
|
|
|
120
124
|
makeActionURL<ActionName extends keyof Actions>(
|
|
@@ -137,13 +141,14 @@ export abstract class StatefulPage<
|
|
|
137
141
|
ExtractTail<ExtractTail<Parameters<Actions[ActionName]>>>
|
|
138
142
|
>
|
|
139
143
|
) {
|
|
140
|
-
const { label, content } =
|
|
144
|
+
const { label, content, disabled } =
|
|
141
145
|
this.extractActionAndLabel(action_description);
|
|
142
146
|
return /* HTML */ `
|
|
143
147
|
<button
|
|
144
148
|
type="submit"
|
|
145
149
|
formaction="${this.makeActionURL(action_description, ...args)}"
|
|
146
150
|
title="${label}"
|
|
151
|
+
${disabled ? "disabled" : ""}
|
|
147
152
|
>
|
|
148
153
|
${content}
|
|
149
154
|
</button>
|