1
Fork 0
mirror of https://github.com/Steffo99/sophon.git synced 2024-12-22 06:44:21 +00:00
This commit is contained in:
Steffo 2021-10-17 01:27:35 +02:00 committed by Stefano Pigozzi
parent 97d795b175
commit df89faad26
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="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="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="PyTrailingSemicolonInspection" 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 pk = path?.[pathSegment]
if(viewSet === undefined) {
return (
<Box>
<Loading text={"Connecting..."}/>
</Box>
)
}
return React.useMemo(
() => {
if(viewSet === undefined) {
return (
<Box>
<Loading text={"Connecting..."}/>
</Box>
)
}
// If an error happens, display it in a ErrorBox
if(viewSet.error) {
return (
<ErrorBox error={viewSet.error}/>
)
}
// If an error happens, display it in a ErrorBox
if(viewSet.error) {
return (
<ErrorBox error={viewSet.error}/>
)
}
// If the viewset is still loading, display a loading message
if(viewSet.resources === null) {
return (
<Box>
<Loading/>
</Box>
)
}
// If the viewset is still loading, display a loading message
if(viewSet.resources === null) {
return (
<Box>
<Loading/>
</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 (
<ResourceRouter
selection={selection}
unselectedRoute={(props) => <UnselectedRoute viewSet={viewSet} {...props}/>}
selectedRoute={(props) => <SelectedRoute {...props}/>}
/>
return (
<ResourceRouter
selection={selection}
unselectedRoute={(props) => <UnselectedRoute viewSet={viewSet} {...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],
)
if(!viewset) {
return undefined
}
return React.useMemo(
() => {
if(!viewset) {
return undefined
}
return {
busy: state.busy,
error: state.error,
operationError: state.operationError,
resources,
refresh,
create,
command,
}
return {
busy: state.busy,
error: state.error,
operationError: state.operationError,
resources,
refresh,
create,
command,
}
},
[state, resources, refresh, create, command]
)
}

View file

@ -149,9 +149,15 @@ export function useViewSet<Resource>(baseRoute: string): ViewSet<Resource> | und
[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],
)
}