Skip to content

Commit

Permalink
Modernize DatasetStorage.vue.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Feb 7, 2024
1 parent 364797c commit c743c58
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 69 deletions.
2 changes: 2 additions & 0 deletions client/src/api/datasets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export async function getDatasets(options: GetDatasetsOptions = {}) {

export const fetchDataset = fetcher.path("/api/datasets/{dataset_id}").method("get").create();

export const fetchDatasetStorage = fetcher.path("/api/datasets/{dataset_id}/storage").method("get").create();

export async function fetchDatasetDetails(params: { id: string }): Promise<DatasetDetails> {
const { data } = await fetchDataset({ dataset_id: params.id, view: "detailed" });
// We know that the server will return a DatasetDetails object because of the view parameter
Expand Down
5 changes: 5 additions & 0 deletions client/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ export type DatasetSummary = components["schemas"]["HDASummary"];
*/
export type DatasetDetails = components["schemas"]["HDADetailed"];

/**
* Contains storage (object store, quota, etc..) details for a dataset.
*/
export type DatasetStorageDetails = components["schemas"]["DatasetStorageDetails"];

/**
* Represents a HistoryDatasetAssociation with either summary or detailed information.
*/
Expand Down
129 changes: 60 additions & 69 deletions client/src/components/Dataset/DatasetStorage/DatasetStorage.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,63 @@
<script setup lang="ts">
import { computed, ref, watch } from "vue";
import { DatasetStorageDetails } from "@/api";
import { fetchDatasetStorage } from "@/api/datasets";
import { errorMessageAsString } from "@/utils/simple-error";
import LoadingSpan from "@/components/LoadingSpan.vue";
import DescribeObjectStore from "@/components/ObjectStore/DescribeObjectStore.vue";
interface DatasetStorageProps {
datasetId: string;
datasetType: "hda" | "ldda";
includeTitle: boolean;
}
const props = withDefaults(defineProps<DatasetStorageProps>(), {
datasetType: "hda",
includeTitle: true,
});
const storageInfo = ref<DatasetStorageDetails | null>(null);
const errorMessage = ref<string | null>(null);
const discarded = computed(() => {
return storageInfo.value?.dataset_state == "discarded";
});
const deferred = computed(() => {
return storageInfo.value?.dataset_state == "deferred";
});
const sourceUri = computed(() => {
const sources = storageInfo.value?.sources;
if (!sources) {
return null;
}
const rootSources = sources.filter((source) => !source.extra_files_path);
if (rootSources.length == 0) {
return null;
}
return rootSources[0]?.source_uri;
});
watch(
props,
async () => {
const datasetId = props.datasetId;
const datasetType = props.datasetType;
try {
const { data } = await fetchDatasetStorage({ dataset_id: datasetId, hda_ldda: datasetType });
storageInfo.value = data;
} catch (error) {
errorMessage.value = errorMessageAsString(error);
}
},
{ immediate: true }
);
</script>

<template>
<div>
<h2 v-if="includeTitle" class="h-md">Dataset Storage</h2>
Expand All @@ -20,72 +80,3 @@
</div>
</div>
</template>

<script>
import axios from "axios";
import LoadingSpan from "components/LoadingSpan";
import DescribeObjectStore from "components/ObjectStore/DescribeObjectStore";
import { getAppRoot } from "onload/loadConfig";
import { errorMessageAsString } from "utils/simple-error";
export default {
components: {
DescribeObjectStore,
LoadingSpan,
},
props: {
datasetId: {
type: String,
},
datasetType: {
type: String,
default: "hda",
},
includeTitle: {
type: Boolean,
default: true,
},
},
data() {
return {
storageInfo: null,
errorMessage: null,
};
},
computed: {
discarded() {
return this.storageInfo.dataset_state == "discarded";
},
deferred() {
return this.storageInfo.dataset_state == "deferred";
},
sourceUri() {
const sources = this.storageInfo.sources;
if (!sources) {
return null;
}
const rootSources = sources.filter((source) => !source.extra_files_path);
if (rootSources.length == 0) {
return null;
}
return rootSources[0].source_uri;
},
},
created() {
const datasetId = this.datasetId;
const datasetType = this.datasetType;
axios
.get(`${getAppRoot()}api/datasets/${datasetId}/storage`, { hda_ldda: datasetType })
.then(this.handleResponse)
.catch((errorMessage) => {
this.errorMessage = errorMessageAsString(errorMessage);
});
},
methods: {
handleResponse(response) {
const storageInfo = response.data;
this.storageInfo = storageInfo;
},
},
};
</script>

0 comments on commit c743c58

Please sign in to comment.