Skip to content
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mobility-database",
"version": "1.0.0",
"version": "1.0.1",
"private": true,
"dependencies": {
"@emotion/cache": "11.14.0",
Expand Down
27 changes: 27 additions & 0 deletions src/app/[locale]/feeds/components/FeedsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export default function FeedsScreen(): React.ReactElement {
features: selectedFeatures,
gbfsVersions: selectedGbfsVersions,
licenses: selectedLicenses,
licenseTags: selectedLicenseTags,
hasTransitFeedsRedirect: hasTransitFeedsRedirectParam,
} = derivedPageState;

Expand Down Expand Up @@ -95,6 +96,7 @@ export default function FeedsScreen(): React.ReactElement {
features: selectedFeatures,
gbfsVersions: selectedGbfsVersions,
licenses: selectedLicenses,
licenseTags: selectedLicenseTags,
utmSource,
...overrides,
});
Expand All @@ -109,6 +111,7 @@ export default function FeedsScreen(): React.ReactElement {
selectedFeatures,
selectedGbfsVersions,
selectedLicenses,
selectedLicenseTags,
utmSource,
router,
],
Expand All @@ -134,6 +137,7 @@ export default function FeedsScreen(): React.ReactElement {
features: [],
gbfsVersions: [],
licenses: [],
licenseTags: [],
isOfficial: false,
});
}
Expand Down Expand Up @@ -288,6 +292,7 @@ export default function FeedsScreen(): React.ReactElement {
selectedFeatures={selectedFeatures}
selectedGbfsVersions={selectedGbfsVersions}
selectedLicenses={selectedLicenses}
selectedLicenseTags={selectedLicenseTags}
setSelectedFeedTypes={(feedTypes) => {
navigate({ feedTypes: { ...feedTypes }, page: 1 });
}}
Expand All @@ -303,6 +308,9 @@ export default function FeedsScreen(): React.ReactElement {
setSelectedLicenses={(licenses) => {
navigate({ licenses, page: 1 });
}}
setSelectedLicenseTags={(licenseTags) => {
navigate({ licenseTags, page: 1 });
}}
isOfficialTagFilterEnabled={isOfficialTagFilterEnabled}
areFeatureFiltersEnabled={areFeatureFiltersEnabled}
areGBFSFiltersEnabled={areGBFSFiltersEnabled}
Expand Down Expand Up @@ -417,9 +425,27 @@ export default function FeedsScreen(): React.ReactElement {
/>
))}

{selectedLicenseTags.map((licenseTag) => (
<Chip
color='primary'
variant='outlined'
size='small'
label={licenseTag}
key={licenseTag}
onDelete={() => {
navigate({
licenseTags: selectedLicenseTags.filter(
(lt) => lt !== licenseTag,
),
});
}}
/>
))}

{(selectedFeatures.length > 0 ||
selectedGbfsVersions.length > 0 ||
selectedLicenses.length > 0 ||
selectedLicenseTags.length > 0 ||
isOfficialFeedSearch ||
selectedFeedTypes.gtfs_rt ||
selectedFeedTypes.gtfs ||
Expand Down Expand Up @@ -553,6 +579,7 @@ export default function FeedsScreen(): React.ReactElement {
feedsData={feedsData}
selectedFeatures={selectedFeatures}
selectedGbfsVersions={selectedGbfsVersions}
selectedLicenseTags={selectedLicenseTags}
isLoadingFeeds={isLoading || isValidating}
/>
)}
Expand Down
13 changes: 13 additions & 0 deletions src/app/[locale]/feeds/lib/useFeedsSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export function deriveSearchParams(searchParams: URLSearchParams): {
features: string[];
gbfsVersions: string[];
licenses: string[];
licenseTags: string[];
hasTransitFeedsRedirect: boolean;
} {
const feedTypes = getInitialSelectedFeedTypes(searchParams);
Expand All @@ -76,6 +77,8 @@ export function deriveSearchParams(searchParams: URLSearchParams): {
gbfsVersions:
searchParams.get('gbfs_versions')?.split(',').filter(Boolean) ?? [],
licenses: searchParams.get('licenses')?.split(',').filter(Boolean) ?? [],
licenseTags:
searchParams.get('license_tags')?.split(',').filter(Boolean) ?? [],
hasTransitFeedsRedirect: searchParams.get('utm_source') === 'transitfeeds',
};
}
Expand Down Expand Up @@ -116,6 +119,7 @@ function buildSwrKey(derived: ReturnType<typeof deriveSearchParams>): string {
features,
gbfsVersions,
licenses,
licenseTags,
} = derived;
const flags = deriveFilterFlags(feedTypes);
const cacheWindow = Math.floor(Date.now() / CACHE_TTL_MS);
Expand All @@ -138,6 +142,9 @@ function buildSwrKey(derived: ReturnType<typeof deriveSearchParams>): string {
if (licenses.length > 0) {
params.set('licenses', licenses.join(','));
}
if (licenseTags.length > 0) {
params.set('license_tags', licenseTags.join(','));
}
return `feeds-search?${params.toString()}`;
}

Expand All @@ -156,6 +163,7 @@ async function feedsFetcher(
features,
gbfsVersions,
licenses,
licenseTags,
} = derivedSearchParams;
const flags = deriveFilterFlags(feedTypes);
const offset = (page - 1) * SEARCH_LIMIT;
Expand All @@ -175,6 +183,7 @@ async function feedsFetcher(
? gbfsVersions.join(',').replaceAll('v', '')
: undefined,
license_ids: licenses.length > 0 ? licenses.join(',') : undefined,
license_tags: licenseTags.length > 0 ? licenseTags.join(',') : undefined,
},
};

Expand Down Expand Up @@ -249,6 +258,7 @@ export function buildSearchUrl(
features?: string[];
gbfsVersions?: string[];
licenses?: string[];
licenseTags?: string[];
utmSource?: string | null;
},
): string {
Expand Down Expand Up @@ -278,6 +288,9 @@ export function buildSearchUrl(
if (filters.licenses != null && filters.licenses.length > 0) {
params.set('licenses', filters.licenses.join(','));
}
if (filters.licenseTags != null && filters.licenseTags.length > 0) {
params.set('license_tags', filters.licenseTags.join(','));
}
if (filters.isOfficial === true) {
params.set('official', 'true');
}
Expand Down
104 changes: 85 additions & 19 deletions src/app/screens/Feeds/AdvancedSearchTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as React from 'react';
import { FeedStatusIndicator } from '../../components/FeedStatus';
import { useTranslations } from 'next-intl';
import LockIcon from '@mui/icons-material/Lock';
import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined';
import GtfsRtEntities from './GtfsRtEntities';
import { getEmojiFlag, type TCountryCode } from 'countries-list';
import OfficialChip from '../../components/OfficialChip';
Expand All @@ -33,18 +34,28 @@ export interface AdvancedSearchTableProps {
feedsData: AllFeedsType | undefined;
selectedFeatures: string[] | undefined;
selectedGbfsVersions: string[] | undefined;
selectedLicenseTags: string[] | undefined;
isLoadingFeeds: boolean;
}

interface DetailsContainerProps {
children: React.ReactNode;
feedSearchItem: SearchFeedItem;
selectedLicenseTags: string[];
}

const DetailsContainer = ({
children,
feedSearchItem,
selectedLicenseTags,
}: DetailsContainerProps): React.ReactElement => {
const licenseTags = feedSearchItem.source_info?.license_tags;
const licenseTagsTitle =
licenseTags != null && licenseTags.length > 0
? licenseTags.join(', ')
: undefined;
const matchingTags =
licenseTags?.filter((tag) => selectedLicenseTags.includes(tag)) ?? [];
return (
<Box
sx={{
Expand All @@ -55,20 +66,52 @@ const DetailsContainer = ({
}}
>
<Box sx={{ width: 'calc(100% - 100px' }}>{children}</Box>
<Tooltip title={'Feed License'} placement={'top-end'}>
<Typography
variant='caption'
sx={{
opacity: 0.7,
ml: { xs: 0, lg: 2 },
minWidth: { xs: '100%', lg: '100px' },
textAlign: 'right',
pt: { xs: 1, lg: 0 },
}}
<Box
sx={{
display: 'flex',
alignItems: 'center',
gap: 0.5,
ml: { xs: 0, lg: 2 },
minWidth: { xs: '100%', lg: '100px' },
justifyContent: 'flex-end',
flexWrap: 'wrap',
pt: { xs: 1, lg: 0 },
}}
>
{matchingTags.map((tag) => (
<Chip
key={tag}
label={tag}
size='small'
color='primary'
variant='outlined'
sx={{ opacity: 0.8 }}
/>
))}
<Tooltip
title={licenseTagsTitle ?? ''}
placement='top-end'
disableTouchListener={licenseTagsTitle == null}
>
{feedSearchItem.source_info?.license_id}
</Typography>
</Tooltip>
<Box
sx={{
display: 'flex',
alignItems: 'center',
gap: 0.5,
}}
>
{licenseTagsTitle != null && (
<InfoOutlinedIcon sx={{ fontSize: 14, opacity: 0.7 }} />
)}
<Typography
variant='caption'
sx={{ opacity: 0.7, textAlign: 'right' }}
>
{feedSearchItem.source_info?.license_id}
</Typography>
</Box>
</Tooltip>
</Box>
</Box>
);
};
Expand All @@ -77,11 +120,15 @@ const renderGTFSDetails = (
gtfsFeed: SearchFeedItem,
selectedFeatures: string[],
theme: Theme,
selectedLicenseTags: string[],
): React.ReactElement => {
const feedFeatures =
gtfsFeed?.latest_dataset?.validation_report?.features ?? [];
return (
<DetailsContainer feedSearchItem={gtfsFeed}>
<DetailsContainer
feedSearchItem={gtfsFeed}
selectedLicenseTags={selectedLicenseTags}
>
{gtfsFeed?.feed_name != null && (
<Typography
variant='body1'
Expand Down Expand Up @@ -123,9 +170,13 @@ const renderGTFSDetails = (

const renderGTFSRTDetails = (
gtfsRtFeed: SearchFeedItem,
selectedLicenseTags: string[],
): React.ReactElement => {
return (
<DetailsContainer feedSearchItem={gtfsRtFeed}>
<DetailsContainer
feedSearchItem={gtfsRtFeed}
selectedLicenseTags={selectedLicenseTags}
>
<GtfsRtEntities
entities={gtfsRtFeed?.entity_types}
includeName={true}
Expand All @@ -138,9 +189,13 @@ const renderGBFSDetails = (
gbfsFeedSearchElement: SearchFeedItem,
selectedGbfsVersions: string[],
theme: Theme,
selectedLicenseTags: string[],
): React.ReactElement => {
return (
<DetailsContainer feedSearchItem={gbfsFeedSearchElement}>
<DetailsContainer
feedSearchItem={gbfsFeedSearchElement}
selectedLicenseTags={selectedLicenseTags}
>
{gbfsFeedSearchElement.versions?.map((version: string, index: number) => (
<Chip
label={'v' + version}
Expand All @@ -164,6 +219,7 @@ export default function AdvancedSearchTable({
feedsData,
selectedFeatures,
selectedGbfsVersions,
selectedLicenseTags,
isLoadingFeeds,
}: AdvancedSearchTableProps): React.ReactElement {
const t = useTranslations('feeds');
Expand Down Expand Up @@ -390,18 +446,28 @@ export default function AdvancedSearchTable({
: {}
}
>
{renderGTFSDetails(feed, selectedFeatures ?? [], theme)}
{renderGTFSDetails(
feed,
selectedFeatures ?? [],
theme,
selectedLicenseTags ?? [],
)}
</Box>
)}
{feed.data_type === 'gtfs_rt' && (
<Box sx={descriptionDividerStyle}>
{renderGTFSRTDetails(feed)}
{renderGTFSRTDetails(feed, selectedLicenseTags ?? [])}
</Box>
)}

{feed.data_type === 'gbfs' && (
<Box sx={hasGbfsVersions ? descriptionDividerStyle : {}}>
{renderGBFSDetails(feed, selectedGbfsVersions ?? [], theme)}
{renderGBFSDetails(
feed,
selectedGbfsVersions ?? [],
theme,
selectedLicenseTags ?? [],
)}
</Box>
)}
</Box>
Expand Down
Loading
Loading