Skip to content

Commit 17b6b12

Browse files
authored
Merge pull request #21038 from guerler/remove_jquery.000
Convert Modal to plain JavaScript and remove from Galaxy object
2 parents 2f12ae9 + 97af8b7 commit 17b6b12

37 files changed

+298
-886
lines changed

client/src/bundleEntries.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,18 @@
66
* to exist until such time as we replace the overall application with a Vue component which
77
* will handle initializations for components individually.
88
*
9-
* legacy/grid_base.mako: window.bundleEntries.LegacyGridView
10-
* webapps/galaxy/dataset/tabular_chunked.mako: window.bundleEntries.createTabularDatasetChunkedView
11-
* webapps/galaxy/dataset/display.mako: window.bundleEntries.createTabularDatasetChunkedView
12-
* webapps/reports/run_stats.mako: window.bundleEntries.create_chart
13-
* webapps/reports/run_stats.mako: window.bundleEntries.create_histogram
14-
* tagging_common.mako: show_in_overlay
159
*/
10+
import { replaceChildrenWithComponent } from "utils/mountVueComponent";
1611

17-
export { getGalaxyInstance, setGalaxyInstance } from "app";
12+
import TabularChunkedView from "components/Visualizations/Tabular/TabularChunkedView.vue";
13+
14+
// legacy/grid_base.mako
1815
export { default as LegacyGridView } from "legacy/grid/grid-view";
19-
export { createTabularDatasetChunkedView } from "mvc/dataset/data";
20-
export { create_chart, create_histogram } from "reports/run_stats";
21-
export { Toast } from "ui/toast"; // TODO: remove when external consumers are updated/gone (IES right now)
2216

23-
// Previously wandering around as window.thing = thing in the onload script
24-
export { show_in_overlay } from "layout/modal";
17+
// webapps/reports/run_stats.mako
18+
export { create_chart, create_histogram } from "reports/run_stats";
2519

26-
// Used in common.mako
27-
export { default as store } from "storemodern";
20+
// webapps/galaxy/dataset/{ display | tabular_chunked }.mako
21+
export const createTabularDatasetChunkedView = (options) => {
22+
return replaceChildrenWithComponent(options.parent_elt, TabularChunkedView, { options });
23+
};

client/src/components/Collections/ListCollectionCreator.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
<script setup lang="ts">
2-
import "ui/hoverhighlight";
3-
42
import { faSquare } from "@fortawesome/free-regular-svg-icons";
53
import { faMinus, faSortAlphaDown, faTimes, faUndo } from "@fortawesome/free-solid-svg-icons";
64
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
Lines changed: 67 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,78 @@
11
import _l from "utils/localization";
2+
import Modal from "utils/modal";
23
import Vue from "vue";
34

45
import { rawToTable } from "@/components/Collections/tables";
56

6-
import { collectionCreatorModalSetup } from "./common/modal";
7+
const modal = new Modal();
78

8-
function ruleBasedCollectionCreatorModal(elements, elementsType, importType, options) {
9+
async function ruleBasedCollectionCreatorModal(elements, elementsType, importType, options) {
910
// importType in [datasets, collection]
1011
// elementsType in [raw, ftp, datasets]
1112
let title;
12-
if (importType == "datasets") {
13+
if (importType === "datasets") {
1314
title = _l("Build Rules for Uploading Datasets");
14-
} else if (elementsType == "collection_contents") {
15+
} else if (elementsType === "collection_contents") {
1516
title = _l("Build Rules for Applying to Existing Collection");
16-
} else if (elementsType == "datasets" || elementsType == "library_datasets") {
17+
} else if (elementsType === "datasets" || elementsType === "library_datasets") {
1718
title = _l("Build Rules for Creating Collection(s)");
1819
} else {
1920
title = _l("Build Rules for Uploading Collections");
2021
}
21-
options.title = title;
22-
// Prevents user from accidentally closing the modal by clicking outside the bounds
23-
options.closing_events = false;
24-
const { promise, showEl } = collectionCreatorModalSetup(options);
25-
return import(/* webpackChunkName: "ruleCollectionBuilder" */ "components/RuleCollectionBuilder.vue").then(
26-
(module) => {
27-
var ruleCollectionBuilderInstance = Vue.extend(module.default);
28-
var vm = document.createElement("div");
29-
showEl(vm);
30-
new ruleCollectionBuilderInstance({
31-
propsData: {
32-
initialElements: elements,
33-
elementsType: elementsType,
34-
importType: importType,
35-
ftpUploadSite: options.ftpUploadSite,
36-
creationFn: options.creationFn,
37-
oncancel: options.oncancel,
38-
oncreate: options.oncreate,
39-
defaultHideSourceItems: options.defaultHideSourceItems,
40-
saveRulesFn: options.saveRulesFn,
41-
initialRules: options.initialRules,
42-
},
43-
}).$mount(vm);
44-
return promise;
22+
23+
const promise = new Promise((resolve, reject) => {
24+
options.oncancel = function () {
25+
modal.hide();
26+
resolve();
27+
};
28+
options.oncreate = function (response) {
29+
modal.hide();
30+
resolve(response);
31+
};
32+
});
33+
34+
const module = await import(/* webpackChunkName: "ruleCollectionBuilder" */ "components/RuleCollectionBuilder.vue");
35+
const ruleCollectionBuilderInstance = Vue.extend(module.default);
36+
const vm = document.createElement("div");
37+
38+
// Prepare modal
39+
const titleSuffix = options.historyName ? `From history: <b>${options.historyName}</b>` : "";
40+
const titleHtml = `<div class='d-flex justify-content-between unselectable'>
41+
<span>${title}</span>
42+
<span>${titleSuffix}</span>
43+
</div>`;
44+
modal.show({
45+
title: titleHtml,
46+
body: vm,
47+
width: "85%",
48+
height: "100%",
49+
});
50+
51+
// Inject rule builder component
52+
new ruleCollectionBuilderInstance({
53+
propsData: {
54+
initialElements: elements,
55+
elementsType: elementsType,
56+
importType: importType,
57+
ftpUploadSite: options.ftpUploadSite,
58+
creationFn: options.creationFn,
59+
oncancel: options.oncancel,
60+
oncreate: options.oncreate,
61+
defaultHideSourceItems: options.defaultHideSourceItems,
62+
saveRulesFn: options.saveRulesFn,
63+
initialRules: options.initialRules,
4564
},
46-
);
65+
}).$mount(vm);
66+
67+
return promise;
4768
}
48-
function createCollectionViaRules(selection, defaultHideSourceItems = true) {
69+
70+
export async function createCollectionViaRules(selection, defaultHideSourceItems = true) {
4971
let elements;
5072
let elementsType;
5173
let importType;
5274
const selectionType = selection.selectionType;
5375
if (!selectionType) {
54-
// Have HDAs from the history panel.
5576
elements = selection.toJSON();
5677
elementsType = "datasets";
5778
importType = "collections";
@@ -64,17 +85,18 @@ function createCollectionViaRules(selection, defaultHideSourceItems = true) {
6485
elementsType = selection.selectionType;
6586
importType = selection.dataType || "collections";
6687
}
67-
const promise = ruleBasedCollectionCreatorModal(elements, elementsType, importType, {
68-
ftpUploadSite: selection.ftpUploadSite,
69-
defaultHideSourceItems: defaultHideSourceItems,
70-
creationFn: function (elements, collectionType, name, hideSourceItems) {
71-
return selection.createHDCA(elements, collectionType, name, hideSourceItems);
72-
},
73-
});
74-
return promise;
75-
}
7688

77-
export default {
78-
ruleBasedCollectionCreatorModal: ruleBasedCollectionCreatorModal,
79-
createCollectionViaRules: createCollectionViaRules,
80-
};
89+
try {
90+
const result = await ruleBasedCollectionCreatorModal(elements, elementsType, importType, {
91+
ftpUploadSite: selection.ftpUploadSite,
92+
defaultHideSourceItems: defaultHideSourceItems,
93+
creationFn: async (elements, collectionType, name, hideSourceItems) => {
94+
return selection.createHDCA(elements, collectionType, name, hideSourceItems);
95+
},
96+
});
97+
return result;
98+
} catch (error) {
99+
console.error("Error in rule-based collection creation:", error);
100+
throw error;
101+
}
102+
}

client/src/components/Collections/common/buildCollectionModal.ts

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
/**
2-
* TODO: Update this description...
3-
* Temporary adapter to launch bootstrap modals from Vue components, for use with
4-
* the collection assembly modals. i.e. With selected..... create dataset collection,
5-
* create paired collection, etc.
6-
*
7-
* The goal is to use the existing "createListCollection", etc. functions but doctor
8-
* the content parameter to have the API of a backbone model which requires a
9-
* deprecated jquery Deferred object.
2+
* Launch bootstrap modals with Vue components, for use with the collection assembly modals.
3+
* i.e. With selected..... create dataset collection, create paired collection, etc.
104
*/
115

12-
import jQuery from "jquery";
13-
146
import type { HDASummary, HistoryItemSummary } from "@/api";
157
import type { CollectionType } from "@/api/datasetCollections";
16-
import RULE_BASED_COLLECTION_CREATOR from "@/components/Collections/RuleBasedCollectionCreatorModal";
8+
import { createCollectionViaRules } from "@/components/Collections/RuleBasedCollectionCreatorModal";
179
import { createDatasetCollection } from "@/components/History/model/queries";
1810
import { useHistoryStore } from "@/stores/historyStore";
1911

@@ -72,54 +64,34 @@ export async function buildCollectionFromRules(
7264
});
7365
}
7466
if (historyId) {
75-
const modalResult = await buildRuleCollectionModal(selectionContent, historyId, fromRulesInput);
67+
const content = fromRulesInput ? selectionContent : createContent(historyId, selectionContent);
68+
const modalResult = await createCollectionViaRules(content);
7669
if (modalResult) {
7770
console.debug("Submitting collection build request.", modalResult);
7871
await createDatasetCollection({ id: historyId } as any, modalResult);
7972
}
8073
}
8174
}
8275

83-
// stand-in for buildCollection from history-view-edit.js
84-
export async function buildRuleCollectionModal(
85-
selectedContent: HistoryItemSummary[],
86-
historyId: string,
87-
fromRulesInput = false,
88-
defaultHideSourceItems = true,
89-
) {
90-
// select legacy function
91-
const createFunc = RULE_BASED_COLLECTION_CREATOR.createCollectionViaRules;
92-
// pull up cached content by type_ids;
93-
if (fromRulesInput) {
94-
return await createFunc(selectedContent);
95-
} else {
96-
const fakeBackboneContent = createBackboneContent(historyId, selectedContent, defaultHideSourceItems);
97-
return await createFunc(fakeBackboneContent);
98-
}
99-
}
100-
101-
const createBackboneContent = (historyId: string, selection: HistoryItemSummary[], defaultHideSourceItems: boolean) => {
76+
const createContent = (historyId: string, selection: HistoryItemSummary[], defaultHideSourceItems: boolean = true) => {
10277
const selectionJson = Array.from(selection.values());
10378
return {
10479
historyId,
10580
toJSON: () => selectionJson,
106-
// result must be a $.Deferred object instead of a promise because
107-
// that's the kind of deprecated data format that backbone likes to use.
108-
createHDCA(
81+
async createHDCA(
10982
element_identifiers: any,
11083
collection_type: CollectionType,
11184
name: string,
11285
hide_source_items: boolean,
11386
options = {},
11487
) {
115-
const def = jQuery.Deferred();
116-
return def.resolve(null, {
88+
return {
11789
collection_type,
11890
name,
11991
hide_source_items,
12092
element_identifiers,
12193
options,
122-
});
94+
};
12395
},
12496
defaultHideSourceItems,
12597
};

client/src/components/Collections/common/modal.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

client/src/components/Collections/common/modal.test.js

Lines changed: 0 additions & 61 deletions
This file was deleted.

client/src/components/Collections/common/useCollectionCreator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { computed, type Ref, ref, unref, watch } from "vue";
22

33
import type { CollectionElementIdentifiers, CreateNewCollectionPayload, HistoryItemSummary } from "@/api";
44
import type RuleCollectionBuilder from "@/components/RuleCollectionBuilder.vue";
5-
import STATES from "@/mvc/dataset/states";
5+
import STATES from "@/utils/datasetStates";
66
import localize from "@/utils/localization";
77

88
import type ListCollectionCreator from "./ListCollectionCreator.vue";

client/src/components/History/Content/ContentItem.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,18 +236,19 @@ function onDisplay() {
236236
// vue-router 4 supports a native force push with clean URLs,
237237
// but we're using a __vkey__ bit as a workaround
238238
// Only conditionally force to keep urls clean most of the time.
239+
const hidInfo = props.item.hid ? `${props.item.hid}: ` : "";
239240
if (route.path === itemUrls.value.display) {
240241
const options: RouterPushOptions = {
241242
force: true,
242243
preventWindowManager: !isWindowManagerActive,
243-
title: isWindowManagerActive ? `${props.item.hid}: ${props.name}` : undefined,
244+
title: isWindowManagerActive ? `${hidInfo} ${props.name}` : undefined,
244245
};
245246
// @ts-ignore - monkeypatched router, drop with migration.
246247
router.push(displayUrl, options);
247248
} else if (displayUrl) {
248249
const options: RouterPushOptions = {
249250
preventWindowManager: !isWindowManagerActive,
250-
title: isWindowManagerActive ? `${props.item.hid}: ${props.name}` : undefined,
251+
title: isWindowManagerActive ? `${hidInfo} ${props.name}` : undefined,
251252
};
252253
// @ts-ignore - monkeypatched router, drop with migration.
253254
router.push(displayUrl, options);

0 commit comments

Comments
 (0)