Feat(Popup): Use external data to find categorical labels#185
Feat(Popup): Use external data to find categorical labels#185arnaudfnr wants to merge 10 commits into
Conversation
fccda2b to
3a176a2
Compare
| try { | ||
| const isValid = await verifyToken(token); | ||
| if (isValid) { | ||
| setToken(storedToken); |
| if not request.user.has_perm("users.view_data"): | ||
| return Response(status=status.HTTP_403_FORBIDDEN) |
There was a problem hiding this comment.
We can define a custom class CanViewData follow this practice: https://www.django-rest-framework.org/api-guide/permissions/#setting-the-permission-policy. Permissions classes would be "IsAuthenticated & CanViewData"
There was a problem hiding this comment.
I know but I went for the less code / quicker option here 😄
| @api_view(["POST"]) | ||
| @permission_classes([IsAuthenticated]) | ||
| def resource_list_view(request, layer_id): | ||
| # authorization: ensure user has the custom add_data permission |
There was a problem hiding this comment.
| # authorization: ensure user has the custom add_data permission | |
| # authorization: ensure user has the custom view_data permission |
|
|
||
| resources_payload = {} | ||
| for resource_name in resource_list: | ||
| target_path = catalog_path / f"{layer_id}" / f"{resource_name}.parquet" |
There was a problem hiding this comment.
Shall we check layer id is defined or an existing path ?
| data={data.treeDiversity.relative_abundance} | ||
| metadata={metadata} | ||
| externalData={metadata} | ||
| proj={rawData.projet} |
There was a problem hiding this comment.
Can we keep full-verbose naming for proops ? "project" instead of "proj" ?
| // t must be passed to the fallback render function because the error boundary fallback component cannot call hooks like useTranslation | ||
| // See https://react.dev/warnings/invalid-hook-call-warning | ||
| // > 🔴 Do not call Hooks in class components. | ||
| // while ErrorBoundary is a class component: https://github.com/bvaughn/react-error-boundary/blob/main/lib/components/ErrorBoundary.tsx#L45 | ||
| export function getFallbackRender({ | ||
| retry, | ||
| t, | ||
| }: { | ||
| retry?: () => void; | ||
| t: TFunction<"common", undefined>; | ||
| }) { | ||
| function FallbackRender({ error }: FallbackProps) { |
There was a problem hiding this comment.
You can just extract the JSX into a Functional component, no ?
const FallbackRender= (...) => {
const { t } = useTranslation();
...
}
<ErrorBoundary
fallbackRender={(...) => <FallbackRender ... />}
```
You can't use hooks in class components but you can use Functional Components though| /> | ||
| </Suspense> | ||
| </ErrorBoundary> | ||
| ); |
There was a problem hiding this comment.
Comments on the behavior:
- Now people have to be logged in to see data => Can't share data to the public now, so, it wouldn't make sense to be able to land on the map view
- IMO, the boundary should be restricted to the data slice it is related to. Here, it's to fetch the label only, right ? This should be the data slice wrapped in the Boundary.
- But then comes again the question about: what is pubicly accessible, what should be hidden, what to dislay in case of failure (for public access) ?
There was a problem hiding this comment.
Well your comments are absolutely right.
In the new final data, there is a new field "conf" for confidentiality that I did not integrate yet.
So the behavior will be :
- When a user is not connected, they will see all data publicly available (conf=1 , yes that's illogic)
- External data won't be protected (to confirm with Cathalijne, so yes the current behavior is going to change) so even public users will see the labels. But this requires to think about the backend a little bit here, that's why I protected the resources for now. We can also open it for the time we think about that.
- You are right, maybe we can just wrap the indicators that require the promise inside the boundary. We could also make a silent fail with a fallback to values. I think I just wanted to play with the ErroBoundary stuff after having seen it from @severo ^^
| // Retrieve external data before rendering popup | ||
| const [reloadKey, setReloadKey] = useState(0); | ||
| const externalDataPromise = useMemo( | ||
| () => | ||
| fetchData({ | ||
| force: reloadKey > 0, | ||
| promiseFunc, | ||
| }), | ||
| [reloadKey, promiseFunc], | ||
| ); | ||
|
|
||
| const retry = useCallback(() => { | ||
| setReloadKey((k) => k + 1); | ||
| }, []); | ||
| const fallbackRender = useMemo( | ||
| () => getFallbackRender({ retry, t }), | ||
| [retry, t], | ||
| ); |
There was a problem hiding this comment.
As far as we used it in my company, so far, you pass the retry function to the FallbackRender, it contains a reload button, and that's all : on demand refetch from the error boundary. No need for state, memoization, callbacks, cache.
Interally, we can do a retry on fail for 3 times for instance (it's just a loop while getting error. But things can be remain simple
There was a problem hiding this comment.
I see. Maybe we could improve that later, it's a bit off of what I'm trying to do here and as I said in the previous command it's basically a copy and paste of @severo work, can we have the debate on mattermost it it's important to you ?
|
|
||
| return ( | ||
| <ErrorBoundary | ||
| fallbackRender={fallbackRender} |
There was a problem hiding this comment.
The fallback render component should have the same height limitation as provided in childrenProps.className
| "undefined": "not found" | ||
| }, | ||
| "error": { | ||
| "pleaseLogon": "Please sign in", |
There was a problem hiding this comment.
| "pleaseLogon": "Please sign in", | |
| "pleaseLogin": "Please sign in", |
(french key)
david-bretaud-dev
left a comment
There was a problem hiding this comment.
A couple of improvements we can bring to the code.
The main thing that struck me though was the need to be logged in to see the full popup -not just the label-
(Since we have access to the whole style.json anyway, this limitation does not rely exist)
WHAT CHANGES
Backend
Frontend
=> No labels have been provided for socio eco data yet
Capture.video.du.2026-07-05.23-00-51.mp4