-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: OperatorSelector inconsistencies, operator filter bugs (#522)
- Loading branch information
Showing
8 changed files
with
49 additions
and
100 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,24 @@ | ||
import getAgencyList, { Agency } from 'src/api/agencyList' | ||
import getAgencyList from 'src/api/agencyList' | ||
|
||
export type Operator = { | ||
name: string | ||
id: string | ||
} | ||
|
||
export const getRelevantOperators = async (onlyRelevantOperators: boolean) => { | ||
export const MAJOR_OPERATORS = ['3', '5', '15', '18', '25', '34'] // ['אלקטרה אפיקים', 'דן', 'מטרופולין', 'קווים', 'אגד', 'תנופה'] | ||
|
||
/** | ||
* Get operators list, based on agencies fetched from MOT api | ||
* @param filter Operator ID list | ||
* @returns List of operators | ||
*/ | ||
export async function getOperators(filter?: string[]): Promise<Operator[]> { | ||
const agencyList = await getAgencyList() | ||
if (!onlyRelevantOperators) { | ||
const allOperators = agencyList.map((agency) => ({ | ||
name: agency.agency_name, | ||
id: agency.operator_ref.toString(), | ||
})) | ||
return allOperators | ||
} | ||
const relevant = [ | ||
'אגד', | ||
'אגד תעבורה', | ||
'אלקטרה אפיקים', | ||
'דן', | ||
'מטרופולין', | ||
'נתיב אקספרס', | ||
'סופרבוס', | ||
'קווים', | ||
'תנופה', | ||
] | ||
const agencyMap: Map<string, Agency> = new Map() | ||
agencyList.forEach((obj) => { | ||
if (obj) { | ||
agencyMap.set(obj.agency_name, obj) | ||
} | ||
}) | ||
const allOperators: Operator[] = agencyList.map((agency) => ({ | ||
name: agency.agency_name, | ||
id: agency.operator_ref.toString(), | ||
})) | ||
const res = allOperators.filter((op, i, a) => a.findIndex((op2) => op2.id === op.id) === i) // Filter duplicates | ||
|
||
const res = relevant.reduce((acc: Operator[], name: string): Operator[] => { | ||
return agencyMap.has(name) | ||
? [...acc, { name, id: (agencyMap.get(name) as Agency).operator_ref.toString() }] | ||
: acc | ||
}, []) | ||
return res | ||
return !filter ? res : res.filter((operator) => filter.includes(operator.id)) | ||
} |
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 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 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