зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1815500 - [devtools] Migrate `selectSource` action to receive source and sourceActor objects. r=bomsy,devtools-reviewers
This will help then craft a location with `source` and `sourceActor` objects from selectSource. I migrated the unique usage of this method passing a location to selectSpecificLocation as selectSource is mostly meant to avoid having to think about/create a location object. Differential Revision: https://phabricator.services.mozilla.com/D169330
This commit is contained in:
Родитель
8e538acac8
Коммит
13a1dc1ac4
|
@ -328,7 +328,7 @@ class DebuggerPanel {
|
|||
threadActorID
|
||||
);
|
||||
const cx = this._selectors.getContext(this._getState());
|
||||
await this._actions.selectSource(cx, source.id, sourceActor.id);
|
||||
await this._actions.selectSource(cx, source, sourceActor);
|
||||
}
|
||||
|
||||
selectThread(threadActorID) {
|
||||
|
|
|
@ -116,7 +116,7 @@ function selectPrettyLocation(cx, prettySource) {
|
|||
);
|
||||
}
|
||||
|
||||
return dispatch(selectSource(cx, prettySource.id));
|
||||
return dispatch(selectSource(cx, prettySource));
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -88,18 +88,20 @@ export function selectSourceURL(cx, url, options) {
|
|||
* the precise generated/original source passed as argument.
|
||||
*
|
||||
* @param {Object} cx
|
||||
* @param {String} sourceId
|
||||
* @param {String} source
|
||||
* The precise source to select.
|
||||
* @param {String} sourceActorId
|
||||
* @param {String} sourceActor
|
||||
* The specific source actor of the source to
|
||||
* select the source text. This is optional.
|
||||
* @param {Object} location
|
||||
* Optional precise location to select, if we need to select
|
||||
* a precise line/column.
|
||||
*/
|
||||
export function selectSource(cx, sourceId, sourceActorId, location = {}) {
|
||||
export function selectSource(cx, source, sourceActor) {
|
||||
return async ({ dispatch }) => {
|
||||
location = createLocation({ ...location, sourceId, sourceActorId });
|
||||
// `createLocation` requires a source object, but we may use selectSource to close the last tab,
|
||||
// where source will be null and the location will be an empty object.
|
||||
const location = source
|
||||
? createLocation({ sourceId: source.id, sourceActorId: sourceActor?.id })
|
||||
: {};
|
||||
|
||||
return dispatch(selectSpecificLocation(cx, location));
|
||||
};
|
||||
}
|
||||
|
|
|
@ -242,7 +242,7 @@ describe("sources", () => {
|
|||
actions.newOriginalSources([makeOriginalSource(baseSource)])
|
||||
);
|
||||
|
||||
await dispatch(actions.selectSource(cx, originalBaseSources[0].id));
|
||||
await dispatch(actions.selectSource(cx, originalBaseSources[0]));
|
||||
|
||||
const fooSource = await dispatch(
|
||||
actions.newGeneratedSource(makeSource("foo.js"))
|
||||
|
@ -274,7 +274,7 @@ describe("sources", () => {
|
|||
const baseSources = await dispatch(
|
||||
actions.newOriginalSources([makeOriginalSource(baseGenSource)])
|
||||
);
|
||||
await dispatch(actions.selectSource(cx, baseSources[0].id));
|
||||
await dispatch(actions.selectSource(cx, baseSources[0]));
|
||||
|
||||
await dispatch(
|
||||
actions.selectSpecificLocation(cx, {
|
||||
|
|
|
@ -13,7 +13,7 @@ import { selectSource } from "./sources";
|
|||
import {
|
||||
getSourceByURL,
|
||||
getSourceTabs,
|
||||
getNewSelectedSourceId,
|
||||
getNewSelectedSource,
|
||||
} from "../selectors";
|
||||
|
||||
export function addTab(source, sourceActor) {
|
||||
|
@ -51,8 +51,8 @@ export function closeTab(cx, source, reason = "click") {
|
|||
const tabs = getSourceTabs(getState());
|
||||
dispatch({ type: "CLOSE_TAB", source });
|
||||
|
||||
const sourceId = getNewSelectedSourceId(getState(), tabs);
|
||||
dispatch(selectSource(cx, sourceId));
|
||||
const newSource = getNewSelectedSource(getState(), tabs);
|
||||
dispatch(selectSource(cx, newSource));
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ export function closeTabs(cx, urls) {
|
|||
sources.map(source => removeDocument(source.id));
|
||||
dispatch({ type: "CLOSE_TABS", sources });
|
||||
|
||||
const sourceId = getNewSelectedSourceId(getState(), tabs);
|
||||
dispatch(selectSource(cx, sourceId));
|
||||
const source = getNewSelectedSource(getState(), tabs);
|
||||
dispatch(selectSource(cx, source));
|
||||
};
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ async function pause(store, client) {
|
|||
actions.newGeneratedSource(makeSource("base.js"))
|
||||
);
|
||||
|
||||
await dispatch(actions.selectSource(cx, base.id));
|
||||
await dispatch(actions.selectSource(cx, base));
|
||||
await waitForState(store, state => selectors.getSymbols(state, base));
|
||||
|
||||
const { thread } = cx;
|
||||
|
@ -84,7 +84,7 @@ describe("preview", () => {
|
|||
actions.newGeneratedSource(makeSource("base.js"))
|
||||
);
|
||||
|
||||
await dispatch(actions.selectSource(cx, base.id));
|
||||
await dispatch(actions.selectSource(cx, base));
|
||||
await waitForState(store, state => selectors.getSymbols(state, base));
|
||||
const frames = [makeFrame({ id: "f1", sourceId: base.id })];
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ export function showSource(cx, sourceId) {
|
|||
|
||||
dispatch(setPrimaryPaneTab("sources"));
|
||||
|
||||
dispatch(selectSource(cx, source.id));
|
||||
dispatch(selectSource(cx, source));
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -204,7 +204,7 @@ class Tab extends PureComponent {
|
|||
function handleTabClick(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
return selectSource(cx, sourceId, sourceActor?.actor);
|
||||
return selectSource(cx, source, sourceActor);
|
||||
}
|
||||
|
||||
const className = classnames("source-tab", {
|
||||
|
|
|
@ -165,7 +165,7 @@ class Tabs extends PureComponent {
|
|||
const { cx, selectSource } = this.props;
|
||||
const filename = getFilename(source);
|
||||
|
||||
const onClick = () => selectSource(cx, source.id);
|
||||
const onClick = () => selectSource(cx, source);
|
||||
return (
|
||||
<li key={source.id} onClick={onClick} title={getFileURL(source, false)}>
|
||||
<AccessibleImage
|
||||
|
|
|
@ -150,11 +150,7 @@ class SourcesTree extends Component {
|
|||
}
|
||||
|
||||
selectSourceItem = item => {
|
||||
this.props.selectSource(
|
||||
this.props.cx,
|
||||
item.source.id,
|
||||
item.sourceActor.actor
|
||||
);
|
||||
this.props.selectSource(this.props.cx, item.source, item.sourceActor);
|
||||
};
|
||||
|
||||
onFocus = item => {
|
||||
|
|
|
@ -43,7 +43,7 @@ class BreakpointHeading extends PureComponent {
|
|||
<div
|
||||
className="breakpoint-heading"
|
||||
title={getFileURL(source, false)}
|
||||
onClick={() => selectSource(cx, source.id)}
|
||||
onClick={() => selectSource(cx, source)}
|
||||
onContextMenu={this.onContextMenu}
|
||||
>
|
||||
<SourceIcon
|
||||
|
|
|
@ -47,16 +47,16 @@ export function hasPrettyTab(state, sourceUrl) {
|
|||
* 2. if it is gone, the next available tab to the left should be active
|
||||
* 3. if the first tab is active and closed, select the second tab
|
||||
*/
|
||||
export function getNewSelectedSourceId(state, tabList) {
|
||||
export function getNewSelectedSource(state, tabList) {
|
||||
const { selectedLocation } = state.sources;
|
||||
const availableTabs = state.tabs.tabs;
|
||||
if (!selectedLocation) {
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
|
||||
const selectedTab = getLocationSource(state, selectedLocation);
|
||||
if (!selectedTab) {
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
|
||||
const matchingTab = availableTabs.find(tab =>
|
||||
|
@ -66,7 +66,7 @@ export function getNewSelectedSourceId(state, tabList) {
|
|||
if (matchingTab) {
|
||||
const { sources } = state.sources;
|
||||
if (!sources) {
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
|
||||
const selectedSource = getSpecificSourceByURL(
|
||||
|
@ -76,10 +76,10 @@ export function getNewSelectedSourceId(state, tabList) {
|
|||
);
|
||||
|
||||
if (selectedSource) {
|
||||
return selectedSource.id;
|
||||
return selectedSource;
|
||||
}
|
||||
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
|
||||
const tabUrls = tabList.map(tab => tab.url);
|
||||
|
@ -96,9 +96,9 @@ export function getNewSelectedSourceId(state, tabList) {
|
|||
);
|
||||
|
||||
if (tabSource) {
|
||||
return tabSource.id;
|
||||
return tabSource;
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче