Skip to content

Commit c54e0e5

Browse files
committed
refactor
1 parent f2fd02f commit c54e0e5

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

src/components/ControlPlane/ManagedResources.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ type ResourceRow = {
5656
conditionSyncedMessage: string;
5757
};
5858

59+
/**
60+
* Checks if a resource is managed by Flux based on the kustomize.toolkit.fluxcd.io/name label
61+
*/
62+
const isResourceFluxManaged = (item: ManagedResourceItem | undefined): boolean => {
63+
if (!item) return false;
64+
65+
const fluxLabelValue = (item?.metadata?.labels as unknown as Record<string, unknown> | undefined)?.[
66+
'kustomize.toolkit.fluxcd.io/name'
67+
];
68+
69+
return fluxLabelValue != null && (typeof fluxLabelValue !== 'string' || fluxLabelValue.trim() !== '');
70+
};
71+
5972
export function ManagedResources() {
6073
const { t } = useTranslation();
6174
const toast = useToast();
@@ -169,11 +182,7 @@ export function ManagedResources() {
169182
disableFilters: true,
170183
Cell: ({ row }) => {
171184
const { original } = row;
172-
const fluxLabelValue = (
173-
original?.item?.metadata?.labels as unknown as Record<string, unknown> | undefined
174-
)?.['kustomize.toolkit.fluxcd.io/name'];
175-
const isFluxManaged =
176-
typeof fluxLabelValue === 'string' ? fluxLabelValue.trim() !== '' : fluxLabelValue != null;
185+
const isFluxManaged = isResourceFluxManaged(original?.item);
177186
return original?.item ? (
178187
<YamlViewButton
179188
variant="resource"
@@ -207,11 +216,7 @@ export function ManagedResources() {
207216
const item = original?.item;
208217
if (!item) return undefined;
209218

210-
const fluxLabelValue = (item?.metadata?.labels as unknown as Record<string, unknown> | undefined)?.[
211-
'kustomize.toolkit.fluxcd.io/name'
212-
];
213-
const isFluxManaged =
214-
typeof fluxLabelValue === 'string' ? fluxLabelValue.trim() !== '' : fluxLabelValue != null;
219+
const isFluxManaged = isResourceFluxManaged(item);
215220

216221
const actions: ActionItem<ManagedResourceItem>[] = [
217222
{

src/spaces/mcp/auth/AuthContextMcp.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@ const AuthContextMcp = createContext<AuthContextMcpType | null>(null);
1717

1818
export function AuthProviderMcp({ children, mcpUsers = [] }: { children: ReactNode; mcpUsers?: RoleBinding[] }) {
1919
const auth = useAuthOnboarding();
20+
2021
const userEmail = auth.user?.email;
2122

22-
const matchingRoleBinding = mcpUsers.find((roleBinding) => roleBinding.subjects[0]?.name?.includes(userEmail ?? ''));
23+
const matchingRoleBinding = mcpUsers.find(
24+
(roleBinding) =>
25+
Array.isArray(roleBinding.subjects) &&
26+
roleBinding.subjects.some((subject) => subject?.name?.includes(userEmail ?? '')),
27+
);
2328
const hasMCPAdminRights = matchingRoleBinding?.role === 'admin';
2429

2530
const [isAuthenticated, setIsAuthenticated] = useState(false);

0 commit comments

Comments
 (0)