Skip to content

Commit

Permalink
container selection for connect operations
Browse files Browse the repository at this point in the history
  • Loading branch information
mruoss committed Dec 13, 2024
1 parent 6abf614 commit 41fa4e2
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 18 deletions.
33 changes: 30 additions & 3 deletions assets/packs/get_cell/connect_operation_form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ const ConnectOperationForm: React.FC<{
updateField: UpdateFieldFun<GetCellFields>
}> = ({ fields, updateField }) => (
<div className="flex gap-x-5 p-3">
<SearchSelect<GVK>
className="opacity-60"
name="gvk"
label="Resource Kind"
onSearch={updateField('search_term')}
searchTerm={fields.search_term}
resultItemsKeyField={'index'}
resultItems={fields.search_result_items}
onSelect={updateField('gvk')}
itemRenderer={(item: GVK) => <GVKOption gvk={item} />}
selectedValue={fields.gvk?.kind}
placeholder="apps/v1 Deployment"
disabled={true}
/>

{fields.namespaces && (
<SelectOrInput
name="namespace"
Expand All @@ -27,14 +42,26 @@ const ConnectOperationForm: React.FC<{
<SelectOrInput
name="resource"
label={fields.gvk.kind}
options={fields.resources.map((ns) => ({
label: ns,
value: ns,
options={fields.resources.map((resource) => ({
label: resource,
value: resource,
}))}
selectedOption={fields.resource}
onChange={updateField('resource')}
/>
)}
{fields.containers && (
<SelectOrInput
name="container"
label="Container"
options={fields.containers.map((container) => ({
label: container,
value: container,
}))}
selectedOption={fields.container}
onChange={updateField('container')}
/>
)}
</div>
)

Expand Down
2 changes: 2 additions & 0 deletions assets/packs/get_cell/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export interface GetCellFields extends Fields {
namespace: string
resources?: [string]
resource?: string
containers?: [string]
container?: string
}

export interface ConnectionState {
Expand Down
9 changes: 7 additions & 2 deletions assets/shared/search_select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type SearchInputProps = {
searchTerm: string
onSearch: (searchTerm: string) => void
placeholder?: string
disabled?: boolean
}

const SearchInput: React.FC<SearchInputProps> = ({
Expand All @@ -16,6 +17,7 @@ const SearchInput: React.FC<SearchInputProps> = ({
searchTerm,
onSearch,
placeholder,
disabled = false,
}: SearchInputProps) => {
const performSearch = debounce((searchTerm) => {
onSearch(searchTerm.toLowerCase())
Expand Down Expand Up @@ -61,6 +63,7 @@ const SearchInput: React.FC<SearchInputProps> = ({
type="text"
value={localSearchTerm}
name={name}
disabled={disabled}
autoComplete="off"
placeholder={placeholder}
onInput={(e: React.ChangeEvent<HTMLInputElement>) => {
Expand Down Expand Up @@ -104,7 +107,7 @@ const SearchResult = <ItemType,>({
)
}

type SearchSelectProps = { label: string; className: string }
type SearchSelectProps = { label: string; className?: string }

const SearchSelect = <ItemType,>({
name,
Expand All @@ -114,10 +117,11 @@ const SearchSelect = <ItemType,>({
resultItems,
resultItemsKeyField,
itemRenderer,
className,
className = '',
onSelect,
selectedValue,
placeholder,
disabled = false,
}: SearchInputProps & SearchResultProps<ItemType> & SearchSelectProps) => {
return (
<div className={className}>
Expand All @@ -130,6 +134,7 @@ const SearchSelect = <ItemType,>({
searchTerm={searchTerm}
selectedValue={selectedValue}
placeholder={placeholder}
disabled={disabled}
/>
{(resultItems && resultItems.length) > 0 && (
<SearchResult
Expand Down
2 changes: 1 addition & 1 deletion lib/assets/get_cell/build/main.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 41fa4e2

Please sign in to comment.