Skip to content

Commit 1dc1b3e

Browse files
added secret as link
1 parent c80c5ec commit 1dc1b3e

File tree

5 files changed

+111
-16
lines changed

5 files changed

+111
-16
lines changed

src/ui/components/forms/index.tsx

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,14 @@ export const MakeSecretField = (
348348

349349
export const EditField = (
350350
props: {
351+
filteredSecretId?: string;
351352
label: string;
352353
labelColor: any;
353354
placeholder: any;
354355
value: string;
355356
defaultValue?: string;
356357
optional: boolean;
358+
viewSecretDetail?: any;
357359
} & any,
358360
): JSX.Element => {
359361
return (
@@ -365,16 +367,48 @@ export const EditField = (
365367
optional={props.optional}
366368
labelColor={props.labelColor}
367369
InputComponent={
368-
<TextInput
369-
{...props}
370-
style={{
371-
backgroundColor: props.disabled && '#E9EAEC',
372-
borderWidth: props.disabled && '0px',
373-
}}
374-
defaultValue={props?.defaultValue}
375-
value={props.value}
376-
placeholder={props.placeholder}
377-
/>
370+
<>
371+
{props.filteredSecretId ? (
372+
<Box
373+
paddingLeft="md"
374+
style={{
375+
height: '40px',
376+
width: '30vw',
377+
backgroundColor: props.disabled && '#F6F7F7',
378+
borderWidth: props.disabled && '0px',
379+
borderRadius: '4px',
380+
justifyContent: 'flex-start',
381+
alignItems: 'center',
382+
display: 'flex',
383+
}}
384+
>
385+
<Paragraph
386+
onClick={() => props.viewSecretDetail()}
387+
style={{
388+
cursor: 'pointer',
389+
textAlign: 'center',
390+
fontSize: '16px',
391+
color: '#22BBDD',
392+
textDecorationLine: 'underline',
393+
}}
394+
>
395+
{props.defaultValue}
396+
</Paragraph>
397+
</Box>
398+
) : (
399+
<TextInput
400+
{...props}
401+
style={{
402+
backgroundColor: props.disabled && '#E9EAEC',
403+
borderWidth: props.disabled && '0px',
404+
}}
405+
filteredSecretId={props.filteredSecretId}
406+
defaultValue={props?.defaultValue}
407+
value={props.value}
408+
placeholder={props.placeholder}
409+
/>
410+
)}
411+
</>
378412
}
379413
/>
380414
{!props.disabled && (

src/ui/layouts/NonEditableConfig/index.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ import {
99
import { ToggleField } from '../common/FormElement';
1010
import styles from './index.module.scss';
1111
import { useService } from './useService';
12+
import { routePaths } from '../../../routes/routePaths';
13+
import { useSelector } from 'react-redux';
14+
import { secretSelectors, workspaceSelectors } from '../../../redux/selectors';
15+
import { useHistory } from '../../hooks';
1216

1317
export const NonEditableConfig: React.FC<{ details: any }> = ({ details }) => {
18+
const secrets = useSelector(secretSelectors.mySecrets);
19+
const selectedWorkspace = useSelector(workspaceSelectors.selectedWorkspace);
20+
const history = useHistory();
1421
const { flavor } = useService({
1522
details,
1623
});
@@ -27,12 +34,26 @@ export const NonEditableConfig: React.FC<{ details: any }> = ({ details }) => {
2734

2835
const getFormElement: any = (elementName: any, elementSchema: any) => {
2936
if (flavor?.config_schema?.properties[elementName]?.type === 'string') {
37+
const extracted = elementSchema.split(/\./)[0];
38+
const secretName = extracted.replace(/{{|}}|\./g, '').trim();
39+
const filteredSecret = secrets?.filter(
40+
(item) => item.name === secretName,
41+
);
3042
return (
3143
<>
3244
{flavor?.config_schema?.properties[elementName].sensitive ? (
3345
<Box marginTop="lg" style={{ width: '30vw' }}>
3446
<EditField
3547
disabled
48+
viewSecretDetail={() => {
49+
history.push(
50+
routePaths.secret.configuration(
51+
filteredSecret[0]?.id,
52+
selectedWorkspace,
53+
),
54+
);
55+
}}
56+
filteredSecretId={filteredSecret[0]?.id}
3657
// onKeyDown={(e: any) => onPressEnter(e, 'string', elementName)}
3758
// onChangeText={(e: any) => onPressEnter(e, 'string', elementName)}
3859
label={titleCase(elementName) + ' (Secret)'}

src/ui/layouts/NonEditableConfig/useService.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
import { useDispatch } from 'react-redux';
1+
import { useDispatch, useSelector } from 'react-redux';
22
// import { stackComponentSelectors } from '../../../redux/selectors';
33

44
// import YAML from 'json2yaml';
55
import { useEffect, useState } from 'react';
66
// import { useLocationPath } from '../../hooks';
7-
import { flavorPagesActions, flavorsActions } from '../../../redux/actions';
7+
import {
8+
flavorPagesActions,
9+
flavorsActions,
10+
secretsActions,
11+
} from '../../../redux/actions';
12+
import { workspaceSelectors } from '../../../redux/selectors';
813

914
interface ServiceInterface {
1015
flavor: any;
@@ -13,7 +18,7 @@ interface ServiceInterface {
1318
export const useService = ({ details }: { details: any }): ServiceInterface => {
1419
// const locationPath = useLocationPath();
1520
const [flavor, setFlavor] = useState();
16-
// debugger;
21+
const selectedWorkspace = useSelector(workspaceSelectors.selectedWorkspace);
1722
const dispatch = useDispatch();
1823
useEffect(() => {
1924
setFetching(true);
@@ -28,6 +33,12 @@ export const useService = ({ details }: { details: any }): ServiceInterface => {
2833
onFailure: () => setFetching(false),
2934
}),
3035
);
36+
dispatch(
37+
secretsActions.getMy({
38+
size: 1000,
39+
workspace: selectedWorkspace,
40+
}),
41+
);
3142
// eslint-disable-next-line react-hooks/exhaustive-deps
3243
}, []);
3344

src/ui/layouts/stackComponents/StackDetail/Configuration/index.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
useSelector,
2222
} from '../../../../hooks';
2323
import {
24+
secretSelectors,
2425
sessionSelectors,
2526
userSelectors,
2627
workspaceSelectors,
@@ -46,6 +47,8 @@ export const Configuration: React.FC<{ stackId: TId; loading?: boolean }> = ({
4647
});
4748
const user = useSelector(userSelectors.myUser);
4849
const [fetching, setFetching] = useState(false);
50+
const secrets = useSelector(secretSelectors.mySecrets);
51+
4952
const authToken = useSelector(sessionSelectors.authenticationToken);
5053
const selectedWorkspace = useSelector(workspaceSelectors.selectedWorkspace);
5154
const dispatch = useDispatch();
@@ -55,7 +58,7 @@ export const Configuration: React.FC<{ stackId: TId; loading?: boolean }> = ({
5558
s.replace(/^_*(.)|_+(.)/g, (s: any, c: string, d: string) =>
5659
c ? c.toUpperCase() : ' ' + d.toUpperCase(),
5760
);
58-
61+
console.log(secrets, 'asdasd1232323cwwcwf');
5962
const onCallApi = (updateConfig: any) => {
6063
// ;
6164
const { id }: any = workspaces.find(
@@ -247,12 +250,28 @@ export const Configuration: React.FC<{ stackId: TId; loading?: boolean }> = ({
247250

248251
const getFormElement: any = (elementName: any, elementSchema: any) => {
249252
if (flavor?.configSchema?.properties[elementName]?.type === 'string') {
253+
const extracted = elementSchema.split(/\./)[0];
254+
const secretName = extracted.replace(/{{|}}|\./g, '').trim();
255+
const filteredSecret = secrets?.filter(
256+
(item) => item.name === secretName,
257+
);
258+
259+
// console.log(filteredSecret, 'asd123ffwwvweer');
250260
return (
251261
<>
252262
{flavor?.configSchema?.properties[elementName].sensitive ? (
253263
<Box marginTop="lg" style={{ width: '30vw' }}>
254264
<EditField
255265
disabled
266+
viewSecretDetail={() => {
267+
history.push(
268+
routePaths.secret.configuration(
269+
filteredSecret[0]?.id,
270+
selectedWorkspace,
271+
),
272+
);
273+
}}
274+
filteredSecretId={filteredSecret[0]?.id}
256275
// onKeyDown={(e: any) => onPressEnter(e, 'string', elementName)}
257276
// onChangeText={(e: any) => onPressEnter(e, 'string', elementName)}
258277
label={titleCase(elementName) + ' (Secret)'}

src/ui/layouts/stackComponents/StackDetail/Configuration/useService.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import { useSelector } from 'react-redux';
1+
import { useDispatch, useSelector } from 'react-redux';
22
import {
33
flavorSelectors,
44
stackComponentSelectors,
5+
workspaceSelectors,
56
} from '../../../../../redux/selectors';
67

78
import YAML from 'json2yaml';
89
import { useEffect, useState } from 'react';
910
import { useLocationPath } from '../../../../hooks';
11+
import { secretsActions } from '../../../../../redux/actions';
1012
// import {
1113
// flavorPagesActions,
1214
// // flavorsActions,
@@ -23,13 +25,21 @@ export const useService = ({ stackId }: { stackId: TId }): ServiceInterface => {
2325
const stackComponent: TStack = useSelector(
2426
stackComponentSelectors.stackComponentForId(stackId),
2527
);
28+
const selectedWorkspace = useSelector(workspaceSelectors.selectedWorkspace);
29+
2630
const locationPath = useLocationPath();
2731
const [flavor, setFlavor] = useState();
2832
const flavors = useSelector(flavorSelectors.myFlavorsAll);
29-
33+
const dispatch = useDispatch();
3034
// const dispatch = useDispatch();
3135
useEffect(() => {
3236
setFlavor(flavors[0] as any);
37+
dispatch(
38+
secretsActions.getMy({
39+
size: 1000,
40+
workspace: selectedWorkspace,
41+
}),
42+
);
3343

3444
// eslint-disable-next-line react-hooks/exhaustive-deps
3545
}, [locationPath]);

0 commit comments

Comments
 (0)