Skip to content

Commit b554ab6

Browse files
committed
Let the presets stick to files that are already downloaded
Now that picked files can be fetched when sharing, "Selected threads" and "All available files" can set off a lot of downloads from one click. Add an "Only already downloaded files" checkbox under the presets, per panel, on by default. With it on, the presets only pick files whose contents are in hand, and toggling it re-applies the active preset. Fetchable files can still be picked by hand in the tree. The checkbox only shows up while some pickable file would have to be fetched. Turning the option on when nothing is downloaded yet would pick nothing, so in that case it falls back to the full presets and unchecks the box.
1 parent d43c266 commit b554ab6

10 files changed

Lines changed: 371 additions & 70 deletions

File tree

‎locales/en-US/app.ftl‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,10 @@ MenuButtons--publish--source-code-preset-selected-threads = Selected threads
813813
# Selects every source file that was fetched or came with the profile, and that
814814
# can be shared.
815815
MenuButtons--publish--source-code-preset-all-available-files = All available files
816+
# A checkbox next to the presets. When checked, "Selected threads" and "All
817+
# available files" only pick files whose contents are already downloaded, so
818+
# that sharing doesn't download anything more.
819+
MenuButtons--publish--source-code-downloaded-only = Only already downloaded files
816820
# Not something the user can pick. This is shown as the selected option once the
817821
# user has edited the file tree so that it no longer matches any of the others.
818822
MenuButtons--publish--source-code-preset-custom = Custom

‎src/actions/publish.ts‎

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import {
1414
getSanitizedProfileEncodingState,
1515
getSourceFilesToFetch,
1616
getSourceCodeFetchState,
17+
getActiveSourceSharingPreset,
1718
getSourceFilesForOfferedPresets,
19+
getSourceSharingDownloadedOnly,
1820
} from 'firefox-profiler/selectors/publish';
1921
import { fetchSourceCode } from './code';
2022
import {
@@ -374,11 +376,26 @@ export function encodeSanitizedProfile(
374376
}
375377

376378
/**
377-
* Turn the "Include source code" option on, picking the narrowest preset.
379+
* Turn the "Include source code" option on, picking the narrowest preset. When
380+
* nothing is downloaded yet, the downloaded-only presets are all empty, so fall
381+
* back to the full ones and show that by turning the downloaded-only option
382+
* off.
378383
*/
379384
export function turnOnSourceCodeSharing(mode: SharingMode): ThunkAction<void> {
380385
return (dispatch, getState) => {
381-
const [firstPreset] = getSourceFilesForOfferedPresets(getState());
386+
let presets = getSourceFilesForOfferedPresets(getState(), mode);
387+
if (
388+
presets.size === 0 &&
389+
getSourceSharingDownloadedOnly(getState(), mode)
390+
) {
391+
dispatch({
392+
type: 'UPDATE_SOURCE_SHARING_DOWNLOADED_ONLY',
393+
mode,
394+
value: false,
395+
});
396+
presets = getSourceFilesForOfferedPresets(getState(), mode);
397+
}
398+
const [firstPreset] = presets;
382399
if (firstPreset === undefined) {
383400
return;
384401
}
@@ -388,6 +405,30 @@ export function turnOnSourceCodeSharing(mode: SharingMode): ThunkAction<void> {
388405
};
389406
}
390407

408+
/**
409+
* Turn "only files that are already downloaded" on or off for the presets.
410+
* When a preset is active, the selection follows it to its new meaning.
411+
*/
412+
export function setSourceSharingDownloadedOnly(
413+
mode: SharingMode,
414+
value: boolean
415+
): ThunkAction<void> {
416+
return (dispatch, getState) => {
417+
const activePreset = getActiveSourceSharingPreset(getState(), mode);
418+
dispatch({ type: 'UPDATE_SOURCE_SHARING_DOWNLOADED_ONLY', mode, value });
419+
if (activePreset === 'custom') {
420+
return;
421+
}
422+
const files = getSourceFilesForOfferedPresets(getState(), mode).get(
423+
activePreset
424+
);
425+
if (files !== undefined) {
426+
dispatch(updateSourceFilesToShare(mode, files, activePreset));
427+
dispatch(encodeSanitizedProfile(mode));
428+
}
429+
};
430+
}
431+
391432
export function cancelSourceCodeFetch(): Action {
392433
return { type: 'SOURCE_CODE_FETCH_CANCELLED' };
393434
}

‎src/components/app/MenuButtons/PublishSourceCode.tsx‎

Lines changed: 68 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
updateSourceFilesToShare,
1010
fetchSourceFilesToShare,
1111
cancelSourceCodeFetch,
12+
setSourceSharingDownloadedOnly,
1213
turnOnSourceCodeSharing,
1314
encodeSanitizedProfile,
1415
} from 'firefox-profiler/actions/publish';
@@ -18,6 +19,7 @@ import {
1819
getSourceCodeSharingStats,
1920
getSourceFilesToFetch,
2021
getSourceCodeFetchState,
22+
getSourceSharingDownloadedOnly,
2123
getSourceCodeSharingSummary,
2224
getSourceFileTree,
2325
getSourceFilesForOfferedPresets,
@@ -100,6 +102,7 @@ type StateProps = {
100102
readonly sourceCodeSharingStats: SourceCodeSharingStats;
101103
readonly sourceFilesToFetch: ReadonlySet<IndexIntoSourceTable>;
102104
readonly sourceCodeFetchState: SourceCodeFetchState;
105+
readonly sourceSharingDownloadedOnly: boolean;
103106
readonly sourceFileTree: SourceFileTreeNode[];
104107
readonly sourceFilesToShare: ReadonlySet<IndexIntoSourceTable>;
105108
readonly sourceFilesForPresets: Map<
@@ -114,6 +117,7 @@ type DispatchProps = {
114117
readonly updateSourceFilesToShare: typeof updateSourceFilesToShare;
115118
readonly fetchSourceFilesToShare: typeof fetchSourceFilesToShare;
116119
readonly cancelSourceCodeFetch: typeof cancelSourceCodeFetch;
120+
readonly setSourceSharingDownloadedOnly: typeof setSourceSharingDownloadedOnly;
117121
readonly turnOnSourceCodeSharing: typeof turnOnSourceCodeSharing;
118122
readonly encodeSanitizedProfile: typeof encodeSanitizedProfile;
119123
};
@@ -159,6 +163,13 @@ class PublishSourceCodeSectionImpl extends React.PureComponent<Props> {
159163
this.props.encodeSanitizedProfile(mode);
160164
};
161165

166+
_onToggleDownloadedOnly = (e: React.ChangeEvent<HTMLInputElement>) => {
167+
this.props.setSourceSharingDownloadedOnly(
168+
this.props.mode,
169+
e.target.checked
170+
);
171+
};
172+
162173
_onFetchSourceFiles = () => {
163174
this.props.fetchSourceFilesToShare(this.props.mode);
164175
};
@@ -262,43 +273,70 @@ class PublishSourceCodeSectionImpl extends React.PureComponent<Props> {
262273
}
263274

264275
_renderPresets() {
265-
const { mode, activeSourceSharingPreset, sourceFilesForPresets } =
266-
this.props;
267-
if (sourceFilesForPresets.size < 2) {
268-
return null;
269-
}
276+
const {
277+
mode,
278+
activeSourceSharingPreset,
279+
sourceFilesForPresets,
280+
sourceCodeSharingStats,
281+
sourceSharingDownloadedOnly,
282+
} = this.props;
283+
284+
const showPresets = sourceFilesForPresets.size >= 2;
285+
// The downloaded-only option only matters while some pickable file would
286+
// have to be fetched.
287+
const showDownloadedOnly =
288+
sourceCodeSharingStats.pickableFileCount >
289+
sourceCodeSharingStats.downloadedFileCount;
270290

271291
const presets: SourceSharingPreset[] = [...sourceFilesForPresets.keys()];
272292
if (activeSourceSharingPreset === 'custom') {
273293
presets.push('custom');
274294
}
275295

276296
return (
277-
<fieldset className="publishPanelSourceCodePresets">
278-
<Localized id="MenuButtons--publish--source-code-preset-legend">
279-
<legend className="publishPanelSourceCodePresetsLegend">
280-
Include:
281-
</legend>
282-
</Localized>
283-
{presets.map((preset) => (
284-
<label
285-
key={preset}
286-
className="photon-label publishPanelSourceCodePresetLabel"
287-
>
297+
<>
298+
{showPresets ? (
299+
<fieldset className="publishPanelSourceCodePresets">
300+
<Localized id="MenuButtons--publish--source-code-preset-legend">
301+
<legend className="publishPanelSourceCodePresetsLegend">
302+
Include:
303+
</legend>
304+
</Localized>
305+
{presets.map((preset) => (
306+
<label
307+
key={preset}
308+
className="photon-label publishPanelSourceCodePresetLabel"
309+
>
310+
<input
311+
type="radio"
312+
className="photon-radio photon-radio-micro"
313+
name={`sourceCodePreset-${mode}`}
314+
value={preset}
315+
checked={activeSourceSharingPreset === preset}
316+
// "Custom" only reports the state of the tree.
317+
disabled={this._isUploading() || preset === 'custom'}
318+
onChange={this._onPresetChange}
319+
/>
320+
<Localized id={PRESET_L10N_IDS[preset]} />
321+
</label>
322+
))}
323+
</fieldset>
324+
) : null}
325+
{showDownloadedOnly ? (
326+
<label className="photon-label publishPanelSourceCodeDownloadedOnly">
288327
<input
289-
type="radio"
290-
className="photon-radio photon-radio-micro"
291-
name={`sourceCodePreset-${mode}`}
292-
value={preset}
293-
checked={activeSourceSharingPreset === preset}
294-
// "Custom" only reports the state of the tree.
295-
disabled={this._isUploading() || preset === 'custom'}
296-
onChange={this._onPresetChange}
328+
type="checkbox"
329+
className="photon-checkbox photon-checkbox-micro"
330+
checked={sourceSharingDownloadedOnly}
331+
disabled={this._isUploading()}
332+
onChange={this._onToggleDownloadedOnly}
297333
/>
298-
<Localized id={PRESET_L10N_IDS[preset]} />
334+
<Localized id="MenuButtons--publish--source-code-downloaded-only">
335+
Only already downloaded files
336+
</Localized>
299337
</label>
300-
))}
301-
</fieldset>
338+
) : null}
339+
</>
302340
);
303341
}
304342

@@ -394,16 +432,18 @@ export const PublishSourceCodeSection = explicitConnect<
394432
sourceCodeSharingStats: getSourceCodeSharingStats(state),
395433
sourceFilesToFetch: getSourceFilesToFetch(state, mode),
396434
sourceCodeFetchState: getSourceCodeFetchState(state),
435+
sourceSharingDownloadedOnly: getSourceSharingDownloadedOnly(state, mode),
397436
sourceFileTree: getSourceFileTree(state),
398437
sourceFilesToShare: getSourceFilesToShare(state, mode),
399-
sourceFilesForPresets: getSourceFilesForOfferedPresets(state),
438+
sourceFilesForPresets: getSourceFilesForOfferedPresets(state, mode),
400439
activeSourceSharingPreset: getActiveSourceSharingPreset(state, mode),
401440
sourceCodeSharingSummary: getSourceCodeSharingSummary(state, mode),
402441
}),
403442
mapDispatchToProps: {
404443
updateSourceFilesToShare,
405444
fetchSourceFilesToShare,
406445
cancelSourceCodeFetch,
446+
setSourceSharingDownloadedOnly,
407447
turnOnSourceCodeSharing,
408448
encodeSanitizedProfile,
409449
},

‎src/components/app/MenuButtons/SourceFileTree.css‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@
175175
float: left;
176176
}
177177

178+
.publishPanelSourceCodeDownloadedOnly {
179+
display: flex;
180+
align-items: center;
181+
margin: 2px 0 0;
182+
}
183+
178184
.publishPanelSourceCodePresetLabel {
179185
display: flex;
180186
align-items: center;

‎src/reducers/publish.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,22 @@ const sourceFileSelection: Reducer<
103103
}
104104
};
105105

106+
// On by default, so that picking a preset doesn't download anything unless
107+
// the user asks for it.
108+
const sourceSharingDownloadedOnly: Reducer<Record<SharingMode, boolean>> = (
109+
state = { download: true, upload: true },
110+
action
111+
) => {
112+
switch (action.type) {
113+
case 'PROFILE_LOADED':
114+
return { download: true, upload: true };
115+
case 'UPDATE_SOURCE_SHARING_DOWNLOADED_ONLY':
116+
return { ...state, [action.mode]: action.value };
117+
default:
118+
return state;
119+
}
120+
};
121+
106122
// This is a diagram explaining the ordering of actions for uploading
107123
//
108124
// UPLOAD_COMPRESSION_STARTED
@@ -319,6 +335,7 @@ const sourceCodeFetch: Reducer<SourceCodeFetchState> = (
319335
const publishReducer: Reducer<PublishState> = combineReducers({
320336
checkedSharingOptions,
321337
sourceFileSelection,
338+
sourceSharingDownloadedOnly,
322339
sanitizedProfileEncodingState,
323340
sourceCodeFetch,
324341
upload,

0 commit comments

Comments
 (0)