Skip to content

Commit

Permalink
chore: added types annotations to all components
Browse files Browse the repository at this point in the history
  • Loading branch information
EDM115 committed Mar 26, 2024
1 parent 6a3df48 commit bc1a377
Show file tree
Hide file tree
Showing 18 changed files with 176 additions and 83 deletions.
3 changes: 3 additions & 0 deletions ui/assets/sources/file/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { parse } from 'path'

const pumpPromise = promisify(pump)

/**
* @param {Record<string, any>} config
*/
export async function run(config) {
const response = await ofetch.raw(config.url, { responseType: 'arrayBuffer' })
const tmpFile = await file()
Expand Down
3 changes: 3 additions & 0 deletions ui/assets/sources/gbfs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
// de vélos en libre-service (VLS) Vélocéo de Vannes
import { ofetch } from 'ofetch'

/**
* @param {Record<string, any>} config
*/
export async function run(config) {
const infos = await ofetch(config.infosUrl)
const status = await ofetch(config.statusUrl)
Expand Down
3 changes: 3 additions & 0 deletions ui/assets/sources/gtfs-rt/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import GtfsRealtimeBindings from 'gtfs-realtime-bindings'
import { ofetch } from 'ofetch'

/**
* @param {Record<string, any>} config
*/
export async function run(config) {
const result = await ofetch(config.url, { responseType: 'arrayBuffer' })
const feed = GtfsRealtimeBindings.transit_realtime.FeedMessage.decode(result)
Expand Down
4 changes: 2 additions & 2 deletions ui/components/Notifications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
import useEventBus from '~/composables/event-bus'
import { onMounted, ref } from 'vue'
const notification = ref(null)
const /** @type {Record<String, any>} */ notification = ref(null)
const showSnackbar = ref(false)
const eventBus = useEventBus()
onMounted(() => {
eventBus.on('notification', async (notif) => {
eventBus.on('notification', async (/** @type {Record<String, any>} */ notif) => {
if (showSnackbar.value) {
showSnackbar.value = false
await new Promise(resolve => setTimeout(resolve, 300))
Expand Down
12 changes: 6 additions & 6 deletions ui/components/PrivateAccess.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
:custom-filter="() => true"
:multiple="true"
:clearable="true"
:item-title="(item) => item && `${item.name || item.id} (${item.type})`"
:item-value="(item) => item && `${item.type}:${item.id}`"
:item-title="(/** @type {Record<String, any>} */ item) => item && `${item.name || item.id} (${item.type})`"
:item-value="(/** @type {Record<String, any>} */ item) => item && `${item.type}:${item.id}`"
:label="t('privateAccess')"
:placeholder="t('searchName')"
return-object
Expand Down Expand Up @@ -77,14 +77,14 @@ async function listSuggestions() {
}
loading.value = true
const orgsResponse = await $fetch('/simple-directory/api/organizations', {
const /** @type {Record<String, any>} */ orgsResponse = await $fetch('/simple-directory/api/organizations', {
params: { q: search.value }
})
const orgs = orgsResponse.results.map(r => ({ ...r, type: 'organization' }))
const usersResponse = await $fetch('/simple-directory/api/users', {
const orgs = orgsResponse.results.map(/** @param {any} r */ r => ({ ...r, type: 'organization' }))
const /** @type {Record<String, any>} */ usersResponse = await $fetch('/simple-directory/api/users', {
params: { q: search.value }
})
const users = usersResponse.results.map(r => ({ ...r, type: 'user' }))
const users = usersResponse.results.map(/** @param {any} r */ r => ({ ...r, type: 'user' }))
suggestions.value = props.patch.privateAccess.concat(orgs, users)
emit('change', props.patch)
loading.value = false
Expand Down
38 changes: 19 additions & 19 deletions ui/components/ProcessingsActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
</v-menu>
<v-text-field
v-model="search"
:loading="processings == [] ? 'primary' : false"
:loading="processings.length === 0 ? 'primary' : false"
placeholder="rechercher"
variant="outlined"
hide-details
Expand Down Expand Up @@ -120,28 +120,28 @@
</v-list>
</template>

<script setup>
<script setup lang="ts">
import useEventBus from '~/composables/event-bus'
import { ref } from 'vue'
import { type PropType, ref } from 'vue'
const eventBus = useEventBus()
const processingProps = defineProps({
installedPlugins: { type: Object, required: true },
installedPlugins: { type: Object as PropType<Record<string, any>>, required: true },
isSmall: Boolean,
processings: { type: Array, required: true }
processings: { type: Array as PropType<Array<Record<string, any>>>, required: true }
})
const inCreate = ref(false)
const showCreateMenu = ref(false)
const newProcessing = ref({})
const plugins = ref([])
const newProcessing: Ref<Record<string, any>> = ref({})
const plugins: Ref<Array<string> | Array<never>> = ref([])
const search = ref('')
const selectedPlugins = ref([])
const selectedStatuses = ref([])
const statuses = ref([])
const statuses: Ref<Array<string> | Array<never>> = ref([])
const statusText = {
const statusText: Record<string, string> = {
error: 'En échec',
finished: 'Terminé',
kill: 'Interruption',
Expand All @@ -154,7 +154,7 @@ const statusText = {
function getProcessingStatus() {
if (!processingProps.processings) return statuses
const array = []
const array: Array<string> = []
for (const processing of processingProps.processings) {
if (processing.lastRun) {
const status = processing.lastRun.status
Expand All @@ -176,32 +176,32 @@ function getProcessingStatus() {
let includes = false
let index = 0
for (const element of array) {
if (element.includes(statusText['none'])) {
if (element.includes(statusText.none)) {
includes = true
index = array.indexOf(element)
break
}
}
if (includes) {
array[index] = `${statusText['none']} (${Number(array[index].split('(')[1].replace(')', '')) + 1})`
array[index] = `${statusText.none} (${Number(array[index].split('(')[1].replace(')', '')) + 1})`
} else {
array.push(`${statusText['none']} (1)`)
array.push(`${statusText.none} (1)`)
}
}
if (processing.nextRun) {
let includes = false
let index = 0
for (const element of array) {
if (element.includes(statusText['scheduled'])) {
if (element.includes(statusText.scheduled)) {
includes = true
index = array.indexOf(element)
break
}
}
if (includes) {
array[index] = `${statusText['scheduled']} (${Number(array[index].split('(')[1].replace(')', '')) + 1})`
array[index] = `${statusText.scheduled} (${Number(array[index].split('(')[1].replace(')', '')) + 1})`
} else {
array.push(`${statusText['scheduled']} (1)`)
array.push(`${statusText.scheduled} (1)`)
}
}
}
Expand All @@ -211,9 +211,9 @@ function getProcessingStatus() {
function getUsedPlugins() {
if (!processingProps.processings) return plugins
const /** @type {Array<String>} */ array = []
const array: Array<string> = []
for (const processing of processingProps.processings) {
const plugin = processingProps.installedPlugins.results.find(plugin => plugin.id === processing.plugin)
const plugin = processingProps.installedPlugins.results.find((plugin: Record<string, any>) => plugin.id === processing.plugin)
if (plugin) {
if (!array.includes(plugin.customName)) {
array.push(plugin.customName)
Expand All @@ -230,7 +230,7 @@ function getUsedPlugins() {
const createProcessing = async () => {
inCreate.value = true
const processing = await $fetch('/api/v1/processings', {
const processing: Record<string, any> = await $fetch('/api/v1/processings', {
method: 'POST',
body: JSON.stringify(newProcessing.value)
})
Expand Down
4 changes: 2 additions & 2 deletions ui/components/processing/ProcessingActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ const properties = defineProps({
// The iframe have by default a style="background: transparent;" that causes issues in dark mode
// Basically none of the text is visible and the background is pure white
// Each time the iframe loads, we remove the style attribute
const observer = new MutationObserver((mutationsList, observer) => {
const observer = new MutationObserver((mutationsList) => {
for (const mutation of mutationsList) {
if (mutation.type === 'childList') {
const vIframeDiv = document.querySelector('.v-iframe')
Expand Down Expand Up @@ -239,7 +239,7 @@ const triggerDelay = ref(0)
const webhookKey = ref(null)
const session = useSession()
const activeAccount = computed(() => session.state.account)
const /** @type {Record<String, any>} */ activeAccount = computed(() => session.state.account)
const notifUrl = computed(() => {
const topics = [
Expand Down
7 changes: 5 additions & 2 deletions ui/components/processing/ProcessingRuns.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ const props = defineProps({
const eventBus = useEventBus()
const loading = ref(false)
const runs = ref(null)
const /** @type {Ref<Record<String, any>|null>} */ runs = ref(null)
const wsChannel = computed(() => `processings/${props.processing._id}/run-patch`)
/**
* @param {Record<String, any>} runPatch
*/
function onRunPatch(runPatch) {
console.log('message from', wsChannel.value, runPatch)
if (!runs.value) return
const matchingRun = runs.value.results.find(run => run._id === runPatch._id)
const matchingRun = runs.value.results.find(/** @param {Record<String, any>} run */ run => run._id === runPatch._id)
if (!matchingRun) {
console.log('received info from WS about an unknown run, refresh list')
return refresh()
Expand Down
4 changes: 4 additions & 0 deletions ui/components/run/RunListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ const props = defineProps({
}
})
/**
* @param {String} start
* @param {String} end
*/
function duration(start, end) {
return dayjs.duration(dayjs(end).diff(dayjs(start))).humanize()
}
Expand Down
22 changes: 21 additions & 1 deletion ui/components/run/RunLogsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,31 @@
</template>

<script setup>
/**
* Defines a log entry in the logs array.
* @typedef {Object} LogEntry
* @property {string} date - The date of the log.
* @property {string} type - The type of the log.
* @property {Record<String, any>} msg - The message of the log.
* @property {number} progress - The progress of the log.
* @property {number} total - The total of the log.
* @property {string} progressDate - The progress date of the log.
*/
/**
* Defines props for the component.
* @typedef {Object} LogProps
* @property {LogEntry[]} logs - An array of log entries.
*/
/**
* @type {LogProps}
*/
defineProps({
logs: { type: Array, required: true }
})
const taskColor = (log) => {
const taskColor = (/** @type {Record<String, any>} */ log) => {
if (log.progress && log.progress === log.total) return 'success'
return 'primary'
}
Expand Down
2 changes: 1 addition & 1 deletion ui/composables/event-bus.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function useEventBus() {
function emit(event, ...args) {
const handlers = events.get(event)
if (handlers) {
handlers.forEach(handler => handler(...args))
handlers.forEach(/** @param {any} handler */ handler => handler(...args))
}
}

Expand Down
1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@nuxtjs/google-fonts": "^3.2.0",
"@nuxtjs/i18n": "^8.2.0",
"@pinia/nuxt": "^0.5.1",
"@types/pump": "^1.1.3",
"clean-modules": "^3.0.4",
"eslint-plugin-vuetify": "^2.1.1",
"iframe-resizer": "^4.3.9",
Expand Down
Loading

0 comments on commit bc1a377

Please sign in to comment.