1
Fork 0
mirror of https://github.com/Steffo99/sophon.git synced 2024-12-22 23:04:21 +00:00
This commit is contained in:
Steffo 2021-10-17 01:27:35 +02:00 committed by Stefano Pigozzi
parent 3ed4a330cc
commit 615a59806a
4 changed files with 62 additions and 51 deletions

View file

@ -40,13 +40,6 @@
<inspection_tool class="PyRelativeImportInspection" enabled="true" level="WARNING" enabled_by_default="true" /> <inspection_tool class="PyRelativeImportInspection" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="PyReturnFromInitInspection" enabled="true" level="ERROR" enabled_by_default="true" /> <inspection_tool class="PyReturnFromInitInspection" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="PySetFunctionToLiteralInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" /> <inspection_tool class="PySetFunctionToLiteralInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="PyShadowingBuiltinsInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredNames">
<list>
<option value="format" />
</list>
</option>
</inspection_tool>
<inspection_tool class="PyStringFormatInspection" enabled="true" level="ERROR" enabled_by_default="true" /> <inspection_tool class="PyStringFormatInspection" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="PyTrailingSemicolonInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" /> <inspection_tool class="PyTrailingSemicolonInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="PyUnnecessaryBackslashInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" /> <inspection_tool class="PyUnnecessaryBackslashInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />

View file

@ -24,37 +24,44 @@ export function ViewSetRouter<Resource extends DjangoResource>({viewSet, unselec
const path = useSophonPath() const path = useSophonPath()
const pk = path?.[pathSegment] const pk = path?.[pathSegment]
if(viewSet === undefined) { return React.useMemo(
return ( () => {
<Box> if(viewSet === undefined) {
<Loading text={"Connecting..."}/> return (
</Box> <Box>
) <Loading text={"Connecting..."}/>
} </Box>
)
}
// If an error happens, display it in a ErrorBox // If an error happens, display it in a ErrorBox
if(viewSet.error) { if(viewSet.error) {
return ( return (
<ErrorBox error={viewSet.error}/> <ErrorBox error={viewSet.error}/>
) )
} }
// If the viewset is still loading, display a loading message // If the viewset is still loading, display a loading message
if(viewSet.resources === null) { if(viewSet.resources === null) {
return ( return (
<Box> <Box>
<Loading/> <Loading/>
</Box> </Box>
) )
} }
const selection = pk ? viewSet.resources?.find(res => res.value[pkKey] === pk) : undefined const selection = pk ? viewSet.resources?.find(res => res.value[pkKey] === pk) : undefined
return ( return (
<ResourceRouter <ResourceRouter
selection={selection} selection={selection}
unselectedRoute={(props) => <UnselectedRoute viewSet={viewSet} {...props}/>} unselectedRoute={(props) => <UnselectedRoute viewSet={viewSet} {...props}/>}
selectedRoute={(props) => <SelectedRoute {...props}/>} selectedRoute={(props) => <SelectedRoute {...props}/>}
/> />
)
},
[viewSet, UnselectedRoute, SelectedRoute, pk, pkKey],
) )
} }

View file

@ -617,17 +617,22 @@ export function useManagedViewSet<Resource extends DjangoResource>(baseRoute: st
[refresh, state, refreshOnMount, viewset, baseRoute], [refresh, state, refreshOnMount, viewset, baseRoute],
) )
if(!viewset) { return React.useMemo(
return undefined () => {
} if(!viewset) {
return undefined
}
return { return {
busy: state.busy, busy: state.busy,
error: state.error, error: state.error,
operationError: state.operationError, operationError: state.operationError,
resources, resources,
refresh, refresh,
create, create,
command, command,
} }
},
[state, resources, refresh, create, command]
)
} }

View file

@ -149,9 +149,15 @@ export function useViewSet<Resource>(baseRoute: string): ViewSet<Resource> | und
[action, baseRoute], [action, baseRoute],
) )
if(!api) {
return undefined
}
return {command, action, list, retrieve, create, update, destroy} return React.useMemo(
() => {
if(!api) {
return undefined
}
return {command, action, list, retrieve, create, update, destroy}
},
[command, action, list, retrieve, create, update, destroy],
)
} }