Skip to content

Commit b9a5c63

Browse files
committed
Fix secrets save
Signed-off-by: Trung Nguyen <[email protected]>
1 parent 91a6555 commit b9a5c63

File tree

1 file changed

+46
-19
lines changed
  • src/extension/ui/src/components/tile

1 file changed

+46
-19
lines changed

src/extension/ui/src/components/tile/Modal.tsx

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { v1 } from '@docker/extension-api-client-types';
22
import CheckOutlined from '@mui/icons-material/CheckOutlined';
33
import Close from '@mui/icons-material/Close';
44
import CloseOutlined from '@mui/icons-material/CloseOutlined';
5-
import DeleteOutlined from '@mui/icons-material/DeleteOutlined';
5+
import EditOutlinedIcon from '@mui/icons-material/EditOutlined';
66
import Launch from '@mui/icons-material/Launch';
77
import {
88
Alert,
@@ -17,7 +17,6 @@ import {
1717
DialogTitle,
1818
IconButton,
1919
Link,
20-
OutlinedInput,
2120
Paper,
2221
Stack,
2322
Switch,
@@ -34,16 +33,20 @@ import {
3433
Typography,
3534
useTheme,
3635
} from '@mui/material';
37-
import { useEffect, useState } from 'react';
36+
import { useEffect, useRef, useState } from 'react';
3837

39-
import { ASSIGNED_SECRET_PLACEHOLDER, getUnsupportedSecretMessage, MCP_POLICY_NAME } from '../../Constants';
38+
import {
39+
ASSIGNED_SECRET_PLACEHOLDER,
40+
getUnsupportedSecretMessage,
41+
MCP_POLICY_NAME,
42+
} from '../../Constants';
43+
import { formatName } from '../../formatName';
4044
import { useCatalogOperations } from '../../queries/useCatalog';
4145
import { useConfig } from '../../queries/useConfig';
46+
import useDDInfo from '../../queries/useDDInfo';
4247
import { useSecrets } from '../../queries/useSecrets';
4348
import { CatalogItemRichened } from '../../types/catalog';
4449
import ConfigEditor from './ConfigEditor';
45-
import { formatName } from '../../formatName';
46-
import useDDInfo from '../../queries/useDDInfo';
4750

4851
interface TabPanelProps {
4952
children?: React.ReactNode;
@@ -86,6 +89,9 @@ const ConfigurationModal = ({
8689
const [localSecrets, setLocalSecrets] = useState<
8790
{ [key: string]: string | undefined } | undefined
8891
>(undefined);
92+
93+
const inputRefs = useRef<HTMLInputElement[]>([]);
94+
8995
const theme = useTheme();
9096

9197
const { isLoading: secretsLoading, mutate: mutateSecret } =
@@ -293,7 +299,13 @@ const ConfigurationModal = ({
293299
</TableCell>
294300
<TableCell>
295301
<Link
296-
onClick={() => client.host.openExternal(`${catalogItem.readme}#tool-${tool.name.replaceAll(' ', '-')}` || '')}
302+
onClick={() =>
303+
client.host.openExternal(
304+
`${
305+
catalogItem.readme
306+
}#tool-${tool.name.replaceAll(' ', '-')}` || ''
307+
)
308+
}
297309
href="#"
298310
target="_blank"
299311
>
@@ -317,7 +329,7 @@ const ConfigurationModal = ({
317329
minHeight: '180px',
318330
}}
319331
>
320-
<Stack direction="column" spacing={2} >
332+
<Stack direction="column" spacing={2}>
321333
<ConfigEditor catalogItem={catalogItem} client={client} />
322334
<Stack>
323335
<Typography variant="subtitle2">Secrets</Typography>
@@ -332,13 +344,13 @@ const ConfigurationModal = ({
332344
</Alert>
333345
)}
334346
{ddInfo?.hasSecretSupport &&
335-
catalogItem.secrets &&
336-
catalogItem.secrets?.length > 0 ? (
337-
catalogItem.secrets.map((secret) => {
347+
catalogItem.secrets &&
348+
catalogItem.secrets?.length > 0 ? (
349+
catalogItem.secrets.map((secret, index) => {
338350
const secretEdited =
339351
(secret.assigned &&
340352
localSecrets[secret.name] !==
341-
ASSIGNED_SECRET_PLACEHOLDER) ||
353+
ASSIGNED_SECRET_PLACEHOLDER) ||
342354
(!secret.assigned &&
343355
localSecrets[secret.name] !== '');
344356
return (
@@ -350,6 +362,10 @@ const ConfigurationModal = ({
350362
>
351363
<TextField
352364
size="small"
365+
inputRef={(element) =>
366+
(inputRefs.current[index] = element)
367+
}
368+
disabled={secret.assigned}
353369
key={secret.name}
354370
label={secret.name}
355371
value={localSecrets[secret.name]}
@@ -365,21 +381,28 @@ const ConfigurationModal = ({
365381
{secret.assigned && !secretEdited && (
366382
<IconButton
367383
size="small"
368-
color="error"
369384
onClick={() => {
385+
setLocalSecrets({
386+
...localSecrets,
387+
[secret.name]: '',
388+
});
389+
// We need to enable the input to be able to focus on it
390+
inputRefs.current[index].disabled = false;
391+
inputRefs.current[index].focus();
370392
mutateSecret.mutateAsync({
371393
name: secret.name,
372394
value: undefined,
373395
policies: [MCP_POLICY_NAME],
374396
});
375397
}}
376398
>
377-
<DeleteOutlined />
399+
<EditOutlinedIcon fontSize="small" />
378400
</IconButton>
379401
)}
380402
{secretEdited && (
381403
<ButtonGroup>
382404
<IconButton
405+
size="small"
383406
onClick={async () => {
384407
await mutateSecret.mutateAsync({
385408
name: secret.name,
@@ -389,10 +412,12 @@ const ConfigurationModal = ({
389412
}}
390413
>
391414
<CheckOutlined
415+
fontSize="small"
392416
sx={{ color: 'success.main' }}
393417
/>
394418
</IconButton>
395419
<IconButton
420+
size="small"
396421
onClick={async () => {
397422
setLocalSecrets({
398423
...localSecrets,
@@ -402,7 +427,10 @@ const ConfigurationModal = ({
402427
});
403428
}}
404429
>
405-
<CloseOutlined sx={{ color: 'error.main' }} />
430+
<CloseOutlined
431+
fontSize="small"
432+
sx={{ color: 'error.main' }}
433+
/>
406434
</IconButton>
407435
</ButtonGroup>
408436
)}
@@ -417,10 +445,9 @@ const ConfigurationModal = ({
417445
</Stack>
418446
</TabPanel>
419447
</>
420-
)
421-
}
422-
</DialogContent >
423-
</Dialog >
448+
)}
449+
</DialogContent>
450+
</Dialog>
424451
);
425452
};
426453

0 commit comments

Comments
 (0)