Skip to content

Commit

Permalink
Merge pull request #17175 from davelopez/migrate_dataset_path_destina…
Browse files Browse the repository at this point in the history
…tion_store

Convert dataset path destination store to composable
  • Loading branch information
mvdbeek authored Dec 14, 2023
2 parents 5d40192 + 103205c commit f10614e
Show file tree
Hide file tree
Showing 11 changed files with 290 additions and 312 deletions.
7 changes: 7 additions & 0 deletions client/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,10 @@ export function isHDCA(entry?: CollectionEntry): entry is HDCASummary {
export function isCollectionElement(element: DCESummary): element is DCECollection {
return element.element_type === "dataset_collection";
}

/**
* Returns true if the given dataset entry is an instance of DatasetDetails.
*/
export function hasDetails(entry: DatasetEntry): entry is DatasetDetails {
return "peek" in entry;
}
64 changes: 28 additions & 36 deletions client/src/components/Dataset/DatasetAsImage/DatasetAsImage.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
<script setup lang="ts">
import { computed } from "vue";
import { type PathDestination, useDatasetPathDestination } from "@/composables/datasetPathDestination";
import { getAppRoot } from "@/onload/loadConfig";
interface Props {
historyDatasetId: string;
path?: string;
}
const { datasetPathDestination } = useDatasetPathDestination();
const props = defineProps<Props>();
const pathDestination = computed<PathDestination | null>(() =>
datasetPathDestination.value(props.historyDatasetId, props.path)
);
const imageUrl = computed(() => {
if (props.path === undefined || props.path === "undefined") {
return `${getAppRoot()}dataset/display?dataset_id=${props.historyDatasetId}`;
}
return pathDestination.value?.fileLink;
});
</script>

<template>
<div>
<div v-if="imageUrl" class="w-100 p-2">
Expand All @@ -10,39 +38,3 @@
</div>
</div>
</template>

<script>
import { getAppRoot } from "onload/loadConfig";
import { mapCacheActions } from "vuex-cache";
export default {
props: {
history_dataset_id: {
type: String,
required: true,
},
path: {
type: String,
default: null,
},
},
data() {
return {
imageUrl: undefined,
};
},
created() {
if (this.path) {
this.fetchPathDestination({ history_dataset_id: this.history_dataset_id, path: this.path }).then(() => {
const pathDestination = this.$store.getters.pathDestination(this.history_dataset_id, this.path);
this.imageUrl = pathDestination.fileLink;
});
} else {
this.imageUrl = `${getAppRoot()}dataset/display?dataset_id=${this.history_dataset_id}`;
}
},
methods: {
...mapCacheActions(["fetchPathDestination"]),
},
};
</script>
145 changes: 76 additions & 69 deletions client/src/components/Dataset/DatasetIndex/DatasetIndex.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,79 @@
<script setup lang="ts">
import { computed } from "vue";
import type { DatasetExtraFiles } from "@/api/datasets";
import { PathDestination, useDatasetPathDestination } from "@/composables/datasetPathDestination";
interface Props {
historyDatasetId: string;
path?: string;
}
const { datasetPathDestination } = useDatasetPathDestination();
const props = defineProps<Props>();
const pathDestination = computed<PathDestination | null>(() =>
datasetPathDestination.value(props.historyDatasetId, props.path)
);
const directoryContent = computed(() => {
if (!pathDestination.value) {
return;
}
if (pathDestination.value.fileLink) {
return;
}
if (pathDestination.value.isDirectory) {
return removeParentDirectory(pathDestination.value.datasetContent, pathDestination.value.filepath);
} else if (props.path === undefined || props.path === "undefined") {
return pathDestination.value.datasetContent;
}
return pathDestination.value.datasetContent;
});
const errorMessage = computed(() => {
if (!pathDestination.value) {
return `Dataset is not composite!`;
}
if (pathDestination.value.fileLink) {
return `is not a directory!`;
}
if (pathDestination.value.isDirectory) {
return undefined;
} else if (props.path === undefined || props.path === "undefined") {
return undefined;
} else {
return `is not found!`;
}
});
function removeParentDirectory(datasetContent: DatasetExtraFiles, filepath?: string) {
return datasetContent.filter((entry) => {
if (entry.path.startsWith(`${filepath}/`)) {
entry.path = entry.path.replace(`${filepath}/`, "");
return entry;
}
});
}
const fields = [
{
key: "path",
sortable: true,
},
{
key: "class",
label: "Type",
sortable: true,
},
];
</script>

<template>
<div>
<b-table
Expand All @@ -13,72 +89,3 @@
</div>
</div>
</template>

<script>
import { mapCacheActions } from "vuex-cache";
export default {
props: {
history_dataset_id: {
type: String,
required: true,
},
path: {
type: String,
},
},
data() {
return {
directoryContent: false,
fields: [
{
key: "path",
sortable: true,
},
{
key: "class",
label: "Type",
sortable: true,
},
],
errorMessage: undefined,
};
},
created() {
this.fetchPathDestination({ history_dataset_id: this.history_dataset_id, path: this.path }).then(() => {
const pathDestination = this.$store.getters.pathDestination(this.history_dataset_id, this.path);
if (!pathDestination) {
this.errorMessage = `Dataset is not composite!`;
return;
}
if (pathDestination.fileLink) {
this.errorMessage = `is not a directory!`;
return;
}
if (pathDestination.isDirectory) {
this.directoryContent = this.removeParentDirectory(
pathDestination.datasetContent,
pathDestination.filepath
);
} else if (this.path === undefined || this.path === "undefined") {
this.directoryContent = pathDestination.datasetContent;
} else {
this.errorMessage = `is not found!`;
}
});
},
methods: {
...mapCacheActions(["fetchPathDestination"]),
removeParentDirectory(datasetContent, filepath) {
return datasetContent.filter((entry) => {
if (entry.path.startsWith(`${filepath}/`)) {
entry.path = entry.path.replace(`${filepath}/`, "");
return entry;
}
});
},
},
};
</script>
115 changes: 52 additions & 63 deletions client/src/components/Dataset/DatasetLink/DatasetLink.vue
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>
Loading

0 comments on commit f10614e

Please sign in to comment.