-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17175 from davelopez/migrate_dataset_path_destina…
…tion_store Convert dataset path destination store to composable
- Loading branch information
Showing
11 changed files
with
290 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 52 additions & 63 deletions
115
client/src/components/Dataset/DatasetLink/DatasetLink.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,59 @@ | ||
<template> | ||
<div> | ||
<a :href="pathDestination.fileLink" title="test" target="_blank">{{ linkLabel }}</a> | ||
</div> | ||
</template> | ||
<script setup lang="ts"> | ||
import { computed } from "vue"; | ||
<script> | ||
import { mapCacheActions } from "vuex-cache"; | ||
import { hasDetails } from "@/api"; | ||
import { type PathDestination, useDatasetPathDestination } from "@/composables/datasetPathDestination"; | ||
import { useDatasetStore } from "@/stores/datasetStore"; | ||
import { fetchDatasetDetails } from "@/api/datasets"; | ||
interface Props { | ||
historyDatasetId: string; | ||
path?: string; | ||
label?: string; | ||
} | ||
export default { | ||
props: { | ||
history_dataset_id: { | ||
type: String, | ||
required: true, | ||
}, | ||
path: { | ||
type: String, | ||
}, | ||
label: { | ||
type: String, | ||
}, | ||
}, | ||
data() { | ||
return { | ||
pathDestination: undefined, | ||
}; | ||
}, | ||
computed: { | ||
linkLabel() { | ||
// if sub-directory, we could potentially implement subdir compression | ||
if (this.pathDestination.isDirectory) { | ||
return `Path: ${this.path} is a directory!`; | ||
} | ||
const { datasetPathDestination } = useDatasetPathDestination(); | ||
const { getDataset } = useDatasetStore(); | ||
if (!this.pathDestination.fileLink) { | ||
return `Path: ${this.path} was not found!`; | ||
} | ||
const props = defineProps<Props>(); | ||
if (this.label !== undefined && this.label !== "undefined") { | ||
return this.label; | ||
} else { | ||
return `${ | ||
this.pathDestination.datasetRootDir && this.path | ||
? `DATASET: ${this.pathDestination.datasetRootDir} FILEPATH: ${this.path}` | ||
: `${this.history_dataset_id}` | ||
} `; | ||
} | ||
}, | ||
}, | ||
created() { | ||
this.pathDestination = {}; | ||
if (this.path && this.path !== "undefined") { | ||
// download individual file from composite dataset | ||
this.fetchPathDestination({ history_dataset_id: this.history_dataset_id, path: this.path }).then(() => { | ||
this.pathDestination = this.$store.getters.pathDestination(this.history_dataset_id, this.path); | ||
}); | ||
} else { | ||
// download whole dataset | ||
fetchDatasetDetails({ id: this.history_dataset_id }).then((response) => { | ||
this.pathDestination = { fileLink: `${response.download_url}?to_ext=${response.file_ext}` }; | ||
}); | ||
const pathDestination = computed<PathDestination | null>(() => | ||
datasetPathDestination.value(props.historyDatasetId, props.path) | ||
); | ||
const dataset = computed(() => getDataset(props.historyDatasetId)); | ||
const fileLink = computed(() => { | ||
if (props.path === undefined || props.path === "undefined") { | ||
// Download whole dataset | ||
if (dataset.value && hasDetails(dataset.value)) { | ||
return `${dataset.value.download_url}?to_ext=${dataset.value.file_ext}`; | ||
} | ||
}, | ||
methods: { | ||
...mapCacheActions(["fetchPathDestination"]), | ||
}, | ||
}; | ||
} | ||
// Download individual file from composite dataset | ||
return pathDestination.value?.fileLink; | ||
}); | ||
const linkLabel = computed(() => { | ||
if (pathDestination.value?.isDirectory) { | ||
return `Path: ${props.path} is a directory!`; | ||
} | ||
if (!fileLink.value) { | ||
return `Path: ${props.path} was not found!`; | ||
} | ||
if (props.label && props.label !== "undefined") { | ||
return props.label; | ||
} | ||
return `${props.historyDatasetId}`; | ||
}); | ||
const linkTitle = computed(() => `Download ${dataset.value?.name ?? props.historyDatasetId}`); | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<a :href="fileLink" :title="linkTitle" target="_blank">{{ linkLabel }}</a> | ||
</div> | ||
</template> |
Oops, something went wrong.