Skip to content

Commit

Permalink
Support preselecting a file source in RDM export
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed Apr 22, 2024
1 parent 90aed7a commit 0183725
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 20 deletions.
37 changes: 31 additions & 6 deletions client/src/components/Common/ExportRDMForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@
import { BButton, BCard, BFormGroup, BFormInput, BFormRadio, BFormRadioGroup } from "bootstrap-vue";
import { computed, ref } from "vue";
import { CreatedEntry, createRemoteEntry, FilterFileSourcesOptions } from "@/api/remoteFiles";
import {
BrowsableFilesSourcePlugin,
CreatedEntry,
createRemoteEntry,
FilterFileSourcesOptions,
} from "@/api/remoteFiles";
import { useToast } from "@/composables/toast";
import localize from "@/utils/localization";
import { errorMessageAsString } from "@/utils/simple-error";
import { fileSourcePluginToItem } from "../FilesDialog/utilities";
import ExternalLink from "@/components/ExternalLink.vue";
import FilesInput from "@/components/FilesDialog/FilesInput.vue";
Expand All @@ -17,13 +24,19 @@ interface Props {
clearInputAfterExport?: boolean;
defaultRecordName?: string;
defaultFilename?: string;
/**
* If undefined, the user will need to select a repository to export to,
* otherwise this file source will be pre-selected.
*/
fileSource?: BrowsableFilesSourcePlugin;
}
const props = withDefaults(defineProps<Props>(), {
what: "archive",
clearInputAfterExport: false,
defaultRecordName: "",
defaultFilename: "",
fileSource: undefined,
});
const emit = defineEmits<{
Expand All @@ -35,7 +48,7 @@ type ExportChoice = "existing" | "new";
const includeOnlyRDMCompatible: FilterFileSourcesOptions = { include: ["rdm"] };
const recordUri = ref<string>("");
const sourceUri = ref<string>("");
const sourceUri = ref<string>(props.fileSource?.uri_root ?? "");
const fileName = ref<string>(props.defaultFilename);
const exportChoice = ref<ExportChoice>("new");
const recordName = ref<string>(props.defaultRecordName);
Expand All @@ -53,6 +66,9 @@ const recordNameDescription = computed(() => localize("Give the new record a nam
const namePlaceholder = computed(() => localize("File name"));
const recordNamePlaceholder = computed(() => localize("Record name"));
const uniqueSourceId = computed(() => props.fileSource?.id ?? "any");
const fileSourceAsItem = computed(() => (props.fileSource ? fileSourcePluginToItem(props.fileSource) : undefined));
function doExport() {
emit("export", recordUri.value, fileName.value);
Expand All @@ -72,7 +88,7 @@ async function doCreateRecord() {
function clearInputs() {
recordUri.value = "";
sourceUri.value = "";
sourceUri.value = props.fileSource?.uri_root ?? "";
fileName.value = "";
newEntry.value = undefined;
}
Expand All @@ -84,10 +100,17 @@ function clearInputs() {
<BFormInput id="file-name-input" v-model="fileName" :placeholder="namePlaceholder" required />
</BFormGroup>

<p>
Your {{ what }} needs to be uploaded to an existing <i>draft</i> record. You will need to create a
<b>new record</b> or select an existing <b>draft record</b> and then export your {{ what }} to it.
</p>

<BFormRadioGroup v-model="exportChoice" class="export-radio-group">
<BFormRadio id="radio-new" v-localize name="exportChoice" value="new"> Export to new record </BFormRadio>
<BFormRadio :id="`radio-new-${uniqueSourceId}`" v-localize name="exportChoice" value="new">
Export to new record
</BFormRadio>

<BFormRadio id="radio-existing" v-localize name="exportChoice" value="existing">
<BFormRadio :id="`radio-existing-${uniqueSourceId}`" v-localize name="exportChoice" value="existing">
Export to existing draft record
</BFormRadio>
</BFormRadioGroup>
Expand Down Expand Up @@ -123,6 +146,7 @@ function clearInputs() {
</div>
<div v-else>
<BFormGroup
v-if="!props.fileSource"
id="fieldset-record-new"
label-for="source-selector"
:description="repositoryRecordDescription"
Expand Down Expand Up @@ -172,7 +196,8 @@ function clearInputs() {
v-model="recordUri"
mode="directory"
:require-writable="true"
:filter-options="includeOnlyRDMCompatible" />
:filter-options="fileSource ? undefined : includeOnlyRDMCompatible"
:selected-item="fileSourceAsItem" />
</BFormGroup>

<BButton
Expand Down
25 changes: 11 additions & 14 deletions client/src/components/History/Export/HistoryExport.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { faFileExport } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import { BAlert, BButton, BCard, BTab, BTabs } from "bootstrap-vue";
import { computed, onMounted, ref, watch } from "vue";
import { RouterLink } from "vue-router";
import {
exportHistoryToFileSource,
Expand All @@ -23,10 +22,12 @@ import { absPath } from "@/utils/redirect";
import { errorMessageAsString } from "@/utils/simple-error";
import ExportOptions from "./ExportOptions.vue";
import RDMCredentialsInfo from "./RDMCredentialsInfo.vue";
import ExportToFileSourceForm from "@/components/Common/ExportForm.vue";
import ExportToRDMRepositoryForm from "@/components/Common/ExportRDMForm.vue";
import ExportRecordDetails from "@/components/Common/ExportRecordDetails.vue";
import ExportRecordTable from "@/components/Common/ExportRecordTable.vue";
import ExternalLink from "@/components/ExternalLink.vue";
import LoadingSpan from "@/components/LoadingSpan.vue";
const {
Expand Down Expand Up @@ -63,6 +64,7 @@ const isLoadingRecords = ref(true);
const exportRecords = ref<ExportRecord[]>([]);
const historyName = computed(() => history.value?.name ?? props.historyId);
const defaultFileName = computed(() => `(Galaxy History) ${historyName.value}`);
const latestExportRecord = computed(() => (exportRecords.value?.length ? exportRecords.value.at(0) : null));
const isLatestExportRecordReadyToDownload = computed(
() =>
Expand Down Expand Up @@ -203,18 +205,21 @@ function updateExportParams(newParams: ExportParams) {
Here you can generate a temporal download for your history. When your download link expires or
your history changes you can re-generate it again.
</p>

<BAlert show variant="warning">
History archive downloads can expire and are removed at regular intervals. For permanent
storage, export to a <b>remote file</b> or download and then import the archive on another
Galaxy server.
</BAlert>

<BButton
class="gen-direct-download-btn"
:disabled="!canGenerateDownload"
variant="primary"
@click="prepareDownload">
Generate direct download
</BButton>

<span v-if="isPreparingDownload">
<LoadingSpan message="Galaxy is preparing your download, this will likely take a while" />
</span>
Expand All @@ -233,6 +238,7 @@ function updateExportParams(newParams: ExportParams) {
one of the available remote file sources here. You will be able to re-import it later as long as
it remains available on the remote server.
</p>

<ExportToFileSourceForm
what="history"
:clear-input-after-export="true"
Expand All @@ -244,21 +250,12 @@ function updateExportParams(newParams: ExportParams) {
title="to RDM repository"
title-link-class="tab-export-to-rdm-repo">
<p>You can <b>upload your history</b> to one of the available RDM repositories here.</p>
<p>
Your history export archive needs to be uploaded to an existing <i>draft</i> record. You will
need to create a <b>new record</b> on the repository or select an existing
<b>draft record</b> and then export your history to it.
</p>
<BAlert show variant="info">
You may need to setup your credentials for the selected repository in your
<RouterLink to="/user/information" target="_blank">settings page</RouterLink> to be able to
export. You can also define some default options for the export in those settings, like the
public name you want to associate with your records or whether you want to publish them
immediately or keep them as drafts after export.
</BAlert>

<RDMCredentialsInfo what="history export archive" />

<ExportToRDMRepositoryForm
what="history"
:default-filename="historyName + ' (Galaxy History)'"
:default-filename="defaultFileName"
:default-record-name="historyName"
:clear-input-after-export="true"
@export="doExportToFileSource" />
Expand Down
23 changes: 23 additions & 0 deletions client/src/components/History/Export/RDMCredentialsInfo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<script setup lang="ts">
import { BAlert } from "bootstrap-vue";
import { RouterLink } from "vue-router";
interface Props {
selectedRepository?: string;
what?: string;
}
withDefaults(defineProps<Props>(), {
selectedRepository: "the selected repository",
what: "file",
});
</script>

<template>
<BAlert show variant="info">
You may need to setup your credentials for {{ selectedRepository }} in your
<RouterLink to="/user/information" target="_blank">preferences page</RouterLink> to be able to export. You can
also define some default options for the export in those settings, like the public name you want to associate
with your records or whether you want to publish them immediately or keep them as drafts after export.
</BAlert>
</template>

0 comments on commit 0183725

Please sign in to comment.