create-erxes 0.1.4 → 0.1.5
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/dist/index.js +1 -1
- package/dist/templates/base/.agents/skills/ui-patterns/SKILL.md +144 -0
- package/dist/templates/base/AGENTS.md +4 -3
- package/dist/templates/base/api/package.json +2 -2
- package/dist/templates/base/api/src/modules/items/__tests__/items.test.ts +22 -4
- package/dist/templates/base/api/src/modules/items/itemFilter.ts +61 -0
- package/dist/templates/base/api/src/modules/items/items.ts +21 -8
- package/dist/templates/base/ui/AGENTS.md +19 -1
- package/dist/templates/base/ui/package.json +2 -2
- package/dist/templates/base/ui/rsbuild.config.ts +2 -0
- package/dist/templates/base/ui/src/__Pascal__.tsx +9 -4
- package/dist/templates/base/ui/src/config.tsx +25 -2
- package/dist/templates/base/ui/src/modules/items/ItemPanel.tsx +140 -0
- package/dist/templates/base/ui/src/{items → modules/items}/ItemsPage.tsx +33 -22
- package/dist/templates/base/ui/src/{items → modules/items}/useItems.ts +12 -18
- package/dist/templates/base/ui/tsconfig.json +2 -1
- package/dist/templates/migrate/.agents/skills/plugin-migrate/SKILL.md +2 -2
- package/package.json +1 -1
- package/dist/templates/base/ui/src/items/ItemSheet.tsx +0 -107
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import { mkdir, readFile, readdir, symlink, writeFile } from "node:fs/promises";
|
|
|
9
9
|
import { homedir } from "node:os";
|
|
10
10
|
import { fileURLToPath } from "node:url";
|
|
11
11
|
// package.json
|
|
12
|
-
var version = "0.1.
|
|
12
|
+
var version = "0.1.5";
|
|
13
13
|
// src/existing-plugins.ts
|
|
14
14
|
/** The old erxes plugins a new-core plugin can be migrated from (`backend/plugins/<name>_api`). */
|
|
15
15
|
const OLD_PLUGINS = [
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ui-patterns
|
|
3
|
+
description: Make a plugin page look and behave like core's own pages (contacts, products, settings). Use when adding or changing any list, filter, form, record detail or settings page in ui/, and when reviewing one.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
A member moves between core and plugins without noticing the seam. Core's
|
|
7
|
+
web app (erxes repo, branch `postgre`, `apps/web/src/modules`) is the
|
|
8
|
+
reference: `contacts/customers` and `products` for lists and records,
|
|
9
|
+
`settings/tags` for settings. This repo's `ui/src/modules/items` is the same shape,
|
|
10
|
+
built only from what plugins can import. When a page has to differ, say why in
|
|
11
|
+
a comment.
|
|
12
|
+
|
|
13
|
+
## Page
|
|
14
|
+
|
|
15
|
+
- `PageContainer`, then `PageHeader`. `PageHeader.Start` holds the breadcrumb:
|
|
16
|
+
the app's icon and name, then each level, as core's `AppBreadcrumb` draws it
|
|
17
|
+
(ghost buttons, last one not a link). `PageHeader.End` holds the page's one
|
|
18
|
+
primary action ("Add item") and nothing else.
|
|
19
|
+
- No titles, descriptions or stat cards between the header and the list. A
|
|
20
|
+
dashboard is its own page.
|
|
21
|
+
- Several lists under one sidebar item are separate routes in the sidebar, not
|
|
22
|
+
tabs on the page.
|
|
23
|
+
|
|
24
|
+
## List
|
|
25
|
+
|
|
26
|
+
- Under the header, one bar: erxes-ui's `ViewBar` (`allLabel="All items"`) with
|
|
27
|
+
the list's `ListFilter` inside it, as `ui/src/modules/items/ItemsPage.tsx` has it. The
|
|
28
|
+
bar shows the filter's chips, the record count and the filter button. Nothing
|
|
29
|
+
else sits above the table.
|
|
30
|
+
- The table is erxes-ui's `RecordTable` with `RecordTableColumnDef` columns:
|
|
31
|
+
the name column sticky and opening the record, a `more` column with the row
|
|
32
|
+
menu, members as `MemberInline`, dates and amounts through `useFormat()`.
|
|
33
|
+
Not `Table`, not `<table>`, not cards.
|
|
34
|
+
- Lists load by cursor (`useInfiniteQuery` and the table's load-more), and
|
|
35
|
+
show `Empty` with what the list is for and the add button when there is
|
|
36
|
+
nothing yet; a filtered empty list says nothing matches.
|
|
37
|
+
- A board (kanban) is another view of the same list: same header, same bar.
|
|
38
|
+
erxes-ui's `DisplayMenu list="<plugin>-<things>"` inside the `ListFilter`
|
|
39
|
+
switches table and board, and erxes-ui's `useListDisplay`, given the same list, reads the
|
|
40
|
+
choice, remembered in the browser.
|
|
41
|
+
|
|
42
|
+
## Filter
|
|
43
|
+
|
|
44
|
+
erxes-ui's `ListFilter` is core's own filter bar; `ui/src/modules/items/ItemsPage.tsx`
|
|
45
|
+
gives it its fields, and `api/src/modules/items/itemFilter.ts` applies them.
|
|
46
|
+
|
|
47
|
+
- Give it every field the list can be narrowed by: `{ path: 'subject.<column>',
|
|
48
|
+
label, type, options?, icon? }`, type `text`, `number`, `date`, `boolean`,
|
|
49
|
+
`select` (with `options`) or `member`. The menu (`F`) offers search, each
|
|
50
|
+
field and the advanced filter; each condition is a chip.
|
|
51
|
+
- The conditions (core's `ConditionGroup`, rules on those paths; a `member`
|
|
52
|
+
rule's `me` is the member asking) and the search live in the address.
|
|
53
|
+
`useListFilterParams()` gives them to the list's query as `filter` (JSON) and
|
|
54
|
+
`search`; the API parses `filter` with `ConditionGroup` from
|
|
55
|
+
`@erxes/core-contract` and refuses a path it has no column for.
|
|
56
|
+
- Never: a search box, toggle buttons ("Mine", "Archived"), status tabs, a
|
|
57
|
+
ToggleGroup for table and board, or a row of pickers above the table. Each of
|
|
58
|
+
those is a field in the menu or the Display menu.
|
|
59
|
+
- Saved views (the tabs core's contacts lists have) are core's lists only;
|
|
60
|
+
a plugin list shows the one "All …" tab.
|
|
61
|
+
|
|
62
|
+
## Records in core's side panel
|
|
63
|
+
|
|
64
|
+
- The plugin's records open in core's own side panel, exactly as a customer
|
|
65
|
+
does. Core draws the panel (header, Back, expand, close, tabs, resizing,
|
|
66
|
+
drafts, the address `?panel=/detail/<type>/<id>`); the plugin fills slots.
|
|
67
|
+
Register each type in `CONFIG.recordTypes` (`ui/src/config.tsx`):
|
|
68
|
+
`contentType: '<plugin>:<thing>'`, `title`, `icon`, `detailPath(id)`, and the
|
|
69
|
+
slots `Title` (the header's title), `Actions` (its menu), `Detail` (the
|
|
70
|
+
Detail tab), `tabs` (more tabs, after Detail or after Activity) and `New`
|
|
71
|
+
(the draft). `contacts`, given an id, gives the record's customers and companies as
|
|
72
|
+
query options, so other plugins' relation tabs show on it; `activity` names
|
|
73
|
+
a manifest `timelines` type for core's Activity tab.
|
|
74
|
+
- Each slot gets `contentType` and `contentId` and reads the record itself; the
|
|
75
|
+
slots share one query (`ui/src/modules/items/ItemPanel.tsx`). The Detail
|
|
76
|
+
tab is `PanelSection`s of `PanelField` rows. Never an erxes-ui `Sheet`, a
|
|
77
|
+
header or tabs of the plugin's own, or a `?item=` param.
|
|
78
|
+
- Open a record with `useOpenRecord().open({ contentType, contentId })` and a
|
|
79
|
+
draft with `openNew(contentType, defaults)`. `detailPath(id)` is a route of
|
|
80
|
+
the plugin's that renders `<RecordPage contentType contentId />`
|
|
81
|
+
(`ui/src/__Pascal__.tsx`): the expanded record.
|
|
82
|
+
- A plugin whose records belong to customers or companies lists them on other
|
|
83
|
+
records with `CONFIG.relationTabs`: `{ name, title, icon, hosts?, component }`.
|
|
84
|
+
The component gets the host record and its `customerIds` and `companyIds`;
|
|
85
|
+
a record clicked there opens with `useOpenRecord().open` on top in the same
|
|
86
|
+
panel, and Back returns. It shows on core's customers and companies and on
|
|
87
|
+
plugin records that give `contacts`, never on the plugin's own records
|
|
88
|
+
unless `hosts` names them.
|
|
89
|
+
|
|
90
|
+
## Forms
|
|
91
|
+
|
|
92
|
+
- A new record, and any form of a few fields, is the type's `New` in core's
|
|
93
|
+
side panel, under core's "New item" header: `PanelFormLayout` with one
|
|
94
|
+
`PanelFormRow` per field (icon and label left, control right), then Cancel
|
|
95
|
+
and Save at the bottom. Nothing saves until Save; a field's error shows
|
|
96
|
+
under that field. Call `onCreated(id)` after Save, and the record takes the
|
|
97
|
+
draft's place.
|
|
98
|
+
- A form gets its own page only when it has several sections or a live
|
|
99
|
+
preview (a product editor, a page builder). That page keeps the same
|
|
100
|
+
header and breadcrumb, puts sections in one column of the same rows, and
|
|
101
|
+
has Save in `PageHeader.End`.
|
|
102
|
+
- `Dialog` is for confirming (`useConfirm`) and nothing else. Never a form in
|
|
103
|
+
a dialog.
|
|
104
|
+
|
|
105
|
+
## Record detail
|
|
106
|
+
|
|
107
|
+
- Clicking a row's name opens the record in core's side panel. Its title is
|
|
108
|
+
the record's name; the panel shows its fields as the same rows (icon and
|
|
109
|
+
label left, value right), grouped under `PanelSection` headings.
|
|
110
|
+
- Values edit in place where core's do: `PanelField` with erxes-ui's
|
|
111
|
+
`RecordTableInlineCell` (click, Enter saves, Escape cancels) or
|
|
112
|
+
`SelectMember.InlineCell`. Related lists (lines, activity, history) go below
|
|
113
|
+
the fields or in the panel's tabs.
|
|
114
|
+
- The expand button opens the record's own page, `detailPath(id)`: the same
|
|
115
|
+
panel at full size, Detail beside the other tabs.
|
|
116
|
+
|
|
117
|
+
## Related records
|
|
118
|
+
|
|
119
|
+
- A customer or company on a record (a deal's customer, an order's buyer) is
|
|
120
|
+
always erxes-ui's `ContactLink`, given `contacts={contactQueries}` from
|
|
121
|
+
`@erxes/core-contract/client`: its name, and a click opens it in core's side
|
|
122
|
+
panel beside the page. Never its id, a name copied into the plugin's table,
|
|
123
|
+
or a link to a URL. `useOpenRecord()` opens one from your own control.
|
|
124
|
+
- A plugin's records of a customer or company are a relation tab on its panel
|
|
125
|
+
(`relationTabs`, above). `recordSections` still draws a section in the
|
|
126
|
+
customer's Detail tab, for a summary that belongs beside its fields.
|
|
127
|
+
|
|
128
|
+
## Look
|
|
129
|
+
|
|
130
|
+
- erxes-ui components and tokens only: no raw colours, inline styles or
|
|
131
|
+
hand-made buttons, badges or inputs. Text in rows is `text-xs`, labels
|
|
132
|
+
`font-medium text-accent-foreground`, as core's panel has them.
|
|
133
|
+
- Icons are `@tabler/icons-react`, one per field, the same icon for a field
|
|
134
|
+
everywhere it shows (column header, filter menu, form row).
|
|
135
|
+
- Text through `t(key, 'English default')`.
|
|
136
|
+
|
|
137
|
+
## Before calling it done
|
|
138
|
+
|
|
139
|
+
Open the page beside core's contacts list in the browser (the `verify` skill
|
|
140
|
+
starts both). Header, filter bar, table, side panel and empty state should
|
|
141
|
+
read as the same product. Check: a filter survives reload; a record open in
|
|
142
|
+
the panel survives reload and expands to its page; a new record's draft saves
|
|
143
|
+
into the record; no dialog holds a form; no control sits above the table
|
|
144
|
+
besides the bar.
|
|
@@ -4,8 +4,8 @@ __description__
|
|
|
4
4
|
|
|
5
5
|
An erxes plugin for the new core (Postgres). `api/` is the API: Express 5,
|
|
6
6
|
oRPC and Drizzle. `ui/` is the Module Federation remote web loads. Read the
|
|
7
|
-
`AGENTS.md` in the folder you edit. `api/src/modules/items` and
|
|
8
|
-
are the reference feature: copy their shape for a new one.
|
|
7
|
+
`AGENTS.md` in the folder you edit. `api/src/modules/items` and
|
|
8
|
+
`ui/src/modules/items` are the reference feature: copy their shape for a new one.
|
|
9
9
|
|
|
10
10
|
<!-- quality:start -->
|
|
11
11
|
|
|
@@ -57,6 +57,7 @@ without line-by-line review.
|
|
|
57
57
|
with `verifyPluginSession`. There is no public route yet, because core can't
|
|
58
58
|
tell a public request's organisation.
|
|
59
59
|
- Skills in `.agents/skills/`: `endpoint` for a procedure, `schema-change` for a
|
|
60
|
-
table or column, `
|
|
60
|
+
table or column, `ui-patterns` for any page (lists, filters, forms, record
|
|
61
|
+
details look like core's), `verify` before calling a change done.__migrationSkill__
|
|
61
62
|
- What core promises plugins, and what counts as a breaking change, is core's
|
|
62
63
|
`plugin-contract` skill (erxes repo, branch `postgre`).
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"db:check": "drizzle-kit check"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@erxes/core-contract": "0.1.0-v2.
|
|
25
|
-
"@erxes/plugin-sdk": "0.1.0-v2.
|
|
24
|
+
"@erxes/core-contract": "0.1.0-v2.6",
|
|
25
|
+
"@erxes/plugin-sdk": "0.1.0-v2.5",
|
|
26
26
|
"@opentelemetry/instrumentation-express": "^0.73.0",
|
|
27
27
|
"@opentelemetry/instrumentation-http": "^0.301.1",
|
|
28
28
|
"@opentelemetry/instrumentation-pg": "^0.78.0",
|
|
@@ -20,6 +20,9 @@ const clientAs = (orgId: string, permissions: string[] = Object.values(PERMISSIO
|
|
|
20
20
|
return createRouterClient(router, { context: { member } });
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
+
/** The filter bar's conditions: core's condition group as JSON. */
|
|
24
|
+
const filter = (rules: unknown[], match = 'all') => JSON.stringify({ match, rules });
|
|
25
|
+
|
|
23
26
|
describe('items', () => {
|
|
24
27
|
it('creates, lists newest first in pages, updates and deletes', async () => {
|
|
25
28
|
const client = clientAs('org-a');
|
|
@@ -38,12 +41,26 @@ describe('items', () => {
|
|
|
38
41
|
|
|
39
42
|
expect(next.items.map((item) => item.id)).toEqual([first.id]);
|
|
40
43
|
expect(next.nextCursor).toBeNull();
|
|
41
|
-
await expect(client.items.
|
|
44
|
+
await expect(client.items.get({ id: first.id })).resolves.toMatchObject({ name: 'First' });
|
|
45
|
+
|
|
46
|
+
const mine = { path: 'subject.createdBy', op: 'in', value: ['me'] };
|
|
47
|
+
|
|
48
|
+
await expect(client.items.list({ filter: filter([mine]) })).resolves.toMatchObject({
|
|
42
49
|
items: [{ id: second.id }, { id: first.id }],
|
|
43
50
|
});
|
|
44
|
-
await expect(
|
|
45
|
-
items
|
|
46
|
-
|
|
51
|
+
await expect(
|
|
52
|
+
client.items.list({
|
|
53
|
+
filter: filter([mine, { path: 'subject.name', op: 'contains', value: 'sec' }]),
|
|
54
|
+
}),
|
|
55
|
+
).resolves.toMatchObject({ items: [{ id: second.id }] });
|
|
56
|
+
await expect(
|
|
57
|
+
client.items.list({
|
|
58
|
+
filter: filter([{ path: 'subject.createdBy', op: 'eq', value: 'someone-else' }]),
|
|
59
|
+
}),
|
|
60
|
+
).resolves.toMatchObject({ items: [] });
|
|
61
|
+
await expect(
|
|
62
|
+
client.items.list({ filter: filter([{ path: 'subject.color', op: 'eq', value: 'red' }]) }),
|
|
63
|
+
).rejects.toMatchObject({ status: 400 });
|
|
47
64
|
|
|
48
65
|
await expect(
|
|
49
66
|
client.items.update({ id: first.id, name: 'First', description: 'Changed' }),
|
|
@@ -77,6 +94,7 @@ describe('items', () => {
|
|
|
77
94
|
await expect(ours.items.create({ name: 'Shared name' })).resolves.toMatchObject({
|
|
78
95
|
name: 'Shared name',
|
|
79
96
|
});
|
|
97
|
+
await expect(ours.items.get({ id: theirs.id })).rejects.toMatchObject({ code: 'NOT_FOUND' });
|
|
80
98
|
await expect(ours.items.update({ id: theirs.id, name: 'Mine now' })).rejects.toMatchObject({
|
|
81
99
|
code: 'NOT_FOUND',
|
|
82
100
|
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ConditionGroup, type ConditionRule } from '@erxes/core-contract';
|
|
2
|
+
import { ORPCError } from '@orpc/server';
|
|
3
|
+
import { and, ilike, inArray, or, type SQL } from 'drizzle-orm';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { items } from '#/db/schema.ts';
|
|
6
|
+
|
|
7
|
+
export const escapeLike = (text: string) => text.replaceAll(/[\\%_]/g, '\\$&');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The list's filter bar (erxes-ui's `ListFilter`) sends core's condition group as JSON, its
|
|
11
|
+
* rules on the fields the UI gives it: `subject.name` and `subject.createdBy`.
|
|
12
|
+
*/
|
|
13
|
+
export const ItemFilter = z
|
|
14
|
+
.string()
|
|
15
|
+
.transform((text, context) => {
|
|
16
|
+
try {
|
|
17
|
+
const parsed: unknown = JSON.parse(text);
|
|
18
|
+
|
|
19
|
+
return parsed;
|
|
20
|
+
} catch {
|
|
21
|
+
context.addIssue({ code: 'custom', message: 'filter is not JSON' });
|
|
22
|
+
|
|
23
|
+
return z.NEVER;
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
.pipe(ConditionGroup);
|
|
27
|
+
|
|
28
|
+
const Values = z.array(z.string());
|
|
29
|
+
|
|
30
|
+
/** One rule as SQL; `me` is the member asking. A rule the list has no field for is refused. */
|
|
31
|
+
const ruleSql = (rule: ConditionRule, userId: string): SQL | undefined => {
|
|
32
|
+
if (rule.path === 'subject.name' && rule.op === 'contains' && typeof rule.value === 'string') {
|
|
33
|
+
return ilike(items.name, `%${escapeLike(rule.value)}%`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const picked = Values.safeParse(rule.op === 'in' ? rule.value : [rule.value]);
|
|
37
|
+
|
|
38
|
+
if (
|
|
39
|
+
rule.path === 'subject.createdBy' &&
|
|
40
|
+
(rule.op === 'in' || rule.op === 'eq') &&
|
|
41
|
+
picked.success
|
|
42
|
+
) {
|
|
43
|
+
return inArray(
|
|
44
|
+
items.createdBy,
|
|
45
|
+
picked.data.map((id) => (id === 'me' ? userId : id)),
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
throw new ORPCError('BAD_REQUEST', {
|
|
50
|
+
message: `Items can't be filtered by ${rule.path} ${rule.op}`,
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** The filter's rules as SQL: all of them, or any (a group from the advanced filter). */
|
|
55
|
+
export const filterSql = (group: ConditionGroup, userId: string): SQL | undefined => {
|
|
56
|
+
const parts = group.rules.map((part) =>
|
|
57
|
+
'rules' in part ? filterSql(part, userId) : ruleSql(part, userId),
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
return group.match === 'any' ? or(...parts) : and(...parts);
|
|
61
|
+
};
|
|
@@ -6,6 +6,7 @@ import { PERMISSIONS } from '#/core.ts';
|
|
|
6
6
|
import { uniqueViolation } from '#/db/client.ts';
|
|
7
7
|
import { ITEM_NAME_INDEX, items } from '#/db/schema.ts';
|
|
8
8
|
import { reads, writes } from '#/orpc.ts';
|
|
9
|
+
import { escapeLike, filterSql, ItemFilter } from './itemFilter.ts';
|
|
9
10
|
|
|
10
11
|
/** What a procedure returns: the row without `org_id`, which the caller already knows. */
|
|
11
12
|
const { orgId, ...columns } = getTableColumns(items);
|
|
@@ -38,21 +39,21 @@ const nameTaken =
|
|
|
38
39
|
throw error;
|
|
39
40
|
};
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Newest first, in keyset pages: `nextCursor` is the id to pass for the next page. `filter` and
|
|
44
|
+
* `search` are what the list's filter bar holds (erxes-ui's `useListFilterParams()`).
|
|
45
|
+
*/
|
|
44
46
|
const list = reads(PERMISSIONS.view)
|
|
45
47
|
.input(
|
|
46
48
|
z.object({
|
|
47
49
|
search: z.string().trim().max(200).optional(),
|
|
48
|
-
|
|
49
|
-
createdBy: z.string().optional(),
|
|
50
|
+
filter: ItemFilter.optional(),
|
|
50
51
|
cursor: z.string().optional(),
|
|
51
52
|
limit: z.number().int().min(1).max(100).default(50),
|
|
52
53
|
}),
|
|
53
54
|
)
|
|
54
55
|
.output(z.object({ items: z.array(Item), nextCursor: z.string().nullable() }))
|
|
55
|
-
.handler(async ({ input, context: { tx } }) => {
|
|
56
|
+
.handler(async ({ input, context: { tx, member } }) => {
|
|
56
57
|
const after = input.cursor
|
|
57
58
|
? sql`(${items.createdAt}, ${items.id}) < (select created_at, id from ${items} where id = ${input.cursor})`
|
|
58
59
|
: undefined;
|
|
@@ -63,7 +64,7 @@ const list = reads(PERMISSIONS.view)
|
|
|
63
64
|
.where(
|
|
64
65
|
and(
|
|
65
66
|
input.search ? ilike(items.name, `%${escapeLike(input.search)}%`) : undefined,
|
|
66
|
-
input.
|
|
67
|
+
input.filter ? filterSql(input.filter, member.userId) : undefined,
|
|
67
68
|
after,
|
|
68
69
|
),
|
|
69
70
|
)
|
|
@@ -78,6 +79,18 @@ const list = reads(PERMISSIONS.view)
|
|
|
78
79
|
};
|
|
79
80
|
});
|
|
80
81
|
|
|
82
|
+
/** One item, for its panel in core's side panel and its own page. */
|
|
83
|
+
const get = reads(PERMISSIONS.view)
|
|
84
|
+
.input(z.object({ id: z.string() }))
|
|
85
|
+
.output(Item)
|
|
86
|
+
.handler(async ({ input, context: { tx } }) => {
|
|
87
|
+
const [item] = await tx.select(columns).from(items).where(eq(items.id, input.id)).limit(1);
|
|
88
|
+
|
|
89
|
+
if (!item) throw new ORPCError('NOT_FOUND', { message: 'No such item' });
|
|
90
|
+
|
|
91
|
+
return item;
|
|
92
|
+
});
|
|
93
|
+
|
|
81
94
|
const create = writes(PERMISSIONS.manage)
|
|
82
95
|
.errors(itemErrors)
|
|
83
96
|
.input(z.object({ name: Name, description: Description.default('') }))
|
|
@@ -122,4 +135,4 @@ const remove = writes(PERMISSIONS.manage)
|
|
|
122
135
|
return item;
|
|
123
136
|
});
|
|
124
137
|
|
|
125
|
-
export const itemProcedures = { list, create, update, remove };
|
|
138
|
+
export const itemProcedures = { list, get, create, update, remove };
|
|
@@ -6,6 +6,10 @@ and renders `./__id__` (the `__Pascal__` export) under `/__id__/*`.
|
|
|
6
6
|
- `rsbuild.config.ts` declares web's shared singletons with `import: false`,
|
|
7
7
|
reading the list from `erxes-ui/federation`, so it follows the installed
|
|
8
8
|
erxes-ui. A missing name bundles a second copy and breaks at runtime.
|
|
9
|
+
- A feature is a folder in `src/modules` (`src/modules/items`); what features
|
|
10
|
+
share sits in `src`, such as `src/orpc.ts`. A folder's own
|
|
11
|
+
files import as `./`; anything else as `@/<feature>/…` (`src/modules`) or
|
|
12
|
+
`~/…` (`src`), set in `tsconfig.json` and `rsbuild.config.ts`. Lint refuses `../`.
|
|
9
13
|
- Build pages from `erxes-ui` components and its root export. The host provides
|
|
10
14
|
React, the router, the query client and erxes-ui, and web's stylesheet styles
|
|
11
15
|
erxes-ui's components.
|
|
@@ -25,9 +29,23 @@ and renders `./__id__` (the `__Pascal__` export) under `/__id__/*`.
|
|
|
25
29
|
procedure asks for (`team.view` for team members).
|
|
26
30
|
- Members: `SelectMember.Field`, `SelectMember.InlineCell`, `MemberInline` and
|
|
27
31
|
`useMembersById` from erxes-ui, given `members={memberQueries}` from
|
|
28
|
-
`@erxes/core-contract/client`. `src/items/ItemsPage.tsx` has a member filter
|
|
32
|
+
`@erxes/core-contract/client`. `src/modules/items/ItemsPage.tsx` has a member filter
|
|
29
33
|
and a "Created by" column. erxes-ui's `EntityPicker` is the searchable list
|
|
30
34
|
under them, for a picker of the plugin's own records.
|
|
35
|
+
- Pages look and behave like core's: follow the `ui-patterns` skill.
|
|
36
|
+
- Lists have core's bar (`src/modules/items/ItemsPage.tsx`): erxes-ui's `ViewBar` with
|
|
37
|
+
`ListFilter`, given the list's fields. Its conditions and search live in the
|
|
38
|
+
address; `useListFilterParams()` hands them to the list's query, and the API
|
|
39
|
+
applies them (`api/src/modules/items/itemFilter.ts`). No search boxes, toggle
|
|
40
|
+
tabs or pickers in a row above the table.
|
|
41
|
+
- Records open in core's side panel, like a customer: core draws the panel and
|
|
42
|
+
`CONFIG.recordTypes` (`src/config.tsx`) fills its slots, the item's `Title`,
|
|
43
|
+
`Detail` and `New` (`src/modules/items/ItemPanel.tsx`). `useOpenRecord()`
|
|
44
|
+
opens them, and `/__id__/:id` renders erxes-ui's `RecordPage` for the expanded
|
|
45
|
+
record. A plugin's records of other records' customers are `relationTabs`
|
|
46
|
+
(the `ui-patterns` skill). Forms are core's
|
|
47
|
+
`PanelFormRow` rows with Cancel and Save at the bottom; nothing saves until
|
|
48
|
+
Save. Dialogs are for confirmations, not forms.
|
|
31
49
|
- Text uses `t(key, 'English default')` from `react-i18next`.
|
|
32
50
|
- Development: `pnpm dev:ui` serves `http://localhost:__uiPort__/remoteEntry.js`;
|
|
33
51
|
web loads it from the manifest's `UI_ENTRY_URL` or from its own
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"build": "rsbuild build"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@erxes/core-contract": "0.1.0-v2.
|
|
11
|
+
"@erxes/core-contract": "0.1.0-v2.6",
|
|
12
12
|
"@orpc/client": "1.16.2",
|
|
13
13
|
"@orpc/tanstack-query": "1.16.2",
|
|
14
14
|
"@tabler/icons-react": "3.34.0",
|
|
15
15
|
"@tanstack/react-query": "^5.107.1",
|
|
16
|
-
"erxes-ui": "npm:@erxes/ui@4.0.0-v2.
|
|
16
|
+
"erxes-ui": "npm:@erxes/ui@4.0.0-v2.7",
|
|
17
17
|
"jotai": "^3.0.2",
|
|
18
18
|
"nuqs": "^2.10.3",
|
|
19
19
|
"react": "19.3.1",
|
|
@@ -30,6 +30,8 @@ export default defineConfig({
|
|
|
30
30
|
}),
|
|
31
31
|
],
|
|
32
32
|
source: { entry: { index: './src/index.ts' } },
|
|
33
|
+
// As tsconfig.json's paths: @/ is a feature in src/modules, ~/ anything else in src.
|
|
34
|
+
resolve: { alias: { '@': './src/modules', '~': './src' } },
|
|
33
35
|
// Chunks load from wherever remoteEntry.js came from, not from web's origin.
|
|
34
36
|
output: { assetPrefix: 'auto' },
|
|
35
37
|
dev: { assetPrefix: true, lazyCompilation: false },
|
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
import { addPluginStyles } from 'erxes-ui';
|
|
2
|
-
import { Route, Routes } from 'react-router-dom';
|
|
3
|
-
import { ItemsPage } from '
|
|
4
|
-
import {
|
|
1
|
+
import { addPluginStyles, RecordPage } from 'erxes-ui';
|
|
2
|
+
import { Route, Routes, useParams } from 'react-router-dom';
|
|
3
|
+
import { ItemsPage } from '@/items/ItemsPage.tsx';
|
|
4
|
+
import { ITEM_TYPE } from '@/items/useItems.ts';
|
|
5
|
+
import { PLUGIN } from '~/orpc.ts';
|
|
5
6
|
import css from './styles.css?inline';
|
|
6
7
|
|
|
7
8
|
addPluginStyles(PLUGIN, css);
|
|
8
9
|
|
|
10
|
+
/** An item on its own page, where its panel's expand button leads: core draws it full size. */
|
|
11
|
+
const ItemPage = () => <RecordPage contentType={ITEM_TYPE} contentId={useParams().id ?? ''} />;
|
|
12
|
+
|
|
9
13
|
/** The page module web renders under `/__id__/*` (loaded as `__id___ui/__id__`). */
|
|
10
14
|
export const __Pascal__ = () => (
|
|
11
15
|
<Routes>
|
|
12
16
|
<Route index element={<ItemsPage />} />
|
|
17
|
+
<Route path=":id" element={<ItemPage />} />
|
|
13
18
|
</Routes>
|
|
14
19
|
);
|
|
@@ -1,11 +1,34 @@
|
|
|
1
1
|
import { IconBox } from '@tabler/icons-react';
|
|
2
2
|
import type { IUIConfig } from 'erxes-ui';
|
|
3
|
-
import {
|
|
3
|
+
import { lazy } from 'react';
|
|
4
|
+
import { ITEM_TYPE } from '@/items/useItems.ts';
|
|
5
|
+
import { PLUGIN } from '~/orpc.ts';
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
// Loaded when an item first opens: web loads `./config` for every page.
|
|
8
|
+
const panel = () => import('@/items/ItemPanel.tsx');
|
|
9
|
+
const ItemTitle = lazy(async () => ({ default: (await panel()).ItemTitle }));
|
|
10
|
+
const ItemDetail = lazy(async () => ({ default: (await panel()).ItemDetail }));
|
|
11
|
+
const ItemNew = lazy(async () => ({ default: (await panel()).ItemNew }));
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* What web reads from `./config`: the app tab, the page module under `/__id__/*`, and the
|
|
15
|
+
* records core's side panel opens. Core draws an item's panel; these slots fill it. An item
|
|
16
|
+
* expands to `/__id__/<id>` (`__Pascal__.tsx`).
|
|
17
|
+
*/
|
|
6
18
|
export const CONFIG: IUIConfig = {
|
|
7
19
|
name: PLUGIN,
|
|
8
20
|
path: PLUGIN,
|
|
9
21
|
icon: IconBox,
|
|
10
22
|
modules: [{ name: PLUGIN, path: PLUGIN, icon: IconBox }],
|
|
23
|
+
recordTypes: [
|
|
24
|
+
{
|
|
25
|
+
contentType: ITEM_TYPE,
|
|
26
|
+
title: 'Item',
|
|
27
|
+
icon: IconBox,
|
|
28
|
+
detailPath: (id) => `/${PLUGIN}/${encodeURIComponent(id)}`,
|
|
29
|
+
Title: ItemTitle,
|
|
30
|
+
Detail: ItemDetail,
|
|
31
|
+
New: ItemNew,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
11
34
|
};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { isDefinedError } from '@orpc/client';
|
|
2
|
+
import { IconAlignLeft, IconLetterCase } from '@tabler/icons-react';
|
|
3
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
4
|
+
import {
|
|
5
|
+
Input,
|
|
6
|
+
PanelFormLayout,
|
|
7
|
+
PanelFormRow,
|
|
8
|
+
PanelSection,
|
|
9
|
+
Skeleton,
|
|
10
|
+
Spinner,
|
|
11
|
+
Textarea,
|
|
12
|
+
type TRecordDraftProps,
|
|
13
|
+
type TRecordSlotProps,
|
|
14
|
+
} from 'erxes-ui';
|
|
15
|
+
import { useRef } from 'react';
|
|
16
|
+
import { useTranslation } from 'react-i18next';
|
|
17
|
+
import { orpc } from '~/orpc.ts';
|
|
18
|
+
import type { Item } from './useItems.ts';
|
|
19
|
+
|
|
20
|
+
const textOf = (value: FormDataEntryValue | null) => (typeof value === 'string' ? value : '');
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* An item's fields in core's form rows: a new one (`item` undefined) or a change to one.
|
|
24
|
+
* Nothing saves until Save; ITEM_NAME_TAKEN shows under the name.
|
|
25
|
+
*/
|
|
26
|
+
const ItemForm = ({
|
|
27
|
+
item,
|
|
28
|
+
onSaved,
|
|
29
|
+
onCancel,
|
|
30
|
+
}: {
|
|
31
|
+
item?: Item;
|
|
32
|
+
onSaved?: (item: Item) => void;
|
|
33
|
+
/** Without it, Cancel puts the fields back. */
|
|
34
|
+
onCancel?: () => void;
|
|
35
|
+
}) => {
|
|
36
|
+
const { t } = useTranslation('__id__');
|
|
37
|
+
const queryClient = useQueryClient();
|
|
38
|
+
const formRef = useRef<HTMLFormElement>(null);
|
|
39
|
+
|
|
40
|
+
const onSuccess = (saved: Item) => {
|
|
41
|
+
void queryClient.invalidateQueries({ queryKey: orpc.items.key() });
|
|
42
|
+
onSaved?.(saved);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const create = useMutation(orpc.items.create.mutationOptions({ onSuccess }));
|
|
46
|
+
const update = useMutation(orpc.items.update.mutationOptions({ onSuccess }));
|
|
47
|
+
const { error, isPending } = item ? update : create;
|
|
48
|
+
|
|
49
|
+
const takenName =
|
|
50
|
+
isDefinedError(error) && error.code === 'ITEM_NAME_TAKEN' ? error.data.name : null;
|
|
51
|
+
|
|
52
|
+
const save = (form: FormData) => {
|
|
53
|
+
const fields = {
|
|
54
|
+
name: textOf(form.get('name')),
|
|
55
|
+
description: textOf(form.get('description')),
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
if (item) update.mutate({ id: item.id, ...fields });
|
|
59
|
+
else create.mutate(fields);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<form ref={formRef} action={save} className="flex min-h-0 flex-1 flex-col">
|
|
64
|
+
<PanelFormLayout
|
|
65
|
+
onCancel={onCancel ?? (() => formRef.current?.reset())}
|
|
66
|
+
saving={isPending}
|
|
67
|
+
saveLabel={item ? t('save', 'Save') : t('create', 'Create item')}
|
|
68
|
+
>
|
|
69
|
+
<PanelFormRow
|
|
70
|
+
label={t('name', 'Name')}
|
|
71
|
+
icon={IconLetterCase}
|
|
72
|
+
required
|
|
73
|
+
error={
|
|
74
|
+
takenName === null
|
|
75
|
+
? undefined
|
|
76
|
+
: t('name-taken', 'Another item is already called {{name}}.', { name: takenName })
|
|
77
|
+
}
|
|
78
|
+
>
|
|
79
|
+
<Input
|
|
80
|
+
name="name"
|
|
81
|
+
required
|
|
82
|
+
defaultValue={item?.name}
|
|
83
|
+
placeholder={t('name', 'Name')}
|
|
84
|
+
aria-invalid={takenName !== null}
|
|
85
|
+
variant="bordered"
|
|
86
|
+
text="sm"
|
|
87
|
+
/>
|
|
88
|
+
</PanelFormRow>
|
|
89
|
+
<PanelFormRow label={t('description', 'Description')} icon={IconAlignLeft}>
|
|
90
|
+
<Textarea name="description" defaultValue={item?.description} />
|
|
91
|
+
</PanelFormRow>
|
|
92
|
+
{error && !isDefinedError(error) && (
|
|
93
|
+
<p role="alert" className="text-xs text-destructive">
|
|
94
|
+
{error.message}
|
|
95
|
+
</p>
|
|
96
|
+
)}
|
|
97
|
+
</PanelFormLayout>
|
|
98
|
+
</form>
|
|
99
|
+
);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/** A new item in core's side panel, under its "New item" header; Save puts the item in its place. */
|
|
103
|
+
export const ItemNew = ({ onCreated, onCancel }: TRecordDraftProps) => (
|
|
104
|
+
<ItemForm onSaved={(item) => onCreated(item.id)} onCancel={onCancel} />
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
/** The item the panel shows; its slots share this one query. */
|
|
108
|
+
const useItem = (contentId: string) =>
|
|
109
|
+
useQuery(orpc.items.get.queryOptions({ input: { id: contentId } }));
|
|
110
|
+
|
|
111
|
+
/** The panel header's title: the item's name. */
|
|
112
|
+
export const ItemTitle = ({ contentId }: TRecordSlotProps) => {
|
|
113
|
+
const item = useItem(contentId);
|
|
114
|
+
|
|
115
|
+
if (item.isPending) return <Skeleton className="h-4 w-32" />;
|
|
116
|
+
|
|
117
|
+
return <span className="truncate">{item.data?.name ?? item.error?.message}</span>;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/** The Detail tab: the item's fields, changed in place and saved with Save. */
|
|
121
|
+
export const ItemDetail = ({ contentId }: TRecordSlotProps) => {
|
|
122
|
+
const { t } = useTranslation('__id__');
|
|
123
|
+
const item = useItem(contentId);
|
|
124
|
+
|
|
125
|
+
if (item.isPending) return <Spinner area="lg" />;
|
|
126
|
+
|
|
127
|
+
if (item.isError) {
|
|
128
|
+
return (
|
|
129
|
+
<p role="alert" className="p-3 text-xs text-destructive">
|
|
130
|
+
{item.error.message}
|
|
131
|
+
</p>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<PanelSection title={t('item', 'Item')}>
|
|
137
|
+
<ItemForm item={item.data} />
|
|
138
|
+
</PanelSection>
|
|
139
|
+
);
|
|
140
|
+
};
|
|
@@ -3,25 +3,31 @@ import { IconBox, IconPlus, IconTrash } from '@tabler/icons-react';
|
|
|
3
3
|
import {
|
|
4
4
|
Button,
|
|
5
5
|
Empty,
|
|
6
|
+
ListFilter,
|
|
6
7
|
MemberInline,
|
|
7
8
|
PageContainer,
|
|
8
9
|
PageHeader,
|
|
9
10
|
RecordTable,
|
|
10
11
|
type RecordTableColumnDef,
|
|
11
12
|
RecordTableInlineCell,
|
|
12
|
-
|
|
13
|
+
type TListFilterField,
|
|
13
14
|
useFormat,
|
|
15
|
+
useOpenRecord,
|
|
16
|
+
ViewBar,
|
|
14
17
|
} from 'erxes-ui';
|
|
15
|
-
import { useState } from 'react';
|
|
16
18
|
import { useTranslation } from 'react-i18next';
|
|
17
|
-
import {
|
|
18
|
-
import { type Item, useItems, useOpenItem, useRemoveItem } from './useItems.ts';
|
|
19
|
+
import { type Item, ITEM_TYPE, useItems, useRemoveItem } from './useItems.ts';
|
|
19
20
|
|
|
21
|
+
/** The name opens the item in core's side panel, as a customer's name does. */
|
|
20
22
|
const NameCell = ({ item }: { item: Item }) => {
|
|
21
|
-
const { open } =
|
|
23
|
+
const { open } = useOpenRecord();
|
|
22
24
|
|
|
23
25
|
return (
|
|
24
|
-
<Button
|
|
26
|
+
<Button
|
|
27
|
+
variant="ghost"
|
|
28
|
+
className="w-full justify-start"
|
|
29
|
+
onClick={() => open({ contentType: ITEM_TYPE, contentId: item.id })}
|
|
30
|
+
>
|
|
25
31
|
{item.name}
|
|
26
32
|
</Button>
|
|
27
33
|
);
|
|
@@ -89,14 +95,22 @@ const columns: RecordTableColumnDef<Item>[] = [
|
|
|
89
95
|
},
|
|
90
96
|
];
|
|
91
97
|
|
|
92
|
-
/**
|
|
98
|
+
/**
|
|
99
|
+
* The item list, newest first, under core's list bar: its one view, then the filter (`F`) on
|
|
100
|
+
* the fields below, whose rules the API applies (`api/src/modules/items/itemFilter.ts`). Each
|
|
101
|
+
* item opens in core's side panel; Add opens a new one there.
|
|
102
|
+
*/
|
|
93
103
|
export const ItemsPage = () => {
|
|
94
104
|
const { t } = useTranslation('__id__');
|
|
95
|
-
const {
|
|
96
|
-
const
|
|
97
|
-
const { data, isPending, error, hasNextPage, fetchNextPage } = useItems(createdBy);
|
|
105
|
+
const { openNew } = useOpenRecord();
|
|
106
|
+
const { data, isPending, error, hasNextPage, fetchNextPage } = useItems();
|
|
98
107
|
const list = data?.pages.flatMap((page) => page.items) ?? [];
|
|
99
108
|
|
|
109
|
+
const fields: TListFilterField[] = [
|
|
110
|
+
{ path: 'subject.name', label: t('name', 'Name'), type: 'text' },
|
|
111
|
+
{ path: 'subject.createdBy', label: t('created-by', 'Created by'), type: 'member' },
|
|
112
|
+
];
|
|
113
|
+
|
|
100
114
|
return (
|
|
101
115
|
<PageContainer>
|
|
102
116
|
<PageHeader>
|
|
@@ -105,22 +119,20 @@ export const ItemsPage = () => {
|
|
|
105
119
|
<h1 className="text-sm font-semibold">{t('items', 'Items')}</h1>
|
|
106
120
|
</PageHeader.Start>
|
|
107
121
|
<PageHeader.End>
|
|
108
|
-
{
|
|
109
|
-
<SelectMember.Field
|
|
110
|
-
aria-label={t('created-by', 'Created by')}
|
|
111
|
-
className="w-40 md:w-64"
|
|
112
|
-
value={createdBy}
|
|
113
|
-
onValueChange={setCreatedBy}
|
|
114
|
-
members={memberQueries}
|
|
115
|
-
placeholder={t('anyone', 'Created by anyone')}
|
|
116
|
-
noneLabel={t('anyone', 'Created by anyone')}
|
|
117
|
-
/>
|
|
118
|
-
<Button onClick={() => open('new')}>
|
|
122
|
+
<Button onClick={() => openNew(ITEM_TYPE)}>
|
|
119
123
|
<IconPlus />
|
|
120
124
|
{t('add', 'Add item')}
|
|
121
125
|
</Button>
|
|
122
126
|
</PageHeader.End>
|
|
123
127
|
</PageHeader>
|
|
128
|
+
<ViewBar allLabel={t('all-items', 'All items')}>
|
|
129
|
+
<ListFilter
|
|
130
|
+
id="__id__-items"
|
|
131
|
+
fields={fields}
|
|
132
|
+
totalCount={isPending ? undefined : list.length}
|
|
133
|
+
totalCapped={hasNextPage}
|
|
134
|
+
/>
|
|
135
|
+
</ViewBar>
|
|
124
136
|
{error ? (
|
|
125
137
|
<p className="m-3 text-sm text-destructive">{error.message}</p>
|
|
126
138
|
) : (
|
|
@@ -143,7 +155,6 @@ export const ItemsPage = () => {
|
|
|
143
155
|
)}
|
|
144
156
|
</RecordTable.Provider>
|
|
145
157
|
)}
|
|
146
|
-
<ItemSheet items={list} />
|
|
147
158
|
</PageContainer>
|
|
148
159
|
);
|
|
149
160
|
};
|
|
@@ -6,24 +6,29 @@ import {
|
|
|
6
6
|
useQueryClient,
|
|
7
7
|
} from '@tanstack/react-query';
|
|
8
8
|
import type { Client } from '@__id__/api';
|
|
9
|
-
import { toast } from 'erxes-ui';
|
|
9
|
+
import { toast, useListFilterParams } from 'erxes-ui';
|
|
10
10
|
import { useTranslation } from 'react-i18next';
|
|
11
|
-
import {
|
|
12
|
-
import { orpc } from '../orpc.ts';
|
|
11
|
+
import { orpc, PLUGIN } from '~/orpc.ts';
|
|
13
12
|
|
|
14
13
|
type Outputs = InferClientOutputs<Client>['items'];
|
|
15
14
|
|
|
16
15
|
export type Item = Outputs['create'];
|
|
17
16
|
|
|
18
|
-
/**
|
|
19
|
-
export const
|
|
20
|
-
|
|
17
|
+
/** An item in core's side panel: `useOpenRecord().open({ contentType: ITEM_TYPE, contentId })`. */
|
|
18
|
+
export const ITEM_TYPE = `${PLUGIN}:item`;
|
|
19
|
+
|
|
20
|
+
/** Every page loaded so far, newest first, narrowed by the filter bar's conditions and search. */
|
|
21
|
+
export const useItems = () => {
|
|
22
|
+
const filters = useListFilterParams();
|
|
23
|
+
|
|
24
|
+
return useInfiniteQuery(
|
|
21
25
|
orpc.items.list.infiniteOptions({
|
|
22
|
-
input: (cursor: string | undefined) => ({ cursor,
|
|
26
|
+
input: (cursor: string | undefined) => ({ cursor, ...filters }),
|
|
23
27
|
initialPageParam: undefined,
|
|
24
28
|
getNextPageParam: (page) => page.nextCursor ?? undefined,
|
|
25
29
|
}),
|
|
26
30
|
);
|
|
31
|
+
};
|
|
27
32
|
|
|
28
33
|
/**
|
|
29
34
|
* Deletes an item. It leaves every loaded list at once and comes back if the
|
|
@@ -66,14 +71,3 @@ export const useRemoveItem = () => {
|
|
|
66
71
|
}),
|
|
67
72
|
);
|
|
68
73
|
};
|
|
69
|
-
|
|
70
|
-
/** `?item=<id>` opens that item in the side panel, `?item=new` a blank one. */
|
|
71
|
-
export const useOpenItem = () => {
|
|
72
|
-
const [params, setParams] = useSearchParams();
|
|
73
|
-
|
|
74
|
-
return {
|
|
75
|
-
openId: params.get('item'),
|
|
76
|
-
open: (id: string) => setParams({ item: id }),
|
|
77
|
-
close: () => setParams({}),
|
|
78
|
-
};
|
|
79
|
-
};
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
"module": "esnext",
|
|
6
6
|
"moduleResolution": "bundler",
|
|
7
7
|
"jsx": "react-jsx",
|
|
8
|
-
"types": ["node", "@rsbuild/core/types"]
|
|
8
|
+
"types": ["node", "@rsbuild/core/types"],
|
|
9
|
+
"paths": { "@/*": ["./src/modules/*"], "~/*": ["./src/*"] }
|
|
9
10
|
},
|
|
10
11
|
"include": ["src", "rsbuild.config.ts"]
|
|
11
12
|
}
|
|
@@ -52,8 +52,8 @@ data only. The inventory reads code, never a database.
|
|
|
52
52
|
drafted with their import from old core's `departments`, `branches` and the
|
|
53
53
|
members' `departmentIds` and `branchIds`. The ids stay the same, so the old
|
|
54
54
|
records' `departmentIds` still match.
|
|
55
|
-
5. Pages. One per UI route, under `ui/src/<module>/`, built from
|
|
56
|
-
the way `ui/src/items/` is. The old `ui-modules` components don't exist
|
|
55
|
+
5. Pages. One per UI route, under `ui/src/modules/<module>/`, built from
|
|
56
|
+
`erxes-ui` the way `ui/src/modules/items/` is, laid out by the `ui-patterns` skill. The old `ui-modules` components don't exist
|
|
57
57
|
here. Member pickers and names become erxes-ui's `SelectMember` and
|
|
58
58
|
`MemberInline`; a picker of other records is erxes-ui's `EntityPicker` over
|
|
59
59
|
the plugin's own query. For erxes-ui components whose props changed, see
|
package/package.json
CHANGED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { isDefinedError } from '@orpc/client';
|
|
2
|
-
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
3
|
-
import { Button, Input, Label, Sheet, Textarea } from 'erxes-ui';
|
|
4
|
-
import { useTranslation } from 'react-i18next';
|
|
5
|
-
import { orpc } from '../orpc.ts';
|
|
6
|
-
import { type Item, useOpenItem } from './useItems.ts';
|
|
7
|
-
|
|
8
|
-
const textOf = (value: FormDataEntryValue | null) => (typeof value === 'string' ? value : '');
|
|
9
|
-
|
|
10
|
-
/** A new item (`item` undefined) or a change to one. ITEM_NAME_TAKEN shows on the name field. */
|
|
11
|
-
const ItemForm = ({ item, onSaved }: { item?: Item; onSaved: () => void }) => {
|
|
12
|
-
const { t } = useTranslation('__id__');
|
|
13
|
-
const queryClient = useQueryClient();
|
|
14
|
-
|
|
15
|
-
const onSuccess = () => {
|
|
16
|
-
void queryClient.invalidateQueries({ queryKey: orpc.items.key() });
|
|
17
|
-
onSaved();
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const create = useMutation(orpc.items.create.mutationOptions({ onSuccess }));
|
|
21
|
-
const update = useMutation(orpc.items.update.mutationOptions({ onSuccess }));
|
|
22
|
-
const { error, isPending } = item ? update : create;
|
|
23
|
-
|
|
24
|
-
const takenName =
|
|
25
|
-
isDefinedError(error) && error.code === 'ITEM_NAME_TAKEN' ? error.data.name : null;
|
|
26
|
-
|
|
27
|
-
const save = (form: FormData) => {
|
|
28
|
-
const fields = {
|
|
29
|
-
name: textOf(form.get('name')),
|
|
30
|
-
description: textOf(form.get('description')),
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
if (item) update.mutate({ id: item.id, ...fields });
|
|
34
|
-
else create.mutate(fields);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
return (
|
|
38
|
-
<form action={save} className="flex flex-1 flex-col">
|
|
39
|
-
<Sheet.Content>
|
|
40
|
-
<div className="flex flex-col gap-4">
|
|
41
|
-
<div className="flex flex-col gap-2">
|
|
42
|
-
<Label htmlFor="item-name">{t('name', 'Name')}</Label>
|
|
43
|
-
<Input
|
|
44
|
-
id="item-name"
|
|
45
|
-
name="name"
|
|
46
|
-
required
|
|
47
|
-
defaultValue={item?.name}
|
|
48
|
-
aria-invalid={takenName !== null}
|
|
49
|
-
aria-describedby={takenName === null ? undefined : 'item-name-error'}
|
|
50
|
-
/>
|
|
51
|
-
{takenName !== null && (
|
|
52
|
-
<p id="item-name-error" className="text-sm text-destructive">
|
|
53
|
-
{t('name-taken', 'Another item is already called {{name}}.', { name: takenName })}
|
|
54
|
-
</p>
|
|
55
|
-
)}
|
|
56
|
-
</div>
|
|
57
|
-
<div className="flex flex-col gap-2">
|
|
58
|
-
<Label htmlFor="item-description">{t('description', 'Description')}</Label>
|
|
59
|
-
<Textarea id="item-description" name="description" defaultValue={item?.description} />
|
|
60
|
-
</div>
|
|
61
|
-
{error && !isDefinedError(error) && (
|
|
62
|
-
<p role="alert" className="text-sm text-destructive">
|
|
63
|
-
{error.message}
|
|
64
|
-
</p>
|
|
65
|
-
)}
|
|
66
|
-
</div>
|
|
67
|
-
</Sheet.Content>
|
|
68
|
-
<Sheet.Footer>
|
|
69
|
-
<Button type="submit" disabled={isPending}>
|
|
70
|
-
{t('save', 'Save')}
|
|
71
|
-
</Button>
|
|
72
|
-
</Sheet.Footer>
|
|
73
|
-
</form>
|
|
74
|
-
);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
/** The side panel: a new item, or one from the list to change. */
|
|
78
|
-
export const ItemSheet = ({ items }: { items: Item[] }) => {
|
|
79
|
-
const { t } = useTranslation('__id__');
|
|
80
|
-
const { openId, close } = useOpenItem();
|
|
81
|
-
const item = items.find((candidate) => candidate.id === openId);
|
|
82
|
-
|
|
83
|
-
return (
|
|
84
|
-
<Sheet open={Boolean(openId)} onOpenChange={(open) => !open && close()}>
|
|
85
|
-
<Sheet.View className="sm:max-w-md">
|
|
86
|
-
<Sheet.Header>
|
|
87
|
-
<Sheet.Title>{item ? item.name : t('new-item', 'New item')}</Sheet.Title>
|
|
88
|
-
<Sheet.Description className="sr-only">
|
|
89
|
-
{item
|
|
90
|
-
? t('edit-item-hint', 'Change the name or the description.')
|
|
91
|
-
: t('new-item-hint', 'Give it a name. The description is optional.')}
|
|
92
|
-
</Sheet.Description>
|
|
93
|
-
<Sheet.Close />
|
|
94
|
-
</Sheet.Header>
|
|
95
|
-
{openId === 'new' || item ? (
|
|
96
|
-
<ItemForm key={item?.id ?? 'new'} item={item} onSaved={close} />
|
|
97
|
-
) : (
|
|
98
|
-
<Sheet.Content>
|
|
99
|
-
<p className="text-sm text-muted-foreground">
|
|
100
|
-
{t('not-found', 'This item is not in the list.')}
|
|
101
|
-
</p>
|
|
102
|
-
</Sheet.Content>
|
|
103
|
-
)}
|
|
104
|
-
</Sheet.View>
|
|
105
|
-
</Sheet>
|
|
106
|
-
);
|
|
107
|
-
};
|