Skip to content

Commit c87a40e

Browse files
fix: minor ux improvements
1 parent a727c70 commit c87a40e

File tree

3 files changed

+78
-13
lines changed

3 files changed

+78
-13
lines changed

src/components/Catalogs.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { makeStyles } from 'tss-react/mui'
55
import { useCreateWorkloadCatalogMutation } from 'redux/otomiApi'
66
import { useSession } from 'providers/Session'
77
import { useHistory } from 'react-router-dom'
8+
import { useSnackbar } from 'notistack'
89
import CatalogCard from './CatalogCard'
910
import TableToolbar from './TableToolbar'
1011
import CatalogAddChartCard from './CatalogAddChartCard'
@@ -75,6 +76,7 @@ export default function ({ teamId, catalogs }: Props): React.ReactElement {
7576
const { user } = useSession()
7677
const { isPlatformAdmin } = user
7778

79+
const { enqueueSnackbar } = useSnackbar()
7880
const [createWorkloadCatalog] = useCreateWorkloadCatalogMutation()
7981

8082
useEffect(() => {
@@ -87,7 +89,7 @@ export default function ({ teamId, catalogs }: Props): React.ReactElement {
8789
setFilteredCatalog(filtered)
8890
}
8991

90-
const addChart = (values: NewChartValues) => {
92+
const addChart = async (values: NewChartValues) => {
9193
let finalUrl = ''
9294

9395
try {
@@ -106,11 +108,21 @@ export default function ({ teamId, catalogs }: Props): React.ReactElement {
106108

107109
const payload: NewChartPayload = { ...values, teamId, userSub: user.sub, url: finalUrl }
108110
console.log('halo add chart no mem leaks', payload)
109-
createWorkloadCatalog({ body: payload }).then((res) => {
110-
console.log(res)
111-
setOpenNewChartModal(false)
112-
history.go(0)
113-
})
111+
try {
112+
const result = await createWorkloadCatalog({ body: payload }).unwrap()
113+
if (result) {
114+
enqueueSnackbar('Chart successfully added', { variant: 'success' })
115+
setOpenNewChartModal(false)
116+
// Refresh catalog:
117+
// await getWorkloadCatalog()
118+
} else {
119+
enqueueSnackbar('Error adding chart', { variant: 'error' })
120+
setOpenNewChartModal(false)
121+
}
122+
} catch (error) {
123+
console.error('Error adding chart:', error)
124+
enqueueSnackbar('Error adding chart', { variant: 'error' })
125+
}
114126
}
115127

116128
return (

src/components/Markdown.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ const Header1 = createMDComp('h1', { ...headerStyle })
2323
const Header2 = createMDComp('h2', { ...headerStyle })
2424
const Header3 = createMDComp('h3', { ...mb })
2525
const Paragraph = createMDComp('p', { ...mb, ...lh })
26-
const Code = createMDComp('code', { borderRadius: '6px', padding: '1.5px 4px', backgroundColor: '#6e768164' })
26+
const UrlLink = createMDComp('a', { color: '#1CCAFF' })
27+
const Code = createMDComp('code', {
28+
borderRadius: '6px',
29+
padding: '1.5px 4px',
30+
backgroundColor: '#6e768164',
31+
textWrap: 'pretty',
32+
})
2733
const Pre = createMDComp('pre', {
2834
...mb,
2935
backgroundColor: '#6e768164',
@@ -64,6 +70,9 @@ export default function Markdown({ readme, sx }: Props) {
6470
p: {
6571
component: Paragraph,
6672
},
73+
a: {
74+
component: UrlLink,
75+
},
6776
code: {
6877
component: Code,
6978
},

src/components/NewChartModal.tsx

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ export default function NewChartModal({
104104
const [revision, setRevision] = useState('')
105105
const [allowTeams, setAllowTeams] = useState(true)
106106

107+
// Determines whether the GitHub URL is valid (i.e. a non-empty string that ends with "chart.yaml")
108+
const isValidGithubChartUrl = githubUrl.trim() !== '' && githubUrl.toLowerCase().endsWith('chart.yaml')
109+
107110
const getChart = async () => {
108111
if (!githubUrl) {
109112
console.error('No URL provided')
@@ -164,6 +167,16 @@ export default function NewChartModal({
164167
}
165168
}
166169

170+
// Common sx style to grey out disabled inputs.
171+
const disabledSx = {
172+
'& .MuiInputBase-root.Mui-disabled': {
173+
backgroundColor: '#58585833',
174+
},
175+
'& .MuiFormLabel-root.MuiInputLabel-root.Mui-disabled': {
176+
color: '#6b6b6b !important',
177+
},
178+
}
179+
167180
return (
168181
<Modal open={open} onClose={handleClose}>
169182
<ModalBox>
@@ -177,6 +190,10 @@ export default function NewChartModal({
177190
)}
178191
<ModalContent>
179192
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
193+
{/* Helper text */}
194+
<Typography variant='body2' color='textSecondary'>
195+
Please provide a valid GitHub URL pointing to a Chart.yaml file. The URL must end with chart.yaml.
196+
</Typography>
180197
{/* Display the chart icon as a non-interactive image.
181198
If chartIcon is not set, show a default placeholder image. */}
182199
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
@@ -202,12 +219,39 @@ export default function NewChartModal({
202219
Test connection
203220
</Button>
204221
</Box>
205-
206-
{/* Editable fields for the fetched chart data */}
207-
<TextField label='Chart Name' value={chartName} onChange={(e) => setChartName(e.target.value)} fullWidth />
208-
<TextField label='Icon URL' value={chartIcon} onChange={(e) => setChartIcon(e.target.value)} fullWidth />
209-
<TextField label='Chart Path' value={chartPath} onChange={(e) => setChartPath(e.target.value)} fullWidth />
210-
<TextField label='Revision' value={revision} onChange={(e) => setRevision(e.target.value)} fullWidth />
222+
{/* Editable fields for the fetched chart data. They remain disabled until a valid URL is provided. */}
223+
<TextField
224+
label='Chart Name'
225+
value={chartName}
226+
onChange={(e) => setChartName(e.target.value)}
227+
fullWidth
228+
disabled={!isValidGithubChartUrl}
229+
sx={disabledSx}
230+
/>
231+
<TextField
232+
label='Icon URL'
233+
value={chartIcon}
234+
onChange={(e) => setChartIcon(e.target.value)}
235+
fullWidth
236+
disabled={!isValidGithubChartUrl}
237+
sx={disabledSx}
238+
/>
239+
<TextField
240+
label='Chart Path'
241+
value={chartPath}
242+
onChange={(e) => setChartPath(e.target.value)}
243+
fullWidth
244+
disabled={!isValidGithubChartUrl}
245+
sx={disabledSx}
246+
/>
247+
<TextField
248+
label='Revision'
249+
value={revision}
250+
onChange={(e) => setRevision(e.target.value)}
251+
fullWidth
252+
disabled={!isValidGithubChartUrl}
253+
sx={disabledSx}
254+
/>
211255
{/* New checkbox: Allow teams to use this chart */}
212256
<FormControlLabel
213257
control={

0 commit comments

Comments
 (0)