Skip to content

Commit 20343d5

Browse files
committed
Fix typescript errors in Vue files
1 parent b6ce2d6 commit 20343d5

File tree

11 files changed

+98
-60
lines changed

11 files changed

+98
-60
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ _testmain.go
2828
*.exe
2929
*.test
3030
*.prof
31+
*.tsbuildinfo
3132

3233
*coverage.out
3334
coverage.all

templates/repo/commit_status.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- make sure this matches the color logic in web_src/js/components/DashboardRepoList.vue -->
1+
<!-- make sure this matches the color logic in web_src/js/types.ts -->
22
{{if eq .State "pending"}}
33
{{svg "octicon-dot-fill" 18 "commit-status icon text yellow"}}
44
{{end}}

web_src/js/components/DashboardRepoList.vue

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,11 @@ import {createApp, nextTick} from 'vue';
33
import {SvgIcon} from '../svg.ts';
44
import {GET} from '../modules/fetch.ts';
55
import {fomanticQuery} from '../modules/fomantic/base.ts';
6+
import {commitStatus} from '../types.ts';
7+
import type {CommitStatus} from '../types.ts';
68
79
const {appSubUrl, assetUrlPrefix, pageData} = window.config;
810
9-
// make sure this matches templates/repo/commit_status.tmpl
10-
const commitStatus = {
11-
pending: {name: 'octicon-dot-fill', color: 'yellow'},
12-
success: {name: 'octicon-check', color: 'green'},
13-
error: {name: 'gitea-exclamation', color: 'red'},
14-
failure: {name: 'octicon-x', color: 'red'},
15-
warning: {name: 'gitea-exclamation', color: 'yellow'},
16-
};
17-
1811
const sfc = {
1912
components: {SvgIcon},
2013
data() {
@@ -281,18 +274,18 @@ const sfc = {
281274
return 'octicon-repo';
282275
},
283276
284-
statusIcon(status) {
277+
statusIcon(status: CommitStatus) {
285278
return commitStatus[status].name;
286279
},
287280
288-
statusColor(status) {
281+
statusColor(status: CommitStatus) {
289282
return commitStatus[status].color;
290283
},
291284
292285
reposFilterKeyControl(e) {
293286
switch (e.key) {
294287
case 'Enter':
295-
document.querySelector('.repo-owner-name-list li.active a')?.click();
288+
document.querySelector<HTMLAnchorElement>('.repo-owner-name-list li.active a')?.click();
296289
break;
297290
case 'ArrowUp':
298291
if (this.activeIndex > 0) {

web_src/js/components/DiffCommitSelector.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default {
1414
issueLink: el.getAttribute('data-issuelink'),
1515
locale: {
1616
filter_changes_by_commit: el.getAttribute('data-filter_changes_by_commit'),
17-
},
17+
} as Record<string, string>,
1818
commits: [],
1919
hoverActivated: false,
2020
lastReviewCommitSha: null,
@@ -41,16 +41,16 @@ export default {
4141
this.$el.removeEventListener('keyup', this.onKeyUp);
4242
},
4343
methods: {
44-
onBodyClick(event) {
44+
onBodyClick(event: MouseEvent) {
4545
// close this menu on click outside of this element when the dropdown is currently visible opened
4646
if (this.$el.contains(event.target)) return;
4747
if (this.menuVisible) {
4848
this.toggleMenu();
4949
}
5050
},
51-
onKeyDown(event) {
51+
onKeyDown(event: KeyboardEvent) {
5252
if (!this.menuVisible) return;
53-
const item = document.activeElement;
53+
const item = document.activeElement as HTMLElement;
5454
if (!this.$el.contains(item)) return;
5555
switch (event.key) {
5656
case 'ArrowDown': // select next element
@@ -73,7 +73,7 @@ export default {
7373
if (commitIdx) this.highlight(this.commits[commitIdx]);
7474
}
7575
},
76-
onKeyUp(event) {
76+
onKeyUp(event: KeyboardEvent) {
7777
if (!this.menuVisible) return;
7878
const item = document.activeElement;
7979
if (!this.$el.contains(item)) return;
@@ -95,7 +95,7 @@ export default {
9595
}
9696
},
9797
/** Focus given element */
98-
focusElem(elem, prevElem) {
98+
focusElem(elem: HTMLElement, prevElem: HTMLElement) {
9999
if (elem) {
100100
elem.tabIndex = 0;
101101
if (prevElem) prevElem.tabIndex = -1;
@@ -149,7 +149,7 @@ export default {
149149
window.location.assign(`${this.issueLink}/files/${this.lastReviewCommitSha}..${this.commits.at(-1).id}${this.queryParams}`);
150150
},
151151
/** Clicking on a single commit opens this specific commit */
152-
commitClicked(commitId, newWindow = false) {
152+
commitClicked(commitId: string, newWindow = false) {
153153
const url = `${this.issueLink}/commits/${commitId}${this.queryParams}`;
154154
if (newWindow) {
155155
window.open(url);

web_src/js/components/RepoActionView.vue

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {toggleElem} from '../utils/dom.ts';
66
import {formatDatetime} from '../utils/time.ts';
77
import {renderAnsi} from '../render/ansi.ts';
88
import {GET, POST, DELETE} from '../modules/fetch.ts';
9+
import type {ActionsStepLogLine, ActionsStatus} from '../types.ts';
910
1011
const sfc = {
1112
name: 'RepoActionView',
@@ -113,12 +114,12 @@ const sfc = {
113114
114115
methods: {
115116
// get the active container element, either the `job-step-logs` or the `job-log-list` in the `job-log-group`
116-
getLogsContainer(idx) {
117+
getLogsContainer(idx: number) {
117118
const el = this.$refs.logs[idx];
118119
return el._stepLogsActiveContainer ?? el;
119120
},
120121
// begin a log group
121-
beginLogGroup(idx) {
122+
beginLogGroup(idx: number) {
122123
const el = this.$refs.logs[idx];
123124
124125
const elJobLogGroup = document.createElement('div');
@@ -135,13 +136,13 @@ const sfc = {
135136
el._stepLogsActiveContainer = elJobLogList;
136137
},
137138
// end a log group
138-
endLogGroup(idx) {
139+
endLogGroup(idx: number) {
139140
const el = this.$refs.logs[idx];
140141
el._stepLogsActiveContainer = null;
141142
},
142143
143144
// show/hide the step logs for a step
144-
toggleStepLogs(idx) {
145+
toggleStepLogs(idx: number) {
145146
this.currentJobStepsStates[idx].expanded = !this.currentJobStepsStates[idx].expanded;
146147
if (this.currentJobStepsStates[idx].expanded) {
147148
this.loadJob(); // try to load the data immediately instead of waiting for next timer interval
@@ -156,29 +157,29 @@ const sfc = {
156157
POST(`${this.run.link}/approve`);
157158
},
158159
159-
createLogLine(line, startTime, stepIndex) {
160+
createLogLine(line: ActionsStepLogLine, startTime: number, stepIndex: number) {
160161
const div = document.createElement('div');
161162
div.classList.add('job-log-line');
162163
div.setAttribute('id', `jobstep-${stepIndex}-${line.index}`);
163164
div._jobLogTime = line.timestamp;
164165
165166
const lineNumber = document.createElement('a');
166167
lineNumber.classList.add('line-num', 'muted');
167-
lineNumber.textContent = line.index;
168+
lineNumber.textContent = String(line.index);
168169
lineNumber.setAttribute('href', `#jobstep-${stepIndex}-${line.index}`);
169170
div.append(lineNumber);
170171
171172
// for "Show timestamps"
172173
const logTimeStamp = document.createElement('span');
173174
logTimeStamp.className = 'log-time-stamp';
174-
const date = new Date(parseFloat(line.timestamp * 1000));
175+
const date = new Date(line.timestamp * 1000);
175176
const timeStamp = formatDatetime(date);
176177
logTimeStamp.textContent = timeStamp;
177178
toggleElem(logTimeStamp, this.timeVisible['log-time-stamp']);
178179
// for "Show seconds"
179180
const logTimeSeconds = document.createElement('span');
180181
logTimeSeconds.className = 'log-time-seconds';
181-
const seconds = Math.floor(parseFloat(line.timestamp) - parseFloat(startTime));
182+
const seconds = Math.floor(line.timestamp - startTime);
182183
logTimeSeconds.textContent = `${seconds}s`;
183184
toggleElem(logTimeSeconds, this.timeVisible['log-time-seconds']);
184185
@@ -192,7 +193,7 @@ const sfc = {
192193
return div;
193194
},
194195
195-
appendLogs(stepIndex, logLines, startTime) {
196+
appendLogs(stepIndex: number, logLines: Array<ActionsStepLogLine>, startTime: number) {
196197
for (const line of logLines) {
197198
// TODO: group support: ##[group]GroupTitle , ##[endgroup]
198199
const el = this.getLogsContainer(stepIndex);
@@ -205,7 +206,7 @@ const sfc = {
205206
return await resp.json();
206207
},
207208
208-
async deleteArtifact(name) {
209+
async deleteArtifact(name: string) {
209210
if (!window.confirm(this.locale.confirmDeleteArtifact.replace('%s', name))) return;
210211
await DELETE(`${this.run.link}/artifacts/${name}`);
211212
await this.loadJob();
@@ -269,19 +270,19 @@ const sfc = {
269270
}
270271
},
271272
272-
isDone(status) {
273+
isDone(status: ActionsStatus) {
273274
return ['success', 'skipped', 'failure', 'cancelled'].includes(status);
274275
},
275276
276-
isExpandable(status) {
277+
isExpandable(status: ActionsStatus) {
277278
return ['success', 'running', 'failure', 'cancelled'].includes(status);
278279
},
279280
280281
closeDropdown() {
281282
if (this.menuVisible) this.menuVisible = false;
282283
},
283284
284-
toggleTimeDisplay(type) {
285+
toggleTimeDisplay(type: 'seconds' | 'stamp') {
285286
this.timeVisible[`log-time-${type}`] = !this.timeVisible[`log-time-${type}`];
286287
for (const el of this.$refs.steps.querySelectorAll(`.log-time-${type}`)) {
287288
toggleElem(el, this.timeVisible[`log-time-${type}`]);
@@ -332,7 +333,7 @@ export function initRepositoryActionView() {
332333
333334
// TODO: the parent element's full height doesn't work well now,
334335
// but we can not pollute the global style at the moment, only fix the height problem for pages with this component
335-
const parentFullHeight = document.querySelector('body > div.full.height');
336+
const parentFullHeight = document.querySelector<HTMLDivElement>('body > div.full.height');
336337
if (parentFullHeight) parentFullHeight.style.paddingBottom = '0';
337338
338339
const view = createApp(sfc, {

web_src/js/components/RepoCodeFrequency.vue

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
PointElement,
99
LineElement,
1010
Filler,
11+
type ChartOptions,
12+
type ChartData,
1113
} from 'chart.js';
1214
import {GET} from '../modules/fetch.ts';
1315
import {Line as ChartLine} from 'vue-chartjs';
@@ -16,6 +18,7 @@ import {
1618
firstStartDateAfterDate,
1719
fillEmptyStartDaysWithZeroes,
1820
type DayData,
21+
type DayDataObject,
1922
} from '../utils/time.ts';
2023
import {chartJsColors} from '../utils/color.ts';
2124
import {sleep} from '../utils.ts';
@@ -64,12 +67,12 @@ async function fetchGraphData() {
6467
}
6568
} while (response.status === 202);
6669
if (response.ok) {
67-
data.value = await response.json();
68-
const weekValues = Object.values(data.value);
70+
const dayDataObject: DayDataObject = await response.json();
71+
const weekValues = Object.values(dayDataObject);
6972
const start = weekValues[0].week;
7073
const end = firstStartDateAfterDate(new Date());
7174
const startDays = startDaysBetween(start, end);
72-
data.value = fillEmptyStartDaysWithZeroes(startDays, data.value);
75+
data.value = fillEmptyStartDaysWithZeroes(startDays, dayDataObject);
7376
errorText.value = '';
7477
} else {
7578
errorText.value = response.statusText;
@@ -81,7 +84,7 @@ async function fetchGraphData() {
8184
}
8285
}
8386
84-
function toGraphData(data) {
87+
function toGraphData(data: Array<Record<string, any>>): ChartData<'line'> {
8588
return {
8689
datasets: [
8790
{
@@ -108,10 +111,9 @@ function toGraphData(data) {
108111
};
109112
}
110113
111-
const options = {
114+
const options: ChartOptions<'line'> = {
112115
responsive: true,
113116
maintainAspectRatio: false,
114-
animation: true,
115117
plugins: {
116118
legend: {
117119
display: true,

web_src/js/components/RepoContributors.vue

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import {
99
PointElement,
1010
LineElement,
1111
Filler,
12+
type ChartOptions,
13+
type ChartData,
14+
type Plugin,
1215
} from 'chart.js';
1316
import {GET} from '../modules/fetch.ts';
1417
import zoomPlugin from 'chartjs-plugin-zoom';
@@ -22,8 +25,9 @@ import {chartJsColors} from '../utils/color.ts';
2225
import {sleep} from '../utils.ts';
2326
import 'chartjs-adapter-dayjs-4/dist/chartjs-adapter-dayjs-4.esm';
2427
import {fomanticQuery} from '../modules/fomantic/base.ts';
28+
import type {Entries} from 'type-fest';
2529
26-
const customEventListener = {
30+
const customEventListener: Plugin = {
2731
id: 'customEventListener',
2832
afterEvent: (chart, args, opts) => {
2933
// event will be replayed from chart.update when reset zoom,
@@ -65,10 +69,10 @@ export default {
6569
data: () => ({
6670
isLoading: false,
6771
errorText: '',
68-
totalStats: {},
69-
sortedContributors: {},
72+
totalStats: {} as Record<string, any>,
73+
sortedContributors: {} as Record<string, any>,
7074
type: 'commits',
71-
contributorsStats: [],
75+
contributorsStats: [] as Record<string, any>,
7276
xAxisStart: null,
7377
xAxisEnd: null,
7478
xAxisMin: null,
@@ -99,7 +103,7 @@ export default {
99103
async fetchGraphData() {
100104
this.isLoading = true;
101105
try {
102-
let response;
106+
let response: Response;
103107
do {
104108
response = await GET(`${this.repoLink}/activity/contributors/data`);
105109
if (response.status === 202) {
@@ -112,15 +116,15 @@ export default {
112116
// below line might be deleted if we are sure go produces map always sorted by keys
113117
total.weeks = Object.fromEntries(Object.entries(total.weeks).sort());
114118
115-
const weekValues = Object.values(total.weeks);
119+
const weekValues = Object.values(total.weeks) as any;
116120
this.xAxisStart = weekValues[0].week;
117121
this.xAxisEnd = firstStartDateAfterDate(new Date());
118122
const startDays = startDaysBetween(this.xAxisStart, this.xAxisEnd);
119123
total.weeks = fillEmptyStartDaysWithZeroes(startDays, total.weeks);
120124
this.xAxisMin = this.xAxisStart;
121125
this.xAxisMax = this.xAxisEnd;
122126
this.contributorsStats = {};
123-
for (const [email, user] of Object.entries(rest)) {
127+
for (const [email, user] of Object.entries(rest) as Entries<Record<string, Record<string, any>>>) {
124128
user.weeks = fillEmptyStartDaysWithZeroes(startDays, user.weeks);
125129
this.contributorsStats[email] = user;
126130
}
@@ -146,7 +150,7 @@ export default {
146150
user.total_additions = 0;
147151
user.total_deletions = 0;
148152
user.max_contribution_type = 0;
149-
const filteredWeeks = user.weeks.filter((week) => {
153+
const filteredWeeks = user.weeks.filter((week: Record<string, number>) => {
150154
const oneWeek = 7 * 24 * 60 * 60 * 1000;
151155
if (week.week >= this.xAxisMin - oneWeek && week.week <= this.xAxisMax + oneWeek) {
152156
user.total_commits += week.commits;
@@ -195,7 +199,7 @@ export default {
195199
return (1 - (coefficient % 1)) * 10 ** exp + maxValue;
196200
},
197201
198-
toGraphData(data) {
202+
toGraphData(data: Array<Record<string, any>>): ChartData<'line'> {
199203
return {
200204
datasets: [
201205
{
@@ -211,9 +215,9 @@ export default {
211215
};
212216
},
213217
214-
updateOtherCharts(event, reset) {
215-
const minVal = event.chart.options.scales.x.min;
216-
const maxVal = event.chart.options.scales.x.max;
218+
updateOtherCharts({chart}: {chart: Chart}, reset?: boolean) {
219+
const minVal = chart.options.scales.x.min;
220+
const maxVal = chart.options.scales.x.max;
217221
if (reset) {
218222
this.xAxisMin = this.xAxisStart;
219223
this.xAxisMax = this.xAxisEnd;
@@ -225,7 +229,7 @@ export default {
225229
}
226230
},
227231
228-
getOptions(type) {
232+
getOptions(type: 'main' | 'contributor'): ChartOptions<'line'> {
229233
return {
230234
responsive: true,
231235
maintainAspectRatio: false,
@@ -238,6 +242,7 @@ export default {
238242
position: 'top',
239243
align: 'center',
240244
},
245+
// @ts-expect-error: bug in chartjs types
241246
customEventListener: {
242247
chartType: type,
243248
instance: this,

0 commit comments

Comments
 (0)