-
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 #17145 from davelopez/migrate_dataset_ext_files_st…
…ore_pinia Migrate dataset extra files store to Pinia
- Loading branch information
Showing
9 changed files
with
176 additions
and
89 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { DatasetExtraFiles, getCompositeDatasetLink } from "@/api/datasets"; | ||
import { useDatasetExtraFilesStore } from "@/stores/datasetExtraFilesStore"; | ||
|
||
interface PathDestination { | ||
datasetContent: DatasetExtraFiles; | ||
isDirectory: boolean; | ||
filepath?: string; | ||
fileLink?: string; | ||
} | ||
|
||
export async function getPathDestination(dataset_id: string, path?: string): Promise<PathDestination | null> { | ||
const datasetExtraFilesStore = useDatasetExtraFilesStore(); | ||
|
||
let datasetExtraFiles = datasetExtraFilesStore.getDatasetExtraFiles(dataset_id); | ||
if (!datasetExtraFiles) { | ||
await datasetExtraFilesStore.fetchDatasetExtFilesByDatasetId({ id: dataset_id }); | ||
datasetExtraFiles = datasetExtraFilesStore.getDatasetExtraFiles(dataset_id); | ||
} | ||
|
||
if (datasetExtraFiles === null) { | ||
return null; | ||
} | ||
|
||
const pathDestination: PathDestination = { datasetContent: datasetExtraFiles, isDirectory: false, filepath: path }; | ||
|
||
if (path === undefined || path === "undefined") { | ||
return pathDestination; | ||
} | ||
|
||
const filepath = path; | ||
|
||
const datasetEntry = datasetExtraFiles?.find((entry) => { | ||
return filepath === entry.path; | ||
}); | ||
|
||
if (datasetEntry) { | ||
if (datasetEntry.class === "Directory") { | ||
pathDestination.isDirectory = true; | ||
pathDestination.filepath = filepath; | ||
return pathDestination; | ||
} | ||
pathDestination.fileLink = getCompositeDatasetLink(dataset_id, datasetEntry.path); | ||
} | ||
return pathDestination; | ||
} |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { defineStore } from "pinia"; | ||
import { computed, del, ref, set } from "vue"; | ||
|
||
import { DatasetExtraFiles, fetchDatasetExtraFiles } from "@/api/datasets"; | ||
|
||
export const useDatasetExtraFilesStore = defineStore("datasetExtraFilesStore", () => { | ||
const storedDatasetExtraFiles = ref<{ [key: string]: DatasetExtraFiles }>({}); | ||
const loading = ref<{ [key: string]: boolean }>({}); | ||
|
||
const getDatasetExtraFiles = computed(() => { | ||
return (datasetId: string) => { | ||
const datasetExtFiles = storedDatasetExtraFiles.value[datasetId]; | ||
if (!datasetExtFiles && !loading.value[datasetId]) { | ||
fetchDatasetExtFilesByDatasetId({ id: datasetId }); | ||
} | ||
return datasetExtFiles ?? null; | ||
}; | ||
}); | ||
|
||
const isLoadingDatasetExtraFiles = computed(() => { | ||
return (datasetId: string) => { | ||
return loading.value[datasetId] ?? false; | ||
}; | ||
}); | ||
|
||
async function fetchDatasetExtFilesByDatasetId(params: { id: string }) { | ||
const datasetId = params.id; | ||
set(loading.value, datasetId, true); | ||
try { | ||
const { data: datasetExtFiles } = await fetchDatasetExtraFiles({ | ||
dataset_id: datasetId, | ||
}); | ||
set(storedDatasetExtraFiles.value, datasetId, datasetExtFiles); | ||
return datasetExtFiles; | ||
} finally { | ||
del(loading.value, datasetId); | ||
} | ||
} | ||
|
||
return { | ||
storedDatasetExtraFiles, | ||
getDatasetExtraFiles, | ||
isLoadingDatasetExtraFiles, | ||
fetchDatasetExtFilesByDatasetId, | ||
}; | ||
}); |
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