Skip to content

Fix/1967 nutrition removal unclear #1978

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

Merged
merged 4 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
[#1971](https://github.com./nextcloud/cookbook/pull/1971) @seyfeb
- Fill prep, cook, and total time in `RecipeEdit` after loading
[#1973](https://github.com./nextcloud/cookbook/pull/1973) @seyfeb
- Remove unclear nutrition option for deleting nutrition info items and replace with designated delete button
[#1978](https://github.com./nextcloud/cookbook/pull/1978) @seyfeb

### Maintenance
- Add PHP lint checker to ensure valid (legacy) PHP syntax
Expand Down
7 changes: 5 additions & 2 deletions src/components/AppControls/AppControls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,18 @@
<NcActionInput
icon="icon-quota"
:value="filterValue"
aria-label="Filter current recipes"
:aria-label="t('cookbook', 'Filter current recipes')"
@update:value="updateFilters"
>
<template #icon>
<FilterIcon :size="20" />
</template>
{{ t('cookbook', 'Filter') }}
</NcActionInput>
<NcActionInput aria-label="Search recipes" @submit="search">
<NcActionInput
aria-label="t('cookbook', 'Search recipes')"
@submit="search"
>
<template #icon>
<SearchIcon :size="20" />
</template>
Expand Down
57 changes: 34 additions & 23 deletions src/components/FormComponents/EditMultiselectInputGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
class="val"
@change="updateByText($event, index)"
/>
<NcButton
class="ml-2"
:aria-label="t('cookbook', 'Delete nutrition item')"
@click="deleteEntry(index)"
>
<template #icon>
<DeleteIcon :size="20" />
</template>
</NcButton>
</li>
<li v-if="showAdditionalRow">
<NcSelect
Expand All @@ -42,9 +51,12 @@
</template>

<script setup>
import NcSelect from '@nextcloud/vue/dist/Components/NcSelect.js';
import { ref, defineProps, defineEmits, computed } from 'vue';

import NcButton from '@nextcloud/vue/dist/Components/NcButton.js';
import NcSelect from '@nextcloud/vue/dist/Components/NcSelect.js';
import DeleteIcon from 'vue-material-design-icons/Delete.vue';

const emits = defineEmits(['input']);

const props = defineProps({
Expand Down Expand Up @@ -114,27 +126,27 @@ const unusedOptions = computed(() =>
// Create a list of lists of available options for the individual rows (just the internal keys)
// This will be a list. Each (top) list entry represents the internal keys of the available options for the corresponding row.
// Note that each row can set the option to any yet unused option or the currently selected one.
const availabeOptionKeys = computed(() =>
const availableOptionKeys = computed(() =>
valueFilteredKeys.value.map((x) => [...unusedOptionKeys.value, x]),
);

// This is mainly the same as the availabelOptionKeys but uses full objects and sorts these according to the input property
const availableOptionsPure = computed(() =>
availabeOptionKeys.value.map((x) =>
// This is mainly the same as the availableOptionKeys but uses full objects and sorts these according to the input property
const availableOptions = computed(() =>
availableOptionKeys.value.map((x) =>
props.options.filter((y) => x.includes(y.key)),
),
);

// The actual available options per row are augmented by an option to remove a row.
const availableOptions = computed(() =>
availableOptionsPure.value.map((x) => [
{
key: null,
label: '---',
},
...x,
]),
);
/**
* Delete a nutrition item.
* @param index The index of the item to delete in the `value` property.
*/
function deleteEntry(index) {
const data = { ...props.value };
const { key } = rowsFromValue.value[index].selectedOption;
delete data[key];
emits('input', data);
}

// Add a new row to the model
function newRowByOption(ev) {
Expand All @@ -154,14 +166,9 @@ function updateByText(ev, idx) {
function updateByOption(ev, index) {
const data = { ...props.value };
const { key } = rowsFromValue.value[index].selectedOption;
if (ev.key === null) {
delete data[key];
emits('input', data);
} else {
data[ev.key] = data[key];
delete data[key];
emits('input', data);
}
data[ev.key] = data[key];
delete data[key];
emits('input', data);
}
</script>

Expand All @@ -172,6 +179,10 @@ export default {
</script>

<style scoped>
.ml-2 {
margin-left: 0.5rem;
}

fieldset {
width: 100%;
margin-bottom: 1em;
Expand Down
2 changes: 1 addition & 1 deletion src/components/RecipeView/RecipeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
v-if="scaledIngredients.length"
class="copy-ingredients print-hidden"
:type="'tertiary'"
aria-label="Copy all ingredients to the clipboard"
aria-label="t('cookbook', 'Copy ingredients to the clipboard')"
:title="t('cookbook', 'Copy ingredients')"
@click="copyIngredientsToClipboard"
>
Expand Down