Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new observation form for custom observations #70

Open
wants to merge 27 commits into
base: main
Choose a base branch
from

Conversation

Bo-Duke
Copy link
Member

@Bo-Duke Bo-Duke commented Apr 24, 2024

No description provided.

@Bo-Duke Bo-Duke force-pushed the new_observation_types branch 4 times, most recently from bc0db61 to 72d19ec Compare April 29, 2024 17:00
@Bo-Duke Bo-Duke marked this pull request as ready for review April 29, 2024 17:02
): Promise<ObservationDetails | null> {
const schema = await fetchObservation(type);
const detailsList = await fetchObservationDetails(type);
const values = detailsList?.find(detail => detail.id === parseInt(id));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const values = detailsList?.find(detail => detail.id === parseInt(id));
const values = detailsList?.find(detail => detail.id === Number(id));

or parseInt(id, 10))

label: (schema?.json_schema_form.properties?.[key] as any)?.title,
})),
id,
contributedAt: values?.contributed_at,
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional chaining seems useless with the early return line 90

Comment on lines +86 to +87
const schema = await fetchObservation(type);
const detailsList = await fetchObservationDetails(type);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you can use a Promise.all to parallelize queries?

Comment on lines +111 to +120
const observation = await fetchObservation(id);
return {
...observation,
json_schema_form: {
...observation?.json_schema_form,
properties: {
...observation?.json_schema_form?.properties,
},
},
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it's more readable to remove all optional chaining by using an early return if observation === null

Comment on lines +73 to +82
const station = await fetchStation(id);
const observations = await fetchStationObservations(id);
if (station) {
return {
...station,
observations,
};
} else {
return null;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const station = await fetchStation(id);
const observations = await fetchStationObservations(id);
if (station) {
return {
...station,
observations,
};
} else {
return null;
}
const station = await fetchStation(id);
if (!station) {
return null;
};
const observations = await fetchStationObservations(id);
return {
...station,
observations,
};

Or Promise.all the queries

@@ -34,10 +35,12 @@
"next": "^13.5.4",
"next-intl": "2.15.0-beta.5",
"next-themes": "^0.2.1",
"node-fetch": "^3.3.2",
Copy link
Contributor

Choose a reason for hiding this comment

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

Useful?

Comment on lines +15 to 27
if (
properties === null ||
(!properties.name && !properties.category && !properties.label)
) {
return null;
}
if (layer.type === undefined || !layer.url || !properties.id) {
return <Tooltip>{properties.name ?? properties.category}</Tooltip>;
return (
<Tooltip>
{properties.name ?? properties.category ?? properties.label}
</Tooltip>
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

const label = properties?.name || properties?.category || properties?.label;
if (!label) {
  return null;
}
// [...]
return (<Tooltip>{label}</Tooltip>

const [observations, setObservations] = useState<Observation[]>([]);

useEffect(() => {
getObservations().then(res => setObservations(res));
Copy link
Contributor

Choose a reason for hiding this comment

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

To do this, we need useQuery or its equivalent

}?${params.toString()}`}
title={observation.label}
>
{observation.description ?? ''}
Copy link
Contributor

Choose a reason for hiding this comment

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

Without description, it results an empty link?

Copy link
Member Author

Choose a reason for hiding this comment

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

Description should be a prop of ListItem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants