-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move GShootListRowActions from GShootListRow to GShootList component (#…
…2148) * Move GShootListRowActions from GShootListRow to GShootList component * Use shared composable instead of event propagation to distribute state (#2155) * Uniform handling of action and menu events on ShootList * fixed lint errors * Added License * Improved `useShootAction` composable * License header format * Do not unset shootItem when menu closes * Update frontend/src/components/GShootListActions.vue Co-authored-by: Peter Sutter <[email protected]> --------- Co-authored-by: Peter Sutter <[email protected]> * Update frontend/src/views/GShootList.vue Co-authored-by: Peter Sutter <[email protected]> --------- Co-authored-by: Holger Koser <[email protected]> Co-authored-by: Peter Sutter <[email protected]>
- Loading branch information
1 parent
218d7ea
commit ec8b341
Showing
4 changed files
with
141 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// | ||
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import { | ||
reactive, | ||
computed, | ||
toRef, | ||
inject, | ||
provide, | ||
} from 'vue' | ||
|
||
import { useShootStore } from '@/store/shoot' | ||
|
||
import { get } from '@/lodash' | ||
|
||
export function createShootActionEventComposable (options = {}) { | ||
const { | ||
shootStore = useShootStore(), | ||
} = options | ||
|
||
const state = reactive({ | ||
name: '', | ||
target: null, | ||
}) | ||
|
||
const shootActionItem = toRef(shootStore, 'selectedShoot') | ||
const shootActionTarget = computed(() => state.target) | ||
|
||
function setShootAction (name, shootItem, target = null) { | ||
const metadata = get(shootItem, ['metadata'], null) | ||
shootStore.setSelection(metadata) | ||
state.name = name | ||
state.target = target | ||
} | ||
|
||
function unsetShootAction () { | ||
setShootAction('', null, null) | ||
} | ||
|
||
function createShootActionFlag (name) { | ||
return computed({ | ||
get () { | ||
return state.name === name | ||
}, | ||
set (value) { | ||
if (!value) { | ||
state.name = '' | ||
} | ||
}, | ||
}) | ||
} | ||
|
||
return { | ||
shootActionItem, | ||
shootActionTarget, | ||
setShootAction, | ||
unsetShootAction, | ||
createShootActionFlag, | ||
} | ||
} | ||
|
||
export function useShootAction () { | ||
return inject('shoot-action-event', null) | ||
} | ||
|
||
export function useProvideShootAction (options) { | ||
const composable = createShootActionEventComposable(options) | ||
provide('shoot-action-event', composable) | ||
return composable | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters