Skip to content

Commit da2085e

Browse files
committed
fix: some adjustments and cleanup
1 parent a3965af commit da2085e

File tree

3 files changed

+43
-48
lines changed

3 files changed

+43
-48
lines changed

src/components/KymaCompanion/components/Chat/messages/CodePanel.tsx

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
Button,
88
} from '@ui5/webcomponents-react';
99
import {
10+
CodeSegment,
1011
Segment,
1112
formatCodeSegment,
1213
} from 'components/KymaCompanion/utils/formatMarkdown';
@@ -77,68 +78,65 @@ export default function CodePanel({
7778
const { language, code } = formatCodeSegment(segment?.content ?? segment);
7879
const [layoutState, setLayoutColumn] = useRecoilState(columnLayoutState);
7980
const navigate = useNavigate();
80-
const [searchParams] = useSearchParams();
8181
const cluster = useRecoilValue(clusterState);
8282

8383
const createUrl = (namespace, resType, type, resName) => {
8484
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;
8891

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+
});
9897

99-
return `${basePath}${resourcePath}?${params}`;
98+
return `${basePath}${fullResourcePath}?${params.toString()}`;
10099
};
101100

102101
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
104103
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', '')) || {};
108105

109106
if (parts[0] === 'namespaces') {
110107
[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-
});
135108
} else {
136109
[resType, resName] = [parts[0], parts[1]];
137110
}
138111

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+
139138
navigate(createUrl(namespace, resType, type, resName));
140139
};
141-
142140
return !language ? (
143141
<div className="code-response sap-margin-y-small">
144142
<Icon

src/components/KymaCompanion/components/Chat/messages/Message.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { Text } from '@ui5/webcomponents-react';
22
import CodePanel from './CodePanel';
33
import TasksList from './TasksList';
4-
import {
5-
handleResponseFormatting,
6-
segmentMarkdownText,
7-
} from 'components/KymaCompanion/utils/formatMarkdown';
4+
import { handleResponseFormatting } from 'components/KymaCompanion/utils/formatMarkdown';
85
import './Message.scss';
96

107
interface MessageProps {

src/state/columnLayoutAtom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export type ShowCreate = {
1111
resourceType: null | string;
1212
namespaceId: null | string;
1313
resource?: null | object;
14-
resourceUrl: null | string;
14+
resourceUrl?: null | string;
1515
};
1616
export type ShowEdit = ColumnState & {
1717
resource?: object | null;

0 commit comments

Comments
 (0)