From c80496dafadba9778a930090cc07438703a05693 Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Mon, 23 May 2022 18:05:35 -0400 Subject: [PATCH 1/3] improvement(GtfsPlusField): Add a GTFS_ROUTE_NOT_ADDED type that hides route_ids alreadyin use. --- gtfsplus.yml | 2 +- lib/gtfs/components/gtfs-search.js | 24 +++++++++++++++++++++--- lib/gtfsplus/components/GtfsPlusField.js | 19 ++++++++++++++----- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/gtfsplus.yml b/gtfsplus.yml index 8a568cdc4..f92b0187d 100644 --- a/gtfsplus.yml +++ b/gtfsplus.yml @@ -347,7 +347,7 @@ fields: - name: route_id required: true - inputType: GTFS_ROUTE + inputType: GTFS_ROUTE_NOT_ADDED columnWidth: 4 helpContent: From GTFS routes.txt file. This is necessary to maintain relationship between routes in this file and routes in the standard GTFS routes.txt file. - name: category diff --git a/lib/gtfs/components/gtfs-search.js b/lib/gtfs/components/gtfs-search.js index da82b4984..6a8e26faa 100644 --- a/lib/gtfs/components/gtfs-search.js +++ b/lib/gtfs/components/gtfs-search.js @@ -7,7 +7,6 @@ import {Async} from 'react-select' import {getRouteName} from '../../editor/util/gtfs' import {searchEntitiesWithString} from '../util' - import type {Feed, GtfsRoute, GtfsStop, User} from '../../types' import type {AppState} from '../../types/reducers' @@ -21,6 +20,7 @@ export type GtfsOption = { type Props = { entities: Array, + excludedEntityIds: Array, feeds: Array, filterByRoute?: GtfsRoute, filterByStop?: GtfsStop, @@ -109,7 +109,16 @@ class GtfsSearch extends Component { * @param {String} input text string to search */ _loadOptions = (input: string) => { - const {entities, feeds, filterByRoute, filterByStop, namespace, user} = this.props + const { + entities, + excludedEntityIds, + feeds, + filterByRoute, + filterByStop, + namespace, + user, + value: currentOption + } = this.props // $FlowFixMe kind of cryptic error, ignoring for now let queries = [] if (namespace) { @@ -142,7 +151,16 @@ class GtfsSearch extends Component { // Entities must be mapped to options here in order to make use of // feed references. stops && stopOptions.push(...stops.map(s => _entityToOption(s, feed))) - routes && routeOptions.push(...routes.map(r => _entityToOption(r, feed))) + routes && routeOptions.push( + ...routes + // Remove specified entity ids (route ids in this case) to exclude, except the current value. + .filter(route => + !excludedEntityIds.includes(route.route_id) || + // (Extended type checks are for flow validation.) + (route.route_id === (typeof currentOption === 'object' ? currentOption && currentOption.value : currentOption)) + ) + .map(r => _entityToOption(r, feed)) + ) } else { const feedName = feed ? feed.name : responseNamespace console.warn(`Could not search GTFS entities (query: "${input}") for ${feedName}`, results) diff --git a/lib/gtfsplus/components/GtfsPlusField.js b/lib/gtfsplus/components/GtfsPlusField.js index bb894e769..30b7669cb 100644 --- a/lib/gtfsplus/components/GtfsPlusField.js +++ b/lib/gtfsplus/components/GtfsPlusField.js @@ -42,7 +42,7 @@ export default class GtfsPlusField extends Component { } render () { - const {currentValue, data: rowData, feedVersionSummary, field, getGtfsEntity} = this.props + const {currentValue, data: rowData, feedVersionSummary, field, getGtfsEntity, rows} = this.props const namespace = feedVersionSummary && feedVersionSummary.namespace switch (field.inputType) { case 'TEXT': @@ -98,6 +98,7 @@ export default class GtfsPlusField extends Component { ) case 'GTFS_ROUTE': + case 'GTFS_ROUTE_NOT_ADDED': const routeEntity = ((getGtfsEntity('route', currentValue): any): GtfsRoute) const routeValue = routeEntity ? { @@ -106,16 +107,24 @@ export default class GtfsPlusField extends Component { } : null + // If this field is of type GTFS_ROUTE_NOT_ADDED, only display in the dropdown route ids + // that are not already used as route_id in other rows in the table. + const excludedEntityIds = field.inputType === 'GTFS_ROUTE_NOT_ADDED' + ? rows.map(row => row.route_id) + : [] + return ( + value={routeValue} + /> ) case 'GTFS_STOP': const stopEntity = ((getGtfsEntity('stop', currentValue): any): GtfsStop) From 9dee4be05cbbc4378bc6431226a48fb144fa57e8 Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Thu, 26 May 2022 15:42:59 -0400 Subject: [PATCH 2/3] refactor(GtfsPlusField): Display unused routes using entries from entire table. --- lib/gtfsplus/components/GtfsPlusField.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/gtfsplus/components/GtfsPlusField.js b/lib/gtfsplus/components/GtfsPlusField.js index 30b7669cb..5946e185e 100644 --- a/lib/gtfsplus/components/GtfsPlusField.js +++ b/lib/gtfsplus/components/GtfsPlusField.js @@ -42,7 +42,14 @@ export default class GtfsPlusField extends Component { } render () { - const {currentValue, data: rowData, feedVersionSummary, field, getGtfsEntity, rows} = this.props + const { + currentValue, + data: rowData, + feedVersionSummary, + field, + getGtfsEntity, + tableData + } = this.props const namespace = feedVersionSummary && feedVersionSummary.namespace switch (field.inputType) { case 'TEXT': @@ -108,9 +115,9 @@ export default class GtfsPlusField extends Component { : null // If this field is of type GTFS_ROUTE_NOT_ADDED, only display in the dropdown route ids - // that are not already used as route_id in other rows in the table. - const excludedEntityIds = field.inputType === 'GTFS_ROUTE_NOT_ADDED' - ? rows.map(row => row.route_id) + // that are not already used as route_id in other rows in the entire table. + const excludedEntityIds = field.inputType === 'GTFS_ROUTE_NOT_ADDED' && tableData + ? tableData.route_attributes.map(row => row.route_id) : [] return ( From 7c7c5997f0ecc9c6f5c722af3324e86766859223 Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Thu, 26 May 2022 17:12:19 -0400 Subject: [PATCH 3/3] fix(gtfs/util): Remove the hardcoded limit of 30 to make it work with GTFS_ROUTE_NOT_ADDED dropdown. --- lib/gtfs/util/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/gtfs/util/index.js b/lib/gtfs/util/index.js index a65575e91..296219720 100644 --- a/lib/gtfs/util/index.js +++ b/lib/gtfs/util/index.js @@ -6,7 +6,6 @@ import {GTFS_GRAPHQL_PREFIX} from '../../common/constants' import {getGtfsSpec} from '../../common/util/config' import {routeSearch, stopSearch} from '../util/graphql' import {getHeaders} from '../../common/util/util' - import type {GtfsRoute, GtfsStop, User} from '../../types' export function getEntityIdField (type: string): string { @@ -229,6 +228,8 @@ export function searchEntitiesWithString ( const includeStopSubQuery = !!filterByRoute // Build routes/stops query based on entities searching and whether we're // filtering by a specific route or stop ID. + // FIXME: Removed the hardcoded limit of 30 on the route search so it works with the GTFS_ROUTE_NOT_ADDED field, + // but does removing that negatively affect anything else? const body = JSON.stringify({ query: ` query ( @@ -239,7 +240,7 @@ query ( ) { feed(namespace: $namespace) { ${queryForRoutes && includeRouteSubQuery ? stopSearch(true, 30) : ''} - ${queryForRoutes && !includeRouteSubQuery ? routeSearch(false, 30) : ''} + ${queryForRoutes && !includeRouteSubQuery ? routeSearch(false) : ''} ${queryForStops && includeStopSubQuery ? routeSearch(true, 30) : ''} ${queryForStops && !includeStopSubQuery ? stopSearch(false, 30) : ''} }