Skip to content

Commit d948441

Browse files
committed
#123: add docs to frontend
1 parent 4620409 commit d948441

File tree

7 files changed

+62
-6
lines changed

7 files changed

+62
-6
lines changed

frontend/src/components/Dashboard.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ const Dashboard: React.FC<DashboardProps> = ({
4040
const dispatch = useAppDispatch()
4141
const navigate = useNavigate()
4242

43-
//used to navigate directly to /cluster instead of /
4443
useEffect(() => {
44+
// used to navigate directly from / to /cluster
4545
if (location.pathname === '/') navigate('/cluster')
46+
// fetch all filter options once beforehand
4647
dispatch(fetchOptionsThunk())
4748
}, [])
4849

@@ -264,7 +265,9 @@ const Dashboard: React.FC<DashboardProps> = ({
264265
}
265266
}
266267
*/
267-
268+
/**
269+
* Resets all filters and triggers another page request to update the currently displayed cards
270+
*/
268271
const resetFilters = () => {
269272
dispatch(resetAllFilters())
270273
dispatch(triggerRequest())

frontend/src/components/pages/cluster/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,19 @@ export interface ResponseCluster {
1313
clusters: string[]
1414
}
1515

16+
/**
17+
* Card group component for the cluster type.
18+
* Displays the ClusterView cards, title, loading window and network error.
19+
* @returns Rendered cluster view cards for the dashboard component
20+
*/
1621
const ClusterGroup: React.FC = () => {
1722
const [data, setData] = useState<string[]>([])
1823
const [error, setError] = useState<string | null>(null)
1924
const [loading, setLoading] = useState<boolean>(true)
2025
const url = 'http://localhost:8081/api/cluster/all'
2126
const trigger = useAppSelector(selectTrigger)
2227

28+
//Sends get request to /cluster/all for general information everytime the trigger value changes
2329
useEffect(() => {
2430
// Sending GET request
2531
axios

frontend/src/components/pages/namespace/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ export interface ResponseNamespace {
1717
namespaces: NamespaceInfo[]
1818
}
1919

20+
/**
21+
* Card group component for the namespace type.
22+
* Displays the NamespaceView cards, title, loading window and network error.
23+
* @returns Rendered namespace view cards for the dashboard component
24+
*/
2025
const NamespaceGroup: React.FC = () => {
2126
const [data, setData] = useState<NamespaceInfo[]>([])
2227
const [error, setError] = useState<string | null>(null)
@@ -27,6 +32,7 @@ const NamespaceGroup: React.FC = () => {
2732
const baseURL = 'http://localhost:8081/api/namespace/all/'
2833
const trigger = useAppSelector(selectTrigger)
2934

35+
// Sends get request to /namespace/all for general information everytime the trigger value changes
3036
useEffect(() => {
3137
// Query parameters
3238
const clusterQuery = clusterFilter

frontend/src/components/pages/requestTriggerSlice.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const initialState: RequestTriggerState = {
1313
trigger: false,
1414
}
1515

16+
// Slice is mainly used to trigger the reload of the pages.
17+
// Separated from the other Slices to specifically avoid any sudden state changes by other reducers etc that would mess with the reload.
1618
const requestTriggerSlice = createSlice({
1719
name: 'triggerControl',
1820
initialState,

frontend/src/components/pages/tenant/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ export interface ResponseTenant {
1313
tenants: TenantInfo[]
1414
}
1515

16+
/**
17+
* Card group component for the tenant type.
18+
* Displays the TenantView cards, title, loading window and network error.
19+
* @returns Rendered tenant view cards for the dashboard component
20+
*/
1621
const TenantGroup: React.FC = () => {
1722
const [data, setData] = useState<TenantInfo[]>([])
1823
const [error, setError] = useState<string | null>(null)
@@ -22,6 +27,7 @@ const TenantGroup: React.FC = () => {
2227
const baseURL = 'http://localhost:8081/api/tenant/all'
2328
const trigger = useAppSelector(selectTrigger)
2429

30+
// Sends get request to /cluster/all for general information everytime the trigger value changes
2531
useEffect(() => {
2632
// Query parameters
2733
const clusterQuery = clusterFilter

frontend/src/components/pages/topic/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ export interface ResponseTopic {
1818
topics: TopicInfo[]
1919
}
2020

21+
/**
22+
* Card group component for the topic type.
23+
* Displays the TopicView cards, title, loading window and network error.
24+
* @returns Rendered topic view cards for the dashboard component
25+
*/
2126
const TopicGroup: React.FC = () => {
2227
const [data, setData] = useState<TopicInfo[]>([])
2328
const [error, setError] = useState<string | null>(null)
@@ -30,6 +35,7 @@ const TopicGroup: React.FC = () => {
3035
const baseURL = 'http://localhost:8081/api/topic/all'
3136
const trigger = useAppSelector(selectTrigger)
3237

38+
// Sends get request to /cluster/all for general information everytime the trigger value changes
3339
useEffect(() => {
3440
// Query parameters
3541
const clusterQuery = clusterFilter

frontend/src/store/filterSlice.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ export type HierarchyInPulsar =
1818
| 'message'
1919

2020
export type FilterState = {
21+
// used to keep track of what curently is filtered and what not:
2122
cluster: string[]
2223
tenant: string[]
2324
namespace: string[]
2425
topic: string[]
2526
message: string[]
27+
// used for displaying the options in the filter dropdowns:
2628
displayedOptions: {
2729
allClusters: string[]
2830
allTenants: string[]
@@ -65,34 +67,57 @@ const backendInstance = axios.create({
6567
timeout: 1000,
6668
})
6769

70+
/**
71+
* Fetches the general cluster information of cluster/all for filter options
72+
* @returns {ResponseCluster} - unedited data from endpoint
73+
*/
6874
const clusterOptionThunk = createAsyncThunk(
6975
'filterController/clusterOption',
7076
async () => {
7177
const response = await backendInstance.get('/cluster/all')
7278
return response.data
7379
}
7480
)
81+
82+
/**
83+
* Fetches the general tenant information of tenant/all for filter options
84+
* @returns {ResponseTenant} - unedited data from endpoint
85+
*/
7586
const tenantOptionThunk = createAsyncThunk(
7687
'filterController/tenantOption',
7788
async () => {
7889
const response = await backendInstance.get('/tenant/all')
7990
return response.data
8091
}
8192
)
93+
94+
/**
95+
* Fetches the general namespace information of namespace/all for filter options
96+
* @returns {ResponseNamespace} - unedited data from endpoint
97+
*/
8298
const namespaceOptionThunk = createAsyncThunk(
8399
'filterController/namespaceOption',
84100
async () => {
85101
const response = await backendInstance.get('/namespace/all')
86102
return response.data
87103
}
88104
)
105+
106+
/**
107+
* Fetches the general topic information of topic/all for filter options
108+
* @returns {ResponseTopic} - unedited data from endpoint
109+
*/
89110
const topicOptionThunk = createAsyncThunk(
90111
'filterController/topicOption',
91112
async () => {
92113
const response = await backendInstance.get('/topic/all')
93114
return response.data
94115
}
95116
)
117+
118+
/**
119+
* Dispatches all option thunks to fill the filter option arrays with information
120+
*/
96121
const fetchOptionsThunk = createAsyncThunk(
97122
'filterController/fetchOptions',
98123
async (_, thunkAPI) => {
@@ -123,19 +148,20 @@ const filterSlice = createSlice({
123148
setTopic: (state, action: PayloadAction<string[]>) => {
124149
state.topic = action.payload
125150
},
126-
// Adds query to one single filter (cluster, tenant, namespace, topic)
151+
// Adds an Id to one single filter array (cluster, tenant, namespace, topic)
127152
addFilter: (state, action: PayloadAction<UpdateSingleFilter>) => {
128153
const filterName = action.payload.filterName
129154
state[filterName].push(action.payload.id)
130155
},
131-
// Deletes query from one single filter (cluster, tenant, namespace, topic)
156+
// Deletes Id from one single filter array (cluster, tenant, namespace, topic)
132157
deleteFilter: (state, action: PayloadAction<UpdateSingleFilter>) => {
133158
const filterName = action.payload.filterName
134159
const query = action.payload.id
135160
state[filterName] = state[filterName].filter((element) => {
136161
return element !== query
137162
})
138163
},
164+
// Adds Id to a filter array while resetting all other Id's in it. Specifically needed for Drill Down Buttons
139165
addFilterByDrillDown: (
140166
state,
141167
action: PayloadAction<UpdateSingleFilter>
@@ -170,15 +196,16 @@ const filterSlice = createSlice({
170196
)
171197
}
172198
},
199+
// Resets all filter arrays / applied filters to initial state
173200
resetAllFilters: (state) => {
174-
//to not accidently delete the displayed options:
201+
// only the filter arrays are affected
175202
state.cluster = initialState.cluster
176203
state.tenant = initialState.tenant
177204
state.namespace = initialState.namespace
178205
state.topic = initialState.topic
179206
state.message = initialState.message
180207
},
181-
// the filtering of lower views do not apply to higher views,
208+
// the filtering of lower views does not apply to higher views,
182209
// those filters shall be reset when the user "goes up".
183210
updateFilterAccordingToNav: (
184211
state,

0 commit comments

Comments
 (0)