Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev-2.x' into trimet-vector-layer
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Sep 13, 2024
2 parents 966a7c9 + c19cef5 commit dd2d0df
Show file tree
Hide file tree
Showing 108 changed files with 25,840 additions and 754 deletions.
2 changes: 1 addition & 1 deletion client/.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VITE_API_URL=/otp/transmodel/v3
VITE_DEBUG_STYLE_URL=/otp/routers/default/inspector/vectortile/style.json

VITE_GRAPHIQL_URL=/graphiql?flavor=transmodel
3 changes: 2 additions & 1 deletion client/.env.development
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
VITE_API_URL=http://localhost:8080/otp/transmodel/v3
VITE_DEBUG_STYLE_URL=http://localhost:8080/otp/routers/default/inspector/vectortile/style.json
VITE_DEBUG_STYLE_URL=http://localhost:8080/otp/routers/default/inspector/vectortile/style.json
VITE_GRAPHIQL_URL=http://localhost:8080/graphiql?flavor=transmodel
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { authorityQueryAsString } from '../../static/query/authorityQuery.tsx';
import { Maybe } from '../../gql/graphql.ts';
const graphiQLUrl = import.meta.env.VITE_GRAPHIQL_URL;

export function ItineraryGraphiQLAuthorityLink({
legId,
legName,
}: {
legId: string | undefined;
legName: Maybe<string> | undefined;
}) {
const queryID = { id: legId };
const formattedQuery = encodeURIComponent(authorityQueryAsString);
const formattedQueryID = encodeURIComponent(JSON.stringify(queryID));

return (
<a
href={graphiQLUrl + '&query=' + formattedQuery + '&variables=' + formattedQueryID}
target={'_blank'}
rel={'noreferrer'}
>
{legName}
</a>
);
}
18 changes: 18 additions & 0 deletions client/src/components/ItineraryList/ItineraryGraphiQLLineLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { lineQueryAsString } from '../../static/query/lineQuery.tsx';
const graphiQLUrl = import.meta.env.VITE_GRAPHIQL_URL;

export function ItineraryGraphiQLLineLink({ legId, legName }: { legId: string; legName: string }) {
const queryID = { id: legId };
const formattedQuery = encodeURIComponent(lineQueryAsString);
const formattedQueryID = encodeURIComponent(JSON.stringify(queryID));

return (
<a
href={graphiQLUrl + '&query=' + formattedQuery + '&variables=' + formattedQueryID}
target={'_blank'}
rel={'noreferrer'}
>
{legName}
</a>
);
}
25 changes: 25 additions & 0 deletions client/src/components/ItineraryList/ItineraryGraphiQLQuayLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { quayQueryAsString } from '../../static/query/quayQuery.tsx';
import { Maybe } from '../../gql/graphql.ts';
const graphiQLUrl = import.meta.env.VITE_GRAPHIQL_URL;

export function ItineraryGraphiQLQuayLink({
legId,
legName,
}: {
legId: string | undefined;
legName: Maybe<string> | undefined;
}) {
const queryID = { id: legId };
const formattedQuery = encodeURIComponent(quayQueryAsString);
const formattedQueryID = encodeURIComponent(JSON.stringify(queryID));

return (
<a
href={graphiQLUrl + '&query=' + formattedQuery + '&variables=' + formattedQueryID}
target={'_blank'}
rel={'noreferrer'}
>
{legName}
</a>
);
}
16 changes: 10 additions & 6 deletions client/src/components/ItineraryList/ItineraryLegDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { LegTime } from './LegTime.tsx';
import { formatDistance } from '../../util/formatDistance.ts';
import { formatDuration } from '../../util/formatDuration.ts';
import { InterchangeInfo } from './InterchangeInfo.tsx';
import { ItineraryGraphiQLLineLink } from './ItineraryGraphiQLLineLink.tsx';
import { ItineraryGraphiQLQuayLink } from './ItineraryGraphiQLQuayLink.tsx';
import { ItineraryGraphiQLAuthorityLink } from './ItineraryGraphiQLAuthorityLink.tsx';

export function ItineraryLegDetails({ leg, isLast }: { leg: Leg; isLast: boolean }) {
return (
Expand All @@ -17,19 +20,20 @@ export function ItineraryLegDetails({ leg, isLast }: { leg: Leg; isLast: boolean
<b>{leg.mode}</b>{' '}
{leg.line && (
<>
<u>
{leg.line.publicCode} {leg.toEstimatedCall?.destinationDisplay?.frontText}
</u>
, {leg.authority?.name}
<ItineraryGraphiQLLineLink
legId={leg.line?.id}
legName={leg.line.publicCode + ' ' + leg.toEstimatedCall?.destinationDisplay?.frontText}
/>
, <ItineraryGraphiQLAuthorityLink legId={leg.authority?.id} legName={leg.authority?.name} />
</>
)}{' '}
{leg.mode !== Mode.Foot && (
<>
<br />
<u title={leg.fromPlace.quay?.id}>{leg.fromPlace.name}</u>{' '}
<ItineraryGraphiQLQuayLink legId={leg.fromPlace.quay?.id} legName={leg.fromPlace.name} />{' '}
</>
)}{' '}
{!isLast && <u title={leg.toPlace.quay?.id}>{leg.toPlace.name}</u>}
{!isLast && <ItineraryGraphiQLQuayLink legId={leg.toPlace.quay?.id} legName={leg.toPlace.name} />}
</div>
</div>
);
Expand Down
18 changes: 18 additions & 0 deletions client/src/components/SearchBar/GraphiQLRouteButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Button } from 'react-bootstrap';
import { TripQueryVariables } from '../../gql/graphql.ts';
import { queryAsString } from '../../static/query/tripQuery.tsx';
const graphiQLUrl = import.meta.env.VITE_GRAPHIQL_URL;

function GraphiQLRouteButton({ tripQueryVariables }: { tripQueryVariables: TripQueryVariables }) {
const formattedVariables = encodeURIComponent(JSON.stringify(tripQueryVariables));
const formattedQuery = encodeURIComponent(queryAsString);

return (
<div className="search-bar-route-button-wrapper">
<Button href={graphiQLUrl + '&query=' + formattedQuery + '&variables=' + formattedVariables} target={'_blank'}>
GraphiQL
</Button>
</div>
);
}
export default GraphiQLRouteButton;
2 changes: 2 additions & 0 deletions client/src/components/SearchBar/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Navbar from 'react-bootstrap/Navbar';
import { ServerInfoTooltip } from './ServerInfoTooltip.tsx';
import { useRef, useState } from 'react';
import logo from '../../static/img/otp-logo.svg';
import GraphiQLRouteButton from './GraphiQLRouteButton.tsx';

type SearchBarProps = {
onRoute: () => void;
Expand Down Expand Up @@ -61,6 +62,7 @@ export function SearchBar({ onRoute, tripQueryVariables, setTripQueryVariables,
Route
</Button>
</div>
<GraphiQLRouteButton tripQueryVariables={tripQueryVariables}></GraphiQLRouteButton>
</div>
);
}
87 changes: 1 addition & 86 deletions client/src/hooks/useTripQuery.ts
Original file line number Diff line number Diff line change
@@ -1,96 +1,12 @@
import { useCallback, useEffect, useState } from 'react';
import { graphql } from '../gql';
import { request } from 'graphql-request'; // eslint-disable-line import/no-unresolved
import { QueryType, TripQueryVariables } from '../gql/graphql.ts';
import { getApiUrl } from '../util/getApiUrl.ts';
import { query } from '../static/query/tripQuery.tsx';

/**
General purpose trip query document for debugging trip searches
TODO: should live in a separate file, and split into fragments for readability
*/
const query = graphql(`
query trip(
$from: Location!
$to: Location!
$arriveBy: Boolean
$dateTime: DateTime
$numTripPatterns: Int
$searchWindow: Int
$modes: Modes
$itineraryFiltersDebug: ItineraryFilterDebugProfile
$pageCursor: String
) {
trip(
from: $from
to: $to
arriveBy: $arriveBy
dateTime: $dateTime
numTripPatterns: $numTripPatterns
searchWindow: $searchWindow
modes: $modes
itineraryFilters: { debug: $itineraryFiltersDebug }
pageCursor: $pageCursor
) {
previousPageCursor
nextPageCursor
tripPatterns {
aimedStartTime
aimedEndTime
expectedEndTime
expectedStartTime
duration
distance
legs {
id
mode
aimedStartTime
aimedEndTime
expectedEndTime
expectedStartTime
realtime
distance
duration
fromPlace {
name
quay {
id
}
}
toPlace {
name
quay {
id
}
}
toEstimatedCall {
destinationDisplay {
frontText
}
}
line {
publicCode
name
}
authority {
name
}
pointsOnLink {
points
}
interchangeTo {
staySeated
}
interchangeFrom {
staySeated
}
}
systemNotices {
tag
}
}
}
}
`);

type TripQueryHook = (
variables?: TripQueryVariables,
Expand Down Expand Up @@ -126,6 +42,5 @@ export const useTripQuery: TripQueryHook = (variables) => {
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [variables?.from, variables?.to]);

return [data, loading, callback];
};
13 changes: 13 additions & 0 deletions client/src/static/query/authorityQuery.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { graphql } from '../../gql';
import { print } from 'graphql/index';

export const query = graphql(`
query authority($id: String!) {
authority(id: $id) {
name
id
}
}
`);

export const authorityQueryAsString = print(query);
13 changes: 13 additions & 0 deletions client/src/static/query/lineQuery.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { graphql } from '../../gql';
import { print } from 'graphql/index';

export const query = graphql(`
query line($id: ID!) {
line(id: $id) {
name
publicCode
}
}
`);

export const lineQueryAsString = print(query);
15 changes: 15 additions & 0 deletions client/src/static/query/quayQuery.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { graphql } from '../../gql';
import { print } from 'graphql/index';

export const query = graphql(`
query quay($id: String!) {
quay(id: $id) {
stopPlace {
id
name
}
}
}
`);

export const quayQueryAsString = print(query);
90 changes: 90 additions & 0 deletions client/src/static/query/tripQuery.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { graphql } from '../../gql';
import { print } from 'graphql/index';

export const query = graphql(`
query trip(
$from: Location!
$to: Location!
$arriveBy: Boolean
$dateTime: DateTime
$numTripPatterns: Int
$searchWindow: Int
$modes: Modes
$itineraryFiltersDebug: ItineraryFilterDebugProfile
$pageCursor: String
) {
trip(
from: $from
to: $to
arriveBy: $arriveBy
dateTime: $dateTime
numTripPatterns: $numTripPatterns
searchWindow: $searchWindow
modes: $modes
itineraryFilters: { debug: $itineraryFiltersDebug }
pageCursor: $pageCursor
) {
previousPageCursor
nextPageCursor
tripPatterns {
aimedStartTime
aimedEndTime
expectedEndTime
expectedStartTime
duration
distance
legs {
id
mode
aimedStartTime
aimedEndTime
expectedEndTime
expectedStartTime
realtime
distance
duration
fromPlace {
name
quay {
id
}
}
toPlace {
name
quay {
id
}
}
toEstimatedCall {
destinationDisplay {
frontText
}
}
line {
publicCode
name
id
}
authority {
name
id
}
pointsOnLink {
points
}
interchangeTo {
staySeated
}
interchangeFrom {
staySeated
}
}
systemNotices {
tag
}
}
}
}
`);

export const queryAsString = print(query);
Loading

0 comments on commit dd2d0df

Please sign in to comment.