Skip to content

Use name where licence number isn't present #330

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

Merged
merged 1 commit into from
Oct 20, 2020
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
10 changes: 6 additions & 4 deletions src/components/crew/crew-view/crew-view.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ class CrewViewPage extends Component {

componentDidMount() {
const filter = JSON.parse(this.props.match.params.filter);
const isCaptain = filter["captain.license"] !== undefined;
let licenseNumber;
const isCaptain = filter["captain.license"] !== undefined || filter["captain.name"] !== undefined;
let licenseNumber, captainName, crewName;
if (isCaptain){
licenseNumber = filter["captain.license"]
captainName = filter["captain.name"]
} else {
licenseNumber = filter["crew.license"];
crewName = filter["crew.name"]
}
this.setState({ loading: true }, () => {
overviewService
Expand All @@ -73,8 +75,8 @@ class CrewViewPage extends Component {
notes: dataHelper.getNotes(licenseNumber),
captainName: dataHelper.getCaptainName(licenseNumber),
crewName: isCaptain ?
dataHelper.getCaptainName(licenseNumber):
dataHelper.getCrewName(licenseNumber),
dataHelper.getCaptainName(licenseNumber || captainName):
dataHelper.getCrewName(licenseNumber || crewName),
Comment on lines +78 to +79
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dataHelper functions find data using name when licence number is absent.

getCaptainName(item) {
let captainName;
this.boardings.forEach((boarding) => {
if (boarding.captain.license === item || boarding.captain.name === item) {
captainName = boarding.captain.name;
}
});
return captainName;
}

photos: dataHelper.getPhotos(licenseNumber),
};

Expand Down
4 changes: 2 additions & 2 deletions src/components/partials/boarding-data.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,12 @@ export default class BoardingDataHelper {
return Object.keys(collection);
}

getCrewName(license) {
getCrewName(item) {
let name;
this.boardings.forEach((boarding) => {
if (boarding.crew && boarding.crew.length) {
for (let crew of boarding.crew) {
if (crew.license === license) {
if (crew.license === item || crew.name === item) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Earlier I missed out the crew name function. This is fixed now.

name = crew.name;
}
}
Expand Down