Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Commit 4b17cb3

Browse files
committed
fix: catch orb parse error, clear search box, hide filter select
1 parent 737419e commit 4b17cb3

4 files changed

Lines changed: 53 additions & 17 deletions

File tree

src/components/menus/definitions/OrbDefinitionsMenu.tsx

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import CollapsibleList from '../../containers/CollapsibleList';
2323

2424
export class OrbImportWithMeta extends orb.OrbImport {
2525
logo_url: string;
26+
url: string;
2627

2728
constructor(
2829
alias: string,
@@ -31,12 +32,14 @@ export class OrbImportWithMeta extends orb.OrbImport {
3132
manifest: OrbImportManifest,
3233
version: string,
3334
logo_url: string,
35+
url: string,
3436
description?: string,
3537
display?: OrbDisplayMeta,
3638
) {
3739
super(alias, namespace, orb, version, manifest, description, display);
3840

3941
this.logo_url = logo_url;
42+
this.url = url;
4043
}
4144
}
4245

@@ -116,11 +119,13 @@ const OrbDefinitionContainer = (props: {
116119
const OrbDefinitionsMenu = (props: OrbDefinitionProps) => {
117120
const orbs = useStoreState((state) => state.definitions.orbs);
118121
const importOrb = useStoreActions((actions) => actions.importOrb);
122+
const unimportOrb = useStoreActions((actions) => actions.unimportOrb);
119123
const [orb, setOrb] = useState<OrbImportWithMeta>();
124+
const [error, setError] = useState(false);
120125

121126
useEffect(() => {
122-
loadOrb(`${props.namespace}/${props.name}@${props.version}`).then(
123-
({ manifest }) => {
127+
loadOrb(`${props.namespace}/${props.name}@${props.version}`)
128+
.then(({ manifest }) => {
124129
setOrb(
125130
new OrbImportWithMeta(
126131
props.name,
@@ -129,11 +134,14 @@ const OrbDefinitionsMenu = (props: OrbDefinitionProps) => {
129134
manifest,
130135
props.version,
131136
props.logo_url,
137+
props.url,
132138
props.description,
133139
),
134140
);
135-
},
136-
);
141+
})
142+
.catch(() => {
143+
setError(true);
144+
});
137145
}, [setOrb, props]);
138146

139147
const inProject = Object.values(orbs).find(
@@ -151,8 +159,8 @@ const OrbDefinitionsMenu = (props: OrbDefinitionProps) => {
151159
<h2 className="text-circle-gray-400">{props.version}</h2>
152160
<a
153161
className="flex ml-auto cursor-pointer tracking-wide hover:underline leading-6 text-sm text-circle-blue font-medium"
154-
href={orb?.display?.source_url}
155-
target="circleci_docs"
162+
href={orb?.url}
163+
target="circleci_devhub"
156164
onClick={(e) => {
157165
e.stopPropagation();
158166
}}
@@ -195,7 +203,16 @@ const OrbDefinitionsMenu = (props: OrbDefinitionProps) => {
195203
</div>
196204
<Footer>
197205
{inProject ? (
198-
<Button variant="dangerous">Remove Orb from Config</Button>
206+
<Button
207+
onClick={() => {
208+
if (orb) {
209+
unimportOrb(orb);
210+
}
211+
}}
212+
variant="dangerous"
213+
>
214+
Remove Orb from Config
215+
</Button>
199216
) : (
200217
<Button
201218
onClick={() => {
@@ -210,6 +227,11 @@ const OrbDefinitionsMenu = (props: OrbDefinitionProps) => {
210227
)}
211228
</Footer>
212229
</div>
230+
) : error ? (
231+
<p className="font-medium pl-3 py-4 text-circle-red-dangerous">
232+
Error loading orb. It likely uses an advanced feature not yet
233+
supported. Sorry for the inconvenience!
234+
</p>
213235
) : (
214236
<div className="flex m-auto">
215237
<Loading />

src/components/menus/definitions/OrbImportMenu.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import algoliasearch from 'algoliasearch/lite';
2+
import { useState } from 'react';
23
import {
34
Hits,
45
HitsPerPage,
@@ -87,6 +88,7 @@ const SearchBox = (
8788
props: UseSearchBoxProps & { className?: string; placeholder?: string },
8889
) => {
8990
const { refine, clear } = useSearchBox(props);
91+
const [value, setValue] = useState('');
9092
const { results } = useInstantSearch();
9193

9294
return (
@@ -96,11 +98,22 @@ const SearchBox = (
9698
className="my-2 rounded border w-fullborder-circle-gray-300 hover:border-circle-gray-700 flex flex-row"
9799
>
98100
<input
101+
value={value}
99102
placeholder={props.placeholder}
100103
className="pl-4 p-2 m-0 flex-grow"
101-
onChange={(e) => refine(e.target.value)}
104+
onChange={(e) => {
105+
setValue(e.target.value);
106+
refine(e.target.value);
107+
}}
102108
/>
103-
<button type="button" className="mx-4" onClick={() => clear()}>
109+
<button
110+
type="button"
111+
className="mx-4"
112+
onClick={() => {
113+
setValue('');
114+
clear();
115+
}}
116+
>
104117
<DeleteItemIcon className="w-3 h-3" />
105118
</button>
106119
</div>
@@ -127,9 +140,9 @@ const OrbImportMenu = (props: InspectorDefinitionProps) => {
127140
<InstantSearch searchClient={searchClient} indexName="orbs-prod">
128141
{/* <RefinementList attribute="brand" /> */}
129142
<p className="font-bold leading-5 tracking-wide">Search Filters</p>
130-
<Select className="mt-2 w-full">
131-
<option>Recommended Orbs</option>
132-
</Select>
143+
{/* <Select className="mt-2 w-full">
144+
<option>Recommended Orbs</option> TODO: implement select for recommended orbs
145+
</Select> */}
133146
<SearchBox placeholder="Search Orb Directory..." />
134147
<HitsPerPage
135148
hidden

src/components/panes/WorkflowsPane.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ const WorkflowsPane = () => {
8686
manifest,
8787
orb.version,
8888
'',
89+
'', // TODO: implement refetching of url
8990
orb.description,
9091
),
9192
};

src/state/Store.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,8 @@ const Actions: StoreActions = {
472472
}),
473473

474474
unimportOrb: action((state, payload) => {
475-
// state.definitions.orbs = state.definitions.orbs.filter(
476-
// (orb) => orb.name !== payload.name && orb.namespace !== payload.namespace,
477-
// );
475+
state.definitions.orbs = { ...state.definitions.orbs };
476+
delete state.definitions.orbs[payload.alias];
478477
}),
479478

480479
error: action((state, payload) => {
@@ -724,18 +723,19 @@ const Actions: StoreActions = {
724723
state.toast = payload ?? undefined;
725724
}),
726725
// this is just to trigger the set toast action
727-
triggerToast: action((_, __) => {}),
726+
triggerToast: action(() => {}),
728727
triggerConfirmation: action((state, payload) => {
729728
state.confirm = payload;
730729
}),
731730
triggerConfigRefresh: thunkOn(
732731
(actions) => [
733732
actions.importOrb,
734-
...generateLifeCycleMatrix(actions),
733+
actions.unimportOrb,
735734
actions.addWorkflowElement,
736735
actions.setWorkflowElements,
737736
actions.removeWorkflowElement,
738737
actions.updateWorkflowElement,
738+
...generateLifeCycleMatrix(actions),
739739
],
740740
(actions) => {
741741
actions.generateConfig();

0 commit comments

Comments
 (0)