Skip to content

Commit dbc3003

Browse files
committed
Convert some files to TypeScript
1 parent e441282 commit dbc3003

File tree

18 files changed

+90
-84
lines changed

18 files changed

+90
-84
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
}
@@ -44,11 +44,6 @@ export const DEFAULT_COMPARATOR = (left: string, right: string): number => {
4444
)
4545
}
4646

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

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)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function gscanWorkflowCompValue (node) {
7070
* Sorts according to getWorkflowTreeSortValue.
7171
*/
7272
export function sortedWorkflowTree (cylcTree) {
73-
const tree = []
73+
const tree: any[] = []
7474
for (let node of cylcTree.children[0].children) {
7575
node = flattenWorkflowParts(node)
7676
if (node) {

src/components/cylc/workspace/Lumino.vue

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

src/components/cylc/workspace/Toolbar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ export default {
285285
/**
286286
* All possible view component classes that can be rendered
287287
*
288-
* @type {Map<string, import('@/views/views.js').CylcView>}
288+
* @type {Map<string, import('@/views/views').CylcView>}
289289
*/
290290
views: {
291291
type: Map,
File renamed without changes.

0 commit comments

Comments
 (0)