Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/frontend/navi/src/action/action_private_properties.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ABORTED, COMPLETED, IDLE, RUNNING } from "./action_run_states.js";

const actionPrivatePropertiesWeakMap = new WeakMap();
export const getActionPrivateProperties = (action) => {
const actionPrivateProperties = actionPrivatePropertiesWeakMap.get(action);
Expand All @@ -9,3 +11,17 @@ export const getActionPrivateProperties = (action) => {
export const setActionPrivateProperties = (action, properties) => {
actionPrivatePropertiesWeakMap.set(action, properties);
};

export const getActionStatus = (action) => {
const { runningStateSignal, errorSignal, computedDataSignal } =
getActionPrivateProperties(action);
const runningState = runningStateSignal.value;
const idle = runningState === IDLE;
const aborted = runningState === ABORTED;
const error = errorSignal.value;
const loading = runningState === RUNNING;
const completed = runningState === COMPLETED;
const data = computedDataSignal.value;

return { idle, loading, aborted, error, completed, data };
};
17 changes: 15 additions & 2 deletions packages/frontend/navi/src/action/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ export const createAction = (callback, rootOptions = {}) => {
}

// ✅ CAS 2: Objet -> vérifier s'il contient des signals
if (newParamsOrSignal && typeof newParamsOrSignal === "object") {
if (isPlainObject(newParamsOrSignal)) {
const staticParams = {};
const signalMap = new Map();

Expand Down Expand Up @@ -727,7 +727,7 @@ export const createAction = (callback, rootOptions = {}) => {
return createActionProxyFromSignal(action, paramsSignal, options);
}

// ✅ CAS 3: Primitive -> action enfant
// ✅ CAS 3: Primitive or objects like DOMEvents etc -> action enfant
return createChildAction({
params: newParamsOrSignal,
...options,
Expand Down Expand Up @@ -1395,6 +1395,19 @@ const generateActionName = (name, params) => {
return `${name}${argsString}`;
};

const isPlainObject = (obj) => {
if (typeof obj !== "object" || obj === null) {
return false;
}
let proto = obj;
while (Object.getPrototypeOf(proto) !== null) {
proto = Object.getPrototypeOf(proto);
}
return (
Object.getPrototypeOf(obj) === proto || Object.getPrototypeOf(obj) === null
);
};

if (import.meta.hot) {
import.meta.hot.dispose(() => {
abortRunningActions();
Expand Down
3 changes: 2 additions & 1 deletion packages/frontend/navi/src/keyboard/keyboard_shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ export const useKeyboardShortcuts = (
return false;
}
const { action } = shortcutCandidate;
return requestAction(element, action, {
const actionWithEvent = action.bindParams(keyboardEvent);
return requestAction(element, actionWithEvent, {
actionOrigin: "keyboard_shortcut",
event: keyboardEvent,
requester: document.activeElement,
Expand Down
Loading
Loading