@micha.bigler/ui-core-micha 4.17.0 → 4.19.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.19.0 - UCM-CHAT-8
4
+
5
+ `ChatWorkspace` starts the status, catalogue and both chat-list requests together on mount and on every scope change,
6
+ instead of waiting for the status first; when the status is not `available` (or fails) the other answers are discarded
7
+ and the unavailable or error state is shown as before. New optional prop `preloadedChats` (`{ scope, results, next }`):
8
+ an active list the app already loaded for the same `scope` replaces the active-list request at the start; the archived
9
+ list is still requested, and later reloads are unchanged. Every consumer now sends catalogue and list requests also when
10
+ the assistant is not configured.
11
+
12
+ ## 4.18.0 - UCM-BILL-10
13
+
14
+ `AccountPage` accepts an optional `billingOperator({ user, account }) => boolean` and passes it as the operator rule to
15
+ the billing users columns it builds when `billingUsers` is set, so status, badge and the "Ohne Abo" switch follow the
16
+ app's rule. Without the prop the superuser default stays; with `billingUsers` off nothing changes.
17
+
3
18
  ## 4.17.0 - UCM-BILL-9
4
19
 
5
20
  Users tab, every app: the billing access column is a short coloured status (`accountAccessText` now returns
package/README.md CHANGED
@@ -29,7 +29,9 @@ With billing in the account page, the user list shows two columns: "Zugang", a s
29
29
  "{Plan} · bis {Datum}", "Team · bis {Datum}", "Schreibgeschützt", "Betreiber"), and "Ohne Abo", the free-access switch
30
30
  without a visible label (only for free and read-only rows; "–" otherwise). Plan names come from the app's own catalogue
31
31
  (`getMe().plans`); a plan without a name shows "Abo", never its key. Operator rows default to `user.is_superuser`;
32
- `useBillingUsersColumn({ isOperator: ({ user, account }) => ... })` overrides that. The built-in delete is an icon button
32
+ `<AccountPage billingUsers billingOperator={({ user }) => user.is_superuser || user.role === 'admin'}>` (or
33
+ `useBillingUsersColumn({ isOperator })` directly) applies the app's own rule; a new function per render does not
34
+ refetch the accounts. The built-in delete is an icon button
33
35
  named "Löschen – {Name}", shown disabled on the own row; confirmation, permissions and app row actions are unchanged.
34
36
 
35
37
  ## Account section: plan choice on the app's own page
@@ -167,7 +169,10 @@ above the composer. Without `composerLayout` the composer is unchanged. `ChatCom
167
169
 
168
170
  `ChatWorkspace` (from `@micha.bigler/ui-core-micha/chat`) takes optional props for apps that put UI around the surface;
169
171
  without them it behaves as before. Each is described in `CHANGELOG.md` under the release that added it.
170
- Since 4.3.0: `getSendContext()` (a plain object attached as `context` to every `send` frame, read by
172
+ Since 4.19.0: `preloadedChats` (`{ scope, results, next }`, the active-list response the app already loaded for that
173
+ `scope`): the start then requests only the archived list. It is used once, at the start, and only when its `scope`
174
+ equals the workspace's `scope`; later reloads request both lists as before. The start requests status, catalogue and
175
+ both lists together; when the status is not available their answers are discarded. Since 4.3.0: `getSendContext()` (a plain object attached as `context` to every `send` frame, read by
171
176
  `django-core-micha` 3.3.0), `sendRequest` (`{ id, text }`, sends a message on the host's behalf) and
172
177
  `onSendRequestHandled({ id, sent })`. Since 4.2.0: `activeChatId`, `onActiveChatChange`, `composerPrefill` and
173
178
  `send(text)` / `canSend` in `renderAnswerExtra`.
@@ -60,9 +60,10 @@ const appendDelta = (turns, text) => {
60
60
  * The complete chat surface: chat list, thread, composer and model picker for one user.
61
61
  *
62
62
  * Props: `apiBase` and `wsUrl` (where the app mounted the chat routes), `api` (partial overrides of the REST
63
- * calls; every function not given keeps its default), `scope` (passed when creating a chat), `sx`.
63
+ * calls; every function not given keeps its default), `scope` (passed when creating a chat),
64
+ * `preloadedChats` (optional active-list response `{ scope, results, next }` already loaded for that exact scope), `sx`.
64
65
  */
65
- export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, sx, unavailableReasonText, sidePanel, sidePanelLabel, renderAnswerExtra, renderComposerExtra, composerLayout = 'standard', renderComposerContext, onAppFrame, activeChatId, onActiveChatChange, composerPrefill, getSendContext, sendRequest, onSendRequestHandled, layout = 'viewport', compactBelow = 720, tokenBalance = null, usageToTokens, longChatTokens = 40000 }) {
66
+ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloadedChats, sx, unavailableReasonText, sidePanel, sidePanelLabel, renderAnswerExtra, renderComposerExtra, composerLayout = 'standard', renderComposerContext, onAppFrame, activeChatId, onActiveChatChange, composerPrefill, getSendContext, sendRequest, onSendRequestHandled, layout = 'viewport', compactBelow = 720, tokenBalance = null, usageToTokens, longChatTokens = 40000 }) {
66
67
  var _a;
67
68
  const { t } = useTranslation();
68
69
  const theme = useTheme();
@@ -165,37 +166,61 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, sx, un
165
166
  // Bumped on every scope change so that a list response of the previous scope is dropped.
166
167
  const scopeVersion = useRef(0);
167
168
  useEffect(() => { scopeVersion.current += 1; setChat(null); setListsLoaded(false); appliedId.current = undefined; unloadableIds.current.clear(); }, [scope]);
168
- const loadLists = useCallback(async () => {
169
+ const loadLists = useCallback(async ({ initial = false, preloaded } = {}) => {
169
170
  const version = scopeVersion.current;
170
171
  // Without a scope the api is called exactly as before the scope existed.
171
- const [active, old] = scope === undefined
172
- ? await Promise.all([api.listChats(), api.listChats({ archived: true })])
173
- : await Promise.all([api.listChats({ scope }), api.listChats({ scope, archived: true })]);
172
+ const activeRequest = preloaded === undefined
173
+ ? (scope === undefined ? api.listChats() : api.listChats({ scope }))
174
+ : Promise.resolve(preloaded);
175
+ const archivedRequest = scope === undefined ? api.listChats({ archived: true }) : api.listChats({ scope, archived: true });
176
+ const [active, old] = await Promise.all([activeRequest, archivedRequest]);
174
177
  if (version !== scopeVersion.current)
175
178
  return undefined;
176
- setChats(active.results || []);
177
- setNextChats(active.next || null);
178
- setArchived(old.results || []);
179
- return [...(active.results || []), ...(old.results || [])];
179
+ if (!initial) {
180
+ setChats(active.results || []);
181
+ setNextChats(active.next || null);
182
+ setArchived(old.results || []);
183
+ }
184
+ return { active, old, all: [...(active.results || []), ...(old.results || [])] };
180
185
  }, [api, scope]);
186
+ // Read through a ref: the preloaded list only matters when a start begins, and an inline object from the app must
187
+ // not restart the start requests on every render.
188
+ const preloadedChatsRef = useRef(preloadedChats);
189
+ preloadedChatsRef.current = preloadedChats;
181
190
  useEffect(() => {
182
191
  let live = true;
183
- const request = scope === undefined ? api.getStatus() : api.getStatus({ scope });
184
- request
185
- .then(async (state) => {
192
+ const offered = preloadedChatsRef.current;
193
+ const preloaded = offered && offered.scope === scope
194
+ ? { results: offered.results, next: offered.next }
195
+ : undefined;
196
+ const statusRequest = Promise.resolve().then(() => (scope === undefined ? api.getStatus() : api.getStatus({ scope })));
197
+ const catalogueRequest = Promise.resolve().then(() => api.getCatalogue());
198
+ const listsRequest = Promise.resolve().then(() => loadLists({ initial: true, preloaded }));
199
+ // These may finish after an unavailable status; attach rejection handlers immediately and never expose their answers.
200
+ catalogueRequest.catch(() => { });
201
+ listsRequest.catch(() => { });
202
+ statusRequest
203
+ .then((state) => {
204
+ if (!live)
205
+ return;
186
206
  if (state.status !== 'available') {
187
- if (live) {
188
- setStatus(state.status);
189
- setUnavailableReason(state.reason || null);
190
- }
207
+ setStatus(state.status);
208
+ setUnavailableReason(state.reason || null);
191
209
  return;
192
210
  }
193
- const [entries] = await Promise.all([api.getCatalogue(), loadLists()]);
194
- if (live) {
195
- setStatus(state.status);
211
+ Promise.all([catalogueRequest, listsRequest]).then(([entries, lists]) => {
212
+ if (!live || lists === undefined)
213
+ return;
214
+ const { active, old } = lists;
196
215
  setCatalogue(entries);
216
+ setChats(active.results || []);
217
+ setNextChats(active.next || null);
218
+ setArchived(old.results || []);
219
+ setStatus(state.status);
197
220
  setListsLoaded(true);
198
- }
221
+ setUnavailableReason(null);
222
+ }).catch(() => { if (live)
223
+ setStatus('error'); });
199
224
  })
200
225
  .catch(() => { if (live)
201
226
  setStatus('error'); });
@@ -238,7 +263,7 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, sx, un
238
263
  loadLists().then((loaded) => {
239
264
  if (!live || loaded === undefined || latestWantedId.current === undefined || String(latestWantedId.current) !== wantedKey)
240
265
  return;
241
- const found = loaded.find((item) => String(item.id) === wantedKey);
266
+ const found = loaded.all.find((item) => String(item.id) === wantedKey);
242
267
  if (!found)
243
268
  unloadableIds.current.add(wantedKey);
244
269
  setChat(found || null);
@@ -27,7 +27,12 @@ import { BulkInviteCsvTab } from '../components/BulkInviteCsvTab';
27
27
  import { fetchAuthPolicy, updateUserProfile } from '../auth/authApi'; // Ggf. Pfad anpassen
28
28
  import { defaultBillingApi } from '../billing/api';
29
29
  import { useBillingUsersColumn } from '../billing/useBillingUsersColumn';
30
- export function AccountPage({ userListExtraColumns = [], userListExtraRowActions = [], userListExtraContext = null, userListRefreshTrigger = 0, userListCanEditUser = null, userListShowNewColumn = true, userListShowSuccessfulLoginColumn = true, userListShowRoleColumn = true, userListOnChangeRole = null, userListShowDeleteAction = true, userListCanDeleteUser = null, userListOnDeleteUser = null, showBulkInviteCsvTab = false, bulkInviteCsvProps = {}, extraTabs = [], showProfileStatements = true, billingUsers = false, }) {
30
+ /**
31
+ * `billingOperator({ user, account }) => boolean` (optional, UCM-BILL-10): the app's operator rule for the billing
32
+ * users columns built when `billingUsers` is set (status, badge and the "Ohne Abo" switch). Without it superusers are
33
+ * the operators. A new function on each render only recomputes the columns; it does not refetch the accounts.
34
+ */
35
+ export function AccountPage({ userListExtraColumns = [], userListExtraRowActions = [], userListExtraContext = null, userListRefreshTrigger = 0, userListCanEditUser = null, userListShowNewColumn = true, userListShowSuccessfulLoginColumn = true, userListShowRoleColumn = true, userListOnChangeRole = null, userListShowDeleteAction = true, userListCanDeleteUser = null, userListOnDeleteUser = null, showBulkInviteCsvTab = false, bulkInviteCsvProps = {}, extraTabs = [], showProfileStatements = true, billingUsers = false, billingOperator, }) {
31
36
  var _a;
32
37
  const { t, i18n } = useTranslation();
33
38
  const { user, login, loading } = useContext(AuthContext);
@@ -37,7 +42,7 @@ export function AccountPage({ userListExtraColumns = [], userListExtraRowActions
37
42
  const theme = useTheme();
38
43
  const isMobile = useMediaQuery(theme.breakpoints.down('md'));
39
44
  const billingApi = billingUsers && typeof billingUsers === 'object' ? billingUsers : defaultBillingApi;
40
- const billing = useBillingUsersColumn({ api: billingApi, enabled: Boolean(billingUsers) });
45
+ const billing = useBillingUsersColumn(Object.assign({ api: billingApi, enabled: Boolean(billingUsers) }, (billingOperator ? { isOperator: billingOperator } : {})));
41
46
  // 1. URL State Management
42
47
  const currentTabRaw = searchParams.get('tab') || 'profile';
43
48
  const currentTab = ['invite', 'bulk-invite-csv', 'access'].includes(currentTabRaw)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micha.bigler/ui-core-micha",
3
- "version": "4.17.0",
3
+ "version": "4.19.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "exports": {