Skip to content

Commit

Permalink
search and pagination in the step palette (#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
srdjan-harness authored Nov 26, 2024
1 parent 65fd025 commit b58ff29
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 91 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { Button, Icon } from '@harnessio/canary'
import { useMemo, useRef, useState } from 'react'

import { Button, Icon, Input, Spacer } from '@harnessio/canary'
import { useListGlobalTemplatesQuery } from '@harnessio/code-service-client'
import {
harnessStepGroups,
harnessSteps,
PaginationComponent,
SkeletonList,
StepForm,
StepsPalette,
StepsPaletteContent,
StepsPaletteItem
} from '@harnessio/views'

import { PageResponseHeader } from '../../../types'
import { StepSource } from '../context/data-store/types'
import { usePipelineDataContext } from '../context/PipelineStudioDataProvider'
import { StepDrawer, usePipelineViewContext } from '../context/PipelineStudioViewProvider'
Expand All @@ -26,112 +31,161 @@ const PipelineStudioStepPalette = (props: PipelineStudioStepFormProps): JSX.Elem
} = usePipelineDataContext()
const { setStepDrawerOpen } = usePipelineViewContext()

// TODO: only 100 items
const { data: { body: pluginsResponse } = {} } = useListGlobalTemplatesQuery({
queryParams: { limit: 100, page: 1 }
const [page, setPage] = useState(1)
const [query, setQuery] = useState('')

const { data: { body: pluginsResponse, headers } = {}, isFetching } = useListGlobalTemplatesQuery({
queryParams: { limit: 100, page, query }
})

const xNextPage = parseInt(headers?.get(PageResponseHeader.xNextPage) || '')
const xPrevPage = parseInt(headers?.get(PageResponseHeader.xPrevPage) || '')

const templatesSectionRef = useRef<HTMLDivElement | null>(null)

const harnessStepGroupsFiltered = useMemo(
() => harnessStepGroups.filter(harnessStepGroup => harnessStepGroup.identifier.includes(query)),
[query, harnessStepGroups]
)

const harnessStepsFiltered = useMemo(
() => harnessSteps.filter(harnessStep => harnessStep.identifier.includes(query)),
[query, harnessSteps]
)

return (
<StepsPalette.Root>
<StepsPalette.Header>
<StepsPalette.Title>Add Step</StepsPalette.Title>
{/* <Input placeholder="Search" />
<StepPaletteFilters /> */}
<Input
placeholder="Search"
onChange={value => {
setQuery(value.target.value)
setPage(1)
}}
/>
{/* <StepPaletteFilters /> */}
</StepsPalette.Header>
<StepsPaletteContent.Root>
<StepsPaletteContent.Section>
<StepsPaletteContent.SectionHeader>Groups</StepsPaletteContent.SectionHeader>

{harnessStepGroups.map(harnessStepGroup => (
<StepsPaletteContent.SectionItem key={harnessStepGroup.identifier}>
<StepsPaletteItem.Root
onClick={() => {
if (addStepIntention) {
requestYamlModifications.injectInArray({
path: addStepIntention.path,
position: addStepIntention.position,
item: { [harnessStepGroup.identifier]: { steps: [] } }
})
}
{harnessStepGroupsFiltered.length > 0 ? (
harnessStepGroupsFiltered.map(harnessStepGroup => (
<StepsPaletteContent.SectionItem key={harnessStepGroup.identifier}>
<StepsPaletteItem.Root
onClick={() => {
if (addStepIntention) {
requestYamlModifications.injectInArray({
path: addStepIntention.path,
position: addStepIntention.position,
item: { [harnessStepGroup.identifier]: { steps: [] } }
})
}

requestClose()
}}
>
<StepsPaletteItem.Left>
<Icon name="harness-plugin" size={36} />
</StepsPaletteItem.Left>
<StepsPaletteItem.Right>
<StepsPaletteItem.Header>
<StepsPaletteItem.Title>{harnessStepGroup.identifier}</StepsPaletteItem.Title>
{/* <StepsPaletteItem.BadgeWrapper>verified</StepsPaletteItem.BadgeWrapper> */}
</StepsPaletteItem.Header>
<StepsPaletteItem.Description>{harnessStepGroup.description}</StepsPaletteItem.Description>
</StepsPaletteItem.Right>
</StepsPaletteItem.Root>
</StepsPaletteContent.SectionItem>
))}
requestClose()
}}
>
<StepsPaletteItem.Left>
<Icon name="harness-plugin" size={36} />
</StepsPaletteItem.Left>
<StepsPaletteItem.Right>
<StepsPaletteItem.Header>
<StepsPaletteItem.Title>{harnessStepGroup.identifier}</StepsPaletteItem.Title>
{/* <StepsPaletteItem.BadgeWrapper>verified</StepsPaletteItem.BadgeWrapper> */}
</StepsPaletteItem.Header>
<StepsPaletteItem.Description>{harnessStepGroup.description}</StepsPaletteItem.Description>
</StepsPaletteItem.Right>
</StepsPaletteItem.Root>
</StepsPaletteContent.SectionItem>
))
) : (
<p className="text-muted-foreground">There is no steps for provided query.</p>
)}
</StepsPaletteContent.Section>
<StepsPaletteContent.Section>
<StepsPaletteContent.SectionHeader>Harness</StepsPaletteContent.SectionHeader>

{harnessSteps.map(harnessStep => (
<StepsPaletteContent.SectionItem key={harnessStep.identifier}>
<StepsPaletteItem.Root
onClick={() => {
setFormStep({
stepSource: StepSource.Harness,
data: {
identifier: harnessStep.identifier,
description: harnessStep.description
}
})
setStepDrawerOpen(StepDrawer.Form)
}}
>
<StepsPaletteItem.Left>
<Icon name="harness-plugin" size={36} />
</StepsPaletteItem.Left>
<StepsPaletteItem.Right>
<StepsPaletteItem.Header>
<StepsPaletteItem.Title>{harnessStep.identifier}</StepsPaletteItem.Title>
</StepsPaletteItem.Header>
<StepsPaletteItem.Description>{harnessStep.description}</StepsPaletteItem.Description>
</StepsPaletteItem.Right>
</StepsPaletteItem.Root>
</StepsPaletteContent.SectionItem>
))}
</StepsPaletteContent.Section>
<StepsPaletteContent.Section>
<StepsPaletteContent.SectionHeader>Templates</StepsPaletteContent.SectionHeader>
{pluginsResponse?.map(item => (
<StepsPaletteContent.SectionItem key={item.identifier}>
<StepsPaletteItem.Root
onClick={() => {
if (addStepIntention?.path && addStepIntention?.position && item.data) {
{harnessStepsFiltered.length > 0 ? (
harnessStepsFiltered.map(harnessStep => (
<StepsPaletteContent.SectionItem key={harnessStep.identifier}>
<StepsPaletteItem.Root
onClick={() => {
setFormStep({
stepSource: StepSource.Templates,
data: item
stepSource: StepSource.Harness,
data: {
identifier: harnessStep.identifier,
description: harnessStep.description
}
})
setStepDrawerOpen(StepDrawer.Form)
} else {
//TODO: TOAST HERE
}
}}
>
<StepsPaletteItem.Left>
<Icon name="harness-plugin" size={36} />
</StepsPaletteItem.Left>
<StepsPaletteItem.Right>
<StepsPaletteItem.Header>
<StepsPaletteItem.Title>{item.identifier}</StepsPaletteItem.Title>
{/* <StepsPaletteItem.BadgeWrapper>verified</StepsPaletteItem.BadgeWrapper> */}
</StepsPaletteItem.Header>
<StepsPaletteItem.Description>{item.description}</StepsPaletteItem.Description>
</StepsPaletteItem.Right>
</StepsPaletteItem.Root>
</StepsPaletteContent.SectionItem>
))}
}}
>
<StepsPaletteItem.Left>
<Icon name="harness-plugin" size={36} />
</StepsPaletteItem.Left>
<StepsPaletteItem.Right>
<StepsPaletteItem.Header>
<StepsPaletteItem.Title>{harnessStep.identifier}</StepsPaletteItem.Title>
</StepsPaletteItem.Header>
<StepsPaletteItem.Description>{harnessStep.description}</StepsPaletteItem.Description>
</StepsPaletteItem.Right>
</StepsPaletteItem.Root>
</StepsPaletteContent.SectionItem>
))
) : (
<p className="text-muted-foreground">There is no steps for provided query.</p>
)}
</StepsPaletteContent.Section>
<StepsPaletteContent.Section ref={templatesSectionRef}>
<StepsPaletteContent.SectionHeader>Templates</StepsPaletteContent.SectionHeader>
{isFetching ? (
<SkeletonList />
) : (
pluginsResponse?.map(item => (
<StepsPaletteContent.SectionItem key={item.identifier}>
<StepsPaletteItem.Root
onClick={() => {
if (addStepIntention?.path && addStepIntention?.position && item.data) {
setFormStep({
stepSource: StepSource.Templates,
data: item
})
setStepDrawerOpen(StepDrawer.Form)
} else {
//TODO: TOAST HERE
}
}}
>
<StepsPaletteItem.Left>
<Icon name="harness-plugin" size={36} />
</StepsPaletteItem.Left>
<StepsPaletteItem.Right>
<StepsPaletteItem.Header>
<StepsPaletteItem.Title>{item.identifier}</StepsPaletteItem.Title>
{/* <StepsPaletteItem.BadgeWrapper>verified</StepsPaletteItem.BadgeWrapper> */}
</StepsPaletteItem.Header>
<StepsPaletteItem.Description>{item.description}</StepsPaletteItem.Description>
</StepsPaletteItem.Right>
</StepsPaletteItem.Root>
</StepsPaletteContent.SectionItem>
))
)}
{!isFetching && pluginsResponse?.length === 0 ? (
<p className="text-muted-foreground">There is no steps for provided query.</p>
) : null}
</StepsPaletteContent.Section>
<Spacer size={8} />
<PaginationComponent
nextPage={xNextPage}
previousPage={xPrevPage}
currentPage={page}
goToPage={(pageNum: number) => {
templatesSectionRef.current?.scrollIntoView()
setPage(pageNum)
}}
/>
<Spacer size={8} />
</StepsPaletteContent.Root>
<StepForm.Footer>
<Button variant="secondary" onClick={requestClose}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import { forwardRef } from 'react'

const StepsPaletteContent = {
Root: function Content({ children }: { children: React.ReactNode }) {
return <div className="flex flex-col overflow-scroll">{children}</div>
},

Section: function Section({ children }: { children: React.ReactNode }) {
return <div className="mx-4 flex flex-col pt-4">{children}</div>
},
Section: forwardRef<HTMLDivElement, { children: React.ReactNode }>(function Section({ children }, ref) {
return (
<div ref={ref} className="mx-4 flex flex-col pt-4">
{children}
</div>
)
}),

SectionHeader: function SectionHeader({ children }: { children: React.ReactNode }) {
return <div className="text-accent-foreground mb-3 flex flex-row justify-between">{children}</div>
return <div className="mb-3 flex flex-row justify-between text-accent-foreground">{children}</div>
},

SectionItem: function SectionHeader({ children }: { children: React.ReactNode }) {
Expand Down

0 comments on commit b58ff29

Please sign in to comment.