-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a7e2c17
commit 315d091
Showing
40 changed files
with
529 additions
and
619 deletions.
There are no files selected for viewing
56 changes: 0 additions & 56 deletions
56
frontend/packages/dev-console/src/components/dropdown/PipelineResourceDropdown.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 12 additions & 5 deletions
17
frontend/packages/dev-console/src/components/pipelines/const.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
export enum PipelineResourceType { | ||
'' = 'Select resource type', | ||
git = 'Git', | ||
image = 'Image', | ||
cluster = 'Cluster', | ||
storage = 'Storage', | ||
git = 'git', | ||
image = 'image', | ||
cluster = 'cluster', | ||
storage = 'storage', | ||
} | ||
|
||
export const pipelineResourceTypeSelections = { | ||
'': 'Select resource type', | ||
[PipelineResourceType.git]: 'Git', | ||
[PipelineResourceType.image]: 'Image', | ||
[PipelineResourceType.cluster]: 'Cluster', | ||
[PipelineResourceType.storage]: 'Storage', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...packages/dev-console/src/components/pipelines/modals/common/PipelineResourceDropdown.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.odc-pipeline-resource-dropdown { | ||
li[role=presentation] { | ||
list-style: none; | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
.../packages/dev-console/src/components/pipelines/modals/common/PipelineResourceDropdown.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import * as React from 'react'; | ||
import * as _ from 'lodash'; | ||
import { FormikValues, useField, useFormikContext } from 'formik'; | ||
import { Select, SelectOption } from '@patternfly/react-core'; | ||
import { referenceForModel } from '@console/internal/module/k8s'; | ||
import { | ||
useK8sWatchResource, | ||
WatchK8sResource, | ||
} from '@console/internal/components/utils/k8s-watch-hook'; | ||
import { PipelineResourceModel } from '../../../../models'; | ||
import { PipelineResourceKind } from '../../../../utils/pipeline-augment'; | ||
|
||
import './PipelineResourceDropdown.scss'; | ||
import { LoadingInline } from '@console/internal/components/utils'; | ||
import { CREATE_PIPELINE_RESOURCE } from './const'; | ||
|
||
type PipelineResourceDropdownProps = { | ||
autoSelect?: boolean; | ||
filterType: string; | ||
name: string; | ||
namespace: string; | ||
selectedKey: string; | ||
}; | ||
|
||
const PipelineResourceDropdown: React.FC<PipelineResourceDropdownProps> = (props) => { | ||
const { autoSelect, filterType, name, namespace, selectedKey } = props; | ||
|
||
const [isExpanded, setExpanded] = React.useState(false); | ||
const { setFieldValue, setFieldTouched } = useFormikContext<FormikValues>(); | ||
const [, { touched }] = useField(name); | ||
|
||
const resourceDefinition: WatchK8sResource = React.useMemo( | ||
() => ({ | ||
isList: true, | ||
namespace, | ||
kind: referenceForModel(PipelineResourceModel), | ||
}), | ||
[namespace], | ||
); | ||
const [resources, loaded, error] = useK8sWatchResource<PipelineResourceKind[]>( | ||
resourceDefinition, | ||
); | ||
|
||
const availableResources: PipelineResourceKind[] = resources.filter( | ||
(resource) => resource.spec.type === filterType, | ||
); | ||
|
||
const canAutoSelect = autoSelect && !touched && loaded && !error; | ||
React.useEffect(() => { | ||
if (canAutoSelect) { | ||
if (availableResources.length === 0) { | ||
setFieldValue(name, CREATE_PIPELINE_RESOURCE); | ||
} else { | ||
setFieldValue(name, availableResources[0].metadata.name); | ||
} | ||
setFieldTouched(name); | ||
} | ||
}, [canAutoSelect, name, availableResources, setFieldTouched, setFieldValue]); | ||
|
||
const options = [ | ||
{ label: 'Create Pipeline Resource', value: CREATE_PIPELINE_RESOURCE }, | ||
...availableResources.map((resource) => { | ||
const resourceName = resource.metadata.name; | ||
const url = _.get(_.find(resource.spec.params, ['name', 'url']), 'value', ''); | ||
const label = url.trim().length > 0 ? `${url} (${resourceName})` : resourceName; | ||
|
||
return { label, value: resourceName }; | ||
}), | ||
]; | ||
|
||
return ( | ||
<Select | ||
className="odc-pipeline-resource-dropdown" | ||
selections={selectedKey} | ||
isExpanded={isExpanded} | ||
onToggle={() => setExpanded(!isExpanded)} | ||
onSelect={(e, value) => { | ||
setFieldValue(name, value); | ||
setExpanded(false); | ||
}} | ||
placeholderText={!loaded ? <LoadingInline /> : 'Select Pipeline Resource'} | ||
isDisabled={loaded && resources.length === 0} | ||
> | ||
{options.map(({ label, value }) => ( | ||
<SelectOption key={value} value={value}> | ||
{label} | ||
</SelectOption> | ||
))} | ||
</Select> | ||
); | ||
}; | ||
|
||
export default PipelineResourceDropdown; |
Oops, something went wrong.