Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

4.2 KB
Raw Blame
'use client'

import type { AgentPublicationCountsResponse } from '@dify/contracts/api/console/agent/types.gen'
import type { RosterFilterValue } from './roster-filter'
import { Checkbox } from '@langgenius/dify-ui/checkbox'
import { SegmentedControl, SegmentedControlItem } from '@langgenius/dify-ui/segmented-control'
import { useQueryState } from 'nuqs'
import { useTranslation } from 'react-i18next'
import { SearchInput } from '@/app/components/base/search-input'
import {
  rosterCreatedByMeQueryParser,
  rosterFilterQueryParser,
  rosterKeywordQueryParser,
  rosterQueryParamNames,
} from '../query-params'
import { RosterCreateMenu } from './roster-create-menu'
import { RosterSortSelect } from './roster-sort-select'

type RosterToolbarProps = {
  publicationCounts: AgentPublicationCountsResponse
}

type RosterFilterItemProps = {
  count?: number
  label: string
  value: RosterFilterValue
}

function RosterFilterItem({ count, label, value }: RosterFilterItemProps) {
  return (
    <SegmentedControlItem value={value} className="gap-1 data-checked:text-text-secondary">
      <span>{label}</span>
      {count !== undefined && (
        <span className="flex min-w-4 shrink-0 items-center justify-center rounded-[5px] border border-divider-deep bg-components-badge-bg-dimm px-1 py-0.5 system-2xs-medium-uppercase text-text-tertiary tabular-nums">
          <span className="min-w-px flex-1 text-center">{count}</span>
        </span>
      )}
    </SegmentedControlItem>
  )
}

function RosterStatusFilter({ publicationCounts }: RosterToolbarProps) {
  const { t } = useTranslation(['agentRoster'])
  const [filter, setFilter] = useQueryState(rosterQueryParamNames.filter, rosterFilterQueryParser)

  return (
    <SegmentedControl
      aria-label={t(($) => $['roster.filters.label'], { ns: 'agentRoster' })}
      className="shrink-0"
      value={filter}
      onValueChange={(value) => void setFilter(value)}
    >
      <RosterFilterItem
        value="all"
        label={t(($) => $['roster.filters.all'], { ns: 'agentRoster' })}
      />
      <RosterFilterItem
        value="published"
        label={t(($) => $['roster.filters.published'], { ns: 'agentRoster' })}
        count={publicationCounts.published}
      />
      <RosterFilterItem
        value="drafts"
        label={t(($) => $['roster.filters.drafts'], { ns: 'agentRoster' })}
        count={publicationCounts.drafts}
      />
    </SegmentedControl>
  )
}

function RosterSearchFilter() {
  const { t } = useTranslation(['agentRoster'])
  const [keyword, setKeyword] = useQueryState(
    rosterQueryParamNames.keyword,
    rosterKeywordQueryParser,
  )

  return (
    <SearchInput
      aria-label={t(($) => $['roster.searchLabel'], { ns: 'agentRoster' })}
      className="h-8 w-full min-w-0 sm:w-50"
      placeholder={t(($) => $['roster.searchPlaceholder'], { ns: 'agentRoster' })}
      value={keyword}
      onValueChange={(value) => {
        void setKeyword(value)
      }}
    />
  )
}

function RosterCreatedByMeFilter() {
  const { t } = useTranslation(['agentRoster'])
  const [createdByMe, setCreatedByMe] = useQueryState(
    rosterQueryParamNames.createdByMe,
    rosterCreatedByMeQueryParser,
  )

  return (
    <label className="flex h-8 shrink-0 cursor-pointer items-center gap-1 rounded-lg bg-components-input-bg-normal px-2 py-1 whitespace-nowrap">
      <Checkbox
        checked={createdByMe}
        onCheckedChange={(checked) => {
          void setCreatedByMe(checked === true)
        }}
      />
      <span className="p-1 system-sm-regular text-text-tertiary">
        {t(($) => $['roster.filters.createdByMe'], { ns: 'agentRoster' })}
      </span>
    </label>
  )
}

export function RosterToolbar({ publicationCounts }: RosterToolbarProps) {
  return (
    <div className="flex min-w-0 flex-wrap items-center gap-2">
      <RosterStatusFilter publicationCounts={publicationCounts} />
      <RosterSearchFilter />
      <div className="hidden h-4 shrink-0 px-1 sm:flex" aria-hidden="true">
        <div className="h-full w-px bg-divider-regular" />
      </div>
      <RosterCreatedByMeFilter />
      <div className="ms-auto flex flex-wrap items-center justify-end gap-2">
        <RosterSortSelect />
        <RosterCreateMenu />
      </div>
    </div>
  )
}