function useProjectKeyFromLocation() {
const location = useLocation();
+ // Permissions Templates page uses id in query for template id, so to avoid conflict and unwanted fetching we don't search for project there
+ if (location.pathname.includes('permission_templates')) {
+ return null;
+ }
const search = new URLSearchParams(location.search);
const id = search.get('id');
return id as string;
const projectKey = project ?? keyFromUrl;
return useQuery({
- queryKey: ['devops_integration', projectKey, 'binding'],
+ queryKey: ['devops_integration', projectKey ?? '_blank_', 'binding'],
queryFn: ({ queryKey: [_, key] }) =>
getProjectAlmBinding(key).catch((e: Response) => {
if (e.status === HttpStatus.NotFound) {
}),
staleTime: 60_000,
retry: false,
+ enabled: projectKey !== null,
...options,
});
}
const keyFromUrl = useProjectKeyFromLocation();
const client = useQueryClient();
return useMutation({
- mutationFn: () => deleteProjectAlmBinding(project ?? keyFromUrl),
+ mutationFn: () => {
+ const key = project ?? keyFromUrl;
+ if (key === null) {
+ throw new Error('No project key');
+ }
+ return deleteProjectAlmBinding(key);
+ },
onSuccess: () => {
client.invalidateQueries({
queryKey: ['devops_integration', project ?? keyFromUrl, 'binding'],
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { useQuery } from '@tanstack/react-query';
+import { UseQueryOptions, useQuery } from '@tanstack/react-query';
import { getSystemInfo } from '../../api/system';
-import { SysInfoCluster } from '../../types/types';
+import { Provider, SysInfoCluster } from '../../types/types';
-export function useIdentityProviderQuery() {
+export function useIdentityProviderQuery<T = { provider: Provider }>(
+ options?: Omit<UseQueryOptions<{ provider: Provider }, Error, T>, 'queryKey' | 'queryFn'>,
+) {
return useQuery({
queryKey: ['identity_provider', 'users_and_groups_provider'],
queryFn: async () => {
const info = (await getSystemInfo()) as SysInfoCluster;
return { provider: info.System['External Users and Groups Provisioning'] };
},
+ ...options,
});
}