Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Typescript noImplicitThis #33250

Merged
merged 5 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"stripInternal": true,
"strict": false,
"strictFunctionTypes": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noPropertyAccessFromIndexSignature": false,
Expand Down
14 changes: 3 additions & 11 deletions web_src/js/components/DashboardRepoList.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import {createApp, nextTick} from 'vue';
import {nextTick, defineComponent} from 'vue';
import {SvgIcon} from '../svg.ts';
import {GET} from '../modules/fetch.ts';
import {fomanticQuery} from '../modules/fomantic/base.ts';
Expand All @@ -24,7 +24,7 @@ const commitStatus: CommitStatusMap = {
warning: {name: 'gitea-exclamation', color: 'yellow'},
};

const sfc = {
export default defineComponent({
components: {SvgIcon},
data() {
const params = new URLSearchParams(window.location.search);
Expand Down Expand Up @@ -335,16 +335,8 @@ const sfc = {
}
},
},
};

export function initDashboardRepoList() {
const el = document.querySelector('#dashboard-repo-list');
if (el) {
createApp(sfc).mount(el);
}
}
});

export default sfc; // activate the IDE's Vue plugin
</script>
<template>
<div>
Expand Down
13 changes: 7 additions & 6 deletions web_src/js/components/DiffCommitSelector.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<script lang="ts">
import {defineComponent} from 'vue';
import {SvgIcon} from '../svg.ts';
import {GET} from '../modules/fetch.ts';
import {generateAriaId} from '../modules/fomantic/base.ts';

export default {
export default defineComponent({
components: {SvgIcon},
data: () => {
const el = document.querySelector('#diff-commit-select');
Expand Down Expand Up @@ -55,11 +56,11 @@ export default {
switch (event.key) {
case 'ArrowDown': // select next element
event.preventDefault();
this.focusElem(item.nextElementSibling, item);
this.focusElem(item.nextElementSibling as HTMLElement, item);
break;
case 'ArrowUp': // select previous element
event.preventDefault();
this.focusElem(item.previousElementSibling, item);
this.focusElem(item.previousElementSibling as HTMLElement, item);
break;
case 'Escape': // close menu
event.preventDefault();
Expand Down Expand Up @@ -118,9 +119,9 @@ export default {
// set correct tabindex to allow easier navigation
this.$nextTick(() => {
if (this.menuVisible) {
this.focusElem(this.$refs.showAllChanges, this.$refs.expandBtn);
this.focusElem(this.$refs.showAllChanges as HTMLElement, this.$refs.expandBtn as HTMLElement);
} else {
this.focusElem(this.$refs.expandBtn, this.$refs.showAllChanges);
this.focusElem(this.$refs.expandBtn as HTMLElement, this.$refs.showAllChanges as HTMLElement);
}
});
},
Expand Down Expand Up @@ -188,7 +189,7 @@ export default {
}
},
},
};
});
</script>
<template>
<div class="ui scrolling dropdown custom diff-commit-selector">
Expand Down
4 changes: 2 additions & 2 deletions web_src/js/components/DiffFileList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function toggleFileList() {
store.fileListIsVisible = !store.fileListIsVisible;
}

function diffTypeToString(pType) {
function diffTypeToString(pType: number) {
const diffTypes = {
1: 'add',
2: 'modify',
Expand All @@ -28,7 +28,7 @@ function diffTypeToString(pType) {
return diffTypes[pType];
}

function diffStatsWidth(adds, dels) {
function diffStatsWidth(adds: number, dels: number) {
return `${adds / (adds + dels) * 100}%`;
}

Expand Down
6 changes: 3 additions & 3 deletions web_src/js/components/DiffFileTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const fileTree = computed(() => {
parent = newParent;
}
}
const mergeChildIfOnlyOneDir = (entries) => {
const mergeChildIfOnlyOneDir = (entries: Array<Record<string, any>>) => {
for (const entry of entries) {
if (entry.children) {
mergeChildIfOnlyOneDir(entry.children);
Expand Down Expand Up @@ -110,13 +110,13 @@ function toggleVisibility() {
updateVisibility(!store.fileTreeIsVisible);
}

function updateVisibility(visible) {
function updateVisibility(visible: boolean) {
store.fileTreeIsVisible = visible;
localStorage.setItem(LOCAL_STORAGE_KEY, store.fileTreeIsVisible);
updateState(store.fileTreeIsVisible);
}

function updateState(visible) {
function updateState(visible: boolean) {
const btn = document.querySelector('.diff-toggle-file-tree-button');
const [toShow, toHide] = btn.querySelectorAll('.icon');
const tree = document.querySelector('#diff-file-tree');
Expand Down
4 changes: 2 additions & 2 deletions web_src/js/components/DiffFileTreeItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ defineProps<{
const store = diffTreeStore();
const collapsed = ref(false);

function getIconForDiffType(pType) {
function getIconForDiffType(pType: number) {
const diffTypes = {
1: {name: 'octicon-diff-added', classes: ['text', 'green']},
2: {name: 'octicon-diff-modified', classes: ['text', 'yellow']},
Expand All @@ -36,7 +36,7 @@ function getIconForDiffType(pType) {
return diffTypes[pType];
}

function fileIcon(file) {
function fileIcon(file: File) {
if (file.IsSubmodule) {
return 'octicon-file-submodule';
}
Expand Down
2 changes: 1 addition & 1 deletion web_src/js/components/PullRequestMergeForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function toggleActionForm(show: boolean) {
mergeMessageFieldValue.value = mergeStyleDetail.value.mergeMessageFieldText;
}

function switchMergeStyle(name, autoMerge = false) {
function switchMergeStyle(name: string, autoMerge = false) {
mergeStyle.value = name;
autoMergeWhenSucceed.value = autoMerge;
}
Expand Down
104 changes: 36 additions & 68 deletions web_src/js/components/RepoActionView.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import {SvgIcon} from '../svg.ts';
import ActionRunStatus from './ActionRunStatus.vue';
import {createApp} from 'vue';
import {defineComponent, type PropType} from 'vue';
import {createElementFromAttrs, toggleElem} from '../utils/dom.ts';
import {formatDatetime} from '../utils/time.ts';
import {renderAnsi} from '../render/ansi.ts';
Expand Down Expand Up @@ -38,7 +38,7 @@ function parseLineCommand(line: LogLine): LogLineCommand | null {
return null;
}

function isLogElementInViewport(el: HTMLElement): boolean {
function isLogElementInViewport(el: Element): boolean {
const rect = el.getBoundingClientRect();
return rect.top >= 0 && rect.bottom <= window.innerHeight; // only check height but not width
}
Expand All @@ -57,25 +57,28 @@ function getLocaleStorageOptions(): LocaleStorageOptions {
return {autoScroll: true, expandRunning: false};
}

const sfc = {
export default defineComponent({
name: 'RepoActionView',
components: {
SvgIcon,
ActionRunStatus,
},
props: {
runIndex: String,
jobIndex: String,
actionsURL: String,
locale: Object,
},

watch: {
optionAlwaysAutoScroll() {
this.saveLocaleStorageOptions();
runIndex: {
type: String,
default: '',
},
optionAlwaysExpandRunning() {
this.saveLocaleStorageOptions();
jobIndex: {
type: String,
default: '',
},
actionsURL: {
type: String,
default: '',
},
locale: {
type: Object as PropType<Record<string, string>>,
default: null,
},
},

Expand All @@ -102,10 +105,11 @@ const sfc = {
link: '',
title: '',
titleHTML: '',
status: '',
status: 'unknown' as RunStatus,
canCancel: false,
canApprove: false,
canRerun: false,
canDeleteArtifact: false,
done: false,
workflowID: '',
workflowLink: '',
Expand All @@ -131,6 +135,7 @@ const sfc = {
branch: {
name: '',
link: '',
isDeleted: false,
},
},
},
Expand All @@ -148,7 +153,16 @@ const sfc = {
};
},

async mounted() {
watch: {
optionAlwaysAutoScroll() {
this.saveLocaleStorageOptions();
},
optionAlwaysExpandRunning() {
this.saveLocaleStorageOptions();
},
},

async mounted() { // eslint-disable-line @typescript-eslint/no-misused-promises
// load job data and then auto-reload periodically
// need to await first loadJob so this.currentJobStepsStates is initialized and can be used in hashChangeListener
await this.loadJob();
Expand Down Expand Up @@ -186,6 +200,7 @@ const sfc = {
// get the active logs container element, either the `job-step-logs` or the `job-log-list` in the `job-log-group`
getActiveLogsContainer(stepIndex: number): HTMLElement {
const el = this.getJobStepLogsContainer(stepIndex);
// @ts-expect-error - _stepLogsActiveContainer is a custom property
return el._stepLogsActiveContainer ?? el;
},
// begin a log group
Expand Down Expand Up @@ -263,7 +278,7 @@ const sfc = {
const el = this.getJobStepLogsContainer(stepIndex);
// if the logs container is empty, then auto-scroll if the step is expanded
if (!el.lastChild) return this.currentJobStepsStates[stepIndex].expanded;
return isLogElementInViewport(el.lastChild);
return isLogElementInViewport(el.lastChild as Element);
},

appendLogs(stepIndex: number, startTime: number, logLines: LogLine[]) {
Expand Down Expand Up @@ -380,7 +395,7 @@ const sfc = {

toggleTimeDisplay(type: string) {
this.timeVisible[`log-time-${type}`] = !this.timeVisible[`log-time-${type}`];
for (const el of this.$refs.steps.querySelectorAll(`.log-time-${type}`)) {
for (const el of (this.$refs.steps as HTMLElement).querySelectorAll(`.log-time-${type}`)) {
toggleElem(el, this.timeVisible[`log-time-${type}`]);
}
},
Expand Down Expand Up @@ -414,59 +429,12 @@ const sfc = {
// so logline can be selected by querySelector
await this.loadJob();
}
const logLine = this.$refs.steps.querySelector(selectedLogStep);
const logLine = (this.$refs.steps as HTMLElement).querySelector(selectedLogStep);
if (!logLine) return;
logLine.querySelector('.line-num').click();
logLine.querySelector<HTMLAnchorElement>('.line-num').click();
},
},
};

export default sfc;

export function initRepositoryActionView() {
const el = document.querySelector('#repo-action-view');
if (!el) return;

// TODO: the parent element's full height doesn't work well now,
// but we can not pollute the global style at the moment, only fix the height problem for pages with this component
const parentFullHeight = document.querySelector<HTMLElement>('body > div.full.height');
if (parentFullHeight) parentFullHeight.style.paddingBottom = '0';

const view = createApp(sfc, {
runIndex: el.getAttribute('data-run-index'),
jobIndex: el.getAttribute('data-job-index'),
actionsURL: el.getAttribute('data-actions-url'),
locale: {
approve: el.getAttribute('data-locale-approve'),
cancel: el.getAttribute('data-locale-cancel'),
rerun: el.getAttribute('data-locale-rerun'),
rerun_all: el.getAttribute('data-locale-rerun-all'),
scheduled: el.getAttribute('data-locale-runs-scheduled'),
commit: el.getAttribute('data-locale-runs-commit'),
pushedBy: el.getAttribute('data-locale-runs-pushed-by'),
artifactsTitle: el.getAttribute('data-locale-artifacts-title'),
areYouSure: el.getAttribute('data-locale-are-you-sure'),
confirmDeleteArtifact: el.getAttribute('data-locale-confirm-delete-artifact'),
showTimeStamps: el.getAttribute('data-locale-show-timestamps'),
showLogSeconds: el.getAttribute('data-locale-show-log-seconds'),
showFullScreen: el.getAttribute('data-locale-show-full-screen'),
downloadLogs: el.getAttribute('data-locale-download-logs'),
status: {
unknown: el.getAttribute('data-locale-status-unknown'),
waiting: el.getAttribute('data-locale-status-waiting'),
running: el.getAttribute('data-locale-status-running'),
success: el.getAttribute('data-locale-status-success'),
failure: el.getAttribute('data-locale-status-failure'),
cancelled: el.getAttribute('data-locale-status-cancelled'),
skipped: el.getAttribute('data-locale-status-skipped'),
blocked: el.getAttribute('data-locale-status-blocked'),
},
logsAlwaysAutoScroll: el.getAttribute('data-locale-logs-always-auto-scroll'),
logsAlwaysExpandRunning: el.getAttribute('data-locale-logs-always-expand-running'),
},
});
view.mount(el);
}
});
</script>
<template>
<div class="ui container action-view-container">
Expand Down
18 changes: 10 additions & 8 deletions web_src/js/components/RepoActivityTopAuthors.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ const colors = ref({
textAltColor: 'white',
});

// possible keys:
// * avatar_link: (...)
// * commits: (...)
// * home_link: (...)
// * login: (...)
// * name: (...)
const activityTopAuthors = window.config.pageData.repoActivityTopAuthors || [];
type ActivityAuthorData = {
avatar_link: string;
commits: number;
home_link: string;
login: string;
name: string;
}

const activityTopAuthors: Array<ActivityAuthorData> = window.config.pageData.repoActivityTopAuthors || [];

const graphPoints = computed(() => {
return activityTopAuthors.map((item) => {
Expand All @@ -26,7 +28,7 @@ const graphPoints = computed(() => {
});

const graphAuthors = computed(() => {
return activityTopAuthors.map((item, idx) => {
return activityTopAuthors.map((item, idx: number) => {
return {
position: idx + 1,
...item,
Expand Down
Loading
Loading