Skip to content

Commit

Permalink
Merge pull request #17018 from hujambo-dunia/enhance-tool-form
Browse files Browse the repository at this point in the history
Enhancement to Tool Form page, Repeating form fields implement parameter instructions
  • Loading branch information
ElectronicBlueberry authored Nov 28, 2023
2 parents 143d35d + ee435d7 commit 315a127
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 15 deletions.
57 changes: 43 additions & 14 deletions client/src/components/Form/FormRepeat.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { library } from "@fortawesome/fontawesome-svg-core";
import { faCaretDown, faCaretUp, faPlus, faTrashAlt } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import { defineAsyncComponent, nextTick, type PropType } from "vue";
import { computed } from "vue";
import { useKeyedObjects } from "@/composables/keyedObjects";
import localize from "@/utils/localization";
import FormCard from "./FormCard.vue";
Expand All @@ -13,10 +15,33 @@ const FormNode = defineAsyncComponent(() => import("./FormInputs.vue"));
interface Input {
name: string;
title: string;
min: number;
default: number;
max: number | string;
help?: string;
cache: Array<Record<string, unknown>>;
}
const maxRepeats = computed(() => {
return typeof props.input.max === "number" ? props.input.cache?.length >= props.input.max : false;
});
const minRepeats = computed(() => {
return typeof props.input.min === "number" ? props.input.cache?.length > props.input.min : true;
});
const buttonTooltip = computed(() => {
return maxRepeats.value
? localize(`Maximum number of ${props.input.title || "Repeat"} fields reached`)
: localize(`Click to add ${props.input.title || "Repeat"} fields`);
});
const deleteTooltip = computed(() => {
return !minRepeats.value
? localize(`Minimum number of ${props.input.title || "Repeat"} fields reached`)
: localize(`Click to delete ${props.input.title || "Repeat"} fields`);
});
const props = defineProps({
input: {
type: Object as PropType<Input>,
Expand Down Expand Up @@ -128,16 +153,18 @@ const { keyObject } = useKeyedObjects();
</b-button>
</b-button-group>

<b-button
v-b-tooltip.hover.bottom
title="delete"
role="button"
variant="link"
size="sm"
class="ml-0"
@click="() => onDelete(cacheId)">
<FontAwesomeIcon icon="trash-alt" />
</b-button>
<span v-b-tooltip.hover.bottom :title="deleteTooltip">
<b-button
:disabled="!minRepeats"
title="delete"
role="button"
variant="link"
size="sm"
class="ml-0"
@click="() => onDelete(cacheId)">
<FontAwesomeIcon icon="trash-alt" />
</b-button>
</span>
</span>
</template>

Expand All @@ -146,9 +173,11 @@ const { keyObject } = useKeyedObjects();
</template>
</FormCard>

<b-button v-if="!props.sustainRepeats" @click="onInsert">
<FontAwesomeIcon icon="plus" class="mr-1" />
<span data-description="repeat insert">Insert {{ props.input.title || "Repeat" }}</span>
</b-button>
<span v-b-tooltip.hover :title="buttonTooltip">
<b-button v-if="!props.sustainRepeats" :disabled="maxRepeats" @click="onInsert">
<FontAwesomeIcon icon="plus" class="mr-1" />
<span data-description="repeat insert">Insert {{ props.input.title || "Repeat" }}</span>
</b-button>
</span>
</div>
</template>
3 changes: 2 additions & 1 deletion lib/galaxy/tools/parameters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,10 @@ def _populate_state_legacy(
del group_state[:]
while True:
rep_prefix = "%s_%d" % (key, rep_index)
rep_min_default = input.default if input.default > input.min else input.min
if (
not any(incoming_key.startswith(rep_prefix) for incoming_key in incoming.keys())
and rep_index >= input.min
and rep_index >= rep_min_default
):
break
if rep_index < input.max:
Expand Down

0 comments on commit 315a127

Please sign in to comment.