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
10 changes: 10 additions & 0 deletions external_types/DatabaseCatalogAPI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ paths:
- $ref: "#/components/parameters/version_query_param"
- $ref: "#/components/parameters/search_text_query_param"
- $ref: "#/components/parameters/feature"
- $ref: "#/components/parameters/license_ids_query_param"
security:
- Authentication: []
responses:
Expand Down Expand Up @@ -1793,6 +1794,15 @@ components:
type: string
example: 2.3

license_ids_query_param:
name: license_ids
in: query
description: Comma separated list of license IDs to filter by.
required: False
schema:
type: string
example: CC-BY-4.0,CC0-1.0

securitySchemes:
Authentication:
$ref: "./BearerTokenSchema.yaml#/components/securitySchemes/Authentication"
Expand Down
55 changes: 47 additions & 8 deletions src/app/screens/Feeds/AdvancedSearchTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,43 @@ export interface AdvancedSearchTableProps {
selectedGbfsVersions: string[] | undefined;
}

interface DetailsContainerProps {
children: React.ReactNode;
feedSearchItem: SearchFeedItem;
}

const DetailsContainer = ({
children,
feedSearchItem,
}: DetailsContainerProps): React.ReactElement => {
return (
<Box
sx={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'end',
flexWrap: { xs: 'wrap', lg: 'nowrap' },
}}
>
<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 },
}}
>
{feedSearchItem.source_info?.license_id}
</Typography>
</Tooltip>
</Box>
);
};

const renderGTFSDetails = (
gtfsFeed: SearchFeedItem,
selectedFeatures: string[],
Expand All @@ -39,7 +76,7 @@ const renderGTFSDetails = (
const feedFeatures =
gtfsFeed?.latest_dataset?.validation_report?.features ?? [];
return (
<>
<DetailsContainer feedSearchItem={gtfsFeed}>
{gtfsFeed?.feed_name != null && (
<Typography
variant='body1'
Expand Down Expand Up @@ -75,18 +112,20 @@ const renderGTFSDetails = (
},
)}
</Box>
</>
</DetailsContainer>
);
};

const renderGTFSRTDetails = (
gtfsRtFeed: SearchFeedItem,
): React.ReactElement => {
return (
<GtfsRtEntities
entities={gtfsRtFeed?.entity_types}
includeName={true}
></GtfsRtEntities>
<DetailsContainer feedSearchItem={gtfsRtFeed}>
<GtfsRtEntities
entities={gtfsRtFeed?.entity_types}
includeName={true}
></GtfsRtEntities>
</DetailsContainer>
);
};

Expand All @@ -96,7 +135,7 @@ const renderGBFSDetails = (
): React.ReactElement => {
const theme = useTheme();
return (
<Box>
<DetailsContainer feedSearchItem={gbfsFeedSearchElement}>
{gbfsFeedSearchElement.versions?.map((version: string, index: number) => (
<Chip
label={'v' + version}
Expand All @@ -112,7 +151,7 @@ const renderGBFSDetails = (
}}
/>
))}
</Box>
</DetailsContainer>
);
};

Expand Down
74 changes: 74 additions & 0 deletions src/app/screens/Feeds/SearchFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ interface SearchFiltersProps {
isOfficialFeedSearch: boolean;
selectedFeatures: string[];
selectedGbfsVersions: string[];
selectedLicenses: string[];
setSelectedFeedTypes: (selectedFeedTypes: Record<string, boolean>) => void;
setIsOfficialFeedSearch: (isOfficialFeedSearch: boolean) => void;
setSelectedFeatures: (selectedFeatures: string[]) => void;
setSelectedGbfsVerions: (selectedVersions: string[]) => void;
setSelectedLicenses: (selectedLicenses: string[]) => void;
isOfficialTagFilterEnabled: boolean;
areFeatureFiltersEnabled: boolean;
areGBFSFiltersEnabled: boolean;
Expand All @@ -41,10 +43,12 @@ export function SearchFilters({
isOfficialFeedSearch,
selectedFeatures,
selectedGbfsVersions,
selectedLicenses,
setSelectedFeedTypes,
setIsOfficialFeedSearch,
setSelectedFeatures,
setSelectedGbfsVerions,
setSelectedLicenses,
isOfficialTagFilterEnabled,
areFeatureFiltersEnabled,
areGBFSFiltersEnabled,
Expand All @@ -61,6 +65,7 @@ export function SearchFilters({
features: areFeatureFiltersEnabled,
tags: isOfficialTagFilterEnabled,
gbfsVersions: true,
licenses: true,
});
const [featureCheckboxData, setFeatureCheckboxData] = useState<
CheckboxStructure[]
Expand Down Expand Up @@ -279,6 +284,75 @@ export function SearchFilters({
></NestedCheckboxList>
</AccordionDetails>
</Accordion>

<Accordion
disableGutters
variant={'outlined'}
sx={{
border: 0,
'&::before': {
display: 'none',
},
}}
expanded={expandedCategories.licenses}
onChange={() => {
setExpandedCategories({
...expandedCategories,
licenses: !expandedCategories.licenses,
});
}}
>
<AccordionSummary
expandIcon={<ExpandMoreIcon />}
aria-controls='panel-licenses-content'
sx={{
px: 0,
}}
>
<SearchHeader variant='h6'>Licenses</SearchHeader>
</AccordionSummary>
<AccordionDetails sx={{ p: 0, m: 0, border: 0 }}>
<NestedCheckboxList
debounceTime={500}
checkboxData={[
{
title: 'CC-BY-4.0',
checked: selectedLicenses.includes('CC-BY-4.0'),
type: 'checkbox',
},
{
title: 'etalab-2.0',
checked: selectedLicenses.includes('etalab-2.0'),
type: 'checkbox',
},
{
title: 'CC0-1.0',
checked: selectedLicenses.includes('CC0-1.0'),
type: 'checkbox',
},
{
title: 'ODbL-1.0',
checked: selectedLicenses.includes('ODbL-1.0'),
type: 'checkbox',
},
{
title: 'OGL-UK-3.0',
checked: selectedLicenses.includes('OGL-UK-3.0'),
type: 'checkbox',
},
]}
onCheckboxChange={(checkboxData) => {
const selectedLicenseIds: string[] = [];
checkboxData.forEach((checkbox) => {
if (checkbox.checked) {
selectedLicenseIds.push(checkbox.title);
}
});
setSelectedLicenses([...selectedLicenseIds]);
}}
></NestedCheckboxList>
</AccordionDetails>
</Accordion>
</>
);
}
39 changes: 39 additions & 0 deletions src/app/screens/Feeds/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ export default function Feed(): React.ReactElement {
const [selectGbfsVersions, setSelectGbfsVersions] = useState<string[]>(
searchParams.get('gbfs_versions')?.split(',') ?? [],
);
const [selectedLicenses, setSelectedLicenses] = useState<string[]>(
searchParams.get('licenses')?.split(',') ?? [],
);
const [activePagination, setActivePagination] = useState(
searchParams.get('o') !== null ? Number(searchParams.get('o')) : 1,
);
Expand Down Expand Up @@ -130,6 +133,10 @@ export default function Feed(): React.ReactElement {
version: areGBFSFiltersEnabled
? selectGbfsVersions.join(',').replaceAll('v', '')
: undefined,
license_ids:
selectedLicenses.length > 0
? selectedLicenses.join(',')
: undefined,
},
},
}),
Expand All @@ -143,6 +150,7 @@ export default function Feed(): React.ReactElement {
isOfficialFeedSearch,
selectedFeatures,
selectGbfsVersions,
selectedLicenses,
]);

useEffect(() => {
Expand All @@ -169,6 +177,9 @@ export default function Feed(): React.ReactElement {
if (selectGbfsVersions.length > 0) {
newSearchParams.set('gbfs_versions', selectGbfsVersions.join(','));
}
if (selectedLicenses.length > 0) {
newSearchParams.set('licenses', selectedLicenses.join(','));
}
if (isOfficialFeedSearch) {
newSearchParams.set('official', 'true');
}
Expand All @@ -187,6 +198,7 @@ export default function Feed(): React.ReactElement {
selectedFeedTypes,
selectedFeatures,
selectGbfsVersions,
selectedLicenses,
isOfficialFeedSearch,
]);

Expand Down Expand Up @@ -214,6 +226,11 @@ export default function Feed(): React.ReactElement {
setSelectGbfsVersions([...newGbfsVersions]);
}

const newLicenses = searchParams.get('licenses')?.split(',') ?? [];
if (newLicenses.join(',') !== selectedLicenses.join(',')) {
setSelectedLicenses([...newLicenses]);
}

const newSearchOfficial = Boolean(searchParams.get('official')) ?? false;
if (newSearchOfficial !== isOfficialFeedSearch) {
setIsOfficialFeedSearch(newSearchOfficial);
Expand Down Expand Up @@ -265,6 +282,7 @@ export default function Feed(): React.ReactElement {
});
setSelectedFeatures([]);
setSelectGbfsVersions([]);
setSelectedLicenses([]);
setIsOfficialFeedSearch(false);
}

Expand Down Expand Up @@ -400,6 +418,7 @@ export default function Feed(): React.ReactElement {
isOfficialFeedSearch={isOfficialFeedSearch}
selectedFeatures={selectedFeatures}
selectedGbfsVersions={selectGbfsVersions}
selectedLicenses={selectedLicenses}
setSelectedFeedTypes={(feedTypes) => {
setActivePagination(1);
setSelectedFeedTypes({ ...feedTypes });
Expand All @@ -416,6 +435,10 @@ export default function Feed(): React.ReactElement {
setSelectGbfsVersions(versions);
setActivePagination(1);
}}
setSelectedLicenses={(licenses) => {
setActivePagination(1);
setSelectedLicenses(licenses);
}}
isOfficialTagFilterEnabled={isOfficialTagFilterEnabled}
areFeatureFiltersEnabled={areFeatureFiltersEnabled}
areGBFSFiltersEnabled={areGBFSFiltersEnabled}
Expand Down Expand Up @@ -515,8 +538,24 @@ export default function Feed(): React.ReactElement {
/>
))}

{selectedLicenses.map((license) => (
<Chip
color='primary'
variant='outlined'
size='small'
label={license}
key={license}
onDelete={() => {
setSelectedLicenses([
...selectedLicenses.filter((sl) => sl !== license),
]);
}}
/>
))}

{(selectedFeatures.length > 0 ||
selectGbfsVersions.length > 0 ||
selectedLicenses.length > 0 ||
isOfficialFeedSearch ||
selectedFeedTypes.gtfs_rt ||
selectedFeedTypes.gtfs ||
Expand Down
Loading