Skip to content

Commit 2fe2ff9

Browse files
authored
Merge pull request #23 from ChathuraIshara/display-sanitized-intergration-name
Add sanitized intergration name preview in ProjectForm component
2 parents 677c742 + 14537b1 commit 2fe2ff9

File tree

1 file changed

+60
-8
lines changed
  • workspaces/ballerina/ballerina-visualizer/src/views/BI/ProjectForm

1 file changed

+60
-8
lines changed

workspaces/ballerina/ballerina-visualizer/src/views/BI/ProjectForm/index.tsx

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
import React, { useEffect, useState } from "react";
20-
import { Button, Icon, LocationSelector, TextField, Typography } from "@wso2/ui-toolkit";
20+
import { Button, Icon, LocationSelector, TextField, Typography,Codicon,Tooltip } from "@wso2/ui-toolkit";
2121
import styled from "@emotion/styled";
2222
import { useRpcContext } from "@wso2/ballerina-rpc-client";
2323
import { BodyText } from "../../styles";
@@ -47,6 +47,48 @@ const IconButton = styled.div`
4747
}
4848
`;
4949

50+
const PreviewContainer = styled.div`
51+
border: 1px solid var(--vscode-input-border);
52+
border-radius: 4px;
53+
padding: 8px 12px;
54+
display: inline-flex;
55+
align-items: center;
56+
width: fit-content;
57+
height: 28px;
58+
gap: 8px;
59+
background-color: var(--vscode-editor-background);
60+
* {
61+
cursor: default !important;
62+
}
63+
`;
64+
65+
const InputPreviewWrapper = styled.div`
66+
display: flex;
67+
flex-direction: column;
68+
gap: 3px;
69+
margin: 20px 0;
70+
`;
71+
72+
const PreviewText = styled(Typography)`
73+
color: var(--vscode-sideBarTitle-foreground);
74+
opacity: 0.5;
75+
font-family: var(--vscode-editor-font-family, 'Monaco', 'Menlo', 'Ubuntu Mono', monospace);
76+
word-break: break-all;
77+
min-width: 100px;
78+
display: flex;
79+
align-items: center;
80+
line-height: 1;
81+
`;
82+
83+
const PreviewIcon = styled(Codicon)`
84+
display: flex;
85+
align-items: center;
86+
`;
87+
88+
const sanitizeProjectName = (name: string): string => {
89+
return name.replace(/[^a-z0-9]/gi, '_').toLowerCase();
90+
};
91+
5092
export function ProjectForm() {
5193
const { rpcClient } = useRpcContext();
5294
const [selectedModule, setSelectedModule] = useState("Main");
@@ -94,13 +136,23 @@ export function ProjectForm() {
94136
<BodyText>
95137
Name your integration and select a location to start building.
96138
</BodyText>
97-
<TextField
98-
onTextChange={handleProjectName}
99-
sx={{ marginTop: 20, marginBottom: 20 }}
100-
value={name}
101-
label="Integration Name"
102-
placeholder="Enter a integration name"
103-
/>
139+
<InputPreviewWrapper>
140+
<TextField
141+
onTextChange={handleProjectName}
142+
value={name}
143+
label="Integration Name"
144+
placeholder="Enter a integration name"
145+
autoFocus={true}
146+
/>
147+
<PreviewContainer>
148+
<PreviewIcon name="project" iconSx={{ fontSize: 14, color: "var(--vscode-descriptionForeground)" }} />
149+
<Tooltip content="A unique identifier for your intergration">
150+
<PreviewText variant="caption">
151+
{name ? sanitizeProjectName(name) : "integration_id"}
152+
</PreviewText>
153+
</Tooltip>
154+
</PreviewContainer>
155+
</InputPreviewWrapper>
104156
<LocationSelector
105157
label="Select Integration Path"
106158
selectedFile={path}

0 commit comments

Comments
 (0)