[REF] web: linting
This commit is contained in:
committed by
Aaron Bohy
parent
f0ee615290
commit
b124343d21
@@ -26,15 +26,18 @@ export function useAutofocus(params = {}) {
|
||||
}
|
||||
const selector = params.selector || "[autofocus]";
|
||||
let forceFocusCount = 0;
|
||||
useEffect(function autofocus(target) {
|
||||
if (target) {
|
||||
target.focus();
|
||||
if (["INPUT", "TEXTAREA"].includes(target.tagName)) {
|
||||
const inputEl = target;
|
||||
inputEl.selectionStart = inputEl.selectionEnd = inputEl.value.length;
|
||||
useEffect(
|
||||
function autofocus(target) {
|
||||
if (target) {
|
||||
target.focus();
|
||||
if (["INPUT", "TEXTAREA"].includes(target.tagName)) {
|
||||
const inputEl = target;
|
||||
inputEl.selectionStart = inputEl.selectionEnd = inputEl.value.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
}, () => [comp.el.querySelector(selector), forceFocusCount]);
|
||||
},
|
||||
() => [comp.el.querySelector(selector), forceFocusCount]
|
||||
);
|
||||
|
||||
return function focusOnUpdate() {
|
||||
forceFocusCount++; // force the effect to rerun on next patch
|
||||
|
||||
@@ -30,8 +30,11 @@ const { useComponent } = owl.hooks;
|
||||
*/
|
||||
export function useBus(bus, eventName, callback) {
|
||||
const component = useComponent();
|
||||
useEffect(() => {
|
||||
bus.on(eventName, component, callback);
|
||||
return () => bus.off(eventName, component);
|
||||
}, () => []);
|
||||
useEffect(
|
||||
() => {
|
||||
bus.on(eventName, component, callback);
|
||||
return () => bus.off(eventName, component);
|
||||
},
|
||||
() => []
|
||||
);
|
||||
}
|
||||
|
||||
@@ -53,27 +53,32 @@ export class Dropdown extends Component {
|
||||
this.close();
|
||||
}
|
||||
});
|
||||
useEffect(() => {
|
||||
Promise.resolve().then(() => {
|
||||
this.myActiveEl = this.ui.activeElement;
|
||||
});
|
||||
}, () => []);
|
||||
useEffect(
|
||||
() => {
|
||||
Promise.resolve().then(() => {
|
||||
this.myActiveEl = this.ui.activeElement;
|
||||
});
|
||||
},
|
||||
() => []
|
||||
);
|
||||
|
||||
// Set up key navigation -----------------------------------------------
|
||||
this.hotkeyService = useService("hotkey");
|
||||
this.hotkeyRemoves = [];
|
||||
|
||||
const nextActiveIndexFns = {
|
||||
"FIRST": () => 0,
|
||||
"LAST": (items) => items.length - 1,
|
||||
"NEXT": (items, prevActiveIndex) => Math.min(prevActiveIndex + 1, items.length - 1),
|
||||
"PREV": (_, prevActiveIndex) => Math.max(0, prevActiveIndex - 1),
|
||||
FIRST: () => 0,
|
||||
LAST: (items) => items.length - 1,
|
||||
NEXT: (items, prevActiveIndex) => Math.min(prevActiveIndex + 1, items.length - 1),
|
||||
PREV: (_, prevActiveIndex) => Math.max(0, prevActiveIndex - 1),
|
||||
};
|
||||
|
||||
/** @type {(direction: "FIRST"|"LAST"|"NEXT"|"PREV") => Function} */
|
||||
function activeItemSetter(direction) {
|
||||
return function () {
|
||||
const items = [...this.el.querySelectorAll(":scope > ul.o_dropdown_menu > .o_dropdown_item")];
|
||||
const items = [
|
||||
...this.el.querySelectorAll(":scope > ul.o_dropdown_menu > .o_dropdown_item"),
|
||||
];
|
||||
const prevActiveIndex = items.findIndex((item) =>
|
||||
[...item.classList].includes("o_dropdown_active")
|
||||
);
|
||||
@@ -85,11 +90,11 @@ export class Dropdown extends Component {
|
||||
}
|
||||
|
||||
const hotkeyCallbacks = {
|
||||
"arrowdown": activeItemSetter("NEXT").bind(this),
|
||||
"arrowup": activeItemSetter("PREV").bind(this),
|
||||
arrowdown: activeItemSetter("NEXT").bind(this),
|
||||
arrowup: activeItemSetter("PREV").bind(this),
|
||||
"shift+arrowdown": activeItemSetter("LAST").bind(this),
|
||||
"shift+arrowup": activeItemSetter("FIRST").bind(this),
|
||||
"enter": () => {
|
||||
enter: () => {
|
||||
const activeItem = this.el.querySelector(
|
||||
":scope > ul.o_dropdown_menu > .o_dropdown_item.o_dropdown_active"
|
||||
);
|
||||
@@ -97,7 +102,7 @@ export class Dropdown extends Component {
|
||||
activeItem.click();
|
||||
}
|
||||
},
|
||||
"escape": this.close.bind(this),
|
||||
escape: this.close.bind(this),
|
||||
};
|
||||
|
||||
/** @this {Dropdown} */
|
||||
|
||||
@@ -49,7 +49,7 @@ export function formatCurrency(value, cid, options = {}) {
|
||||
* @param {number} [options.currencyId]
|
||||
* @returns {number} float
|
||||
*/
|
||||
export function parseCurrency(value, options = {}) {
|
||||
export function parseCurrency(value, options = {}) {
|
||||
let values = value.split(" ");
|
||||
if (values.length === 1) {
|
||||
return parseFloat(value);
|
||||
|
||||
@@ -25,10 +25,13 @@ export const SIZES = { XS: 0, VSM: 1, SM: 2, MD: 3, LG: 4, XL: 5, XXL: 6 };
|
||||
export function useActiveElement(refName = null) {
|
||||
const uiService = useService("ui");
|
||||
const owner = refName ? useRef(refName) : Component.current;
|
||||
useEffect(() => {
|
||||
uiService.activateElement(owner.el);
|
||||
return () => uiService.deactivateElement(owner.el);
|
||||
}, () => []);
|
||||
useEffect(
|
||||
() => {
|
||||
uiService.activateElement(owner.el);
|
||||
return () => uiService.deactivateElement(owner.el);
|
||||
},
|
||||
() => []
|
||||
);
|
||||
}
|
||||
|
||||
export const uiService = {
|
||||
|
||||
@@ -134,13 +134,17 @@ async function _startServices(env, toStart, timeoutId) {
|
||||
if (toStart.size) {
|
||||
const names = [...toStart].map((s) => s.name);
|
||||
const missingDeps = new Set();
|
||||
[...toStart].forEach((s) => s.dependencies.forEach((dep) => {
|
||||
if (!(dep in services) && !names.includes(dep)) {
|
||||
missingDeps.add(dep);
|
||||
}
|
||||
}));
|
||||
[...toStart].forEach((s) =>
|
||||
s.dependencies.forEach((dep) => {
|
||||
if (!(dep in services) && !names.includes(dep)) {
|
||||
missingDeps.add(dep);
|
||||
}
|
||||
})
|
||||
);
|
||||
const depNames = [...missingDeps].join(", ");
|
||||
throw new Error(`Some services could not be started: ${names}. Missing dependencies: ${depNames}`);
|
||||
throw new Error(
|
||||
`Some services could not be started: ${names}. Missing dependencies: ${depNames}`
|
||||
);
|
||||
}
|
||||
|
||||
function findNext() {
|
||||
|
||||
@@ -14,9 +14,12 @@ const { hooks } = owl;
|
||||
patch(Dialog.prototype, "Legacy Adapted Dialog", {
|
||||
setup() {
|
||||
this._super();
|
||||
useEffect(() => {
|
||||
OwlDialog.display(this);
|
||||
return () => OwlDialog.hide(this);
|
||||
}, () => []);
|
||||
useEffect(
|
||||
() => {
|
||||
OwlDialog.display(this);
|
||||
return () => OwlDialog.hide(this);
|
||||
},
|
||||
() => []
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -18,22 +18,25 @@ const scrollSymbol = Symbol("scroll");
|
||||
export function useSetupAction(params) {
|
||||
const component = useComponent();
|
||||
|
||||
useEffect(() => {
|
||||
if (component.props.registerCallback) {
|
||||
if (params.beforeLeave) {
|
||||
component.props.registerCallback("beforeLeave", params.beforeLeave);
|
||||
}
|
||||
component.props.registerCallback("export", () => {
|
||||
const state = {};
|
||||
state[scrollSymbol] = getScrollPosition(component);
|
||||
if (params.export) {
|
||||
Object.assign(state, params.export());
|
||||
useEffect(
|
||||
() => {
|
||||
if (component.props.registerCallback) {
|
||||
if (params.beforeLeave) {
|
||||
component.props.registerCallback("beforeLeave", params.beforeLeave);
|
||||
}
|
||||
return state;
|
||||
});
|
||||
}
|
||||
if (component.props.state) {
|
||||
setScrollPosition(component, component.props.state[scrollSymbol]);
|
||||
}
|
||||
}, () => []);
|
||||
component.props.registerCallback("export", () => {
|
||||
const state = {};
|
||||
state[scrollSymbol] = getScrollPosition(component);
|
||||
if (params.export) {
|
||||
Object.assign(state, params.export());
|
||||
}
|
||||
return state;
|
||||
});
|
||||
}
|
||||
if (component.props.state) {
|
||||
setScrollPosition(component, component.props.state[scrollSymbol]);
|
||||
}
|
||||
},
|
||||
() => []
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
|
||||
const MOUSE_EVENTS = ["mouseover", "mouseenter", "mousedown", "mouseup", "click"];
|
||||
const BLACKLISTED_MENUS = [
|
||||
'base.menu_theme_store',
|
||||
'base.menu_third_party',
|
||||
'account.menu_action_account_bank_journal_form',
|
||||
'pos_adyen.menu_pos_adyen_account',
|
||||
'payment_odoo.menu_adyen_account',
|
||||
"base.menu_theme_store",
|
||||
"base.menu_third_party",
|
||||
"account.menu_action_account_bank_journal_form",
|
||||
"pos_adyen.menu_pos_adyen_account",
|
||||
"payment_odoo.menu_adyen_account",
|
||||
];
|
||||
|
||||
const { isEnterprise } = odoo.info;
|
||||
|
||||
@@ -30,12 +30,15 @@ export class RainbowMan extends Component {
|
||||
const delay = fadeout ? RainbowMan.rainbowFadeouts[fadeout] : false;
|
||||
this.delay = typeof delay === "number" ? delay : false;
|
||||
if (this.delay !== false) {
|
||||
useEffect(() => {
|
||||
const timeout = browser.setTimeout(() => {
|
||||
this.el.classList.add("o_reward_fading");
|
||||
}, this.delay);
|
||||
return () => browser.clearTimeout(timeout);
|
||||
}, () => []);
|
||||
useEffect(
|
||||
() => {
|
||||
const timeout = browser.setTimeout(() => {
|
||||
this.el.classList.add("o_reward_fading");
|
||||
}, this.delay);
|
||||
return () => browser.clearTimeout(timeout);
|
||||
},
|
||||
() => []
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,9 +26,12 @@ export class WebClient extends Component {
|
||||
this.el.classList.toggle("o_fullscreen", mode === "fullscreen");
|
||||
}
|
||||
});
|
||||
useEffect(() => {
|
||||
this.loadRouterState();
|
||||
}, () => []);
|
||||
useEffect(
|
||||
() => {
|
||||
this.loadRouterState();
|
||||
},
|
||||
() => []
|
||||
);
|
||||
}
|
||||
|
||||
mounted() {
|
||||
|
||||
@@ -93,7 +93,7 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
assert.step("notify");
|
||||
},
|
||||
() => {}
|
||||
),
|
||||
)
|
||||
);
|
||||
mockDownload((options) => {
|
||||
assert.step(options.url);
|
||||
@@ -131,7 +131,7 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
assert.step("notify");
|
||||
},
|
||||
() => {}
|
||||
),
|
||||
)
|
||||
);
|
||||
const mockRPC = async (route, args) => {
|
||||
assert.step(args.method || route);
|
||||
|
||||
Reference in New Issue
Block a user