@@ -14,6 +14,8 @@ import jQuery from "jquery";
1414import type { HDASummary , HistoryItemSummary } from "@/api" ;
1515import type { CollectionType } from "@/api/datasetCollections" ;
1616import RULE_BASED_COLLECTION_CREATOR from "@/components/Collections/RuleBasedCollectionCreatorModal" ;
17+ import { createDatasetCollection } from "@/components/History/model/queries" ;
18+ import { useHistoryStore } from "@/stores/historyStore" ;
1719
1820// This is type describes builders we know about - not valid "collection type"s
1921// as the backend/model layer of Galaxy would understand them. Rules is a collection
@@ -52,6 +54,32 @@ export const COLLECTION_TYPE_TO_LABEL: Record<string, string> = {
5254
5355export type DatasetPair = GenericPair < HDASummary > ;
5456
57+ export async function buildCollectionFromRules (
58+ selection : any ,
59+ historyId : string | null = null ,
60+ fromRulesInput = false ,
61+ ) {
62+ let selectionContent : any = null ;
63+ const { loadCurrentHistoryId } = useHistoryStore ( ) ;
64+ historyId = historyId || ( await loadCurrentHistoryId ( ) ) ;
65+
66+ if ( fromRulesInput ) {
67+ selectionContent = selection ;
68+ } else {
69+ selectionContent = new Map ( ) ;
70+ selection . models . forEach ( ( obj : any ) => {
71+ selectionContent . set ( obj . id , obj ) ;
72+ } ) ;
73+ }
74+ if ( historyId ) {
75+ const modalResult = await buildRuleCollectionModal ( selectionContent , historyId , fromRulesInput ) ;
76+ if ( modalResult ) {
77+ console . debug ( "Submitting collection build request." , modalResult ) ;
78+ await createDatasetCollection ( { id : historyId } as any , modalResult ) ;
79+ }
80+ }
81+ }
82+
5583// stand-in for buildCollection from history-view-edit.js
5684export async function buildRuleCollectionModal (
5785 selectedContent : HistoryItemSummary [ ] ,
0 commit comments