Skip to content

Commit f7ccfa3

Browse files
Feat: gbfs autodiscovery in detail page (#1229)
1 parent 4f62811 commit f7ccfa3

File tree

9 files changed

+298
-207
lines changed

9 files changed

+298
-207
lines changed

web-app/public/locales/en/gbfs.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
"feedUrlCopied": "Feed URL Copied",
55
"runValidationReport": "Run Validation Report",
66
"openFeedUrl": "Open Feed URL",
7+
"openAutoDiscoveryUrl": "Open Auto-Discovery URL",
8+
"autoDiscoveryUrl": "Auto-Discovery URL",
9+
"autoDiscoveryVersion": "Auto-Discovery",
10+
"gbfsVersionsJson": "From gbfs_versions.json",
11+
"feedVersionTooltip": "This URL is from gbfs_versions.json",
712
"features": {
813
"gbfs": "GBFS",
914
"system_regions": "System Regions",

web-app/src/app/screens/Feed/Feed.functions.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,17 @@ export const sortGbfsVersions = (
106106
): number => {
107107
const na = parseFloat(String(a.version ?? '0').replace(/[^0-9.]/g, ''));
108108
const nb = parseFloat(String(b.version ?? '0').replace(/[^0-9.]/g, ''));
109+
109110
if (Number.isNaN(na) || Number.isNaN(nb)) {
110111
return -1;
111112
}
112-
return nb - na;
113+
114+
if (na !== nb) {
115+
return nb - na;
116+
}
117+
118+
if (a.source === b.source) return 0;
119+
return a.source === 'autodiscovery' ? -1 : 1;
113120
};
114121

115122
// Could be temporary function

web-app/src/app/screens/Feed/Feed.styles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const ctaContainerStyle: SxProps<Theme> = (theme) => ({
2929

3030
export const featureChipsStyle: SxProps<Theme> = (theme) => ({
3131
color: theme.palette.primary.contrastText,
32-
backgroundColor: theme.palette.primary.dark,
32+
backgroundColor: theme.palette.secondary.dark,
3333
border: `2px solid transparent`,
3434
':hover': {
3535
opacity: 0.95,

web-app/src/app/screens/Feed/components/GbfsFeedInfo.tsx

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@ import LinkIcon from '@mui/icons-material/Link';
99
import DatasetIcon from '@mui/icons-material/Dataset';
1010
import Locations from '../../../components/Locations';
1111
import SettingsIcon from '@mui/icons-material/Settings';
12+
import StoreIcon from '@mui/icons-material/Store';
1213
import FeedAuthenticationSummaryInfo from './FeedAuthenticationSummaryInfo';
1314
import { boxElementStyle, StyledTitleContainer } from '../Feed.styles';
1415

1516
export interface GbfsFeedInfoProps {
1617
feed: GBFSFeedType;
18+
autoDiscoveryUrl?: string;
1719
}
1820

1921
export default function GbfsFeedInfo({
2022
feed,
23+
autoDiscoveryUrl,
2124
}: GbfsFeedInfoProps): React.ReactElement {
2225
const { t } = useTranslation('feeds');
2326
const theme = useTheme();
@@ -40,9 +43,9 @@ export default function GbfsFeedInfo({
4043
</Box>
4144
</Box>
4245

43-
<Box sx={boxElementStyle}>
44-
<StyledTitleContainer>
45-
<LinkIcon></LinkIcon>
46+
<Box sx={{ ...boxElementStyle, mt: 0 }}>
47+
<StyledTitleContainer sx={{ mt: 0 }}>
48+
<StoreIcon></StoreIcon>
4649
<Typography variant='subtitle1' sx={{ fontWeight: 'bold' }}>
4750
{t('producer')}
4851
</Typography>
@@ -57,6 +60,25 @@ export default function GbfsFeedInfo({
5760
</Link>
5861
</Box>
5962

63+
{autoDiscoveryUrl != undefined && (
64+
<Box sx={boxElementStyle}>
65+
<StyledTitleContainer>
66+
<LinkIcon></LinkIcon>
67+
<Typography variant='subtitle1' sx={{ fontWeight: 'bold' }}>
68+
{t('gbfs:autoDiscoveryUrl')}
69+
</Typography>
70+
</StyledTitleContainer>
71+
<Link
72+
href={autoDiscoveryUrl}
73+
variant='body1'
74+
target='_blank'
75+
rel='noreferrer'
76+
>
77+
{autoDiscoveryUrl}
78+
</Link>
79+
</Box>
80+
)}
81+
6082
<Box sx={boxElementStyle}>
6183
<StyledTitleContainer>
6284
<SettingsIcon></SettingsIcon>

web-app/src/app/screens/Feed/components/GbfsVersions.spec.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,39 @@ describe('sortGbfsVersions used with Array.sort()', () => {
159159
{ version: '2.0' },
160160
]);
161161
});
162+
163+
it('prioritizes autodiscovery versions', () => {
164+
const versions: GBFSVersionType[] = [
165+
{ version: '2.0', source: 'gbfs_versions' },
166+
{ version: '2.0', source: 'autodiscovery' },
167+
];
168+
versions.sort(sortGbfsVersions);
169+
expect(versions).toEqual([
170+
{ version: '2.0', source: 'autodiscovery' },
171+
{ version: '2.0', source: 'gbfs_versions' },
172+
]);
173+
174+
const versionsStable: GBFSVersionType[] = [
175+
{ version: '2.0', source: 'autodiscovery' },
176+
{ version: '2.0', source: 'gbfs_versions' },
177+
];
178+
179+
versionsStable.sort(sortGbfsVersions);
180+
expect(versionsStable).toEqual([
181+
{ version: '2.0', source: 'autodiscovery' },
182+
{ version: '2.0', source: 'gbfs_versions' },
183+
]);
184+
185+
const versionsAutoPriority: GBFSVersionType[] = [
186+
{ version: '2.0', source: 'gbfs_versions' },
187+
{ version: '3.0', source: 'gbfs_versions' },
188+
{ version: '2.0', source: 'autodiscovery' },
189+
];
190+
versionsAutoPriority.sort(sortGbfsVersions);
191+
expect(versionsAutoPriority).toEqual([
192+
{ version: '3.0', source: 'gbfs_versions' },
193+
{ version: '2.0', source: 'autodiscovery' },
194+
{ version: '2.0', source: 'gbfs_versions' },
195+
]);
196+
});
162197
});

0 commit comments

Comments
 (0)