1
1
<script setup lang="ts">
2
- import { TeamRole , type Variable } from ' @types'
2
+ import type { Variable } from ' @types'
3
3
4
4
const route = useRoute ()
5
5
const projectId = route .params .projectId as string
@@ -10,6 +10,7 @@ const { loading, fetchVariables } = useVariablesService()
10
10
if (! variables .value ) fetchVariables ()
11
11
12
12
const selectedVariables = ref <Variable []>([])
13
+ const lastSelectedIndex = ref <number | null >(null )
13
14
const searchTerm = ref (' ' )
14
15
const selectedEnvironment = ref ([])
15
16
const order = ref (' desc' )
@@ -50,11 +51,25 @@ const filteredVariables = computed(() => {
50
51
return filtered
51
52
})
52
53
53
- const toggleVariable = (variable : Variable ) => {
54
- if (! isVariableSelected (variable )) {
55
- selectedVariables .value .push (variable )
54
+ const toggleVariable = (variable : Variable , event ? : MouseEvent ) => {
55
+ const filteredIndex = filteredVariables .value .findIndex (v => v .id === variable .id )
56
+
57
+ if (event ?.shiftKey && lastSelectedIndex .value !== null ) {
58
+ const startIndex = Math .min (lastSelectedIndex .value , filteredIndex )
59
+ const endIndex = Math .max (lastSelectedIndex .value , filteredIndex )
60
+ const newSelection = filteredVariables .value .slice (startIndex , endIndex + 1 )
61
+ selectedVariables .value = Array .from (
62
+ new Map (
63
+ [... selectedVariables .value , ... newSelection ].map (item => [item .id , item ])
64
+ ).values ()
65
+ )
56
66
} else {
57
- selectedVariables .value = selectedVariables .value .filter ((v ) => v .id !== variable .id )
67
+ if (! isVariableSelected (variable )) {
68
+ selectedVariables .value .push (variable )
69
+ } else {
70
+ selectedVariables .value = selectedVariables .value .filter ((v ) => v .id !== variable .id )
71
+ }
72
+ lastSelectedIndex .value = filteredIndex
58
73
}
59
74
}
60
75
@@ -70,6 +85,7 @@ const isVariableSelected = (variable: Variable) => {
70
85
<UInput
71
86
v-model =" searchTerm"
72
87
placeholder =" Search variables..."
88
+ icon =" lucide:search"
73
89
class =" w-1/3"
74
90
/>
75
91
<div class =" flex gap-1" >
@@ -84,14 +100,14 @@ const isVariableSelected = (variable: Variable) => {
84
100
<USelectMenu v-model =" selectedEnvironment" multiple :items class =" w-full" placeholder =" Select environment" />
85
101
</div >
86
102
</div >
87
- <LazyVariableSelector v-model =" selectedVariables" />
103
+ <LazyVariableSelector v-model =" selectedVariables" :variables = " filteredVariables " />
88
104
<div v-if =" !loading" class =" flex flex-col gap-4" >
89
105
<div v-for =" variable in filteredVariables" :key =" variable.id" >
90
106
<VariableItem
91
107
:variable
92
108
:environments
93
109
:is-selected =" isVariableSelected(variable)"
94
- @toggle-selected =" toggleVariable(variable)"
110
+ @toggle-selected =" (e) => toggleVariable(variable, e )"
95
111
/>
96
112
</div >
97
113
</div >
0 commit comments