Skip to content

Commit

Permalink
Add consistent support for ldda's, should probably re-consider this u…
Browse files Browse the repository at this point in the history
…se case
  • Loading branch information
guerler committed Aug 23, 2023
1 parent c38501e commit 3d3d45a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe("FormData", () => {
expect(wrapper.emitted().input.length).toEqual(1);
const message = wrapper.findAll(".form-data-entry-label");
expect(message.length).toBe(1);
expect(message.at(0).text()).toBe("1. dceName1");
expect(message.at(0).text()).toBe("1. dceName1 (dce)");
const closeButton = wrapper.find(".alert .close");
await closeButton.trigger("click");
expect(wrapper.emitted().input[1][0]).toEqual(null);
Expand Down
29 changes: 20 additions & 9 deletions client/src/components/Form/Elements/FormData/FormData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,13 @@ const isDCE = computed(() => {
return false;
}
});
const isLDDA = computed(() => {
if (props.value && props.value.values.length > 0) {
return props.value.values.findIndex((v) => v.src !== SOURCE.LIBRARY_DATASET) === -1;
} else {
return false;
}
});
/**
* Provides placeholder label for select field
*/
Expand Down Expand Up @@ -228,7 +234,8 @@ function handleIncoming(incoming: Record<string, unknown>, partial = true) {
const newHid = v.hid;
const newId = v.id;
const newName = v.name ? v.name : newId;
const newSrc = v.history_content_type === "dataset_collection" ? SOURCE.COLLECTION : SOURCE.DATASET;
const newSrc =
v.src || (v.history_content_type === "dataset_collection" ? SOURCE.COLLECTION : SOURCE.DATASET);
const newValue = {
id: newId,
src: newSrc,
Expand Down Expand Up @@ -288,7 +295,9 @@ function matchOption(entry: DataOption) {
*/
function matchName(entry: DataOption) {
const option = matchOption(entry);
return option?.name || entry.id;
const name = option?.name || entry.id;
const src = option?.src || "unknown";
return `${name} (${src})`;
}
/**
Expand All @@ -310,8 +319,8 @@ function matchValues(entries: Array<DataOption>) {
*/
function onBrowse() {
if (currentVariant.value) {
const library = currentVariant.value.library;
const multiple = currentVariant.value.multiple;
const library = !!currentVariant.value.library;
const multiple = !!currentVariant.value.multiple;
getGalaxyInstance().data.dialog(
(response: Record<string, unknown>) => {
handleIncoming(response, false);
Expand Down Expand Up @@ -372,6 +381,8 @@ function setValue(val: Array<DataOption> | DataOption | null) {
let sourceType: string | null = null;
if (isDCE.value) {
sourceType = values[0].hda ? SOURCE.DATASET : SOURCE.COLLECTION;
} else if (isLDDA.value) {
sourceType = SOURCE.DATASET;
} else {
sourceType = values[0].src;
}
Expand All @@ -383,7 +394,7 @@ function setValue(val: Array<DataOption> | DataOption | null) {
let batch: string = BATCH.DISABLED;
if (variantIndex >= 0) {
const variantDetails = variant.value[variantIndex];
if (isDCE.value && variantDetails && variantDetails.batch) {
if ((isLDDA.value || isDCE.value) && variantDetails && variantDetails.batch) {
batch = variantDetails.batch;
} else {
// Switch to another field type if source differs from current field
Expand Down Expand Up @@ -414,7 +425,7 @@ onMounted(() => {
eventBus.$on("waiting", (value: boolean) => {
waiting.value = value;
});
if (isDCE.value && props.value && props.value.values) {
if ((isLDDA.value || isDCE.value) && props.value && props.value.values) {
setValue(matchValues(props.value.values));
} else {
setValue(currentValue.value);
Expand All @@ -439,10 +450,10 @@ watch(
@dragleave.prevent="onDragLeave"
@dragover.prevent="onDragOver"
@drop.prevent="onDrop">
<b-alert v-if="isDCE" variant="info" dismissible show @dismissed="currentValue = null">
<b-alert v-if="isDCE || isLDDA" variant="info" dismissible show @dismissed="$emit('input', null)">
<span v-localize class="font-weight-bold">Using the following datasets (dismiss to reset):</span>
<div v-for="(v, vIndex) of props.value.values" :key="vIndex">
<span class="form-data-entry-label ml-2">{{ vIndex + 1 }}. {{ matchName(v) || v.id }}</span>
<span class="form-data-entry-label ml-2">{{ vIndex + 1 }}. {{ matchName(v) }}</span>
</div>
</b-alert>
<div v-else>
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Form/Elements/FormData/variants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface VariantInterface {
export const BATCH = { DISABLED: "disabled", ENABLED: "enabled", LINKED: "linked" };

/** Data source variations */
export const SOURCE = { DATASET: "hda", COLLECTION: "hdca", COLLECTION_ELEMENT: "dce" };
export const SOURCE = { DATASET: "hda", COLLECTION: "hdca", COLLECTION_ELEMENT: "dce", LIBRARY_DATASET: "ldda" };

/** List of available data input variations */
export const VARIANTS: Record<string, Array<VariantInterface>> = {
Expand Down
23 changes: 22 additions & 1 deletion lib/galaxy/tools/parameters/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2137,6 +2137,9 @@ def from_json(self, value, trans, other_values=None):
elif isinstance(value, (HistoryDatasetAssociation, LibraryDatasetDatasetAssociation)):
rval.append(value)
elif isinstance(value, dict) and "src" in value and "id" in value:
if value["src"] == "ldda":
decoded_id = trans.security.decode_id(value["id"])
rval.append(trans.sa_session.query(LibraryDatasetDatasetAssociation).get(decoded_id))
if value["src"] == "hda":
decoded_id = trans.security.decode_id(value["id"])
rval.append(trans.sa_session.query(HistoryDatasetAssociation).get(decoded_id))
Expand Down Expand Up @@ -2272,7 +2275,7 @@ def to_dict(self, trans, other_values=None):
# For consistency, should these just always be in the dict?
d["min"] = self.min
d["max"] = self.max
d["options"] = {"dce": [], "hda": [], "hdca": []}
d["options"] = {"dce": [], "ldda": [], "hda": [], "hdca": []}
d["tag"] = self.tag

# return dictionary without options if context is unavailable
Expand Down Expand Up @@ -2311,11 +2314,27 @@ def append_dce(dce):
}
)

def append_ldda(ldda):
d["options"]["ldda"].append(
{
"id": trans.security.encode_id(ldda.id),
"name": ldda.name,
"src": "ldda",
"tags": [],
"keep": True,
}
)

# append DCE
if isinstance(other_values.get(self.name), DatasetCollectionElement):
dce = other_values[self.name]
append_dce(dce)

# append LDDA
if isinstance(other_values.get(self.name), LibraryDatasetDatasetAssociation):
ldda = other_values[self.name]
append_ldda(ldda)

# add datasets
hda_list = util.listify(other_values.get(self.name))
# Prefetch all at once, big list of visible, non-deleted datasets.
Expand All @@ -2337,6 +2356,8 @@ def append_dce(dce):
append(d["options"]["hda"], hda, f"({hda_state}) {hda.name}", "hda", True)
elif isinstance(hda, DatasetCollectionElement):
append_dce(hda)
elif isinstance(hda, LibraryDatasetDatasetAssociation):
append_ldda(hda)

# add dataset collections
dataset_collection_matcher = dataset_matcher_factory.dataset_collection_matcher(dataset_matcher)
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy_test/selenium/test_tool_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def test_rerun_dataset_collection_element(self):
self.hda_click_primary_action_button(1, "rerun")
self.sleep_for(self.wait_types.UX_RENDER)
entry_label = self.components.tool_form.parameter_data_entry_label(parameter="input1").wait_for_visible()
assert entry_label.text == "1. test0"
assert entry_label.text == "1. test0 (dce)"
self.tool_form_execute()
self.components.history_panel.collection_view.back_to_history.wait_for_and_click()
self.history_panel_wait_for_hid_ok(9)
Expand Down

0 comments on commit 3d3d45a

Please sign in to comment.