Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GÉANT Service Orchestrator GUI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GÉANT Orchestration and Automation Team
GAP
GÉANT Service Orchestrator GUI
Merge requests
!30
Refactor data fetching and state management in MapsPage
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Refactor data fetching and state management in MapsPage
feature/NAT-574-add-axios-timeout
into
develop
Overview
0
Commits
2
Pipelines
2
Changes
1
Merged
Mohammad Torkashvand
requested to merge
feature/NAT-574-add-axios-timeout
into
develop
9 months ago
Overview
0
Commits
2
Pipelines
2
Changes
1
Expand
Move data fetching logic from NetworkMap to MapsPage
Handle loading and error states in MapsPage
Remove loading and error handling from NetworkMap
Ensure separation of concerns between data fetching and presentation
0
0
Merge request reports
Viewing commit
98b9232a
Prev
Next
Show latest version
1 file
+
5
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
98b9232a
add axoid timeout
· 98b9232a
Mohammad Torkashvand
authored
9 months ago
pages/maps/index.tsx
+
54
−
28
Options
import
NetworkMap
from
'
@/components/NetworkMap/NetworkMap
'
;
import
{
useGsoConfig
}
from
'
@/contexts/GsoConfigContext
'
;
import
{
GSOPolicyResource
}
from
'
@/types/policyResources
'
;
import
{
NetworkTopologyData
}
from
'
@/types/types
'
;
import
{
WfoPolicyRenderPageFallback
}
from
'
@orchestrator-ui/orchestrator-ui-components
'
;
import
{
EuiLoadingSpinner
,
EuiText
}
from
'
@elastic/eui
'
;
import
{
useWfoSession
,
WfoPolicyRenderPageFallback
,
}
from
'
@orchestrator-ui/orchestrator-ui-components
'
;
import
axios
from
'
axios
'
;
import
{
NextPage
,
GetServerSideProps
}
from
'
next
'
;
import
React
from
'
react
'
;
import
React
,
{
useEffect
,
useState
}
from
'
react
'
;
interface
MapsProps
{
networkTopologyData
:
NetworkTopologyData
;
}
const
MapsPage
:
React
.
FC
=
()
=>
{
const
[
networkTopologyData
,
setNetworkTopologyData
]
=
useState
<
NetworkTopologyData
|
null
>
(
null
);
const
[
loading
,
setLoading
]
=
useState
<
boolean
>
(
true
);
const
[
error
,
setError
]
=
useState
<
boolean
>
(
false
);
const
TIMEOUT
=
5000
;
const
config
=
useGsoConfig
();
const
{
session
}
=
useWfoSession
();
useEffect
(()
=>
{
const
fetchData
=
async
()
=>
{
try
{
const
requestHeaders
=
{
Authorization
:
session
?
`Bearer
${
session
.
accessToken
}
`
:
''
,
};
const
response
=
await
axios
.
get
<
NetworkTopologyData
>
(
config.networkTopologyApiUrl!,
{
timeout
:
TIMEOUT
,
headers
:
requestHeaders
,
}
,
);
setNetworkTopologyData(response.data);
setLoading(false);
} catch (error)
{
console
.
error
(
'
Failed to fetch data
'
,
error
);
setError
(
true
);
setLoading
(
false
);
}
};
if (session)
{
fetchData
();
}
else
{
setLoading
(
false
);
setError
(
true
);
}
}, [session]);
const
MapsPage
:
NextPage
<
MapsProps
>
=
({
networkTopologyData
})
=>
{
return (
<
WfoPolicyRenderPageFallback
resource
=
{
GSOPolicyResource
.
NAVIGATION_MAPS
}
>
<
NetworkMap
data
=
{
networkTopologyData
}
/>
{
loading
?
(
<
EuiLoadingSpinner
size
=
"xl"
/>
)
:
error
?
(
<
EuiText
color
=
"danger"
>
Failed to load data. Please try again later.
</
EuiText
>
)
:
(
<
NetworkMap
data
=
{
networkTopologyData
}
/>
)
}
</
WfoPolicyRenderPageFallback
>
);
};
export
const
getServerSideProps
:
GetServerSideProps
=
async
()
=>
{
try
{
const
response
=
await
axios
.
get
(
process
.
env
.
NETWORK_TOPOLOGY_API_URL
!
);
const
networkTopologyData
:
NetworkTopologyData
=
response
.
data
;
return
{
props
:
{
networkTopologyData
,
},
};
}
catch
(
error
)
{
console
.
error
(
'
Failed to fetch data
'
,
error
);
return
{
props
:
{
networkTopologyData
:
null
,
},
};
}
};
export default MapsPage;
Loading