import { useState, useEffect, useCallback } from 'react'; import api from '../../services/api'; import { useToast } from '../../contexts/ToastContext'; /** * Read-mostly facade showing the *resolved* shared variables for a resource — * i.e. the merged effective set from every shared variable group attached to it. * Secret values arrive pre-masked from the backend; this panel never reveals * them. Editing happens in SharedVariableGroups (the group is the source of * truth); this surface is the read-side facade meant to be embedded on a * resource's detail page. * * Props: * resourceType one of SharedResourceService.RESOURCE_TYPES * resourceId the resource's id (number or string) */ const EnvironmentVariablesPanel = ({ resourceType, resourceId }) => { const toast = useToast(); const [variables, setVariables] = useState([]); const [groups, setGroups] = useState([]); const [loading, setLoading] = useState(true); const [filter, setFilter] = useState(''); const load = useCallback(async () => { if (!resourceType || resourceId == null) return; try { setLoading(true); const data = await api.getResolvedVariables(resourceType, resourceId); setVariables(data.variables || []); setGroups(data.groups || []); } catch (err) { toast.error('Failed to load shared variables'); console.error('Failed to load resolved variables:', err); } finally { setLoading(false); } }, [resourceType, resourceId, toast]); useEffect(() => { load(); }, [load]); const filtered = filter ? variables.filter((v) => v.key.toLowerCase().includes(filter.toLowerCase())) : variables; if (loading) { return
Effective variables merged from every shared group attached to this resource. Later-attached groups override earlier ones on key collisions. Secret values are masked.
{variables.length > 5 && (| Key | Value | Source group |
|---|---|---|
| {v.key} | {v.value} | {v.group_name} |