diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /devtools/client/debugger/src/actions/tabs.js | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | devtools/client/debugger/src/actions/tabs.js | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/devtools/client/debugger/src/actions/tabs.js b/devtools/client/debugger/src/actions/tabs.js new file mode 100644 index 0000000000..f3464a7bfb --- /dev/null +++ b/devtools/client/debugger/src/actions/tabs.js @@ -0,0 +1,109 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ + +// @flow + +/** + * Redux actions for the editor tabs + * @module actions/tabs + */ + +import { removeDocument } from "../utils/editor"; +import { recordEvent } from "../utils/telemetry"; +import { selectSource } from "./sources"; + +import { + getSourceByURL, + getSourceTabs, + getNewSelectedSourceId, +} from "../selectors"; + +import type { Action, ThunkArgs } from "./types"; +import type { Source, Context, SourceId, URL } from "../types"; + +export function updateTab(source: Source, framework: string): Action { + const { url, id: sourceId, isOriginal } = source; + + return { + type: "UPDATE_TAB", + url, + framework, + isOriginal, + sourceId, + }; +} + +export function addTab(source: Source): Action { + const { url, id: sourceId, isOriginal } = source; + + return { + type: "ADD_TAB", + url, + isOriginal, + sourceId, + }; +} + +export function moveTab(url: URL, tabIndex: number): Action { + return { + type: "MOVE_TAB", + url, + tabIndex, + }; +} + +export function moveTabBySourceId( + sourceId: SourceId, + tabIndex: number +): Action { + return { + type: "MOVE_TAB_BY_SOURCE_ID", + sourceId, + tabIndex, + }; +} + +/** + * @memberof actions/tabs + * @static + */ +export function closeTab( + cx: Context, + source: Source, + reason: string = "click" +) { + return ({ dispatch, getState, client }: ThunkArgs) => { + removeDocument(source.id); + + const tabs = getSourceTabs(getState()); + dispatch(({ type: "CLOSE_TAB", source }: Action)); + + const sourceId = getNewSelectedSourceId(getState(), tabs); + dispatch(selectSource(cx, sourceId)); + + recordEvent("close_source_tab", { + reason, + num_tabs: tabs.length, + }); + }; +} + +/** + * @memberof actions/tabs + * @static + */ +export function closeTabs(cx: Context, urls: string[]) { + return ({ dispatch, getState, client }: ThunkArgs) => { + const sources = urls + .map(url => getSourceByURL(getState(), url)) + .filter(Boolean); + + const tabs = getSourceTabs(getState()); + sources.map(source => removeDocument(source.id)); + dispatch(({ type: "CLOSE_TABS", sources }: Action)); + + const sourceId = getNewSelectedSourceId(getState(), tabs); + dispatch(selectSource(cx, sourceId)); + }; +} |