Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: download code snippets #1315

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,21 @@ export function getDatasetCodeSnippet(datasetId?: number) {
client = Client()

dataset = Dataset.get_by_id(client, ${datasetId})
dataset.download_everything('${datasetId}')
dataset.download_everything()
`
}

export function getAllTomogramsCodeSnippet(tomogramVoxelId?: number) {
export function getAllTomogramsCodeSnippet(runId?: number) {
return dedent`
from cryoet_data_portal import (
Client,
TomogramVoxelSpacing,
Run,
)

client = Client()
tomogram_voxel_spacing = TomogramVoxelSpacing.get_by_id(
client,
${tomogramVoxelId},
)
run = Run.get_by_id(client, ${runId})

for annotation in tomogram_voxel_spacing.annotations:
for annotation in run.annotations:
annotation.download()
`
}
Expand Down Expand Up @@ -78,8 +75,7 @@ export function getAnnotationCodeSnippet(

export function APIDownloadTab() {
const { t } = useI18n()
const { datasetId, tomogramId, tomogramVoxelId, type } =
useDownloadModalContext()
const { runId, datasetId, tomogramId, type } = useDownloadModalContext()
const { annotationId, downloadConfig, fileFormat } =
useDownloadModalQueryParamState()
const { logPlausibleCopyEvent } = useLogPlausibleCopyEvent()
Expand All @@ -97,7 +93,7 @@ export function APIDownloadTab() {
{ type: 'runs', downloadConfig: DownloadConfig.AllAnnotations },
() => ({
label: t('copyApiCodeSnippet'),
content: getAllTomogramsCodeSnippet(tomogramVoxelId),
content: getAllTomogramsCodeSnippet(runId),
calloutKey: 'preferToDownloadViaApiCode',
logType: 'voxel-spacing-id',
}),
Expand Down Expand Up @@ -134,9 +130,9 @@ export function APIDownloadTab() {
datasetId,
downloadConfig,
fileFormat,
runId,
t,
tomogramId,
tomogramVoxelId,
type,
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ export class DownloadDialogActor {
const clipboardValue = await clipboard.jsonValue()

const { data } = await fetchTestSingleRun(client)
const voxelSpacingId = data.runs[0].tomogram_voxel_spacings[0].id
const expectedCommand = getAllTomogramsCodeSnippet(voxelSpacingId)
const runId = data.runs[0].id
const expectedCommand = getAllTomogramsCodeSnippet(runId)

expect(clipboardValue).toBe(expectedCommand)
}
Expand Down
Loading