Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to store & remove server owner & deployment entries in dropdowns #1503

54 changes: 24 additions & 30 deletions src/components/cylc/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
>
<template v-slot:item="{ item, props }">
<!-- HTML that describe how select should render items when the select is open -->
<div class="d-flex">
<v-list-item
class="flex-grow-1"
:title="item.title"
v-bind="props"
>
<template v-slot:append v-if="item.title !== ownerOnLoad">
<v-icon
@click.stop="removeOwner(item.title)"
color="pink-accent-4"
:icon="mdiClose"
/>
</template>
</v-list-item>
</div>
<v-list-item
:title="item.title"
v-bind="props"
>
<template v-slot:append v-if="item.title !== ownerOnLoad">
<v-icon
@click.stop="removeOwner(item.title)"
color="pink-accent-4"
:icon="mdiClose"
/>
</template>
</v-list-item>
</template>
</v-combobox>
<!-- Deployment combobox -->
Expand All @@ -90,21 +87,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
>
<template v-slot:item="{ item, props }">
<!-- HTML that describe how select should render items when the select is open -->
<div class="d-flex">
<v-list-item
class="flex-grow-1"
:title="item.title"
v-bind="props"
>
<template v-slot:append v-if="item.title !== deploymentOnLoad">
<v-icon
@click.stop="removeDeployment(item.title)"
color="pink-accent-4"
:icon="mdiClose"
/>
</template>
</v-list-item>
</div>
<v-list-item
:title="item.title"
v-bind="props"
>
<template v-slot:append v-if="item.title !== deploymentOnLoad">
<v-icon
@click.stop="removeDeployment(item.title)"
color="pink-accent-4"
:icon="mdiClose"
/>
</template>
</v-list-item>
</template>
</v-combobox>
<v-btn
Expand Down
13 changes: 13 additions & 0 deletions src/composables/useLocalStorage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import { ref } from 'vue'

/**
* Function for initialising, adding to and removing from local storage.
* Values are stored in arrays with and can be accessed
* via a key which specified by the 'key' parameter.
* The local storage array is initialized with a value
* specified by the 'initialValue' parameter.
* Note: this could be replaced by a VueUse composable in the future
* https://vueuse.org/core/useLocalStorage/
*
* @param {string} key
* @param {*} initialValue
* @returns {function}
MetRonnie marked this conversation as resolved.
Show resolved Hide resolved
*/
export default function useLocalStorage (key, initialValue) {
markgrahamdawson marked this conversation as resolved.
Show resolved Hide resolved
const itemOnLoad = initialValue
const item = ref(itemOnLoad)
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/composables/useLocalStorage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ describe('useLocalStorage composable', () => {
expect(Array.from(items.value)).toStrictEqual(['test initial item', 'test item'])
})

it('should not add more than one of the same value to the local store', () => {
addToLocalStorage('test item')
expect(Array.from(items.value)).toStrictEqual(['test initial item', 'test item'])
})

it('should remove a value to the local store', () => {
removeFromLocalStorage('test item')
expect(Array.from(items.value)).toStrictEqual(['test initial item'])
Expand Down