Skip to content

Commit a8863ab

Browse files
edisileCopilot
andauthored
TS types in redux actions and tests (#5535)
* TS types in redux actions and tests (#5529) * Initial plan * Convert 5 simple action files to TypeScript: globalNotification, modal, currentTrack, pendingCloses, revisions Co-authored-by: edisile <4310497+edisile@users.noreply.github.com> * Convert medium complexity action files to TypeScript: branches, architectures, availableRevisionsSelect, channelMap, history Co-authored-by: edisile <4310497+edisile@users.noreply.github.com> * Convert final complex action files to TypeScript: defaultTrack and pendingReleases Co-authored-by: edisile <4310497+edisile@users.noreply.github.com> * Fix test failure: remove extra properties from Progressive object Co-authored-by: edisile <4310497+edisile@users.noreply.github.com> * fix: available revisions action * fix: release response types * fix: types that copilot missed or mangled * fix: tests imports, no idea how they passed before * chore: cleanup unused imports * chore: types for gaEventTracking action --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: edisile <4310497+edisile@users.noreply.github.com> * fix: copilot suggestions --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
1 parent 88804e0 commit a8863ab

53 files changed

Lines changed: 615 additions & 519 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

static/js/publisher/pages/Releases/actions/architectures.js

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import {
2+
GenericReleasesAction,
3+
ReleasesReduxState,
4+
Revision,
5+
} from "../../../types/releaseTypes";
6+
7+
export const UPDATE_ARCHITECTURES = "UPDATE_ARCHITECTURES";
8+
9+
export type UpdateArchitecturesAction = GenericReleasesAction<
10+
typeof UPDATE_ARCHITECTURES,
11+
{
12+
architectures: ReleasesReduxState["architectures"];
13+
}
14+
>;
15+
16+
export type ArchitecturesAction = UpdateArchitecturesAction;
17+
18+
export function updateArchitectures(
19+
revisions: Revision[]
20+
): UpdateArchitecturesAction {
21+
let archs: string[] = [];
22+
23+
revisions.forEach((revision) => {
24+
archs = archs.concat(revision.architectures);
25+
});
26+
27+
// make archs unique and sorted
28+
archs = archs.filter((item, i, ar) => ar.indexOf(item) === i);
29+
30+
return {
31+
type: UPDATE_ARCHITECTURES,
32+
payload: {
33+
architectures: archs,
34+
},
35+
};
36+
}

static/js/publisher/pages/Releases/actions/availableRevisionsSelect.js renamed to static/js/publisher/pages/Releases/actions/availableRevisionsSelect.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,44 @@ import {
1010
getFilteredAvailableRevisionsForArch,
1111
} from "../selectors";
1212
import { getBuildId } from "../helpers";
13+
import {
14+
GenericReleasesAction,
15+
DispatchFn,
16+
ReleasesReduxState,
17+
Revision,
18+
AvailableRevisionsSelect,
19+
} from "../../../types/releaseTypes";
1320

1421
export const SET_AVAILABLE_REVISIONS_SELECT = "SET_AVAILABLE_REVISIONS_SELECT";
1522

16-
export function setAvailableRevisionsSelect(value) {
23+
export type SetAvailableRevisionsSelectAction = GenericReleasesAction<
24+
typeof SET_AVAILABLE_REVISIONS_SELECT,
25+
{
26+
value: AvailableRevisionsSelect;
27+
}
28+
>;
29+
30+
export type AvailableRevisionsSelectAction = SetAvailableRevisionsSelectAction;
31+
32+
export function setAvailableRevisionsSelect(
33+
value: AvailableRevisionsSelect
34+
): SetAvailableRevisionsSelectAction {
1735
return {
1836
type: SET_AVAILABLE_REVISIONS_SELECT,
1937
payload: { value },
2038
};
2139
}
2240

23-
export function selectAvailableRevisions(value) {
24-
return (dispatch, getState) => {
41+
export function selectAvailableRevisions(value: AvailableRevisionsSelect) {
42+
return (dispatch: DispatchFn, getState: () => ReleasesReduxState) => {
2543
dispatch(setAvailableRevisionsSelect(value));
2644
dispatch(clearSelectedRevisions());
2745

2846
const state = getState();
2947

3048
// for each architecture
3149
const archs = getArchitectures(state);
32-
let revisionsFilter = () => true;
50+
let revisionsFilter: (revision: Revision) => boolean = () => true;
3351

3452
// for Recent select only revisions from most recent uploaded version
3553
if (

static/js/publisher/pages/Releases/actions/branches.js

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { GenericReleasesAction, DispatchFn, ReleasesReduxState } from "../../../types/releaseTypes";
2+
3+
export const OPEN_BRANCHES = "OPEN_BRANCHES";
4+
export const CLOSE_BRANCHES = "CLOSE_BRANCHES";
5+
6+
export type OpenBranchesAction = GenericReleasesAction<typeof OPEN_BRANCHES, string>;
7+
8+
export type CloseBranchesAction = GenericReleasesAction<typeof CLOSE_BRANCHES, string>;
9+
10+
export type BranchesAction = OpenBranchesAction | CloseBranchesAction;
11+
12+
export function openBranches(channelName: string): OpenBranchesAction {
13+
return {
14+
type: OPEN_BRANCHES,
15+
payload: channelName,
16+
};
17+
}
18+
19+
export function closeBranches(channelName: string): CloseBranchesAction {
20+
return {
21+
type: CLOSE_BRANCHES,
22+
payload: channelName,
23+
};
24+
}
25+
26+
export function toggleBranches(channelName: string) {
27+
return (dispatch: DispatchFn, getState: () => ReleasesReduxState) => {
28+
const { branches } = getState();
29+
30+
if (branches.includes(channelName)) {
31+
dispatch(closeBranches(channelName));
32+
} else {
33+
dispatch(openBranches(channelName));
34+
}
35+
};
36+
}

static/js/publisher/pages/Releases/actions/channelMap.js

Lines changed: 0 additions & 56 deletions
This file was deleted.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import {
2+
GenericReleasesAction,
3+
ReleasesReduxState,
4+
Revision,
5+
} from "../../../types/releaseTypes";
6+
7+
export const INIT_CHANNEL_MAP = "INIT_CHANNEL_MAP";
8+
export const SELECT_REVISION = "SELECT_REVISION";
9+
export const CLEAR_SELECTED_REVISIONS = "CLEAR_SELECTED_REVISIONS";
10+
export const RELEASE_REVISION_SUCCESS = "RELEASE_REVISION_SUCCESS";
11+
export const CLOSE_CHANNEL_SUCCESS = "CLOSE_CHANNEL_SUCCESS";
12+
13+
export type InitChannelMapAction = GenericReleasesAction<
14+
typeof INIT_CHANNEL_MAP,
15+
{ channelMap: ReleasesReduxState["channelMap"] }
16+
>;
17+
18+
export type SelectRevisionAction = GenericReleasesAction<
19+
typeof SELECT_REVISION,
20+
{
21+
revision: Revision;
22+
toggle: boolean;
23+
}
24+
>;
25+
26+
export type ClearSelectedRevisionAction = GenericReleasesAction<
27+
typeof CLEAR_SELECTED_REVISIONS,
28+
never
29+
>;
30+
31+
export type ReleaseRevisionSuccessAction = GenericReleasesAction<
32+
typeof RELEASE_REVISION_SUCCESS,
33+
{
34+
revision: Revision;
35+
channel: string;
36+
}
37+
>;
38+
39+
export type CloseChannelSuccessAction = GenericReleasesAction<
40+
typeof CLOSE_CHANNEL_SUCCESS,
41+
{
42+
channel: string;
43+
}
44+
>;
45+
46+
export type ChannelMapAction =
47+
| InitChannelMapAction
48+
| SelectRevisionAction
49+
| ClearSelectedRevisionAction
50+
| ReleaseRevisionSuccessAction
51+
| CloseChannelSuccessAction;
52+
53+
export function initChannelMap(
54+
channelMap: ReleasesReduxState["channelMap"]
55+
): InitChannelMapAction {
56+
return {
57+
type: INIT_CHANNEL_MAP,
58+
payload: { channelMap },
59+
};
60+
}
61+
62+
export function selectRevision(revision: Revision): SelectRevisionAction {
63+
return {
64+
type: SELECT_REVISION,
65+
payload: { revision, toggle: false },
66+
};
67+
}
68+
69+
export function toggleRevision(revision: Revision): SelectRevisionAction {
70+
return {
71+
type: SELECT_REVISION,
72+
payload: { revision, toggle: true },
73+
};
74+
}
75+
76+
export function clearSelectedRevisions(): ClearSelectedRevisionAction {
77+
return {
78+
type: CLEAR_SELECTED_REVISIONS,
79+
};
80+
}
81+
82+
export function releaseRevisionSuccess(
83+
revision: Revision,
84+
channel: string
85+
): ReleaseRevisionSuccessAction {
86+
return {
87+
type: RELEASE_REVISION_SUCCESS,
88+
payload: {
89+
revision,
90+
channel,
91+
},
92+
};
93+
}
94+
95+
/**
96+
*
97+
* @param channel Channel to close
98+
* @returns Action to close channel
99+
*/
100+
export function closeChannelSuccess(channel: string): CloseChannelSuccessAction {
101+
return {
102+
type: CLOSE_CHANNEL_SUCCESS,
103+
payload: {
104+
channel,
105+
},
106+
};
107+
}

static/js/publisher/pages/Releases/actions/currentTrack.js

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {
2+
GenericReleasesAction,
3+
ReleasesReduxState,
4+
} from "../../../types/releaseTypes";
5+
6+
export const SET_CURRENT_TRACK = "SET_CURRENT_TRACK";
7+
8+
export type SetCurrentTrackAction = GenericReleasesAction<
9+
typeof SET_CURRENT_TRACK,
10+
{
11+
track: ReleasesReduxState["currentTrack"];
12+
}
13+
>;
14+
15+
export type CurrentTrackAction = SetCurrentTrackAction;
16+
17+
export function setCurrentTrack(
18+
track: ReleasesReduxState["currentTrack"]
19+
): SetCurrentTrackAction {
20+
return {
21+
type: SET_CURRENT_TRACK,
22+
payload: { track },
23+
};
24+
}

0 commit comments

Comments
 (0)