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 selection of datastore when uploading dataset #5952

Merged
merged 3 commits into from
Jan 14, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
- Fixed a bug which caused that the keyboard delay wasn't respected properly when rapidly pressing a key. [#5947](https://github.com/scalableminds/webknossos/pull/5947)
- Fixed a bug where an organization would be created for an already existing email address. [#5949](https://github.com/scalableminds/webknossos/pull/5949)
- Fixed a bug where the paths of uploaded files were not checked correctly. [#5950](https://github.com/scalableminds/webknossos/pull/5950)
- Fixed that the used datastore could not be changed in the UI when uploading a dataset. [#5952](https://github.com/scalableminds/webknossos/pull/5952)

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function DatasetAddBossView(props: Props) {
};

trackAction("Add BossDB dataset");
await addWkConnectDataset(formValues.datastore.url, datasetConfig);
await addWkConnectDataset(formValues.datastoreUrl, datasetConfig);

Toast.success(messages["dataset.add_success"]);
await Utils.sleep(3000); // wait for 3 seconds so the server can catch up / do its thing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function DatasetAddNeuroglancerView({ datastores, onAdded, activeUser }: Props)
};

trackAction("Add Neuroglancer dataset");
await addWkConnectDataset(formValues.datastore.url, datasetConfig);
await addWkConnectDataset(formValues.datastoreUrl, datasetConfig);

Toast.success(messages["dataset.add_success"]);
await Utils.sleep(3000); // wait for 3 seconds so the server can catch up / do its thing
Expand Down
6 changes: 3 additions & 3 deletions frontend/javascripts/admin/dataset/dataset_components.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ export function DatastoreFormItem({
}) {
return (
<FormItem
name="datastore"
name="datastoreUrl"
label="Datastore"
hasFeedback
hidden={hidden || false}
rules={[{ required: true, message: messages["dataset.import.required.datastore"] }]}
initialValue={datastores.length ? datastores[0] : null}
initialValue={datastores.length ? datastores[0].url : null}
>
<Select
showSearch
Expand All @@ -86,7 +86,7 @@ export function DatastoreFormItem({
style={{ width: "100%" }}
options={datastores.map((datastore: APIDataStore) => ({
label: datastore.name,
value: datastore,
philippotto marked this conversation as resolved.
Show resolved Hide resolved
value: datastore.url,
}))}
/>
</FormItem>
Expand Down
24 changes: 17 additions & 7 deletions frontend/javascripts/admin/dataset/dataset_upload_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,13 @@ class DatasetUploadView extends React.Component<PropsWithFormAndRouter, State> {
const uploadableDatastores = this.props.datastores.filter(datastore => datastore.allowsUpload);
const currentFormRef = this.formRef.current;
if (currentFormRef != null) {
const selectedDataStore = currentFormRef.getFieldValue("datastore");
const selectedDataStoreUrl = currentFormRef.getFieldValue("datastoreUrl");
if (
prevProps.datastores.length === 0 &&
uploadableDatastores.length > 0 &&
(selectedDataStore == null || selectedDataStore.url !== uploadableDatastores[0].url)
(selectedDataStoreUrl == null || selectedDataStoreUrl !== uploadableDatastores[0].url)
) {
currentFormRef.setFieldsValue({ datastore: uploadableDatastores[0] });
currentFormRef.setFieldsValue({ datastoreUrl: uploadableDatastores[0].url });
}
}
}
Expand All @@ -178,6 +178,11 @@ class DatasetUploadView extends React.Component<PropsWithFormAndRouter, State> {
this.props.activeUser &&
(this.props.activeUser.isAdmin || this.props.activeUser.isDatasetManager);

getDatastoreForUrl(url: string): ?APIDataStore {
const uploadableDatastores = this.props.datastores.filter(datastore => datastore.allowsUpload);
return uploadableDatastores.find(ds => ds.url === url);
}

handleSubmit = async formValues => {
const { activeUser } = this.props;
const pathNameAtSubmit = window.location.pathname;
Expand Down Expand Up @@ -230,11 +235,11 @@ class DatasetUploadView extends React.Component<PropsWithFormAndRouter, State> {
initialTeams: formValues.initialTeams.map(team => team.id),
};

await reserveDatasetUpload(formValues.datastore.url, reserveUploadInformation);
await reserveDatasetUpload(formValues.datastoreUrl, reserveUploadInformation);

const resumableUpload = await createResumableUpload(
datasetId,
formValues.datastore.url,
formValues.datastoreUrl,
uploadId,
);

Expand All @@ -254,19 +259,24 @@ class DatasetUploadView extends React.Component<PropsWithFormAndRouter, State> {

this.setState({ isFinishing: true });

finishDatasetUpload(formValues.datastore.url, uploadInfo).then(
finishDatasetUpload(formValues.datastoreUrl, uploadInfo).then(
async () => {
trackAction("Upload dataset");
await Utils.sleep(3000); // wait for 3 seconds so the server can catch up / do its thing
Toast.success(messages["dataset.upload_success"]);
let maybeError;
if (this.state.needsConversion) {
try {
const datastore = this.getDatastoreForUrl(formValues.datastoreUrl);
if (!datastore) {
throw new Error("Selected datastore does not match available datastores");
}

await startConvertToWkwJob(
formValues.name,
activeUser.organization,
formValues.scale,
formValues.datastore.name,
datastore.name,
);
} catch (error) {
maybeError = error;
Expand Down