-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pci.kubernetes): add test and admission plugin page
ref: TAPC-33 Signed-off-by: Pierre-Philippe <[email protected]>
- Loading branch information
Pierre-Philippe
committed
Oct 17, 2024
1 parent
8c40e73
commit a2136b1
Showing
12 changed files
with
405 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/manager/apps/pci-kubernetes/src/api/hooks/useAdmissionPlugin/useAdmissionPlugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
import queryClient from '@/queryClient'; | ||
import { getAllKubeQueryKey } from '../useKubernetes'; | ||
|
||
import { updateAdmissionPlugin } from '@/api/data/kubernetes'; | ||
import { TKube } from '@/types'; | ||
|
||
export const useUpdateAdmissionPlugin = ({ | ||
onError, | ||
projectId, | ||
onSuccess, | ||
kubeId, | ||
}) => { | ||
const mutation = useMutation({ | ||
mutationFn: async (customization: TKube['customization']) => | ||
updateAdmissionPlugin({ projectId, kubeId, customization }), | ||
onError, | ||
onSuccess: async () => { | ||
await queryClient.invalidateQueries({ | ||
queryKey: getAllKubeQueryKey(projectId), | ||
}); | ||
onSuccess(); | ||
}, | ||
}); | ||
return { | ||
updateAdmissionPlugins: mutation.mutate, | ||
...mutation, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 0 additions & 68 deletions
68
...es/manager/apps/pci-kubernetes/src/components/service/AdmissionPluginsModal.component.tsx
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
packages/manager/apps/pci-kubernetes/src/hooks/usePluginState.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { renderHook } from '@testing-library/react'; | ||
import usePluginState from './usePluginState'; | ||
|
||
describe('usePluginState', () => { | ||
it('should return "enabled" if the plugin is in the enabled list', () => { | ||
const enabled = ['plugin1', 'plugin2']; | ||
const disabled = ['plugin3']; | ||
const { result } = renderHook(() => usePluginState(enabled, disabled)); | ||
|
||
expect(result.current('plugin1')).toBe('enabled'); | ||
expect(result.current('plugin2')).toBe('enabled'); | ||
}); | ||
|
||
it('should return "disabled" if the plugin is in the disabled list', () => { | ||
const enabled = ['plugin1', 'plugin2']; | ||
const disabled = ['plugin3']; | ||
const { result } = renderHook(() => usePluginState(enabled, disabled)); | ||
|
||
expect(result.current('plugin3')).toBe('disabled'); | ||
}); | ||
|
||
it('should return null if the plugin is not in either list', () => { | ||
const enabled = ['plugin1', 'plugin2']; | ||
const disabled = ['plugin3']; | ||
const { result } = renderHook(() => usePluginState(enabled, disabled)); | ||
|
||
expect(result.current('plugin4')).toBeNull(); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
packages/manager/apps/pci-kubernetes/src/hooks/usePluginState.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { useCallback } from 'react'; | ||
|
||
const usePluginState = (enabled: string[], disabled: string[]) => | ||
useCallback( | ||
(pluginName: string) => { | ||
if (enabled.includes(pluginName)) { | ||
return 'enabled'; | ||
} | ||
if (disabled.includes(pluginName)) { | ||
return 'disabled'; | ||
} | ||
return null; | ||
}, | ||
[enabled, disabled], | ||
); | ||
|
||
export default usePluginState; |
60 changes: 60 additions & 0 deletions
60
packages/manager/apps/pci-kubernetes/src/hooks/useResizeOsdsModal.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { useEffect } from 'react'; | ||
|
||
export const useResponsiveModal = (size) => { | ||
useEffect(() => { | ||
const getStyles = () => { | ||
if (window.innerWidth > 768) { | ||
return { | ||
maxWidth: size, | ||
minWidth: 'auto', | ||
}; | ||
} | ||
return { | ||
maxWidth: 'inherit', | ||
minWidth: 'inherit', | ||
}; | ||
}; | ||
|
||
const applyStyles = (element: HTMLElement) => { | ||
const styles = getStyles(); | ||
Object.assign(element.style, styles); | ||
}; | ||
|
||
const observer = new MutationObserver((mutations) => { | ||
mutations.forEach((mutation) => { | ||
if (mutation.type === 'childList' || mutation.type === 'attributes') { | ||
const popup = document | ||
.querySelector('osds-modal') | ||
?.shadowRoot?.querySelector( | ||
'dialog > div > div.popup', | ||
) as HTMLElement; | ||
|
||
if (popup) { | ||
applyStyles(popup); | ||
window.addEventListener('resize', () => applyStyles(popup)); | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
observer.observe(document.body, { | ||
childList: true, | ||
subtree: true, | ||
attributes: true, | ||
}); | ||
|
||
const initialPopup = document | ||
.querySelector('osds-modal') | ||
?.shadowRoot?.querySelector('dialog > div > div.popup') as HTMLElement; | ||
|
||
if (initialPopup) { | ||
applyStyles(initialPopup); | ||
window.addEventListener('resize', () => applyStyles(initialPopup)); | ||
} | ||
|
||
return () => { | ||
observer.disconnect(); | ||
window.removeEventListener('resize', () => applyStyles(initialPopup)); | ||
}; | ||
}, []); | ||
}; |
Oops, something went wrong.