Skip to content

Commit

Permalink
Merge pull request #1439 from phac-nml/hotfix-ncbi-export
Browse files Browse the repository at this point in the history
HOTFIX: Fixed issue with export file and instrument model using the NCBI Exporter
  • Loading branch information
ericenns authored Dec 21, 2022
2 parents e8eba00 + dd63177 commit 341832e
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 40 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

# Changelog

## Unreleased
* [UI]: Fixed bug on NCBI Export page preventing the export from occuring. See [PR 1439](https://github.com/phac-nml/irida/pull/1439)

## [22.09.5] - 2022/12/14
* [Developer/UI]: Fixed bug preventing a manager of a user group from adding new members when this manager is a collaborator on one of these users projects. Also, fixed issue with a user group member added with an owner role for a group was set with a member role. See [PR 1431](https://github.com/phac-nml/irida/pull/1431)
* [Developer/UI]: Updated synchronize new remote project page to display http errors when setting the url manually and an error is encountered. See [PR 1433](https://github.com/phac-nml/irida/pull/1433)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ import {
Form,
Input,
Layout,
notification,
PageHeader,
Row,
Space,
notification,
} from "antd";
import type { RangePickerProps } from "antd/es/date-picker";
import { LabeledValue } from "antd/lib/select";
import moment from "moment";
import React from "react";
import { useLoaderData, useNavigate, useParams } from "react-router-dom";
import {
NcbiSubmissionBioSample,
NcbiSubmissionRequest,
getNCBISelections,
getNCBISources,
getNCBIStrategies,
NcbiSubmissionBioSample,
NcbiSubmissionRequest,
submitNcbiSubmissionRequest,
} from "../../../../apis/export/ncbi";
import { SequencingFiles } from "../../../../apis/projects/samples";
Expand Down Expand Up @@ -85,12 +85,12 @@ export interface UpdateDefaultValues {
(field: DefaultModifiableField, value: string | string[]): void;
}

enum CreateStatus {
REJECTED,
RESOLVED,
PENDING,
IDLE,
}
const CreateStatus = {
REJECTED: 0,
RESOLVED: 1,
PENDING: 2,
IDLE: 3,
} as const;

/**
* React router loader
Expand Down Expand Up @@ -133,7 +133,7 @@ function CreateNcbiExport(): JSX.Element {
);
const [formSamples, setFormSamples] = React.useState<FormSamples>({});
const [invalid, setInvalid] = React.useState<SampleRecord[]>([]);
const [createStatus, setCreateStatus] = React.useState<CreateStatus>(
const [createStatus, setCreateStatus] = React.useState<number>(
CreateStatus.IDLE
);

Expand Down Expand Up @@ -216,17 +216,15 @@ function CreateNcbiExport(): JSX.Element {
releaseDate: moment.Moment;
samples: {
string: {
files: {
pairs?: number[];
singles?: number[];
};
pairs?: number[];
singles?: number[];
bioSample: string;
libraryName: string;
libraryStrategy: string;
librarySource: string;
libraryConstructionProtocol: string;
instrumentModel: [string, string];
librarySelection: string;
libraryName: { value: string };
libraryStrategy: { value: string };
librarySource: { value: string };
libraryConstructionProtocol: { value: string };
instrumentModel: { value: [string, string] };
librarySelection: { value: string };
};
};
}) => {
Expand All @@ -239,15 +237,26 @@ function CreateNcbiExport(): JSX.Element {
releaseDate: releaseDate.unix(),
samples: Object.values(_samples).map(
({
files = { pairs: [], singles: [] },
pairs = [],
singles = [],
bioSample,
libraryName,
libraryStrategy,
librarySource,
libraryConstructionProtocol,
instrumentModel,
...rest
librarySelection,
}): NcbiSubmissionBioSample => {
return {
...rest,
instrumentModel: instrumentModel[1],
singles: files.singles ? files.singles : [],
pairs: files.pairs ? files.pairs : [],
singles,
pairs,
bioSample,
libraryName: libraryName.value,
libraryStrategy: libraryStrategy.value,
librarySource: librarySource.value,
libraryConstructionProtocol: libraryConstructionProtocol.value,
instrumentModel: instrumentModel.value[1],
librarySelection: librarySelection.value,
};
}
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,36 @@ export default function CreateNcbiSampleDetails({
value: file.id,
}));

async function filesValidator(
singlesFiles = [],
pairsFiles = []
): Promise<string> {
if (singlesFiles.length > 0 || pairsFiles.length > 0) {
return Promise.resolve("");
}
return Promise.reject(
new Error("Must select at least one file of any type.")
);
}

function validateFiles({ getFieldValue, associatedField }) {
return {
validator(_, value) {
const otherFiles = getFieldValue([
"samples",
sample.name,
associatedField,
]);
if (otherFiles.length > 0 || value.length > 0) {
return Promise.resolve("");
}
return Promise.reject(
new Error("Must select at least one file of any type.")
);
},
};
}

return (
<Row gutter={[16, 16]}>
<Col md={12} xs={24}>
Expand Down Expand Up @@ -249,11 +279,19 @@ export default function CreateNcbiSampleDetails({
label={i18n("CreateNcbiExport.singles")}
valuePropName="checked"
className="t-samples-singles"
rules={[
({ getFieldValue }) =>
validateFiles({ getFieldValue, associatedField: "pairs" }),
]}
>
<Checkbox.Group
style={{ width: `100%` }}
options={singles}
onChange={onChange}
onChange={function () {
form
.validateFields([["samples", sample.name, "pairs"]])
.then(onChange);
}}
/>
</Form.Item>
</Col>
Expand All @@ -264,11 +302,19 @@ export default function CreateNcbiSampleDetails({
name={["samples", sample.name, "pairs"]}
label={i18n("CreateNcbiExport.pairs")}
valuePropName="checked"
rules={[
({ getFieldValue }) =>
validateFiles({ getFieldValue, associatedField: "singles" }),
]}
>
<Checkbox.Group
style={{ width: `100%` }}
options={pairs}
onChange={onChange}
onChange={function () {
form
.validateFields([["samples", sample.name, "singles"]])
.then(onChange);
}}
/>
</Form.Item>
</Col>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public void toggleDefaultsPanel() {
public void setDefaultStrategySelect(String strategy) {
defaultStrategySelect.click();
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(1));
List<WebElement> selectOptions = wait
.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.className("ant-select-item")));
List<WebElement> selectOptions = wait.until(
ExpectedConditions.presenceOfAllElementsLocatedBy(By.className("ant-select-item")));
for (WebElement option : selectOptions) {
if (option.getAttribute("title").equals(strategy)) {
option.click();
Expand Down Expand Up @@ -120,8 +120,8 @@ public void setSelectForSampleFieldValue(String field, String value) {
WebElement select = driver.findElement(By.className("t-sample-" + field));
select.click();
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(1));
List<WebElement> selectOptions = wait
.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.className("ant-select-item")));
List<WebElement> selectOptions = wait.until(
ExpectedConditions.presenceOfAllElementsLocatedBy(By.className("ant-select-item")));
for (WebElement option : selectOptions) {
if (option.getAttribute("title").equals(value)) {
option.click();
Expand All @@ -134,8 +134,8 @@ public void setCascaderForSampleField(String field, String firstValue, String se
WebElement cascader = driver.findElement(By.className("t-sample-" + field));
cascader.click();
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(1));
List<WebElement> cascaderMenus = wait
.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.className("ant-cascader-menu")));
List<WebElement> cascaderMenus = wait.until(
ExpectedConditions.presenceOfAllElementsLocatedBy(By.className("ant-cascader-menu")));
for (WebElement option : cascaderMenus.get(0).findElements(By.className("ant-cascader-menu-item"))) {
if (option.getText().equals(firstValue)) {
option.click();
Expand Down Expand Up @@ -182,10 +182,12 @@ public void selectSingleEndSequenceFile(String filename) {
}

public boolean areFormErrorsPresent() {
waitForTime(250);
waitForTime(500);
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
try {
List<WebElement> errors = driver.findElements(By.className("ant-form-item-explain-error"));
return errors != null && errors.size() > 0;
List<WebElement> errors = wait.until(
ExpectedConditions.visibilityOfAllElementsLocatedBy(By.className("ant-form-item-explain-error")));
return errors.size() > 0;
} catch (Exception e) {
return false;
}
Expand All @@ -196,6 +198,11 @@ public void submitExportForm() {
}

public boolean isSuccessAlertDisplayed() {
return driver.findElements(By.cssSelector(".ant-alert.ant-alert-success")).size() == 0;
return driver.findElements(By.cssSelector(".ant-alert.ant-alert-success")).size() == 1;
}

public boolean isUserRedirectedToProjectSamplesPage(int projectId) {
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
return wait.until(ExpectedConditions.urlMatches("/projects/" + projectId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ void testCreateNcbiSubmission() throws Exception {
String DEFAULT_PROTOCOL = "DEFAULT_PROTOCOL";

LoginPage.loginAsManager(driver());
ProjectSamplesPage samplesPage = ProjectSamplesPage.goToPage(driver(), 1);
int PROJECT_ID = 1;
ProjectSamplesPage samplesPage = ProjectSamplesPage.goToPage(driver(), PROJECT_ID);
samplesPage.selectSampleByName(SAMPLE_1);
samplesPage.selectSampleByName(SAMPLE_2);
samplesPage.selectSampleByName(SAMPLE_3);
Expand Down Expand Up @@ -81,6 +82,7 @@ void testCreateNcbiSubmission() throws Exception {

page.submitExportForm();
assertTrue(page.isSuccessAlertDisplayed(), "Success notification should be displayed");

assertTrue(page.isUserRedirectedToProjectSamplesPage(PROJECT_ID),
"User should be redirected within 5 seconds of submission");
}
}

0 comments on commit 341832e

Please sign in to comment.