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(requests): remove duplicate queries #249

Merged
merged 5 commits into from
Aug 26, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions src/app/Events/EventTemplates.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
/*
* Copyright The Cryostat Authors
*
*
* The Universal Permissive License (UPL), Version 1.0
*
*
* Subject to the condition set forth below, permission is hereby granted to any
* person obtaining a copy of this software, associated documentation and/or data
* (collectively the "Software"), free of charge and under any and all copyright
* rights in the Software, and any and all patent rights owned or freely
* licensable by each licensor hereunder covering either (i) the unmodified
* Software as contributed to or provided by such licensor, or (ii) the Larger
* Works (as defined below), to deal in both
*
*
* (a) the Software, and
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
* one is included with the Software (each a "Larger Work" to which the Software
* is contributed by such licensors),
*
*
* without restriction, including without limitation the rights to copy, create
* derivative works of, display, perform, and distribute the Software and make,
* use, sell, offer for sale, import, export, have made, and have sold the
* Software and the Larger Work(s), and to sublicense the foregoing rights on
* either these or other terms.
*
*
* This license is subject to the following condition:
* The above copyright notice and either this complete permission notice or at
* a minimum a reference to the UPL must be included in all copies or
* substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -90,16 +90,16 @@ export const EventTemplates = () => {
setFilteredTemplates([...filtered]);
}, [filterText, templates, sortBy]);

const handleTemplates = (templates) => {
const handleTemplates = React.useCallback((templates) => {
setTemplates(templates);
setIsLoading(false);
setErrorMessage('');
}
}, [setTemplates, setIsLoading, setErrorMessage]);

const handleError = (error) => {
const handleError = React.useCallback((error) => {
setIsLoading(false);
setErrorMessage(error.message);
}
}, [setIsLoading, setErrorMessage]);

const refreshTemplates = React.useCallback(() => {
setIsLoading(true)
Expand All @@ -111,16 +111,15 @@ export const EventTemplates = () => {
concatMap(target => context.api.doGet<EventTemplate[]>(`targets/${encodeURIComponent(target.connectUrl)}/templates`)),
).subscribe(value => handleTemplates(value), err => handleError(err))
);
}, [addSubscription, context.target, context.api]);
}, [addSubscription, context, context.target, context.api, setIsLoading, handleTemplates, handleError]);

React.useEffect(() => {
addSubscription(
context.target.target().subscribe(refreshTemplates)
);
}, []);
}, [context, context.target, addSubscription, refreshTemplates]);

React.useEffect(() => {
refreshTemplates();
if (!context.settings.autoRefreshEnabled()) {
return;
}
Expand Down
26 changes: 11 additions & 15 deletions src/app/Events/EventTypes.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
/*
* Copyright The Cryostat Authors
*
*
* The Universal Permissive License (UPL), Version 1.0
*
*
* Subject to the condition set forth below, permission is hereby granted to any
* person obtaining a copy of this software, associated documentation and/or data
* (collectively the "Software"), free of charge and under any and all copyright
* rights in the Software, and any and all patent rights owned or freely
* licensable by each licensor hereunder covering either (i) the unmodified
* Software as contributed to or provided by such licensor, or (ii) the Larger
* Works (as defined below), to deal in both
*
*
* (a) the Software, and
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
* one is included with the Software (each a "Larger Work" to which the Software
* is contributed by such licensors),
*
*
* without restriction, including without limitation the rights to copy, create
* derivative works of, display, perform, and distribute the Software and make,
* use, sell, offer for sale, import, export, have made, and have sold the
* Software and the Larger Work(s), and to sublicense the foregoing rights on
* either these or other terms.
*
*
* This license is subject to the following condition:
* The above copyright notice and either this complete permission notice or at
* a minimum a reference to the UPL must be included in all copies or
* substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -90,16 +90,16 @@ export const EventTypes = () => {
'Categories'
];

const handleTypes = (types) => {
const handleTypes = React.useCallback((types) => {
setTypes(types);
setIsLoading(false);
setErrorMessage('');
}
}, [setTypes, setIsLoading, setErrorMessage]);

const handleError = (error) => {
const handleError = React.useCallback((error) => {
setIsLoading(false);
setErrorMessage(error.message);
}
}, [setIsLoading, setErrorMessage]);

const refreshEvents = React.useCallback(() => {
setIsLoading(true)
Expand All @@ -118,11 +118,7 @@ export const EventTypes = () => {
addSubscription(
context.target.target().subscribe(refreshEvents)
);
}, []);

React.useEffect(() => {
refreshEvents();
}, []);
}, [addSubscription, context, context.target, refreshEvents]);

React.useEffect(() => {
const sub = context.target.authFailure().subscribe(() => {
Expand Down
19 changes: 9 additions & 10 deletions src/app/RecordingList/ActiveRecordingsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ export const ActiveRecordingsList: React.FunctionComponent<ActiveRecordingsListP
first(),
).subscribe(value => handleRecordings(value), err => handleError(err))
);
}, [addSubscription, context.target, context.api]);
}, [addSubscription, context, context.target, context.api, setIsLoading, handleRecordings, handleError]);

React.useEffect(() => {
addSubscription(
context.target.target().subscribe(refreshRecordingList)
);
}, [addSubscription]);
}, [addSubscription, context, context.target, refreshRecordingList]);

React.useEffect(() => {
addSubscription(context.notificationChannel.messages(NotificationCategory.RecordingCreated)
Expand All @@ -142,7 +142,7 @@ export const ActiveRecordingsList: React.FunctionComponent<ActiveRecordingsListP
notifications.info('Recording Created', `${event.recording} created in target: ${event.target}`);
refreshRecordingList();
}));
}, [addSubscription, context.notificationChannel, notifications, refreshRecordingList]);
}, [addSubscription, context, context.notificationChannel, notifications, refreshRecordingList]);

React.useEffect(() => {
addSubscription(context.notificationChannel.messages(NotificationCategory.RecordingSaved)
Expand All @@ -151,7 +151,7 @@ export const ActiveRecordingsList: React.FunctionComponent<ActiveRecordingsListP
notifications.info('Recording Archived', `${event.recording} was archived`);
refreshRecordingList();
}));
}, [addSubscription, context.notificationChannel, notifications, refreshRecordingList]);
}, [addSubscription, context, context.notificationChannel, notifications, refreshRecordingList]);

React.useEffect(() => {
addSubscription(context.notificationChannel.messages(NotificationCategory.RecordingArchived)
Expand All @@ -160,7 +160,7 @@ export const ActiveRecordingsList: React.FunctionComponent<ActiveRecordingsListP
notifications.info('Recording Archived', `${event.recording} was archived`);
refreshRecordingList();
}));
}, [addSubscription, context.notificationChannel, notifications, refreshRecordingList]);
}, [addSubscription, context, context.notificationChannel, notifications, refreshRecordingList]);

React.useEffect(() => {
addSubscription(context.notificationChannel.messages(NotificationCategory.RecordingDeleted)
Expand All @@ -169,14 +169,14 @@ export const ActiveRecordingsList: React.FunctionComponent<ActiveRecordingsListP
notifications.info('Recording Deleted', `${event.recording} was deleted`);
refreshRecordingList();
}));
}, [addSubscription, context.notificationChannel, notifications, refreshRecordingList]);
}, [addSubscription, context, context.notificationChannel, notifications, refreshRecordingList]);

React.useEffect(() => {
const sub = context.target.authFailure().subscribe(() => {
setErrorMessage("Auth failure");
});
return () => sub.unsubscribe();
}, [context.target, setErrorMessage]);
}, [context, context.target, setErrorMessage]);

const handleArchiveRecordings = React.useCallback(() => {
const tasks: Observable<boolean>[] = [];
Expand Down Expand Up @@ -231,13 +231,12 @@ export const ActiveRecordingsList: React.FunctionComponent<ActiveRecordingsListP
}, [recordings, checkedIndices, handleRowCheck, context.reports, context.api, addSubscription, refreshRecordingList]);

React.useEffect(() => {
refreshRecordingList();
if (!context.settings.autoRefreshEnabled()) {
return;
}
const id = window.setInterval(() => refreshRecordingList(), context.settings.autoRefreshPeriod() * context.settings.autoRefreshUnits());
return () => window.clearInterval(id);
}, [refreshRecordingList, context.settings]);
}, [refreshRecordingList, context, context.settings]);

const RecordingRow = (props) => {
const expandedRowId =`active-table-row-${props.index}-exp`;
Expand Down Expand Up @@ -305,7 +304,7 @@ export const ActiveRecordingsList: React.FunctionComponent<ActiveRecordingsListP
<hr></hr>
<br></br>
<Text>Automated Analysis:</Text>
<ReportFrame recording={props.recording} width="100%" height="640" />
<ReportFrame isExpanded={isExpanded} recording={props.recording} width="100%" height="640" />
</DataListContent>
</DataListItem>
);
Expand Down
33 changes: 16 additions & 17 deletions src/app/RecordingList/ArchivedRecordingsList.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
/*
* Copyright The Cryostat Authors
*
*
* The Universal Permissive License (UPL), Version 1.0
*
*
* Subject to the condition set forth below, permission is hereby granted to any
* person obtaining a copy of this software, associated documentation and/or data
* (collectively the "Software"), free of charge and under any and all copyright
* rights in the Software, and any and all patent rights owned or freely
* licensable by each licensor hereunder covering either (i) the unmodified
* Software as contributed to or provided by such licensor, or (ii) the Larger
* Works (as defined below), to deal in both
*
*
* (a) the Software, and
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
* one is included with the Software (each a "Larger Work" to which the Software
* is contributed by such licensors),
*
*
* without restriction, including without limitation the rights to copy, create
* derivative works of, display, perform, and distribute the Software and make,
* use, sell, offer for sale, import, export, have made, and have sold the
* Software and the Larger Work(s), and to sublicense the foregoing rights on
* either these or other terms.
*
*
* This license is subject to the following condition:
* The above copyright notice and either this complete permission notice or at
* a minimum a reference to the UPL must be included in all copies or
* substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -67,24 +67,24 @@ export const ArchivedRecordingsList: React.FunctionComponent<ArchivedRecordingsL
'Name'
];

const handleHeaderCheck = (checked) => {
const handleHeaderCheck = React.useCallback((checked) => {
setHeaderChecked(checked);
setCheckedIndices(checked ? Array.from(new Array(recordings.length), (x, i) => i) : []);
};
}, [setHeaderChecked, setCheckedIndices, recordings]);

const handleRowCheck = (checked, index) => {
const handleRowCheck = React.useCallback((checked, index) => {
if (checked) {
setCheckedIndices(ci => ([...ci, index]));
} else {
setHeaderChecked(false);
setCheckedIndices(ci => ci.filter(v => v !== index));
}
};
}, [setCheckedIndices, setHeaderChecked]);

const handleRecordings = (recordings) => {
const handleRecordings = React.useCallback((recordings) => {
setRecordings(recordings);
setIsLoading(false);
}
}, [setRecordings, setIsLoading]);

const refreshRecordingList = React.useCallback(() => {
setIsLoading(true);
Expand All @@ -93,13 +93,13 @@ export const ArchivedRecordingsList: React.FunctionComponent<ArchivedRecordingsL
.pipe(first())
.subscribe(handleRecordings)
);
}, [addSubscription, context.api]);
}, [addSubscription, context, context.api, setIsLoading, handleRecordings]);

React.useEffect(() => {
addSubscription(
context.target.target().subscribe(refreshRecordingList)
);
}, []);
}, [addSubscription, context, context.target, refreshRecordingList]);

const handleDeleteRecordings = () => {
const tasks: Observable<any>[] = [];
Expand Down Expand Up @@ -127,13 +127,12 @@ export const ArchivedRecordingsList: React.FunctionComponent<ArchivedRecordingsL
}, [props.updater])

React.useEffect(() => {
refreshRecordingList();
if (!context.settings.autoRefreshEnabled()) {
return;
}
const id = window.setInterval(() => refreshRecordingList(), context.settings.autoRefreshPeriod() * context.settings.autoRefreshUnits());
return () => window.clearInterval(id);
}, []);
}, [context, context.settings, refreshRecordingList]);

const RecordingRow = (props) => {
const expandedRowId =`archived-table-row-${props.index}-exp`;
Expand Down Expand Up @@ -168,7 +167,7 @@ export const ArchivedRecordingsList: React.FunctionComponent<ArchivedRecordingsL
id={`archived-ex-expand-${props.index}`}
isHidden={!isExpanded}
>
<ReportFrame recording={props.recording} width="100%" height="640" />
<ReportFrame isExpanded={isExpanded} recording={props.recording} width="100%" height="640" />
</DataListContent>
</DataListItem>
</>);
Expand Down
Loading