Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/components/study-container.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
useIntlRef,
useNotificationsListener,
useSnackMessage,
BuildStatus,
BuildStatus, fetchUserQuotaState,

Check warning on line 41 in src/components/study-container.jsx

View workflow job for this annotation

GitHub Actions / build / build

Insert `⏎···`
} from '@gridsuite/commons-ui';
import NetworkModificationTreeModel from './graph/network-modification-tree-model';
import { getFirstNodeOfType } from './graph/util/model-functions';
Expand Down Expand Up @@ -493,6 +493,28 @@
listenerCallbackMessage: handleEvent,
});

const handleQuotaEvent = useCallback(

Check warning on line 496 in src/components/study-container.jsx

View workflow job for this annotation

GitHub Actions / build / build

Delete `⏎········`

Check failure on line 496 in src/components/study-container.jsx

View workflow job for this annotation

GitHub Actions / build / build

React Hook useCallback does nothing when called with only one argument. Did you forget to pass an array of dependencies?
(event) => {
const eventData = parseEventData(event);

Check warning on line 498 in src/components/study-container.jsx

View workflow job for this annotation

GitHub Actions / build / build

Replace `············` with `········`
const quotaType = eventData.headers.quotaType;

Check warning on line 499 in src/components/study-container.jsx

View workflow job for this annotation

GitHub Actions / build / build

Delete `····`

fetchUserQuotaState(userName).then((response) => {

Check warning on line 501 in src/components/study-container.jsx

View workflow job for this annotation

GitHub Actions / build / build

Replace `············` with `········`
const currentComputationQuota = response[quotaType]

Check warning on line 502 in src/components/study-container.jsx

View workflow job for this annotation

GitHub Actions / build / build

Replace `················const·currentComputationQuota·=·response[quotaType]` with `············const·currentComputationQuota·=·response[quotaType];`
if (currentComputationQuota != null) {

Check warning on line 503 in src/components/study-container.jsx

View workflow job for this annotation

GitHub Actions / build / build

Replace `················` with `············`
if (currentComputationQuota.current >= currentComputationQuota.max) {

Check warning on line 504 in src/components/study-container.jsx

View workflow job for this annotation

GitHub Actions / build / build

Delete `····`
console.info('TODO: Quota reached', quotaType, currentComputationQuota);

Check warning on line 505 in src/components/study-container.jsx

View workflow job for this annotation

GitHub Actions / build / build

Delete `····`
} else {

Check warning on line 506 in src/components/study-container.jsx

View workflow job for this annotation

GitHub Actions / build / build

Delete `····`
console.info('TODO: Quota available', quotaType, currentComputationQuota);
}
}
})
}
);

useNotificationsListener(NotificationsUrlKeys.QUOTA, {
listenerCallbackMessage: handleQuotaEvent,
});

useEffect(() => {
if (studyUuid) {
websocketExpectedCloseRef.current = false;
Expand Down
6 changes: 5 additions & 1 deletion src/hooks/use-notifications-url-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const useNotificationsUrlGenerator = (): Partial<Record<NotificationsUrlKeys, st
// The websocket API doesn't allow relative urls
const wsBase = getWsBase();
const studyUuid = useSelector((state: AppState) => state.studyUuid);
const userId = useSelector((state: AppState) => state.user?.profile.sub);

// return a mapColumns with NOTIFICATIONS_URL_KEYS and undefined value if URL is not yet buildable (studyUuid)
// it will be used to register listeners as soon as possible.
Expand All @@ -30,14 +31,17 @@ const useNotificationsUrlGenerator = (): Partial<Record<NotificationsUrlKeys, st
[NotificationsUrlKeys.STUDY]: studyUuid
? `${wsBase}${PREFIX_STUDY_NOTIFICATION_WS}/notify?studyUuid=${encodeURIComponent(studyUuid)}`
: undefined,
[NotificationsUrlKeys.QUOTA]: userId
? `${wsBase}${PREFIX_STUDY_NOTIFICATION_WS}/quota?userId=${encodeURIComponent(userId)}`
: undefined,
[NotificationsUrlKeys.DIRECTORY_DELETE_STUDY]: studyUuid
? `${wsBase}${PREFIX_DIRECTORY_NOTIFICATION_WS}/notify?updateType=deleteElement&elementUuid=${encodeURIComponent(
studyUuid
)}`
: undefined,
[NotificationsUrlKeys.DIRECTORY]: `${wsBase}${PREFIX_DIRECTORY_NOTIFICATION_WS}/notify?updateType=directories`,
}),
[wsBase, studyUuid]
[wsBase, studyUuid, userId]
);
};

Expand Down
Loading