|
7 | 7 | Button, |
8 | 8 | } from '@ui5/webcomponents-react'; |
9 | 9 | import { |
| 10 | + CodeSegment, |
10 | 11 | Segment, |
11 | 12 | formatCodeSegment, |
12 | 13 | } from 'components/KymaCompanion/utils/formatMarkdown'; |
@@ -77,68 +78,65 @@ export default function CodePanel({ |
77 | 78 | const { language, code } = formatCodeSegment(segment?.content ?? segment); |
78 | 79 | const [layoutState, setLayoutColumn] = useRecoilState(columnLayoutState); |
79 | 80 | const navigate = useNavigate(); |
80 | | - const [searchParams] = useSearchParams(); |
81 | 81 | const cluster = useRecoilValue(clusterState); |
82 | 82 |
|
83 | 83 | const createUrl = (namespace, resType, type, resName) => { |
84 | 84 | const basePath = `/cluster/${cluster?.contextName}`; |
85 | | - const resourcePath = `${ |
86 | | - namespace ? `/namespaces/${namespace}` : '' |
87 | | - }/${pluralize(resType).toLowerCase()}${resName ? '/' + resName : ''}`; |
| 85 | + const resourcePath = namespace |
| 86 | + ? `/namespaces/${namespace}/${pluralize(resType).toLowerCase()}` |
| 87 | + : `/${pluralize(resType).toLowerCase()}`; |
| 88 | + const fullResourcePath = resName |
| 89 | + ? `${resourcePath}/${resName}` |
| 90 | + : resourcePath; |
88 | 91 |
|
89 | | - const params = new URLSearchParams(); |
90 | | - if (layoutState.layout !== 'OneColumn') { |
91 | | - params.set('layout', layoutState.layout); |
92 | | - } |
93 | | - if (type === 'Update') { |
94 | | - params.set('showEdit', 'true'); |
95 | | - } else { |
96 | | - params.set('showCreate', 'true'); |
97 | | - } |
| 92 | + const params = new URLSearchParams({ |
| 93 | + layout: layoutState.layout !== 'OneColumn' ? layoutState.layout : '', |
| 94 | + showEdit: type === 'Update' ? 'true' : '', |
| 95 | + showCreate: type === 'New' ? 'true' : '', |
| 96 | + }); |
98 | 97 |
|
99 | | - return `${basePath}${resourcePath}?${params}`; |
| 98 | + return `${basePath}${fullResourcePath}?${params.toString()}`; |
100 | 99 | }; |
101 | 100 |
|
102 | 101 | const handleSetupInEditor = (url, resource, type) => { |
103 | | - const parts = url.split('/').slice(1); // Remove the leading empty string from split |
| 102 | + const parts = url.split('/').filter(Boolean); // Remove empty strings from split |
104 | 103 | let [namespace, resType, resName] = [null, '', '']; |
105 | | - const parsedResource = jsyaml.load(resource.replace('yaml', '')) as |
106 | | - | object |
107 | | - | null; |
| 104 | + const parsedResource = jsyaml.load(resource.replace('yaml', '')) || {}; |
108 | 105 |
|
109 | 106 | if (parts[0] === 'namespaces') { |
110 | 107 | [namespace, resType, resName] = [parts[1], parts[2], parts[3]]; |
111 | | - |
112 | | - setLayoutColumn({ |
113 | | - ...layoutState, |
114 | | - layout: 'TwoColumnsMidExpanded', |
115 | | - showCreate: |
116 | | - type === 'New' |
117 | | - ? { |
118 | | - ...layoutState.showCreate, |
119 | | - resource: parsedResource, |
120 | | - resourceType: resType, |
121 | | - namespaceId: namespace, |
122 | | - } |
123 | | - : null, |
124 | | - showEdit: |
125 | | - type === 'Update' |
126 | | - ? { |
127 | | - ...layoutState.showEdit, |
128 | | - resource: parsedResource, |
129 | | - resourceType: resType, |
130 | | - namespaceId: namespace, |
131 | | - resourceName: resName, |
132 | | - } |
133 | | - : null, |
134 | | - }); |
135 | 108 | } else { |
136 | 109 | [resType, resName] = [parts[0], parts[1]]; |
137 | 110 | } |
138 | 111 |
|
| 112 | + setLayoutColumn({ |
| 113 | + ...layoutState, |
| 114 | + layout: 'TwoColumnsMidExpanded', |
| 115 | + showCreate: |
| 116 | + type === 'New' |
| 117 | + ? { |
| 118 | + ...layoutState.showCreate, |
| 119 | + resource: parsedResource, |
| 120 | + resourceType: resType, |
| 121 | + namespaceId: namespace, |
| 122 | + } |
| 123 | + : null, |
| 124 | + showEdit: |
| 125 | + type === 'Update' |
| 126 | + ? { |
| 127 | + ...layoutState.showEdit, |
| 128 | + resource: parsedResource, |
| 129 | + resourceType: resType, |
| 130 | + namespaceId: namespace, |
| 131 | + resourceName: resName, |
| 132 | + apiGroup: null, |
| 133 | + apiVersion: null, |
| 134 | + } |
| 135 | + : null, |
| 136 | + }); |
| 137 | + |
139 | 138 | navigate(createUrl(namespace, resType, type, resName)); |
140 | 139 | }; |
141 | | - |
142 | 140 | return !language ? ( |
143 | 141 | <div className="code-response sap-margin-y-small"> |
144 | 142 | <Icon |
|
0 commit comments