@pisell/private-materials 3.4.156 → 3.4.158

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.
Files changed (70) hide show
  1. package/build/lowcode/assets-daily.json +11 -11
  2. package/build/lowcode/assets-dev.json +2 -2
  3. package/build/lowcode/assets-prod.json +11 -11
  4. package/build/lowcode/meta.js +1 -1
  5. package/build/lowcode/render/default/view.css +1 -1
  6. package/build/lowcode/render/default/view.js +14 -14
  7. package/build/lowcode/view.css +1 -1
  8. package/build/lowcode/view.js +14 -14
  9. package/es/index.d.ts +7 -1
  10. package/es/index.js +5 -1
  11. package/es/plus/inventory/BindingModal.js +94 -0
  12. package/es/plus/inventory/InventoryItemManagement.d.ts +7 -0
  13. package/es/plus/inventory/InventoryItemManagement.js +204 -0
  14. package/es/plus/inventory/InventoryLocationManagement.d.ts +7 -0
  15. package/es/plus/inventory/InventoryLocationManagement.js +296 -0
  16. package/es/plus/inventory/InventoryUnitManagement.d.ts +7 -0
  17. package/es/plus/inventory/InventoryUnitManagement.js +144 -0
  18. package/es/plus/inventory/ItemDrawer.js +266 -0
  19. package/es/plus/inventory/RecordDialog.js +141 -0
  20. package/es/plus/inventory/StockList.js +132 -0
  21. package/es/plus/inventory/api.js +66 -0
  22. package/es/plus/inventory/components.js +172 -0
  23. package/es/plus/inventory/context.js +118 -0
  24. package/es/plus/inventory/forms.js +46 -0
  25. package/es/plus/inventory/hooks.js +235 -0
  26. package/es/plus/inventory/index.less +559 -0
  27. package/es/plus/inventory/locales.js +277 -0
  28. package/es/plus/inventory/types.d.ts +10 -0
  29. package/es/plus/inventory/utils.js +24 -0
  30. package/es/plus/pisellSupersetDashboard/README.md +291 -0
  31. package/es/plus/pisellSupersetDashboard/index.d.ts +15 -0
  32. package/es/plus/pisellSupersetDashboard/index.js +187 -0
  33. package/es/plus/pisellSupersetDashboard/index.less +83 -0
  34. package/es/plus/pisellSupersetDashboard/locales.js +36 -0
  35. package/es/plus/pisellSupersetDashboard/serve.js +51 -0
  36. package/es/plus/pisellSupersetDashboard/types.d.ts +17 -0
  37. package/es/plus/skuOptionsSelection/store/createStore.js +2 -2
  38. package/lib/index.d.ts +7 -1
  39. package/lib/index.js +134 -126
  40. package/lib/plus/inventory/BindingModal.js +96 -0
  41. package/lib/plus/inventory/InventoryItemManagement.d.ts +7 -0
  42. package/lib/plus/inventory/InventoryItemManagement.js +206 -0
  43. package/lib/plus/inventory/InventoryLocationManagement.d.ts +7 -0
  44. package/lib/plus/inventory/InventoryLocationManagement.js +298 -0
  45. package/lib/plus/inventory/InventoryUnitManagement.d.ts +7 -0
  46. package/lib/plus/inventory/InventoryUnitManagement.js +146 -0
  47. package/lib/plus/inventory/ItemDrawer.js +268 -0
  48. package/lib/plus/inventory/RecordDialog.js +143 -0
  49. package/lib/plus/inventory/StockList.js +134 -0
  50. package/lib/plus/inventory/api.js +66 -0
  51. package/lib/plus/inventory/components.js +181 -0
  52. package/lib/plus/inventory/context.js +121 -0
  53. package/lib/plus/inventory/forms.js +50 -0
  54. package/lib/plus/inventory/hooks.js +240 -0
  55. package/lib/plus/inventory/index.less +559 -0
  56. package/lib/plus/inventory/locales.js +277 -0
  57. package/lib/plus/inventory/types.d.ts +10 -0
  58. package/lib/plus/inventory/utils.js +30 -0
  59. package/lib/plus/pisellSupersetDashboard/README.md +291 -0
  60. package/lib/plus/pisellSupersetDashboard/index.d.ts +15 -0
  61. package/lib/plus/pisellSupersetDashboard/index.js +189 -0
  62. package/lib/plus/pisellSupersetDashboard/index.less +83 -0
  63. package/lib/plus/pisellSupersetDashboard/locales.js +36 -0
  64. package/lib/plus/pisellSupersetDashboard/serve.js +52 -0
  65. package/lib/plus/pisellSupersetDashboard/types.d.ts +17 -0
  66. package/lowcode/inventory-item-management/meta.ts +20 -0
  67. package/lowcode/inventory-location-management/meta.ts +20 -0
  68. package/lowcode/inventory-unit-management/meta.ts +20 -0
  69. package/lowcode/pisell-superset-dashboard/meta.ts +75 -0
  70. package/package.json +5 -3
@@ -0,0 +1,266 @@
1
+ import { _asyncToGenerator } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
2
+ import { inventoryQuantity, optionalText } from "./utils.js";
3
+ import { useInventory } from "./context.js";
4
+ import { useInventoryMutation, useInventoryQuery, useUnsavedChanges } from "./hooks.js";
5
+ import { RequestError, StatusTag } from "./components.js";
6
+ import { NameField, StatusField } from "./forms.js";
7
+ import StockList from "./StockList.js";
8
+ import React, { useEffect, useState } from "react";
9
+ import { Alert, Button, Card, Drawer, Form, Input, Select, Spin, Tooltip } from "antd";
10
+ import { AppstoreOutlined, CloseOutlined, InfoCircleOutlined, LinkOutlined } from "@ant-design/icons";
11
+ //#region src/plus/inventory/ItemDrawer.tsx
12
+ function DetailRow({ label, children }) {
13
+ return /* @__PURE__ */ React.createElement("div", { className: "inventory-drawer__info-row" }, /* @__PURE__ */ React.createElement("dt", null, label), /* @__PURE__ */ React.createElement("dd", null, children));
14
+ }
15
+ function ItemDrawer({ target, onClose, onChanged }) {
16
+ const { api, t, name, success, scopeId } = useInventory();
17
+ const [itemId, setItemId] = useState(target.id);
18
+ const [mode, setMode] = useState(target.mode);
19
+ const [tab, setTab] = useState("basic");
20
+ const [bindingsVisited, setBindingsVisited] = useState(false);
21
+ const [form] = Form.useForm();
22
+ const dirty = useUnsavedChanges();
23
+ const mutation = useInventoryMutation();
24
+ const query = useInventoryQuery(() => api.detail("item", itemId, ["unit"]), `item-${itemId}`, !!itemId);
25
+ const units = useInventoryQuery(() => api.units(), "drawer-units");
26
+ const record = query.data;
27
+ const readonly = mode === "view";
28
+ const unavailable = !!itemId && !query.loading && !query.error && record === null;
29
+ const disabled = readonly || mutation.busy || query.loading || !!query.error || unavailable;
30
+ useEffect(() => {
31
+ if (itemId && !record) return;
32
+ form.setFieldsValue(record ? {
33
+ name: record.name,
34
+ unit_id: record.unit_id || null,
35
+ sku: record.sku,
36
+ barcode: record.barcode,
37
+ cover: record.cover,
38
+ note: record.note,
39
+ stock_mode: record.stock_mode,
40
+ status: record.status
41
+ } : {
42
+ name: { original: "" },
43
+ unit_id: null,
44
+ sku: null,
45
+ barcode: null,
46
+ cover: null,
47
+ note: null,
48
+ stock_mode: "tracked",
49
+ status: "active"
50
+ });
51
+ dirty.setDirty(false);
52
+ }, [
53
+ record,
54
+ itemId,
55
+ form
56
+ ]);
57
+ const close = function() {
58
+ var _ref = _asyncToGenerator(function* () {
59
+ if (!mutation.busy && (yield dirty.canLeave())) onClose();
60
+ });
61
+ return function close() {
62
+ return _ref.apply(this, arguments);
63
+ };
64
+ }();
65
+ const cancelEdit = function() {
66
+ var _ref2 = _asyncToGenerator(function* () {
67
+ if (!(yield dirty.canLeave())) return;
68
+ if (!itemId) {
69
+ onClose();
70
+ return;
71
+ }
72
+ dirty.setDirty(false);
73
+ setMode("view");
74
+ query.reload();
75
+ });
76
+ return function cancelEdit() {
77
+ return _ref2.apply(this, arguments);
78
+ };
79
+ }();
80
+ const save = () => mutation.run(_asyncToGenerator(function* () {
81
+ let values;
82
+ try {
83
+ values = yield form.validateFields();
84
+ } catch (_unused) {
85
+ return;
86
+ }
87
+ setItemId((yield api.save("item", itemId, {
88
+ name: values.name,
89
+ unit_id: values.unit_id || null,
90
+ sku: optionalText(values.sku),
91
+ barcode: optionalText(values.barcode),
92
+ cover: optionalText(values.cover),
93
+ note: optionalText(values.note),
94
+ stock_mode: values.stock_mode,
95
+ status: values.status
96
+ })).id);
97
+ setMode("view");
98
+ dirty.setDirty(false);
99
+ query.reload();
100
+ success("success");
101
+ onChanged();
102
+ }));
103
+ const unitOptions = (units.data || []).map((unit) => ({
104
+ value: unit.id,
105
+ label: `${name(unit)}${unit.status === "inactive" ? ` (${t("inactive")})` : ""}`
106
+ }));
107
+ if ((record === null || record === void 0 ? void 0 : record.unit_id) && !unitOptions.some((option) => option.value === record.unit_id)) unitOptions.push({
108
+ value: record.unit_id,
109
+ label: record.unit ? name(record.unit) : `${t("missing")} (#${record.unit_id})`
110
+ });
111
+ const basic = /* @__PURE__ */ React.createElement(Form, {
112
+ form,
113
+ layout: "vertical",
114
+ disabled,
115
+ onValuesChange: () => dirty.setDirty(true)
116
+ }, /* @__PURE__ */ React.createElement(Card, {
117
+ className: "inventory-drawer__card",
118
+ title: t("basic")
119
+ }, /* @__PURE__ */ React.createElement(NameField, { disabled }), /* @__PURE__ */ React.createElement("div", { className: "inventory-form-columns" }, /* @__PURE__ */ React.createElement(Form.Item, {
120
+ name: "sku",
121
+ label: t("sku")
122
+ }, /* @__PURE__ */ React.createElement(Input, { maxLength: 128 })), /* @__PURE__ */ React.createElement(Form.Item, {
123
+ name: "barcode",
124
+ label: t("barcode")
125
+ }, /* @__PURE__ */ React.createElement(Input, { maxLength: 128 })), /* @__PURE__ */ React.createElement(Form.Item, {
126
+ name: "unit_id",
127
+ label: t("unit")
128
+ }, /* @__PURE__ */ React.createElement(Select, {
129
+ showSearch: true,
130
+ allowClear: true,
131
+ optionFilterProp: "label",
132
+ placeholder: t("noUnit"),
133
+ options: unitOptions,
134
+ loading: units.loading,
135
+ onDropdownVisibleChange: (open) => {
136
+ if (open) units.reload();
137
+ }
138
+ })), /* @__PURE__ */ React.createElement(Form.Item, {
139
+ name: "stock_mode",
140
+ label: t("stockMode"),
141
+ rules: [{
142
+ required: true,
143
+ message: t("required")
144
+ }]
145
+ }, /* @__PURE__ */ React.createElement(Select, { options: ["tracked", "unlimited"].map((value) => ({
146
+ value,
147
+ label: t(value)
148
+ })) }))), /* @__PURE__ */ React.createElement(RequestError, {
149
+ error: units.error,
150
+ retry: units.reload
151
+ }), /* @__PURE__ */ React.createElement(Form.Item, {
152
+ name: "cover",
153
+ label: t("cover"),
154
+ rules: [{ validator: (_, value) => {
155
+ if (!(value === null || value === void 0 ? void 0 : value.trim())) return Promise.resolve();
156
+ try {
157
+ const url = new URL(value.trim());
158
+ if (["https:", "http:"].includes(url.protocol) && value.trim().length <= 255) return Promise.resolve();
159
+ } catch (_unused2) {}
160
+ return Promise.reject(new Error(t("invalidUrl")));
161
+ } }]
162
+ }, /* @__PURE__ */ React.createElement(Input, { maxLength: 255 })), /* @__PURE__ */ React.createElement(Form.Item, {
163
+ name: "note",
164
+ label: t("note")
165
+ }, /* @__PURE__ */ React.createElement(Input.TextArea, {
166
+ maxLength: 500,
167
+ rows: 3,
168
+ showCount: true
169
+ })), /* @__PURE__ */ React.createElement(StatusField, null)));
170
+ const details = record && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Card, {
171
+ className: "inventory-drawer__card",
172
+ title: t("basic")
173
+ }, /* @__PURE__ */ React.createElement("dl", { className: "inventory-drawer__info-list" }, /* @__PURE__ */ React.createElement(DetailRow, { label: t("name") }, name(record)), /* @__PURE__ */ React.createElement(DetailRow, { label: t("sku") }, record.sku || "—"), /* @__PURE__ */ React.createElement(DetailRow, { label: t("barcode") }, record.barcode || "—"), /* @__PURE__ */ React.createElement(DetailRow, { label: t("unit") }, record.unit ? name(record.unit) : record.unit_id ? `${t("missing")} (#${record.unit_id})` : t("noUnit")), /* @__PURE__ */ React.createElement(DetailRow, { label: t("cover") }, record.cover || "—"), /* @__PURE__ */ React.createElement(DetailRow, { label: t("note") }, record.note || "—"))), /* @__PURE__ */ React.createElement(Card, {
174
+ className: "inventory-drawer__card",
175
+ title: t("status")
176
+ }, /* @__PURE__ */ React.createElement("dl", { className: "inventory-drawer__info-list" }, /* @__PURE__ */ React.createElement(DetailRow, { label: t("status") }, /* @__PURE__ */ React.createElement(StatusTag, { status: record.status })), /* @__PURE__ */ React.createElement(DetailRow, { label: t("stockMode") }, t(record.stock_mode)))), /* @__PURE__ */ React.createElement(Card, {
177
+ className: "inventory-drawer__card",
178
+ title: t("stockSummary")
179
+ }, /* @__PURE__ */ React.createElement("div", { className: "inventory-metrics" }, /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("span", null, t("totalQuantity")), /* @__PURE__ */ React.createElement("strong", null, inventoryQuantity(record.stock_quantity))), /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("span", null, t("totalAvailable")), /* @__PURE__ */ React.createElement("strong", null, inventoryQuantity(record.stock_available_quantity))))));
180
+ const title = mode === "create" ? `${t("add")} ${t("item")}` : record ? name(record) : `${t("item")} #${itemId}`;
181
+ const bindingDisabled = !itemId || !readonly || query.loading || unavailable || !!query.error;
182
+ const bindingHint = !itemId ? t("saveFirst") : !readonly ? t("editBasicFirst") : void 0;
183
+ return /* @__PURE__ */ React.createElement(Drawer, {
184
+ open: true,
185
+ width: "min(720px, 100vw)",
186
+ onClose: () => void close(),
187
+ maskClosable: false,
188
+ closable: false,
189
+ destroyOnClose: true,
190
+ className: "inventory-drawer",
191
+ rootClassName: "inventory-drawer-root",
192
+ "aria-labelledby": `${scopeId}-item-drawer-title`,
193
+ styles: { body: {
194
+ padding: 0,
195
+ overflow: "hidden"
196
+ } }
197
+ }, /* @__PURE__ */ React.createElement("div", { className: "inventory-drawer__root" }, /* @__PURE__ */ React.createElement("nav", {
198
+ className: "inventory-drawer__sidebar",
199
+ "aria-label": t("item")
200
+ }, /* @__PURE__ */ React.createElement("button", {
201
+ type: "button",
202
+ className: `inventory-drawer__sidebar-item ${tab === "basic" ? "is-active" : ""}`,
203
+ "aria-current": tab === "basic" ? "page" : void 0,
204
+ onClick: () => setTab("basic")
205
+ }, /* @__PURE__ */ React.createElement(InfoCircleOutlined, null), /* @__PURE__ */ React.createElement("span", null, t("basic"))), /* @__PURE__ */ React.createElement(Tooltip, {
206
+ title: bindingHint,
207
+ placement: "right"
208
+ }, /* @__PURE__ */ React.createElement("span", { className: "inventory-drawer__sidebar-slot" }, /* @__PURE__ */ React.createElement("button", {
209
+ type: "button",
210
+ className: `inventory-drawer__sidebar-item ${tab === "bindings" ? "is-active" : ""}`,
211
+ "aria-current": tab === "bindings" ? "page" : void 0,
212
+ disabled: bindingDisabled,
213
+ onClick: () => {
214
+ setBindingsVisited(true);
215
+ setTab("bindings");
216
+ }
217
+ }, /* @__PURE__ */ React.createElement(LinkOutlined, null), /* @__PURE__ */ React.createElement("span", null, t("bindings")))))), /* @__PURE__ */ React.createElement("div", { className: "inventory-drawer__main" }, /* @__PURE__ */ React.createElement("header", { className: "inventory-drawer__header" }, /* @__PURE__ */ React.createElement("div", { className: "inventory-drawer__icon" }, (record === null || record === void 0 ? void 0 : record.cover) && /* @__PURE__ */ React.createElement("img", {
218
+ src: record.cover,
219
+ alt: ""
220
+ }), !(record === null || record === void 0 ? void 0 : record.cover) && /* @__PURE__ */ React.createElement(AppstoreOutlined, null)), /* @__PURE__ */ React.createElement("div", { className: "inventory-drawer__heading" }, /* @__PURE__ */ React.createElement("h2", { id: `${scopeId}-item-drawer-title` }, title), /* @__PURE__ */ React.createElement("div", { className: "inventory-drawer__subtitle" }, (record === null || record === void 0 ? void 0 : record.sku) || t("item"))), /* @__PURE__ */ React.createElement(Button, {
221
+ type: "text",
222
+ icon: /* @__PURE__ */ React.createElement(CloseOutlined, null),
223
+ "aria-label": t("close"),
224
+ disabled: mutation.busy,
225
+ onClick: () => void close()
226
+ })), /* @__PURE__ */ React.createElement("div", { className: "inventory-drawer__content" }, /* @__PURE__ */ React.createElement(RequestError, {
227
+ error: query.error,
228
+ retry: query.reload
229
+ }), unavailable && /* @__PURE__ */ React.createElement(Alert, {
230
+ type: "warning",
231
+ message: t("missing"),
232
+ showIcon: true
233
+ }), /* @__PURE__ */ React.createElement(Spin, { spinning: query.loading }, /* @__PURE__ */ React.createElement("section", {
234
+ hidden: tab !== "basic",
235
+ "aria-label": t("basic")
236
+ }, readonly && details, /* @__PURE__ */ React.createElement("div", { hidden: readonly }, basic)), /* @__PURE__ */ React.createElement("section", {
237
+ hidden: tab !== "bindings",
238
+ "aria-label": t("bindings")
239
+ }, bindingsVisited && itemId && !unavailable && !query.error && /* @__PURE__ */ React.createElement(Card, {
240
+ className: "inventory-drawer__card",
241
+ title: t("bindings")
242
+ }, /* @__PURE__ */ React.createElement(StockList, {
243
+ key: itemId,
244
+ owner: "item",
245
+ id: itemId,
246
+ onChanged: () => {
247
+ query.reload();
248
+ onChanged();
249
+ }
250
+ }))))), /* @__PURE__ */ React.createElement("footer", { className: "inventory-drawer__footer" }, /* @__PURE__ */ React.createElement(Button, {
251
+ disabled: mutation.busy,
252
+ onClick: () => void (readonly ? close() : cancelEdit())
253
+ }, t(readonly ? "close" : "cancel")), /* @__PURE__ */ React.createElement(Button, {
254
+ type: "primary",
255
+ loading: mutation.busy,
256
+ disabled: query.loading || !!query.error || unavailable || readonly && !record,
257
+ onClick: () => {
258
+ if (readonly) {
259
+ setMode("edit");
260
+ setTab("basic");
261
+ } else save();
262
+ }
263
+ }, t(readonly ? "edit" : "save"))))));
264
+ }
265
+ //#endregion
266
+ export { ItemDrawer as default };
@@ -0,0 +1,141 @@
1
+ import { _asyncToGenerator } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
2
+ import { inventoryQuantity } from "./utils.js";
3
+ import { useInventory } from "./context.js";
4
+ import { useInventoryMutation, useInventoryQuery, useUnsavedChanges } from "./hooks.js";
5
+ import { PagedInventorySelect, RequestError } from "./components.js";
6
+ import { NameField, SortField, StatusField } from "./forms.js";
7
+ import StockList from "./StockList.js";
8
+ import React, { useEffect, useState } from "react";
9
+ import { Alert, Form, Spin } from "antd";
10
+ import { PisellModal } from "@pisell/materials";
11
+ //#region src/plus/inventory/RecordDialog.tsx
12
+ function RecordDialog({ target, onClose, onSaved }) {
13
+ var _shelf, _ref, _location;
14
+ const { api, t, success } = useInventory();
15
+ const [form] = Form.useForm();
16
+ const [mode, setMode] = useState(target.mode);
17
+ const dirty = useUnsavedChanges();
18
+ const mutation = useInventoryMutation();
19
+ const query = useInventoryQuery(() => api.detail(target.resource, target.id, target.resource === "shelf" ? ["location"] : target.resource === "space" ? ["shelf.location"] : void 0), `${target.resource}-${target.id}`, !!target.id);
20
+ const readonly = mode === "view";
21
+ const locationId = Form.useWatch("location_id", form);
22
+ const record = query.data;
23
+ const currentShelf = (_shelf = record === null || record === void 0 ? void 0 : record.shelf) !== null && _shelf !== void 0 ? _shelf : target.shelf;
24
+ const currentLocation = (_ref = (_location = record === null || record === void 0 ? void 0 : record.location) !== null && _location !== void 0 ? _location : currentShelf === null || currentShelf === void 0 ? void 0 : currentShelf.location) !== null && _ref !== void 0 ? _ref : target.location;
25
+ useEffect(() => {
26
+ var _record$sort, _target$location$id, _target$location, _target$shelf, _target$shelf2;
27
+ if (target.id && !record) return;
28
+ form.setFieldsValue(record ? {
29
+ name: record.name,
30
+ status: record.status,
31
+ sort: (_record$sort = record.sort) !== null && _record$sort !== void 0 ? _record$sort : 0,
32
+ location_id: target.resource === "shelf" ? record.location_id : currentShelf === null || currentShelf === void 0 ? void 0 : currentShelf.location_id,
33
+ shelf_id: target.resource === "space" ? record.shelf_id : void 0
34
+ } : {
35
+ name: { original: "" },
36
+ status: "active",
37
+ sort: 0,
38
+ location_id: (_target$location$id = (_target$location = target.location) === null || _target$location === void 0 ? void 0 : _target$location.id) !== null && _target$location$id !== void 0 ? _target$location$id : (_target$shelf = target.shelf) === null || _target$shelf === void 0 ? void 0 : _target$shelf.location_id,
39
+ shelf_id: (_target$shelf2 = target.shelf) === null || _target$shelf2 === void 0 ? void 0 : _target$shelf2.id
40
+ });
41
+ dirty.setDirty(false);
42
+ }, [
43
+ record,
44
+ target.id,
45
+ form
46
+ ]);
47
+ const close = function() {
48
+ var _ref2 = _asyncToGenerator(function* () {
49
+ if (!mutation.busy && (yield dirty.canLeave())) onClose();
50
+ });
51
+ return function close() {
52
+ return _ref2.apply(this, arguments);
53
+ };
54
+ }();
55
+ const submit = () => mutation.run(_asyncToGenerator(function* () {
56
+ let values;
57
+ try {
58
+ values = yield form.validateFields();
59
+ } catch (_unused) {
60
+ return;
61
+ }
62
+ const payload = {
63
+ name: values.name,
64
+ status: values.status,
65
+ sort: values.sort
66
+ };
67
+ if (target.resource === "shelf") payload.location_id = values.location_id;
68
+ if (target.resource === "space") payload.shelf_id = values.shelf_id;
69
+ const saved = yield api.save(target.resource, target.id, payload);
70
+ dirty.setDirty(false);
71
+ success("success");
72
+ onSaved(saved);
73
+ }));
74
+ const label = t(target.resource === "item-unit" ? "unit" : target.resource);
75
+ const unavailable = !!target.id && !query.loading && !query.error && record === null;
76
+ const disabled = readonly || mutation.busy || query.loading || !!query.error || unavailable;
77
+ return /* @__PURE__ */ React.createElement(PisellModal, {
78
+ open: true,
79
+ title: `${t(mode === "create" ? "add" : mode === "edit" ? "edit" : "view")} · ${label}`,
80
+ size: target.resource === "space" && readonly ? "large" : "middle",
81
+ onCancel: () => void close(),
82
+ closable: !mutation.busy,
83
+ maskClosable: false,
84
+ cancelText: t(readonly ? "close" : "cancel"),
85
+ cancelButtonProps: { disabled: mutation.busy },
86
+ okText: t(readonly ? "edit" : "save"),
87
+ okVisible: !unavailable && !query.error,
88
+ okButtonProps: { disabled: query.loading },
89
+ confirmLoading: mutation.busy,
90
+ onOk: () => {
91
+ if (readonly) setMode("edit");
92
+ else submit();
93
+ }
94
+ }, /* @__PURE__ */ React.createElement("div", { className: "inventory-modal-body" }, /* @__PURE__ */ React.createElement(RequestError, {
95
+ error: query.error,
96
+ retry: query.reload
97
+ }), unavailable && /* @__PURE__ */ React.createElement(Alert, {
98
+ type: "warning",
99
+ showIcon: true,
100
+ message: t("missing")
101
+ }), /* @__PURE__ */ React.createElement(Spin, { spinning: query.loading }, /* @__PURE__ */ React.createElement(Form, {
102
+ form,
103
+ layout: "vertical",
104
+ disabled,
105
+ onValuesChange: () => dirty.setDirty(true)
106
+ }, /* @__PURE__ */ React.createElement(NameField, { disabled }), target.resource !== "item-unit" && target.resource !== "location" && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Form.Item, {
107
+ name: "location_id",
108
+ label: t("location"),
109
+ rules: [{
110
+ required: true,
111
+ message: t("required")
112
+ }]
113
+ }, /* @__PURE__ */ React.createElement(PagedInventorySelect, {
114
+ resource: "location",
115
+ disabled,
116
+ selected: currentLocation,
117
+ placeholder: t("chooseLocation"),
118
+ onChange: () => {
119
+ if (target.resource === "space") form.setFieldValue("shelf_id", void 0);
120
+ }
121
+ })), target.resource === "space" && /* @__PURE__ */ React.createElement(Form.Item, {
122
+ name: "shelf_id",
123
+ label: t("shelf"),
124
+ rules: [{
125
+ required: true,
126
+ message: t("required")
127
+ }]
128
+ }, /* @__PURE__ */ React.createElement(PagedInventorySelect, {
129
+ key: `shelf-${locationId}`,
130
+ resource: "shelf",
131
+ disabled: disabled || !locationId,
132
+ filters: { location_id: locationId },
133
+ selected: currentShelf,
134
+ placeholder: t("chooseShelf")
135
+ }))), /* @__PURE__ */ React.createElement("div", { className: "inventory-form-columns" }, /* @__PURE__ */ React.createElement(StatusField, null), /* @__PURE__ */ React.createElement(SortField, null))), /* @__PURE__ */ React.createElement("p", { className: "inventory-muted" }, t("statusHint")), !readonly && (target.resource === "shelf" || target.resource === "space") && /* @__PURE__ */ React.createElement("p", { className: "inventory-muted" }, t("parentHint")), readonly && target.resource === "space" && record && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", { className: "inventory-section-heading" }, /* @__PURE__ */ React.createElement("h3", null, t("referencedStock")), /* @__PURE__ */ React.createElement("span", null, t("totalQuantity"), ":", " ", inventoryQuantity(record.stock_quantity))), /* @__PURE__ */ React.createElement(StockList, {
136
+ owner: "space",
137
+ id: record.id
138
+ })))));
139
+ }
140
+ //#endregion
141
+ export { RecordDialog as default };
@@ -0,0 +1,132 @@
1
+ import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
2
+ import { _asyncToGenerator } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
3
+ import { canUnbind, inventoryQuantity } from "./utils.js";
4
+ import { useInventory } from "./context.js";
5
+ import { useInventoryList, useInventoryMutation } from "./hooks.js";
6
+ import { InventoryTable, RequestError, StatusTag } from "./components.js";
7
+ import BindingModal from "./BindingModal.js";
8
+ import React, { useMemo, useState } from "react";
9
+ import { Alert, Button, Space, Tooltip } from "antd";
10
+ //#region src/plus/inventory/StockList.tsx
11
+ function StockList({ owner, id, onChanged }) {
12
+ const { api, t, name, confirm, success } = useInventory();
13
+ const [binding, setBinding] = useState(false);
14
+ const mutation = useInventoryMutation();
15
+ const list = useInventoryList("stock", {
16
+ [owner === "item" ? "item_id" : "space_id"]: id,
17
+ with: owner === "item" ? ["space.shelf.location"] : ["item.unit"]
18
+ });
19
+ const unbind = (stock) => void mutation.run(_asyncToGenerator(function* () {
20
+ if (!canUnbind(stock)) return;
21
+ if (!(yield confirm("unbindTitle", t("unbindHint")))) return;
22
+ try {
23
+ yield api.unbind(stock.id);
24
+ success("unbound");
25
+ } finally {
26
+ list.reload();
27
+ onChanged === null || onChanged === void 0 || onChanged();
28
+ }
29
+ }));
30
+ const columns = useMemo(() => {
31
+ return [
32
+ ...owner === "item" ? [{
33
+ title: t("path"),
34
+ key: "path",
35
+ dataIndex: "space_id",
36
+ width: 320,
37
+ render: (_, stock) => {
38
+ var _space$shelf, _space$shelf2, _space$shelf3;
39
+ const space = stock.space;
40
+ return /* @__PURE__ */ React.createElement("div", { className: "inventory-path" }, /* @__PURE__ */ React.createElement("span", null, space ? `${name((_space$shelf = space.shelf) === null || _space$shelf === void 0 ? void 0 : _space$shelf.location)} / ${name(space.shelf)} / ${name(space)}` : `${t("missing")} (#${stock.space_id})`), /* @__PURE__ */ React.createElement(Space, {
41
+ size: 4,
42
+ wrap: true
43
+ }, (space === null || space === void 0 || (_space$shelf2 = space.shelf) === null || _space$shelf2 === void 0 || (_space$shelf2 = _space$shelf2.location) === null || _space$shelf2 === void 0 ? void 0 : _space$shelf2.status) === "inactive" && /* @__PURE__ */ React.createElement("span", null, t("location"), ": ", /* @__PURE__ */ React.createElement(StatusTag, { status: "inactive" })), (space === null || space === void 0 || (_space$shelf3 = space.shelf) === null || _space$shelf3 === void 0 ? void 0 : _space$shelf3.status) === "inactive" && /* @__PURE__ */ React.createElement("span", null, t("shelf"), ": ", /* @__PURE__ */ React.createElement(StatusTag, { status: "inactive" })), (space === null || space === void 0 ? void 0 : space.status) === "inactive" && /* @__PURE__ */ React.createElement("span", null, t("space"), ": ", /* @__PURE__ */ React.createElement(StatusTag, { status: "inactive" }))));
44
+ }
45
+ }] : [{
46
+ title: t("item"),
47
+ key: "item",
48
+ dataIndex: "item_id",
49
+ width: 230,
50
+ render: (_, stock) => {
51
+ var _stock$item, _stock$item2;
52
+ return /* @__PURE__ */ React.createElement(Space, {
53
+ direction: "vertical",
54
+ size: 0
55
+ }, /* @__PURE__ */ React.createElement("span", null, stock.item ? name(stock.item) : `${t("missing")} (#${stock.item_id})`), /* @__PURE__ */ React.createElement("span", { className: "inventory-muted" }, ((_stock$item = stock.item) === null || _stock$item === void 0 ? void 0 : _stock$item.sku) || "—", " ", /* @__PURE__ */ React.createElement(StatusTag, { status: (_stock$item2 = stock.item) === null || _stock$item2 === void 0 ? void 0 : _stock$item2.status })));
56
+ }
57
+ }, {
58
+ title: t("unit"),
59
+ key: "unit",
60
+ dataIndex: "unit",
61
+ render: (_, stock) => {
62
+ var _stock$item3;
63
+ return ((_stock$item3 = stock.item) === null || _stock$item3 === void 0 ? void 0 : _stock$item3.unit) ? name(stock.item.unit) : "—";
64
+ }
65
+ }],
66
+ {
67
+ title: t("quantity"),
68
+ key: "quantity",
69
+ dataIndex: "quantity",
70
+ align: "right",
71
+ render: inventoryQuantity
72
+ },
73
+ {
74
+ title: t("available"),
75
+ key: "available_quantity",
76
+ dataIndex: "available_quantity",
77
+ align: "right",
78
+ render: inventoryQuantity
79
+ },
80
+ ...owner === "item" ? [{
81
+ title: t("actions"),
82
+ key: "actions",
83
+ dataIndex: "actions",
84
+ render: (_, stock) => /* @__PURE__ */ React.createElement(Tooltip, { title: !canUnbind(stock) ? t("unbindBlocked") : void 0 }, /* @__PURE__ */ React.createElement("span", null, /* @__PURE__ */ React.createElement(Button, {
85
+ type: "link",
86
+ danger: true,
87
+ disabled: !canUnbind(stock) || mutation.busy || list.loading,
88
+ onClick: () => unbind(stock)
89
+ }, t("unbind"))))
90
+ }] : []
91
+ ];
92
+ }, [
93
+ owner,
94
+ t,
95
+ name,
96
+ mutation.busy,
97
+ list.loading,
98
+ confirm,
99
+ api,
100
+ onChanged
101
+ ]);
102
+ return /* @__PURE__ */ React.createElement("section", { className: "inventory-stock-list" }, /* @__PURE__ */ React.createElement(Alert, {
103
+ type: "info",
104
+ showIcon: true,
105
+ className: "inventory-notice",
106
+ message: t("stockReadOnly")
107
+ }), /* @__PURE__ */ React.createElement("div", { className: "inventory-toolbar inventory-toolbar-end" }, /* @__PURE__ */ React.createElement(Button, {
108
+ onClick: list.reload,
109
+ disabled: mutation.busy
110
+ }, t("refresh")), owner === "item" && /* @__PURE__ */ React.createElement(Button, {
111
+ type: "primary",
112
+ onClick: () => setBinding(true),
113
+ disabled: mutation.busy
114
+ }, t("bind"))), /* @__PURE__ */ React.createElement(RequestError, {
115
+ error: list.error,
116
+ retry: list.reload
117
+ }), /* @__PURE__ */ React.createElement(InventoryTable, _objectSpread2(_objectSpread2({}, list), {}, {
118
+ columns,
119
+ loading: list.loading || mutation.busy,
120
+ tableKey: `${owner}-${id}-stocks`
121
+ })), binding && /* @__PURE__ */ React.createElement(BindingModal, {
122
+ itemId: id,
123
+ onClose: () => setBinding(false),
124
+ onBound: () => {
125
+ setBinding(false);
126
+ list.reload();
127
+ onChanged === null || onChanged === void 0 || onChanged();
128
+ }
129
+ }));
130
+ }
131
+ //#endregion
132
+ export { StockList as default };
@@ -0,0 +1,66 @@
1
+ import { _asyncToGenerator } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
2
+ //#region src/plus/inventory/api.ts
3
+ var InventoryRequestError = class extends Error {
4
+ constructor(message, code) {
5
+ super(message);
6
+ this.code = code;
7
+ this.name = "InventoryRequestError";
8
+ }
9
+ };
10
+ const CONFIG = {
11
+ isPisell2: true,
12
+ fullResult: true,
13
+ customToast: () => void 0
14
+ };
15
+ const PREFIX = "/tenant/inventory";
16
+ function createInventoryApi(client) {
17
+ function call(_x, _x2, _x3) {
18
+ return _call.apply(this, arguments);
19
+ }
20
+ function _call() {
21
+ _call = _asyncToGenerator(function* (method, path, params) {
22
+ if (!(client === null || client === void 0 ? void 0 : client[method])) throw new InventoryRequestError("noRequest");
23
+ const result = yield method === "remove" ? client.remove(`${PREFIX}/${path}`, CONFIG) : client[method](`${PREFIX}/${path}`, params, CONFIG);
24
+ if (!result || result.status !== true || result.code !== 200) throw new InventoryRequestError((result === null || result === void 0 ? void 0 : result.message) || "failed", result === null || result === void 0 ? void 0 : result.code);
25
+ return result.data;
26
+ });
27
+ return _call.apply(this, arguments);
28
+ }
29
+ function list(_x4, _x5) {
30
+ return _list.apply(this, arguments);
31
+ }
32
+ function _list() {
33
+ _list = _asyncToGenerator(function* (resource, params) {
34
+ const data = yield call("get", resource, params);
35
+ if (!data || !Array.isArray(data.list) || typeof data.count !== "number") throw new InventoryRequestError("invalidResponse");
36
+ return data;
37
+ });
38
+ return _list.apply(this, arguments);
39
+ }
40
+ return {
41
+ list,
42
+ units() {
43
+ return _asyncToGenerator(function* (params = {}) {
44
+ const data = yield call("get", "item-unit", params);
45
+ if (data !== null && !Array.isArray(data)) throw new InventoryRequestError("invalidResponse");
46
+ return data !== null && data !== void 0 ? data : [];
47
+ }).apply(this, arguments);
48
+ },
49
+ detail: (resource, id, withRelations) => call("get", `${resource}/${id}`, withRelations ? { with: withRelations } : {}),
50
+ save(resource, id, payload) {
51
+ return _asyncToGenerator(function* () {
52
+ const data = yield call(id ? "put" : "post", id ? `${resource}/${id}` : resource, payload);
53
+ if (!data || !Number.isInteger(data.id) || data.id <= 0) throw new InventoryRequestError("invalidResponse");
54
+ return data;
55
+ })();
56
+ },
57
+ remove: (resource, id) => call("remove", `${resource}/${id}`),
58
+ bind: (itemId, spaceId) => call("post", "stock", {
59
+ item_id: itemId,
60
+ space_id: spaceId
61
+ }),
62
+ unbind: (stockId) => call("remove", `stock/${stockId}`)
63
+ };
64
+ }
65
+ //#endregion
66
+ export { createInventoryApi };