Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nms): Initially load count of subscribers correctly #12383

Merged
merged 1 commit into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions nms/app/components/context/SubscriberContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ state: paginated subscribers
sessionState: paginated subscribers session state
metrics: subscriber metrics
gwSubscriberMap: gateway subscriber map
totalCount: total count of subscribers
setState: POST, PUT, DELETE subscriber
*/
export type SubscriberContextType = {
Expand All @@ -43,6 +44,7 @@ export type SubscriberContextType = {
forbiddenNetworkTypes: {[string]: core_network_types},
metrics?: {[string]: Metrics},
gwSubscriberMap: {[gateway_id]: Array<subscriber_id>},
totalCount: number,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: update the comments above

setState?: (
key: string,
val?: mutable_subscriber | mutable_subscribers,
Expand Down
3 changes: 3 additions & 0 deletions nms/app/components/lte/LteContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ export function SubscriberContextProvider(props: Props) {
const [sessionState, setSessionState] = useState({});
const [subscriberMetrics, setSubscriberMetrics] = useState({});
const [isLoading, setIsLoading] = useState(true);
const [totalCount, setTotalCount] = useState(0);
const enqueueSnackbar = useEnqueueSnackbar();
useEffect(() => {
const fetchLteState = async () => {
Expand All @@ -257,6 +258,7 @@ export function SubscriberContextProvider(props: Props) {
setForbiddenNetworkTypes,
setSubscriberMetrics,
setSessionState,
setTotalCount,
enqueueSnackbar,
}),
setIsLoading(false);
Expand All @@ -275,6 +277,7 @@ export function SubscriberContextProvider(props: Props) {
state: subscriberMap,
metrics: subscriberMetrics,
sessionState: sessionState,
totalCount: totalCount,
gwSubscriberMap: getGatewaySubscriberMap(sessionState),
setState: (
key: subscriber_id,
Expand Down
5 changes: 4 additions & 1 deletion nms/app/state/lte/SubscriberState.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ type InitSubscriberStateProps = {
networkId: network_id,
setSubscriberMap: ({[string]: subscriber}) => void,
setSessionState: ({[string]: subscriber_state}) => void,
setSubscriberMetrics?: ({[string]: Metrics}) => void,
setSubscriberMetrics: ({[string]: Metrics}) => void,
setTotalCount: number => void,
enqueueSnackbar?: (
msg: string,
cfg: EnqueueSnackbarOptions,
Expand Down Expand Up @@ -156,6 +157,7 @@ export default async function InitSubscriberState(
setSubscriberMap,
setSubscriberMetrics,
setSessionState,
setTotalCount,
enqueueSnackbar,
} = props;
const subscriberResponse = await FetchSubscribers({
Expand All @@ -164,6 +166,7 @@ export default async function InitSubscriberState(
});
if (subscriberResponse) {
setSubscriberMap(subscriberResponse.subscribers);
setTotalCount(subscriberResponse.total_count);
}

const state = await FetchSubscriberState({networkId, enqueueSnackbar});
Expand Down
2 changes: 1 addition & 1 deletion nms/app/views/network/NetworkKPIs.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function NetworkKPI() {
{
icon: PeopleIcon,
category: 'Subscribers',
value: Object.keys(subscriberCtx.state).length,
value: subscriberCtx.totalCount,
},
{
icon: LibraryBooksIcon,
Expand Down
1 change: 1 addition & 0 deletions nms/app/views/network/__tests__/NetworkTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ describe('<NetworkDashboard />', () => {
const subscriberCtx = {
state: subscribers,
forbidden_network_types: subscribers,
totalCount: 1,
forbiddenNetworkTypes: {},
gwSubscriberMap: {},
sessionState: {},
Expand Down
2 changes: 2 additions & 0 deletions nms/app/views/subscriber/__tests__/SubscriberAddEditTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ describe('<AddSubscriberButton />', () => {
forbiddenNetworkTypes: forbiddenNetworkTypes,
gwSubscriberMap: {},
sessionState: sessionState,
totalCount: 2,
setState: async (key, value?) =>
setSubscriberState({
networkId: 'test',
Expand Down Expand Up @@ -350,6 +351,7 @@ describe('<AddSubscriberButton />', () => {
gwSubscriberMap: {},
forbiddenNetworkTypes: forbiddenNetworkTypes,
sessionState: sessionState,
totalCount: 1,
setState: (key, value?) =>
setSubscriberState({
networkId: 'test',
Expand Down
1 change: 1 addition & 0 deletions nms/app/views/subscriber/__tests__/SubscriberTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ describe('<SubscriberDashboard />', () => {
forbiddenNetworkTypes: {},
gwSubscriberMap: {},
sessionState: {},
totalCount: 2,
};

return (
Expand Down