Skip to content

Commit 9d6c702

Browse files
committed
Convert some files to TypeScript
1 parent a214758 commit 9d6c702

File tree

19 files changed

+93
-88
lines changed

19 files changed

+93
-88
lines changed

src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2525
</v-defaults-provider>
2626
</template>
2727

28-
<script setup>
28+
<script setup lang="ts">
2929
import { computed, onMounted } from 'vue'
3030
import { useRoute } from 'vue-router'
3131
import { useJobTheme, useReducedAnimation } from '@/composables/localStorage'

src/components/core/Alert.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
3838
</v-snackbar>
3939
</template>
4040

41-
<script>
41+
<script lang="ts">
42+
import { defineComponent } from 'vue'
4243
import { mdiClose } from '@mdi/js'
4344
import { mapActions, mapState } from 'vuex'
4445
45-
export default {
46+
export default defineComponent({
4647
name: 'Alert',
4748
4849
computed: {
@@ -62,5 +63,5 @@ export default {
6263
icons: {
6364
mdiClose
6465
}
65-
}
66+
})
6667
</script>

src/components/cylc/common/filter.js renamed to src/components/cylc/common/filter.ts

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,35 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18+
import { type Tokens } from '@/utils/uid'
19+
1820
/* Logic for filtering tasks. */
1921

22+
interface Node {
23+
node: {
24+
state: string
25+
}
26+
tokens: Tokens
27+
}
28+
2029
/**
2130
* Return true if the node ID matches the given ID, or if no ID is given.
22-
*
23-
* @param {Object} node
24-
* @param {?string} id
25-
* @return {boolean}
2631
*/
27-
export function matchID (node, id) {
28-
return !id?.trim() || node.tokens.relativeID.includes(id)
32+
export function matchID (node: Node, id?: string): boolean {
33+
return !id?.trim() || node.tokens.relativeID!.includes(id)
2934
}
3035

3136
/**
3237
* Return true if the given list of states includes the node state, or if
3338
* if the list is empty.
34-
*
35-
* @param {Object} node
36-
* @param {?string[]} states
37-
* @returns {boolean}
3839
*/
39-
export function matchState (node, states) {
40+
export function matchState (node: Node, states?: string[]): boolean {
4041
return !states?.length || states.includes(node.node.state)
4142
}
4243

4344
/**
4445
* Return true if a node matches the specified id/state filter.
45-
*
46-
* @export
47-
* @param {Object} node
48-
* @param {?string} id
49-
* @param {?string[]} states
50-
* @return {boolean}
5146
*/
52-
export function matchNode (node, id, states) {
47+
export function matchNode (node: Node, id?: string, states?: string[]): boolean {
5348
return matchID(node, id) && matchState(node, states)
5449
}

src/components/cylc/common/sort.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type Obj = string | Record<string, string>
2424
*/
2525
type SortedIndexByComparator = (leftObject: Obj, leftValue: string, rightObject: Obj, rightValue: string) => number
2626

27-
type SortedIndexOptions = {
27+
interface SortedIndexOptions {
2828
comparator?: SortedIndexByComparator
2929
reverse?: boolean
3030
}
@@ -45,11 +45,6 @@ export const DEFAULT_COMPARATOR = (left: string, right: string): number => {
4545
)
4646
}
4747

48-
/**
49-
* Declare function used in sortedIndexBy for creating the iteratee.
50-
*/
51-
type SortedIndexByIteratee = (value: string | Record<string, string>) => string
52-
5348
/**
5449
* Given a list of elements, and a value to be added to the list, we
5550
* perform a simple binary search of the list to determine the next
@@ -69,12 +64,19 @@ type SortedIndexByIteratee = (value: string | Record<string, string>) => string
6964
* @param comparator - function used to compare the newValue with otherValues in the list
7065
* @return sorted index
7166
*/
72-
export function sortedIndexBy (array: Obj[], value: Obj, iteratee: SortedIndexByIteratee, options: SortedIndexOptions = {}): number {
67+
export function sortedIndexBy (
68+
array: Obj[],
69+
value: Obj,
70+
iteratee: (value: Obj) => string,
71+
options: SortedIndexOptions = {}
72+
): number {
7373
if (array.length === 0) {
7474
return 0
7575
}
7676
// If given a function, use it. Otherwise, simply use locale sort with numeric enabled
77-
const comparatorFunction = options.comparator || ((leftObject, leftValue, rightObject, rightValue) => DEFAULT_COMPARATOR(leftValue, rightValue))
77+
const comparatorFunction: SortedIndexByComparator = options.comparator || (
78+
(leftObject, leftValue, rightObject, rightValue) => DEFAULT_COMPARATOR(leftValue, rightValue)
79+
)
7880
let low = 0
7981
let high = array.length
8082

src/components/cylc/gscan/GScan.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ import { TaskStateNames } from '@/model/TaskState.model'
121121
import { WorkflowStateNames } from '@/model/WorkflowState.model'
122122
import Tree from '@/components/cylc/tree/Tree.vue'
123123
import { filterByName, filterByState } from '@/components/cylc/gscan/filters'
124-
import { sortedWorkflowTree } from '@/components/cylc/gscan/sort.js'
124+
import { sortedWorkflowTree } from '@/components/cylc/gscan/sort'
125125
import { mutate } from '@/utils/aotf'
126126
import TaskFilterSelect from '@/components/cylc/TaskFilterSelect.vue'
127127

src/components/cylc/gscan/filters.js renamed to src/components/cylc/gscan/filters.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,35 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18-
/**
19-
* @param {WorkflowGScanNode|WorkflowNamePartGScanNode} workflow
20-
* @param {?string} name - name filter
21-
* @returns {boolean}
22-
*/
23-
export function filterByName (workflow, name) {
18+
import { type Tokens } from '@/utils/uid'
19+
20+
interface WorkflowNode {
21+
node: {
22+
status: string
23+
stateTotals: Record<string, number>
24+
}
25+
tokens: Tokens
26+
}
27+
28+
export function filterByName (workflow: WorkflowNode, name: string): boolean {
2429
return !name || workflow.tokens.workflow.toLowerCase().includes(name.toLowerCase())
2530
}
2631

2732
/**
2833
* @private
29-
* @param {Object=} stateTotals - object with the keys being states, and values the count
30-
* @return {string[]}
34+
* @param stateTotals - object with the keys being states, and values the count
3135
*/
32-
function getWorkflowStates (stateTotals) {
36+
function getWorkflowStates (stateTotals: Record<string, number>): string[] {
3337
return !stateTotals
3438
? []
3539
: Object.keys(stateTotals).filter((state) => stateTotals[state] > 0)
3640
}
3741

38-
/**
39-
* @param {WorkflowGScanNode|WorkflowNamePartGScanNode} workflow
40-
* @param {string[]} workflowStates
41-
* @param {string[]} taskStates
42-
* @returns {boolean}
43-
*/
44-
export function filterByState (workflow, workflowStates, taskStates) {
42+
export function filterByState (
43+
workflow: WorkflowNode,
44+
workflowStates: string[],
45+
taskStates: string[]
46+
): boolean {
4547
// workflow states
4648
if (
4749
workflowStates.length && !workflowStates.includes(workflow.node.status)
File renamed without changes.

src/components/cylc/workflow/Lumino.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const props = defineProps({
7676
/**
7777
* All possible view component classes that can be rendered
7878
*
79-
* @type {Map<string, import('@/views/views.js').CylcView>}
79+
* @type {Map<string, import('@/views/views').CylcView>}
8080
*/
8181
allViews: {
8282
type: Map,

src/components/cylc/workflow/Toolbar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ export default {
279279
/**
280280
* All possible view component classes that can be rendered
281281
*
282-
* @type {Map<string, import('@/views/views.js').CylcView>}
282+
* @type {Map<string, import('@/views/views').CylcView>}
283283
*/
284284
views: {
285285
type: Map,
File renamed without changes.

0 commit comments

Comments
 (0)