Skip to content

Commit

Permalink
Rename map_over_type to collection_type to avoid confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Aug 30, 2023
1 parent 646263c commit 4a8288b
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 65 deletions.
95 changes: 68 additions & 27 deletions client/src/components/Form/Elements/FormData/FormData.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const defaultOptions = {
dce: [
{ id: "dce1", name: "dceName1", src: "dce", is_dataset: true },
{ id: "dce2", name: "dceName2", src: "dce" },
{ id: "dce3", name: "dceName3", src: "dce", map_over_type: "mapOverType" },
{ id: "dce3", name: "dceName3", src: "dce", collection_type: "collectionType" },
{ id: "dce4", name: "dceName4", src: "dce", is_dataset: true },
],
hda: [
{ id: "hda1", hid: 1, name: "hdaName1", src: "hda" },
Expand All @@ -54,12 +55,12 @@ describe("FormData", () => {
const value_0 = {
batch: false,
product: false,
values: [{ id: "hda3", src: "hda", map_over_type: null }],
values: [{ id: "hda3", src: "hda", collection_type: null }],
};
const value_1 = {
batch: false,
product: false,
values: [{ id: "hda1", src: "hda", map_over_type: null }],
values: [{ id: "hda1", src: "hda", collection_type: null }],
};
const options = wrapper.find(".btn-group").findAll("button");
expect(options.length).toBe(4);
Expand Down Expand Up @@ -113,8 +114,8 @@ describe("FormData", () => {
batch: false,
product: false,
values: [
{ id: "hda2", map_over_type: null, src: "hda" },
{ id: "hda3", map_over_type: null, src: "hda" },
{ id: "hda2", collection_type: null, src: "hda" },
{ id: "hda3", collection_type: null, src: "hda" },
],
});
expect(wrapper.emitted().input.length).toEqual(1);
Expand All @@ -126,17 +127,25 @@ describe("FormData", () => {
batch: false,
product: false,
values: [
{ id: "hda2", map_over_type: null, src: "hda" },
{ id: "hda3", map_over_type: null, src: "hda" },
{ id: "hda2", collection_type: null, src: "hda" },
{ id: "hda3", collection_type: null, src: "hda" },
],
};
expect(wrapper.emitted().input[0][0]).toEqual(value_0);
await selectedValues.at(0).trigger("click");
const value_1 = { batch: false, product: false, values: [{ id: "hda2", map_over_type: null, src: "hda" }] };
const value_1 = {
batch: false,
product: false,
values: [{ id: "hda2", collection_type: null, src: "hda" }],
};
expect(wrapper.emitted().input[1][0]).toEqual(value_1);
await wrapper.setProps({ value: value_1 });
await selectedValues.at(1).trigger("click");
const value_2 = { batch: false, product: false, values: [{ id: "hda2", map_over_type: null, src: "hda" }] };
const value_2 = {
batch: false,
product: false,
values: [{ id: "hda2", collection_type: null, src: "hda" }],
};
expect(wrapper.emitted().input[1][0]).toEqual(value_2);
await wrapper.setProps({ value: value_2 });
expect(wrapper.emitted().input.length).toBe(3);
Expand All @@ -148,7 +157,11 @@ describe("FormData", () => {
value: { values: [{ id: "dce1", src: "dce" }] },
options: defaultOptions,
});
const value_0 = { batch: false, product: false, values: [{ id: "dce1", map_over_type: null, src: "dce" }] };
const value_0 = {
batch: false,
product: false,
values: [{ id: "dce1", collection_type: null, src: "dce" }],
};
expect(wrapper.emitted().input[0][0]).toEqual(value_0);
expect(wrapper.emitted().input.length).toEqual(1);
const message = wrapper.findAll(".form-data-entry-label");
Expand All @@ -165,34 +178,62 @@ describe("FormData", () => {
expect(wrapper.emitted().input.length).toEqual(2);
});

it("dataset collection as hdca without map_over_type", async () => {
it("dataset collection element as hdca without collection_type", async () => {
const wrapper = createTarget({
value: { values: [{ id: "dce2", src: "dce" }] },
options: defaultOptions,
});
const value_0 = { batch: true, product: false, values: [{ id: "dce2", map_over_type: null, src: "dce" }] };
const value_0 = { batch: true, product: false, values: [{ id: "dce2", collection_type: null, src: "dce" }] };
expect(wrapper.emitted().input[0][0]).toEqual(value_0);
});

it("dataset collection as hdca with map_over_type", async () => {
it("dataset collection element as hdca mapped to batch field", async () => {
const wrapper = createTarget({
value: { values: [{ id: "dce3", src: "dce" }] },
options: defaultOptions,
});
const value_0 = {
batch: true,
product: false,
values: [{ id: "dce3", map_over_type: "mapOverType", src: "dce" }],
values: [{ id: "dce3", collection_type: "collectionType", src: "dce" }],
};
expect(wrapper.emitted().input[0][0]).toEqual(value_0);
});

it("dataset collection element as hdca mapped to non-batch field", async () => {
const wrapper = createTarget({
type: "data_collection",
value: { values: [{ id: "dce3", src: "dce" }] },
options: defaultOptions,
});
const value_0 = {
batch: false,
product: false,
values: [{ id: "dce3", collection_type: "collectionType", src: "dce" }],
};
expect(wrapper.emitted().input[0][0]).toEqual(value_0);
});

it("dataset collection mapped to non-batch field", async () => {
const wrapper = createTarget({
type: "data_collection",
value: { values: [{ id: "hdca4", src: "hdca" }] },
options: defaultOptions,
});
const value_0 = {
batch: false,
product: false,
values: [{ id: "hdca4", collection_type: null, src: "hdca" }],
};
expect(wrapper.emitted().input[0][0]).toEqual(value_0);
});

it("multiple dataset collection values with varying map_over_type", async () => {
it("multiple dataset collection elements (as hdas)", async () => {
const wrapper = createTarget({
value: {
values: [
{ id: "dce2", src: "dce" },
{ id: "dce3", src: "dce" },
{ id: "dce1", src: "dce" },
{ id: "dce4", src: "dce" },
],
},
options: defaultOptions,
Expand All @@ -201,8 +242,8 @@ describe("FormData", () => {
batch: true,
product: false,
values: [
{ id: "dce2", map_over_type: null, src: "dce" },
{ id: "dce3", map_over_type: "mapOverType", src: "dce" },
{ id: "dce1", collection_type: null, src: "dce" },
{ id: "dce4", collection_type: null, src: "dce" },
],
};
expect(wrapper.emitted().input[0][0]).toEqual(value_0);
Expand All @@ -219,15 +260,15 @@ describe("FormData", () => {
expect(wrapper.emitted().input[1][0]).toEqual({
batch: true,
product: false,
values: [{ id: "hdca4", map_over_type: null, src: "hdca" }],
values: [{ id: "hdca4", collection_type: null, src: "hdca" }],
});
eventStore.setDragData({ id: "hda2", history_content_type: "dataset" });
dispatchEvent(wrapper, "dragenter");
dispatchEvent(wrapper, "drop");
expect(wrapper.emitted().input[2][0]).toEqual({
batch: false,
product: false,
values: [{ id: "hda2", map_over_type: null, src: "hda" }],
values: [{ id: "hda2", collection_type: null, src: "hda" }],
});
});

Expand All @@ -240,15 +281,15 @@ describe("FormData", () => {
expect(wrapper.emitted().input[0][0]).toEqual({
batch: false,
product: false,
values: [{ id: "hda3", map_over_type: null, src: "hda" }],
values: [{ id: "hda3", collection_type: null, src: "hda" }],
});
const noCheckLinked = wrapper.find("input[type='checkbox']");
expect(noCheckLinked.exists()).toBeFalsy();
await wrapper.find("[title='Multiple datasets'").trigger("click");
expect(wrapper.emitted().input[1][0]).toEqual({
batch: true,
product: false,
values: [{ id: "hda3", map_over_type: null, src: "hda" }],
values: [{ id: "hda3", collection_type: null, src: "hda" }],
});
const checkLinked = wrapper.find("input[type='checkbox']");
expect(wrapper.find(".custom-switch span").text()).toBe(
Expand All @@ -262,11 +303,11 @@ describe("FormData", () => {
expect(wrapper.emitted().input[2][0]).toEqual({
batch: true,
product: true,
values: [{ id: "hda3", map_over_type: null, src: "hda" }],
values: [{ id: "hda3", collection_type: null, src: "hda" }],
});
});

it("match variation on initial value", async () => {
it("match dataset collection on initial value", async () => {
const wrapper = createTarget({
value: {
values: [{ id: "hdca4", src: "hdca" }],
Expand All @@ -283,7 +324,7 @@ describe("FormData", () => {
expect(wrapper.emitted().input[i][0]).toEqual({
batch: false,
product: false,
values: [{ id: "hdca4", map_over_type: null, src: "hdca" }],
values: [{ id: "hdca4", collection_type: null, src: "hdca" }],
});
}
expect(wrapper.emitted().input.length).toEqual(2);
Expand All @@ -295,7 +336,7 @@ describe("FormData", () => {
expect(wrapper.emitted().input[2][0]).toEqual({
batch: false,
product: false,
values: [{ id: "hda3", map_over_type: null, src: "hda" }],
values: [{ id: "hda3", collection_type: null, src: "hda" }],
});
const newSelectedValues = wrapper.findAll(SELECTED_VALUE);
expect(newSelectedValues.at(0).text()).toBe("3: hdaName3");
Expand Down
21 changes: 11 additions & 10 deletions client/src/components/Form/Elements/FormData/FormData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ function handleIncoming(incoming: Record<string, unknown>, partial = true) {
const incomingValues: Array<DataOption> = [];
values.forEach((v) => {
// Map incoming objects to data option values
v.id = v.element_id || v.id;
const newHid = v.hid;
const newId = v.id;
const newName = v.name ? v.name : newId;
Expand Down Expand Up @@ -381,7 +380,7 @@ function setValue(val: Array<DataOption> | DataOption | null) {
if (val) {
const values = Array.isArray(val) ? val : [val];
if (variant.value && values.length > 0 && values[0]) {
const hasMapOverType = values.find((v) => !!v.map_over_type);
const hasMapOverType = values.find((v) => !!v.collection_type);
const isMultiple = values.length > 1;
// Determine source representation
Expand All @@ -403,14 +402,16 @@ function setValue(val: Array<DataOption> | DataOption | null) {
let batch: string = BATCH.DISABLED;
if (variantIndex >= 0) {
const variantDetails = variant.value[variantIndex];
if ((isLDDA.value || isDCE.value) && variantDetails && variantDetails.batch) {
batch = variantDetails.batch;
} else {
// Switch to another field type if source differs from current field
if (currentVariant.value && currentVariant.value.src !== sourceType) {
currentField.value = variantIndex;
if (variantDetails) {
if ((isLDDA.value || isDCE.value) && variantDetails.batch) {
batch = variantDetails.batch;
} else {
// Switch to another field type if source differs from current field
if (currentVariant.value && currentVariant.value.src !== sourceType) {
currentField.value = variantIndex;
}
batch = (currentVariant.value && currentVariant.value.batch) || BATCH.DISABLED;
}
batch = (currentVariant.value && currentVariant.value.batch) || BATCH.DISABLED;
}
}
Expand All @@ -421,7 +422,7 @@ function setValue(val: Array<DataOption> | DataOption | null) {
values: values.map((entry) => ({
id: entry.id,
src: entry.src,
map_over_type: entry.map_over_type || null,
collection_type: entry.collection_type || null,
})),
});
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/Form/Elements/FormData/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export interface DataOption {
id: string;
collection_type?: string;
hid: number;
is_dataset?: boolean;
keep: boolean;
hid: number;
map_over_type?: string;
name: string;
src: string;
tags: Array<string>;
Expand Down
18 changes: 9 additions & 9 deletions lib/galaxy/tools/parameters/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2289,7 +2289,7 @@ def to_dict(self, trans, other_values=None):
multiple = self.multiple

# build and append a new select option
def append(list, hda, name, src, keep=False, subcollection_type=None):
def append(list, hda, name, src, keep=False, collection_type=None):
value = {
"id": trans.security.encode_id(hda.id),
"hid": hda.hid if hda.hid is not None else -1,
Expand All @@ -2298,8 +2298,8 @@ def append(list, hda, name, src, keep=False, subcollection_type=None):
"src": src,
"keep": keep,
}
if subcollection_type:
value["map_over_type"] = subcollection_type
if collection_type:
value["collection_type"] = collection_type
return list.append(value)

def append_dce(dce):
Expand Down Expand Up @@ -2364,18 +2364,18 @@ def append_ldda(ldda):
for hdca in history.active_visible_dataset_collections:
match = dataset_collection_matcher.hdca_match(hdca)
if match:
subcollection_type = None
collection_type = None
if multiple and hdca.collection.collection_type != "list":
collection_type_description = self._history_query(trans).can_map_over(hdca)
if collection_type_description:
subcollection_type = collection_type_description.collection_type
collection_type = collection_type_description.collection_type
else:
continue

name = hdca.name
if match.implicit_conversion:
name = f"{name} (with implicit datatype conversion)"
append(d["options"]["hdca"], hdca, name, "hdca", subcollection_type=subcollection_type)
append(d["options"]["hdca"], hdca, name, "hdca", collection_type=collection_type)
continue

# sort both lists
Expand Down Expand Up @@ -2519,7 +2519,7 @@ def to_dict(self, trans, other_values=None):
# append DCE
if isinstance(other_values.get(self.name), DatasetCollectionElement):
dce = other_values[self.name]
d["options"]["hdca"].append(
d["options"]["dce"].append(
{
"id": trans.security.encode_id(dce.id),
"hid": -1,
Expand All @@ -2546,18 +2546,18 @@ def to_dict(self, trans, other_values=None):

# append matching subcollections
for hdca, implicit_conversion in self.match_multirun_collections(trans, history, dataset_collection_matcher):
subcollection_type = self._history_query(trans).can_map_over(hdca).collection_type
collection_type = self._history_query(trans).can_map_over(hdca).collection_type
name = hdca.name
if implicit_conversion:
name = f"{name} (with implicit datatype conversion)"
d["options"]["hdca"].append(
{
"id": trans.security.encode_id(hdca.id),
"collection_type": collection_type,
"hid": hdca.hid,
"name": name,
"src": "hdca",
"tags": [t.user_tname if not t.value else f"{t.user_tname}:{t.value}" for t in hdca.tags],
"map_over_type": subcollection_type,
}
)

Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/tools/parameters/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def __expand_collection_parameter(trans, input_key, incoming_val, collections_to
if src != "hdca":
raise exceptions.ToolMetaParameterException(f"Invalid dataset collection source type {src}")
encoded_hdc_id = incoming_val["id"]
subcollection_type = incoming_val.get("map_over_type", None)
subcollection_type = incoming_val.get("collection_type", None)
except TypeError:
encoded_hdc_id = incoming_val
subcollection_type = None
Expand Down
Loading

0 comments on commit 4a8288b

Please sign in to comment.