Skip to content

Commit

Permalink
Manage null value for some fields
Browse files Browse the repository at this point in the history
  • Loading branch information
dtrucs committed Jun 12, 2024
1 parent 8c10104 commit 5cfc2f8
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 38 deletions.
4 changes: 2 additions & 2 deletions frontend/src/components/pages/details/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const DetailsUIWithoutContext: React.FC<Props> = ({ slug, parentId, langu
<>
<PageHead
title={details?.title}
description={cleanHTMLElementsFromString(details?.description_teaser)}
description={cleanHTMLElementsFromString(details?.description_teaser ?? '')}
sharingImageUrl={details?.imgs?.[0]?.url}
/>
{details === undefined ? (
Expand Down Expand Up @@ -546,7 +546,7 @@ export const DetailsUIWithoutContext: React.FC<Props> = ({ slug, parentId, langu
id: `${touristicContent.id}`,
name: touristicContent.name ?? '',
place: touristicContent.category.label,
description: touristicContent.descriptionTeaser,
description: touristicContent.descriptionTeaser ?? '',
thumbnails: touristicContent.thumbnails,
images: touristicContent.images,
iconUri: touristicContent.category.pictogramUri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ interface DetailsDescriptionProps {
id?: string;
descriptionHtml: string;
className?: string;
departure?: string;
arrival?: string;
departure?: string | null;
arrival?: string | null;
cities?: string[];
title?: React.ReactElement;
email?: string;
Expand All @@ -28,8 +28,8 @@ export const DetailsDescription: React.FC<DetailsDescriptionProps> = ({
email,
website,
}) => {
const hasDeparture = departure !== undefined && departure.length > 0;
const hasArrival = arrival !== undefined && arrival.length > 0;
const hasDeparture = typeof departure === 'string' && departure.length > 0;
const hasArrival = typeof arrival === 'string' && arrival.length > 0;
const hasCities = Array.isArray(cities) && cities.length > 0;
const hasEmail = Boolean(email);
const hasWebsite = Boolean(website);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ interface DetailsPreviewInformation extends DetailsInformation {
}

interface DetailsPreviewProps {
ambiance?: string;
ambiance?: string | null;
className?: string;
informations: DetailsPreviewInformation;
place?: string;
tags: string[];
teaser?: string;
teaser?: string | null;
title: string;
trekFamily?: TrekFamily;
details:
Expand Down Expand Up @@ -315,15 +315,15 @@ export const DetailsPreview: React.FC<DetailsPreviewProps> = ({
<div className="desktop:hidden mt-4">
<OfflineButton details={details} type={type} />
</div>
{teaser !== undefined && teaser?.length > 0 && (
{typeof teaser === 'string' && teaser?.length > 0 && (
<div
id="details_teaser"
className="text-Mobile-C1 desktop:text-H4 font-bold mt-4 desktop:mt-9"
>
<HtmlText>{parse(teaser)}</HtmlText>
</div>
)}
{ambiance !== undefined && ambiance?.length > 0 && (
{typeof ambiance === 'string' && ambiance?.length > 0 && (
<div id="details_ambiance" className="text-Mobile-C1 desktop:text-P1 mt-4 desktop:mt-8">
<HtmlText>{parse(ambiance)}</HtmlText>
</div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/pages/site/OutdoorCourseUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ export const OutdoorCourseUIWithoutContext: React.FC<Props> = ({ outdoorCourseUr
id: `${touristicContent.id}`,
name: touristicContent.name ?? '',
place: touristicContent.category.label,
description: touristicContent.descriptionTeaser,
description: touristicContent.descriptionTeaser ?? '',
thumbnails: touristicContent.thumbnails,
images: touristicContent.images,
iconUri: touristicContent.category.pictogramUri,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/pages/site/OutdoorSiteUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const OutdoorSiteUIWithoutContext: React.FC<Props> = ({ outdoorSiteUrl, language
<>
<PageHead
title={outdoorSiteContent?.name}
description={cleanHTMLElementsFromString(outdoorSiteContent?.descriptionTeaser)}
description={cleanHTMLElementsFromString(outdoorSiteContent?.descriptionTeaser ?? '')}
sharingImageUrl={outdoorSiteContent?.images?.[0]?.url}
/>
{outdoorSiteContent === undefined ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const TouristicContentUI: React.FC<TouristicContentUIProps> = ({
<>
<PageHead
title={touristicContent?.name}
description={touristicContent ? touristicContent.descriptionTeaser : ''}
description={touristicContent ? touristicContent.descriptionTeaser ?? '' : ''}
sharingImageUrl={touristicContent?.images?.[0]?.url}
/>
{touristicContent === undefined ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ export const TouristicEventUIWithoutContext: React.FC<Props> = ({
id: `${touristicContent.id}`,
name: touristicContent.name ?? '',
place: touristicContent.category.label,
description: touristicContent.descriptionTeaser,
description: touristicContent.descriptionTeaser ?? '',
thumbnails: touristicContent.thumbnails,
images: touristicContent.images,
iconUri: touristicContent.category.pictogramUri,
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/domain/Trek/Trek.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface Trek {
advice: string;
advised_parking: string;
altimetric_profile: string;
ambiance: string;
ambiance: string | null;
arrival: string;
ascent: number;
images: Attachment[];
Expand All @@ -14,7 +14,7 @@ export interface Trek {
departure: string;
descent: number;
description: string;
description_teaser: string;
description_teaser: string | null;
difficulty: number;
disabled_infrastructure: string;
duration: number;
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/modules/details/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ export const adaptResults = ({
transport: rawDetailsProperties.public_transport,
access: rawDetailsProperties.access,
parking: rawDetailsProperties.advised_parking,
description_teaser: rawDetailsProperties.description_teaser,
ambiance: rawDetailsProperties.ambiance,
description_teaser: rawDetailsProperties.description_teaser ?? null,
ambiance: rawDetailsProperties.ambiance ?? null,
description: rawDetailsProperties.description,
tags: rawDetailsProperties.themes.map(themeId => themes[themeId]?.label).filter(Boolean),
informations: {
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/modules/details/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export interface RawDetailsProperties {
advice: string;
advised_parking: string;
altimetric_profile: string;
ambiance: string;
ambiance?: string | null;
arrival_city: string;
arrival: string;
ascent: number;
Expand All @@ -67,7 +67,7 @@ export interface RawDetailsProperties {
cities: string[];
departure_city: string;
departure: string;
description_teaser: string;
description_teaser: string | null;
description: string;
difficulty: number | null;
disabled_infrastructure: string;
Expand Down Expand Up @@ -103,8 +103,8 @@ export interface DetailsHtml {
transport: string;
access: string;
parking: string;
description_teaser: string;
ambiance: string;
description_teaser: string | null;
ambiance?: string | null;
description: string;
disabledInfrastructure: string;
advice: string;
Expand Down Expand Up @@ -181,8 +181,8 @@ export interface Details extends DetailsHtml {
bbox: Bbox;
children: TrekResultWithGeometryChild[];
sensitiveAreas: SensitiveArea[];
departure: string;
arrival: string;
departure?: string | null;
arrival?: string | null;
cities: string[];
cities_raw: string[];
webLinks: WebLink[];
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/modules/outdoorSite/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ export const adaptOutdoorSiteDetails = ({
})[0],
accessibility: rawOutdoorSiteDetails.properties.accessibility ?? null,
description: rawOutdoorSiteDetails.properties.description,
ambiance: rawOutdoorSiteDetails.properties.ambiance,
ambiance: rawOutdoorSiteDetails.properties.ambiance ?? null,
advice: rawOutdoorSiteDetails.properties.advice,
descriptionTeaser: rawOutdoorSiteDetails.properties.description_teaser,
descriptionTeaser: rawOutdoorSiteDetails.properties.description_teaser ?? null,
bbox: {
corner1: { x: rawOutdoorSiteDetails.bbox[0], y: rawOutdoorSiteDetails.bbox[1] },
corner2: { x: rawOutdoorSiteDetails.bbox[2], y: rawOutdoorSiteDetails.bbox[3] },
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/modules/outdoorSite/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ export interface RawOutdoorSite {
interface RawOutdoorSiteDetailsProperties extends RawOutdoorSite {
accessibility?: string;
advice?: string;
ambiance?: string;
ambiance?: string | null;
children: number[];
description?: string;
description_teaser?: string;
description_teaser?: string | null;
information_desks?: number[];
labels?: number[];
managers?: number[];
Expand Down Expand Up @@ -102,9 +102,9 @@ export interface OutdoorSite {
export interface OutdoorSiteDetails extends OutdoorSite {
accessibility?: string | null;
description?: string;
descriptionTeaser?: string;
descriptionTeaser?: string | null;
bbox: Bbox;
ambiance?: string;
ambiance?: string | null;
advice?: string;
labels?: Label[];
source?: Source[];
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/modules/touristicContent/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const adaptTouristicContent = ({
id: rawTouristicObject.id,
type: 'TOURISTIC_CONTENT',
name: rawTouristicObject.name,
descriptionTeaser: rawTouristicObject.description_teaser,
descriptionTeaser: rawTouristicObject.description_teaser ?? null,
thumbnails: getLargeImagesOrThumbnailsFromAttachments(rawTouristicObject.attachments, true),
images: getLargeImagesOrThumbnailsFromAttachments(rawTouristicObject.attachments, false),
category: touristicContentCategories[rawTouristicObject.category],
Expand Down Expand Up @@ -109,7 +109,7 @@ export const adaptTouristicContentDetails = ({
practicalInfo: rawTCD.properties.practical_info ?? null,
id: rawTCD.id,
name: rawTCD.properties.name,
descriptionTeaser: rawTCD.properties.description_teaser,
descriptionTeaser: rawTCD.properties.description_teaser ?? null,
thumbnails: getLargeImagesOrThumbnailsFromAttachments(rawTCD.properties.attachments, true),
category: touristicContentCategory,
geometry: rawTCD.geometry ? adaptGeometry(rawTCD.geometry) : null,
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/modules/touristicContent/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface RawTouristicContent {
attachments: RawAttachment[];
name: string;
category: number;
description_teaser: string;
description_teaser: string | null;
geometry: RawPointGeometry2D | RawPolygonGeometry | RawLineStringGeometry2D | null;
approved: boolean;
}
Expand All @@ -33,7 +33,7 @@ export interface RawTouristicContentResult {
attachments: RawAttachment[];
name: string;
category: number;
description_teaser: string;
description_teaser: string | null;
themes: number[];
types: Record<number, number[]>;
cities: string[];
Expand Down Expand Up @@ -74,7 +74,7 @@ export interface TouristicContent {
practicalInfo?: string | null;
id: string;
name: string;
descriptionTeaser: string;
descriptionTeaser: string | null;
thumbnails: ImageFromAttachment[];
images: ImageFromAttachment[];
category: TouristicContentCategory;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/modules/touristicEvent/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const adaptTouristicEventDetails = ({
})[0],
// then we add missing fields
description: rawTouristicEventDetails.properties.description,
descriptionTeaser: rawTouristicEventDetails.properties.description_teaser,
descriptionTeaser: rawTouristicEventDetails.properties.description_teaser ?? null,
bbox: {
corner1: { x: rawTouristicEventDetails.bbox[0], y: rawTouristicEventDetails.bbox[1] },
corner2: { x: rawTouristicEventDetails.bbox[2], y: rawTouristicEventDetails.bbox[3] },
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/modules/touristicEvent/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export interface RawTouristicEvent {

interface RawTouristicEventDetailsProperties extends RawTouristicEvent {
description: string;
description_teaser: string;
description_teaser: string | null;
participant_number: number;
pdf: string;
meeting_point: string;
Expand Down Expand Up @@ -99,7 +99,7 @@ export interface TouristicEvent {

export interface TouristicEventDetails extends TouristicEvent {
description: string;
descriptionTeaser: string;
descriptionTeaser: string | null;
bbox: Bbox;
cities: string[];
cities_raw: string[];
Expand Down

0 comments on commit 5cfc2f8

Please sign in to comment.