Skip to content
Closed
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
23 changes: 23 additions & 0 deletions api/admin_ui/src/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,29 @@ export class AdminAPIClient {
return res.json();
}

async v4SetConfig(payload: {
key: string;
value: any;
level: 'global' | 'tenant' | 'department' | 'group' | 'user';
level_id?: string;
reason?: string;
}): Promise<{
key: string;
value: any;
source: string;
level: string;
level_id?: string;
encrypted: boolean;
updated_at: string;
}>{
const res = await this.fetch('/admin/config/v4/set', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
});
return res.json();
}

// User traits (admin-only)
async getUserTraits(): Promise<{ schema_version: number; user: { id: string }; traits: string[] }>{
const res = await this.fetch('/admin/user/traits');
Expand Down
202 changes: 188 additions & 14 deletions api/admin_ui/src/components/ConfigurationManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import {
Visibility as VisibilityIcon,
VisibilityOff as VisibilityOffIcon,
Info as InfoIcon,
FlashOn as FlashOnIcon
FlashOn as FlashOnIcon,
Save as SaveIcon,
Cancel as CancelIcon
} from '@mui/icons-material';

import AdminAPIClient from '../api/client';
Expand Down Expand Up @@ -116,6 +118,14 @@ function ConfigurationManager({ client, docsBase }: ConfigurationManagerProps) {
const [searchTerm, setSearchTerm] = useState<string>('');
const [cacheStats] = useState<any>({ backend: 'memory', memory_items: 0 });

// Editing state
const [editingKey, setEditingKey] = useState<string | null>(null);
const [editValue, setEditValue] = useState<any>(null);
const [editLevel, setEditLevel] = useState<'global' | 'tenant' | 'department' | 'group' | 'user'>('global');
const [editLevelId, setEditLevelId] = useState<string>('');
const [editReason, setEditReason] = useState<string>('');
const [saving, setSaving] = useState<boolean>(false);

// Filter keys based on search and category
const filteredKeys = ALL_KEYS.filter(key => {
const matchesSearch = searchTerm === '' || key.toLowerCase().includes(searchTerm.toLowerCase());
Expand Down Expand Up @@ -236,6 +246,58 @@ function ConfigurationManager({ client, docsBase }: ConfigurationManagerProps) {
}
};

const saveConfigValue = async () => {
if (!editingKey) return;

try {
setSaving(true);
setError(null);

await client.v4SetConfig({
key: editingKey,
value: editValue,
level: editLevel,
level_id: editLevel === 'global' ? undefined : editLevelId,
reason: editReason || 'Configuration update via Admin Console'
});

setSuccess(`Configuration '${editingKey}' updated successfully`);

// Reset editing state
setEditingKey(null);
setEditValue(null);
setEditLevel('global');
setEditLevelId('');
setEditReason('');

// Refresh configuration
await fetchEffectiveConfig();

setTimeout(() => setSuccess(null), 3000);
} catch (err: any) {
console.error('Failed to save config:', err);
setError(err.message || 'Failed to save configuration');
} finally {
setSaving(false);
}
};

const startEditing = (key: string, currentValue: any) => {
setEditingKey(key);
setEditValue(currentValue);
setEditLevel('global'); // Default to global level
setEditLevelId('');
setEditReason('');
};

const cancelEditing = () => {
setEditingKey(null);
setEditValue(null);
setEditLevel('global');
setEditLevelId('');
setEditReason('');
};

const toggleShowValue = (key: string) => {
setShowValues(prev => ({
...prev,
Expand Down Expand Up @@ -445,19 +507,35 @@ function ConfigurationManager({ client, docsBase }: ConfigurationManagerProps) {
config.value || 'Not set'
) : 'Loading...'}
</Typography>
{isSecret && config && (
<Tooltip title={showValue ? 'Hide value' : 'Show value'}>
<IconButton
size="small"
onClick={(e) => {
e.stopPropagation();
toggleShowValue(key);
}}
>
{showValue ? <VisibilityOffIcon fontSize="small" /> : <VisibilityIcon fontSize="small" />}
</IconButton>
</Tooltip>
)}
<Stack direction="row" spacing={1}>
{isSecret && config && (
<Tooltip title={showValue ? 'Hide value' : 'Show value'}>
<IconButton
size="small"
onClick={(e) => {
e.stopPropagation();
toggleShowValue(key);
}}
>
{showValue ? <VisibilityOffIcon fontSize="small" /> : <VisibilityIcon fontSize="small" />}
</IconButton>
</Tooltip>
)}
{config && key in safeKeys && (
<Tooltip title="Edit configuration">
<IconButton
size="small"
color="primary"
onClick={(e) => {
e.stopPropagation();
startEditing(key, config.value);
}}
>
<SettingsIcon fontSize="small" />
</IconButton>
</Tooltip>
)}
</Stack>
</Box>
</Paper>
);
Expand Down Expand Up @@ -559,6 +637,102 @@ function ConfigurationManager({ client, docsBase }: ConfigurationManagerProps) {
</Grid>
)}

{/* Configuration Edit Dialog */}
{editingKey && (
<Paper sx={{ mt: 3, p: 3, border: 2, borderColor: 'primary.main' }}>
<Typography variant="h6" gutterBottom sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
<SettingsIcon />
Edit Configuration: {editingKey}
</Typography>

<Stack spacing={3}>
{/* Level Selector */}
<Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
<TextField
select
label="Configuration Level"
value={editLevel}
onChange={(e) => setEditLevel(e.target.value as any)}
sx={{ minWidth: 200 }}
size="small"
>
<MenuItem value="global">Global (System-wide)</MenuItem>
<MenuItem value="tenant">Tenant</MenuItem>
<MenuItem value="department">Department</MenuItem>
<MenuItem value="group">Group</MenuItem>
<MenuItem value="user">User</MenuItem>
</TextField>

{editLevel !== 'global' && (
<TextField
label={`${editLevel.charAt(0).toUpperCase() + editLevel.slice(1)} ID`}
value={editLevelId}
onChange={(e) => setEditLevelId(e.target.value)}
placeholder={
editLevel === 'department' ? 'tenant_id:department_name' :
editLevel === 'tenant' ? 'tenant_id' :
editLevel === 'group' ? 'group_id' :
'user_id'
}
sx={{ flex: 1 }}
size="small"
required
/>
)}
</Stack>

{/* Value Editor */}
<TextField
label="Configuration Value"
value={editValue}
onChange={(e) => {
const val = e.target.value;
// Try to parse as appropriate type
if (val === 'true') setEditValue(true);
else if (val === 'false') setEditValue(false);
else if (/^\d+$/.test(val)) setEditValue(parseInt(val, 10));
else setEditValue(val);
}}
multiline
rows={2}
fullWidth
size="small"
helperText={`Constraints: ${JSON.stringify(safeKeys[editingKey] || {})}`}
/>

{/* Reason */}
<TextField
label="Reason for Change (Optional)"
value={editReason}
onChange={(e) => setEditReason(e.target.value)}
fullWidth
size="small"
placeholder="Configuration update via Admin Console"
/>

{/* Actions */}
<Stack direction="row" spacing={2} justifyContent="flex-end">
<Button
variant="outlined"
onClick={cancelEditing}
startIcon={<CancelIcon />}
disabled={saving}
>
Cancel
</Button>
<Button
variant="contained"
onClick={saveConfigValue}
startIcon={<SaveIcon />}
disabled={saving || (editLevel !== 'global' && !editLevelId)}
>
{saving ? 'Saving...' : 'Save Configuration'}
</Button>
</Stack>
</Stack>
</Paper>
)}

{/* Info Panel with Stats */}
<Paper sx={{ mt: 3, p: 2, backgroundColor: theme.palette.action.hover }}>
<Grid container spacing={2}>
Expand Down
Loading
Loading