@marktiderman/genesis-ui-native 3.13.0 → 3.14.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.
@@ -2675,15 +2675,25 @@ function Screen(props) {
2675
2675
  const provider = useDataProvider();
2676
2676
  const queryClient = useQueryClient();
2677
2677
  const viewer = useViewer$1();
2678
+ const askCaps = !onAction && !!provider.runAction && !!provider.capabilities;
2679
+ const actionCaps = useCapabilities(view.resource, { enabled: askCaps });
2678
2680
  const runAction = useCallback(
2679
2681
  async (name, row) => {
2680
2682
  if (onAction) await onAction(name, row);
2681
- else if (provider.runAction) await provider.runAction(view.resource, { id: recordKey(view, row), action: name });
2683
+ else if (provider.runAction) {
2684
+ const field = actionCaps.data?.version?.field;
2685
+ const value = field ? row[field] : void 0;
2686
+ await provider.runAction(view.resource, {
2687
+ id: recordKey(view, row),
2688
+ action: name,
2689
+ ...value == null ? {} : { expectedVersion: String(value) }
2690
+ });
2691
+ }
2682
2692
  await queryClient.invalidateQueries({ queryKey: resourceKeys(view.resource).all });
2683
2693
  },
2684
- [onAction, provider, view, queryClient]
2694
+ [onAction, provider, view, queryClient, actionCaps.data]
2685
2695
  );
2686
- const actionsOn = !!onAction || !!provider.runAction;
2696
+ const actionsOn = !!onAction || !!provider.runAction && (!askCaps || actionCaps.isSuccess) && actionCaps.data?.actions !== false;
2687
2697
  const cancelWord = useNativeResourceViewMessages().common.cancel;
2688
2698
  const confirmAction = useCallback(
2689
2699
  (name, row) => {
@@ -2918,7 +2928,7 @@ function Screen(props) {
2918
2928
  ...r.time ? { timestamp: r.time } : {},
2919
2929
  ...r.from || r.badge ? { meta: [r.from, r.badge?.label].filter(Boolean).join(" \xB7 ") } : {},
2920
2930
  onPress: () => {
2921
- if (r.unread && markRead && view.canAction(markRead, row, viewer) === true) void runAction(markRead, row).catch(() => void 0);
2931
+ if (r.unread && markRead && actionsOn && view.canAction(markRead, row, viewer) === true) void runAction(markRead, row).catch(() => void 0);
2922
2932
  press(row);
2923
2933
  },
2924
2934
  // The view's swipe actions (edit, delete, its own), as the list's rows have them.
@@ -3053,7 +3063,9 @@ function useHeaderActions({ view: recordView, row, onAction, can, messages }) {
3053
3063
  const viewer = useViewer$1();
3054
3064
  const actions = recordView.headerFor(row, {
3055
3065
  viewer,
3056
- runnable: Boolean(onAction) || Boolean(provider.runAction) && capabilities.data?.actions !== false,
3066
+ // Not runnable until the provider has answered (an action run before then, or after a failed
3067
+ // answer, would go without its version).
3068
+ runnable: Boolean(onAction) || Boolean(provider.runAction) && (!provider.capabilities || capabilities.isSuccess) && capabilities.data?.actions !== false,
3057
3069
  ...!onAction && described.data?.actions ? { served: described.data.actions.map((a) => a.name) } : {},
3058
3070
  ...can ? { can: (name) => can(name, row) } : {}
3059
3071
  }).actions;
@@ -3065,8 +3077,15 @@ function useHeaderActions({ view: recordView, row, onAction, can, messages }) {
3065
3077
  setPending(true);
3066
3078
  try {
3067
3079
  if (onAction) await onAction(a.name, row);
3068
- else if (provider.runAction) await provider.runAction(view.resource, { id: recordView.recordId(row), action: a.name });
3069
- else throw new DataWriteError("error", fill(words.noRunner, { name: a.label }));
3080
+ else if (provider.runAction) {
3081
+ const field = capabilities.data?.version?.field;
3082
+ const value = field ? row[field] : void 0;
3083
+ await provider.runAction(view.resource, {
3084
+ id: recordView.recordId(row),
3085
+ action: a.name,
3086
+ ...value == null ? {} : { expectedVersion: String(value) }
3087
+ });
3088
+ } else throw new DataWriteError("error", fill(words.noRunner, { name: a.label }));
3070
3089
  await queryClient.invalidateQueries({ queryKey: [...resourceKeys(view.resource).all] });
3071
3090
  } catch (error) {
3072
3091
  Alert.alert(a.label, refusalMessage(error, words.failed));