@diagonal-hq/pages 0.3.4 → 0.4.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/dist/index.d.ts CHANGED
@@ -6542,7 +6542,7 @@ export type SdkHooks = {
6542
6542
  * Keys are isolated from the app's other React Query caches. Begin a key with
6543
6543
  * `'records'` when the endpoint's result depends on resource records, for example
6544
6544
  * `['records', resource.id, 'summary']`; successful resource create/update/delete/restore
6545
- * operations then invalidate it automatically. Other keys refresh only through their
6545
+ * operations and record form submits then invalidate it automatically. Other keys refresh only through their
6546
6546
  * returned `invalidate` function.
6547
6547
  *
6548
6548
  * Keep the key the same between renders. A clock read such as `Date.now()` in the key
@@ -7781,6 +7781,9 @@ export type SdkHooks = {
7781
7781
  * `form.errors` contains only 422 field validation. Other failures are available
7782
7782
  * as `form.failure`; for example, branch on
7783
7783
  * `Sdk.utils.error.isConflict(form.failure)` without inspecting status codes.
7784
+ * A successful submit refreshes no other page data. Call the `invalidate()` of the
7785
+ * data that the workflow changed in `onSuccess`, or `Sdk.hooks.useInvalidateAll()`
7786
+ * when the page cannot name it.
7784
7787
  * Success callbacks receive the parsed workflow body directly. Synchronous
7785
7788
  * output can be a scalar, list, record, or object; asynchronous workflows return
7786
7789
  * `{ execution_id }`. Narrow the value before reading authored output fields.
@@ -7866,12 +7869,20 @@ export type SdkHooks = {
7866
7869
  * `reset()` also starts a fresh key lifecycle. The hook does not poll asynchronous
7867
7870
  * executions.
7868
7871
  *
7872
+ * A successful run refreshes no other page data. When the workflow changes data that
7873
+ * the page shows, call that data's `invalidate()` in `onSuccess`. Use
7874
+ * `Sdk.hooks.useInvalidateAll()` only when the page cannot name what changed. A
7875
+ * workflow that only reads, such as a search called inside a `Sdk.hooks.useApi`
7876
+ * fetcher, needs no `onSuccess`.
7877
+ *
7869
7878
  * @example
7870
7879
  * ```tsx
7871
7880
  * function ReserveButton({ slotId }) {
7881
+ * const slots = Sdk.hooks.useApi(['slots'], (api) => api.get('/api/slots'));
7872
7882
  * const action = Sdk.hooks.useWorkflowAction({
7873
7883
  * workflowId: 'reserve-slot',
7874
- * idempotent: true
7884
+ * idempotent: true,
7885
+ * onSuccess: () => slots.invalidate()
7875
7886
  * });
7876
7887
  *
7877
7888
  * return (
@@ -7901,8 +7912,28 @@ export type SdkHooks = {
7901
7912
  params?: Record<string, any>;
7902
7913
  /** Generate and manage the conventional `idempotency_key` input. */
7903
7914
  idempotent?: boolean;
7915
+ /** Called with the parsed response after every successful run, including a run
7916
+ * that a later run replaced. Refresh the data that the workflow changed here. */
7917
+ onSuccess?: (response: SdkWorkflowResponse) => void;
7904
7918
  }): UseWorkflowActionResult;
7905
7919
 
7920
+ /**
7921
+ * Returns a function that refreshes every data query on the page. Use it after a
7922
+ * write when the page cannot name the data that the write changed. Prefer the
7923
+ * `invalidate()` of each affected data hook, because a full refresh refetches
7924
+ * every query on the page.
7925
+ *
7926
+ * @example
7927
+ * ```tsx
7928
+ * const invalidateAll = Sdk.hooks.useInvalidateAll();
7929
+ * const importMembers = Sdk.hooks.useWorkflowAction({
7930
+ * workflowId: 'import-members',
7931
+ * onSuccess: () => invalidateAll()
7932
+ * });
7933
+ * ```
7934
+ */
7935
+ useInvalidateAll(): () => Promise<void>;
7936
+
7906
7937
  /**
7907
7938
  * Reactive timelines of a record's schedule workflow runs, the data behind
7908
7939
  * `Sdk.Components.RecordScheduleDisplay`, for pages that render a custom
@@ -14217,7 +14248,9 @@ export type WorkflowFormProps = {
14217
14248
  * suppress. */
14218
14249
  successMessage?: string | null;
14219
14250
 
14220
- /** Called after a successful submission with the workflow's response payload. */
14251
+ /** Called after a successful submission with the workflow's response payload. A
14252
+ * submission refreshes no other page data, so call the `invalidate()` of the data
14253
+ * that the workflow changed here. */
14221
14254
  onSuccess?: (response: SdkWorkflowResponse) => void;
14222
14255
 
14223
14256
  /** Called when the submission resolves with a non-2xx response, with
@@ -14526,6 +14559,7 @@ export declare const useForm: SdkInternal.FilePageSdk["useForm"];
14526
14559
  export declare const useHoldScheduledNotification: SdkInternal.FilePageSdk["hooks"]["useHoldScheduledNotification"];
14527
14560
  export declare const useInfiniteRecords: SdkInternal.FilePageSdk["hooks"]["useInfiniteRecords"];
14528
14561
  export declare const useInput: SdkInternal.FilePageSdk["helpers"]["useInput"];
14562
+ export declare const useInvalidateAll: SdkInternal.FilePageSdk["hooks"]["useInvalidateAll"];
14529
14563
  export declare const useLocalStorage: SdkInternal.FilePageSdk["hooks"]["useLocalStorage"];
14530
14564
  export declare const useMenu: SdkInternal.FilePageSdk["useMenu"];
14531
14565
  export declare const useNewCalendarEvent: SdkInternal.FilePageSdk["hooks"]["useNewCalendarEvent"];
package/dist/index.js CHANGED
@@ -180,6 +180,7 @@ export const useForm = undefined;
180
180
  export const useHoldScheduledNotification = undefined;
181
181
  export const useInfiniteRecords = undefined;
182
182
  export const useInput = undefined;
183
+ export const useInvalidateAll = undefined;
183
184
  export const useLocalStorage = undefined;
184
185
  export const useMenu = undefined;
185
186
  export const useNewCalendarEvent = undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diagonal-hq/pages",
3
- "version": "0.3.4",
3
+ "version": "0.4.0",
4
4
  "description": "The Page SDK for the pages of file-based Diagonal workspaces.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {