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
55 changes: 47 additions & 8 deletions web-app/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 = (
): JSX.Element => {
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 web-app/src/app/screens/Feeds/SearchFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,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 @@ -39,10 +41,12 @@ export function SearchFilters({
isOfficialFeedSearch,
selectedFeatures,
selectedGbfsVersions,
selectedLicenses,
setSelectedFeedTypes,
setIsOfficialFeedSearch,
setSelectedFeatures,
setSelectedGbfsVerions,
setSelectedLicenses,
isOfficialTagFilterEnabled,
areFeatureFiltersEnabled,
areGBFSFiltersEnabled,
Expand All @@ -58,6 +62,7 @@ export function SearchFilters({
features: areFeatureFiltersEnabled,
tags: isOfficialTagFilterEnabled,
gbfsVersions: true,
licenses: true,
});
const [featureCheckboxData, setFeatureCheckboxData] = useState<
CheckboxStructure[]
Expand Down Expand Up @@ -276,6 +281,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',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested on QA and this was the only filter to not show any data. Need to confirm if spelling is ok with db

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 web-app/src/app/screens/Feeds/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,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 @@ -127,6 +130,10 @@ export default function Feed(): React.ReactElement {
version: areGBFSFiltersEnabled
? selectGbfsVersions.join(',').replaceAll('v', '')
: undefined,
license_ids:
selectedLicenses.length > 0
? selectedLicenses.join(',')
: undefined,
},
},
}),
Expand All @@ -140,6 +147,7 @@ export default function Feed(): React.ReactElement {
isOfficialFeedSearch,
selectedFeatures,
selectGbfsVersions,
selectedLicenses,
]);

useEffect(() => {
Expand All @@ -166,6 +174,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 @@ -181,6 +192,7 @@ export default function Feed(): React.ReactElement {
selectedFeedTypes,
selectedFeatures,
selectGbfsVersions,
selectedLicenses,
isOfficialFeedSearch,
]);

Expand Down Expand Up @@ -208,6 +220,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 @@ -259,6 +276,7 @@ export default function Feed(): React.ReactElement {
});
setSelectedFeatures([]);
setSelectGbfsVersions([]);
setSelectedLicenses([]);
setIsOfficialFeedSearch(false);
}

Expand Down Expand Up @@ -396,6 +414,7 @@ export default function Feed(): React.ReactElement {
isOfficialFeedSearch={isOfficialFeedSearch}
selectedFeatures={selectedFeatures}
selectedGbfsVersions={selectGbfsVersions}
selectedLicenses={selectedLicenses}
setSelectedFeedTypes={(feedTypes) => {
setActivePagination(1);
setSelectedFeedTypes(feedTypes);
Expand All @@ -412,6 +431,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 @@ -511,8 +534,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