Skip to content

Commit 3ab80f8

Browse files
authored
Merge pull request #2143 from MetRonnie/tidy
2 parents cd8c7bf + 5371b06 commit 3ab80f8

File tree

10 files changed

+101
-108
lines changed

10 files changed

+101
-108
lines changed

src/components/cylc/Drawer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
3838
<v-list-item-title>Dashboard</v-list-item-title>
3939
</v-list-item>
4040

41-
<v-divider class="" />
41+
<v-divider/>
4242

4343
<v-list-item>
4444
<v-list-item-title>Workflows</v-list-item-title>

src/components/cylc/Header.vue

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
<template>
1919
<div class="c-header d-flex flex-column align-center pt-3 pb-5">
2020
<div class="mb-2 px-6">
21-
<svg version="1.1" preserveAspectRatio="xMinYMin meet" width="100%" height="100%" viewBox="0 0 655 260" xmlns="http://www.w3.org/2000/svg">
22-
<g transform="translate(292.53,-49.505)">
23-
<g>
24-
<g>
25-
<g>
26-
<circle r="27.743086" cy="248.39331" cx="-135.70163" transform="scale(-1,1)" style="fill:#ff5966;fill-opacity:1;stroke:none;stroke-width:1.29467726;stroke-opacity:1"/>
27-
<circle r="72.85714" cy="216.6479" cx="201.04846" style="fill:#0dc66e;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-opacity:1"/>
28-
<circle r="37.37936" cy="136.32114" cx="167.3486" style="fill:#ffcc00;fill-opacity:1;stroke:none;stroke-width:1.18934333;stroke-opacity:1"/>
29-
<circle r="49.79998" cy="121.63028" cx="292.31558" style="fill:#00b4fd;fill-opacity:1;stroke:none;stroke-width:0.91736811;stroke-opacity:1"/>
30-
<path d="m -239.15268,150.44225 q 5.28,0 17.92,1.92 l 3.84,0.48 -0.48,9.76 q -12.8,-1.44 -18.88,-1.44 -13.6,0 -18.56,6.56 -4.8,6.4 -4.8,24 0,17.44 4.48,24.32 4.64,6.88 19.04,6.88 l 18.88,-1.44 0.48,9.92 q -14.88,2.24 -22.24,2.24 -18.72,0 -25.92,-9.6 -7.04,-9.6 -7.04,-32.32 0,-22.88 7.68,-32 7.68,-9.28 25.6,-9.28 z" style="fill:#ff5966;fill-opacity:1;stroke:none"/>
31-
<path d="m -175.59268,152.04225 h 12 l 20,69.6 h 5.28 l 20.16,-69.6 h 12 l -33.28,115.52 h -12 l 10.4,-35.52 h -11.84 z" style="fill:#ffcc00;fill-opacity:1;stroke:none"/>
32-
<path d="m -58.612682,232.04225 v -114.88 h 12 v 114.88 z" style="fill:#0dc66e;fill-opacity:1;stroke:none"/>
33-
<path d="m 34.534818,150.44225 q 5.28,0 17.92,1.92 l 3.84,0.48 -0.48,9.76 q -12.8,-1.44 -18.88,-1.44 -13.6,0 -18.56,6.56 -4.8,6.4 -4.8,24 0,17.44 4.48,24.32 4.64,6.88 19.04,6.88 l 18.88,-1.44 0.48,9.92 q -14.88,2.24 -22.24,2.24 -18.72,0 -25.9199999,-9.6 -7.04,-9.6 -7.04,-32.32 0,-22.88 7.68,-32 7.6799999,-9.28 25.5999999,-9.28 z" style="fill:#00b4fd;fill-opacity:1;stroke:none"/>
34-
</g>
35-
</g>
36-
</g>
37-
</g>
38-
</svg>
21+
<img src="/img/logo.svg" style="max-width: 100%; width: 300px"/>
3922
</div>
4023
<div
4124
id="cylc-select-options"

src/components/cylc/TaskFilter.vue

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2828
data-cy="filter-id"
2929
clearable
3030
placeholder="Filter by ID"
31-
v-model="localValue.id"
31+
v-model="model.id"
3232
ref="filterIDInput"
3333
/>
3434
</v-col>
@@ -38,45 +38,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
3838
class="mb-2 mb-md-0"
3939
>
4040
<TaskFilterSelect
41-
v-model="localValue.states"
41+
v-model="model.states"
4242
type="task state"
43-
:items="$options.allStates"
43+
:items="TaskStateNames"
4444
data-cy="filter task state"
4545
placeholder="Filter by task state"
4646
/>
4747
</v-col>
4848
</v-row>
4949
</template>
5050

51-
<script>
51+
<script setup>
5252
import { TaskStateNames } from '@/model/TaskState.model'
5353
import TaskFilterSelect from '@/components/cylc/TaskFilterSelect.vue'
5454
55-
export default {
56-
name: 'TaskFilter',
55+
/** @type {import('vue').Ref<{ id: string?, states: string[]? }>} */
56+
const model = defineModel({
57+
type: Object,
58+
required: true,
59+
})
5760
58-
components: {
59-
TaskFilterSelect
60-
},
61-
62-
props: {
63-
modelValue: {
64-
type: Object,
65-
required: true
66-
} // { id, states }
67-
},
68-
69-
computed: {
70-
localValue: {
71-
get () {
72-
return this.modelValue
73-
},
74-
set (value) {
75-
// Update 'modelValue' prop by notifying parent component's v-model for this component
76-
this.$emit('update:modelValue', value)
77-
}
78-
}
79-
},
80-
allStates: TaskStateNames,
81-
}
8261
</script>

src/components/cylc/TaskFilterSelect.vue

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
:items="items"
44
clearable
55
multiple
6-
v-model="localValue"
6+
v-model="model"
77
>
88
<template #prepend-item>
9-
<v-list-item
10-
@click="selectAll"
11-
>
12-
Select All
13-
</v-list-item>
9+
<v-select-actions>
10+
<v-btn
11+
@click="selectAll()"
12+
data-cy="task-filter-select-all"
13+
>
14+
Select All
15+
</v-btn>
16+
</v-select-actions>
17+
<v-divider/>
1418
</template>
1519

1620
<template #item="{ item, props }">
@@ -33,7 +37,7 @@
3337
<v-chip
3438
v-if="index < maxVisibleStates"
3539
closable
36-
@click:close="removeItem(item.raw)"
40+
@click:close="removeItem(index)"
3741
size="small"
3842
:close-icon="mdiClose"
3943
>
@@ -55,24 +59,18 @@
5559
v-if="index === maxVisibleStates"
5660
class="text-grey text-caption"
5761
>
58-
(+{{ localValue.length - maxVisibleStates }})
62+
(+{{ model.length - maxVisibleStates }})
5963
</span>
6064
</template>
6165
</v-select>
6266
</template>
6367

6468
<script setup>
65-
import { computed } from 'vue'
6669
import { mdiClose } from '@mdi/js'
6770
import Task from '@/components/cylc/Task.vue'
6871
import Workflowicon from '@/components/cylc/gscan/WorkflowIcon.vue'
6972
7073
const props = defineProps({
71-
/** Array of selected states */
72-
modelValue: {
73-
type: Array,
74-
default: () => [],
75-
},
7674
items: {
7775
type: Array,
7876
required: true,
@@ -83,24 +81,16 @@ const props = defineProps({
8381
},
8482
})
8583
86-
const emit = defineEmits(['update:modelValue'])
87-
88-
const localValue = computed({
89-
get () {
90-
return props.modelValue
91-
},
92-
set (val) {
93-
emit('update:modelValue', val)
94-
}
95-
})
84+
/** Array of selected states */
85+
const model = defineModel({ type: Array })
9686
9787
const maxVisibleStates = 4
9888
99-
function removeItem (key) {
100-
localValue.value = localValue.value.filter(item => item !== key)
89+
function removeItem (index) {
90+
model.value.splice(index, 1)
10191
}
10292
10393
function selectAll () {
104-
localValue.value = props.items
94+
model.value = props.items
10595
}
10696
</script>

src/components/cylc/analysis/TimeSeries.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
3333
ref="selectTasks"
3434
>
3535
<template v-slot:prepend-item>
36-
<v-card-actions class="mt-n2">
36+
<v-select-actions>
3737
<v-btn @click="selectSearchResults">
3838
Select all
3939
</v-btn>
4040
<v-btn @click="deselectSearchResults">
4141
Deselect all
4242
</v-btn>
43-
</v-card-actions>
43+
</v-select-actions>
4444
<v-divider/>
4545
</template>
4646
</v-autocomplete>

src/components/cylc/common/sort.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,26 @@ export const DEFAULT_COMPARATOR = (left, right) => {
7070
* @param {Object[]} array - list of string values, or of objects with string values
7171
* @param {Object} value - a value to be inserted in the list, or an object wrapping the value (see iteratee)
7272
* @param {SortedIndexByIteratee=} iteratee - an optional function used to return the value of the element of the list}
73-
* @param {SortedIndexByComparator=} comparator - function used to compare the newValue with otherValues in the list
73+
* @param {{comparator: SortedIndexByComparator, reverse: boolean}=} options - an optional object with a comparator function and a reverse flag
7474
* @return {number} - sorted index
7575
*/
76-
export function sortedIndexBy (array, value, iteratee, options = {}) {
77-
// comparator, reverse = false) {
76+
export function sortedIndexBy (array, value, iteratee = (x) => x, options = {}) {
7877
if (array.length === 0) {
7978
return 0
8079
}
81-
// If given a function, use it. Otherwise, simply use identity function.
82-
const iterateeFunction = iteratee || ((value) => value)
8380
// If given a function, use it. Otherwise, simply use locale sort with numeric enabled
84-
const comparatorFunction = options.comparator || ((leftObject, leftValue, rightObject, rightValue) => DEFAULT_COMPARATOR(leftValue, rightValue))
81+
const comparator = options.comparator || (
82+
(leftObject, leftValue, rightObject, rightValue) => DEFAULT_COMPARATOR(leftValue, rightValue)
83+
)
8584
let low = 0
8685
let high = array.length
8786

88-
const newValue = iterateeFunction(value)
87+
const newValue = iteratee(value)
8988

9089
while (low < high) {
9190
const mid = Math.floor((low + high) / 2)
92-
const midValue = iterateeFunction(array[mid])
93-
let higher = comparatorFunction(value, newValue, array[mid], midValue)
91+
const midValue = iteratee(array[mid])
92+
let higher = comparator(value, newValue, array[mid], midValue)
9493
if (options.reverse) {
9594
higher = higher * -1
9695
}

src/plugins/vuetify.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { VCombobox } from 'vuetify/components/VCombobox'
2222
import { VSelect } from 'vuetify/components/VSelect'
2323
import { VTextarea } from 'vuetify/components/VTextarea'
2424
import { VTextField } from 'vuetify/components/VTextField'
25+
import { VCardActions } from 'vuetify/components/VCard'
2526
import colors from 'vuetify/util/colors'
2627
import { mdiClose } from '@mdi/js'
2728
import { useReducedAnimation } from '@/composables/localStorage'
@@ -75,11 +76,20 @@ export const vuetifyOptions = {
7576
mdi
7677
}
7778
},
79+
aliases: {
80+
VSelectActions: VCardActions,
81+
},
7882
defaults: {
7983
VTooltip: {
8084
activator: 'parent',
8185
location: 'bottom',
8286
},
87+
VList: {
88+
slim: true,
89+
},
90+
VSelectActions: {
91+
class: 'mt-n2'
92+
},
8393
...inputDefaults
8494
},
8595
}

src/store/workflows.module.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ function getIndex (state, id) {
124124
return state.cylcTree.$index[id]
125125
}
126126

127-
/* Add a child node under a parent Node */
127+
/** Add a child node under a parent Node */
128128
function addChild (parentNode, childNode) {
129129
// determine which list to add this node to
130130
// console.log(`$t ++ ${childNode.id}`)
@@ -144,20 +144,12 @@ function addChild (parentNode, childNode) {
144144
}
145145

146146
// insert the child preserving sort order
147-
let comparator
148-
if (['cycle', 'family'].includes(parentNode.type)) {
149-
// sort by type, then name
150-
// (this makes families sort before tasks in the graph)
151-
comparator = (n) => `${n.type}-${n.name}`
152-
} else {
153-
// sort by name
154-
comparator = (n) => n.name
155-
}
147+
const iteratee = (n) => `${n.type}-${n.name}` // (this makes families sort before tasks in the tree)
156148
const reverse = ['cycle', 'job'].includes(childNode.type)
157149
const index = sortedIndexBy(
158150
parentNode[key],
159151
childNode,
160-
comparator,
152+
iteratee,
161153
{ reverse }
162154
)
163155
parentNode[key].splice(index, 0, childNode)

tests/e2e/specs/tree.cy.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -267,18 +267,14 @@ describe('Tree view', () => {
267267

268268
it('Provides a select all functionality', () => {
269269
cy.visit('/#/tree/one')
270-
cy
271-
.get('[data-cy="filter task state"]')
270+
cy.get('[data-cy="filter task state"]')
272271
.get('.v-list-item--active')
273272
.should('have.length', 0)
274-
cy
275-
.get('[data-cy="filter task state"]')
273+
cy.get('[data-cy="filter task state"]')
276274
.click()
277-
.get('.v-list-item')
278-
.contains('Select All')
279-
.click({ force: true })
280-
cy
281-
.get('[data-cy="filter task state"]')
275+
.get('[data-cy=task-filter-select-all]')
276+
.click()
277+
cy.get('[data-cy="filter task state"]')
282278
.get('.v-list-item--active')
283279
.should('have.length', 8)
284280
})

tests/unit/components/cylc/common/sort.spec.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18-
import { DEFAULT_COMPARATOR } from '@/components/cylc/common/sort'
18+
import { DEFAULT_COMPARATOR, sortedIndexBy } from '@/components/cylc/common/sort'
1919

2020
describe('DEFAULT_COMPARATOR', () => {
2121
it.each([
@@ -31,3 +31,47 @@ describe('DEFAULT_COMPARATOR', () => {
3131
expect(DEFAULT_COMPARATOR(a, b)).toEqual(expected)
3232
})
3333
})
34+
35+
describe('sortedIndexBy', () => {
36+
it.each([
37+
[['a', 'c', 'e'], 'a', 0],
38+
[['a', 'c', 'e'], 'b', 1],
39+
[['a', 'c', 'e'], 'c', 1],
40+
[['a', 'c', 'e'], 'd', 2],
41+
[['a', 'c', 'e'], 'x', 3],
42+
[[], 'x', 0],
43+
])('sortedIndexBy(%o, %o) -> %i', (arr, value, expected) => {
44+
expect(sortedIndexBy(arr, value)).toEqual(expected)
45+
})
46+
47+
it('uses the iteratee function to determine the value for comparison', () => {
48+
const arr = [{ key: 'a' }, { key: 'c' }, { key: 'e' }]
49+
const value = { key: 'b' }
50+
const iteratee = (x) => x.key
51+
expect(sortedIndexBy(arr, value, iteratee)).toEqual(1)
52+
})
53+
54+
it.each([
55+
[[8], 0],
56+
[[8, 8], 0],
57+
[[8, 8, 8], 3],
58+
])('%#) uses a custom comparator if provided', (value, expected) => {
59+
const arr = [[8, 8], [8, 8], [8, 8]]
60+
const comparator = (leftObj, leftVal, rightObj, rightVal) => (
61+
leftObj.length - rightObj.length
62+
)
63+
expect(sortedIndexBy(arr, value, (x) => x, { comparator })).toEqual(expected)
64+
})
65+
66+
it('reverses the comparison if reverse option is true', () => {
67+
const arr = ['e', 'c', 'a']
68+
const value = 'd'
69+
expect(sortedIndexBy(arr, value, (x) => x, { reverse: true })).toEqual(1)
70+
})
71+
72+
it('handles numeric collation correctly by default', () => {
73+
const arr = ['1', '2']
74+
const value = '10'
75+
expect(sortedIndexBy(arr, value)).toEqual(2)
76+
})
77+
})

0 commit comments

Comments
 (0)