Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

2.6 KB
Raw Blame
import { useId } from 'react';
import AppIcon from './AppIcon';

export default function AppContextPicker({
  apps = [],
  value = '',
  onChange,
  label = 'App context',
  placeholder = 'PortOS (default)',
  ariaLabel,
  includeDefaultOption = true,
  className = '',
  selectClassName = 'w-full px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white text-sm min-h-[44px]',
  showRepoPath = true,
  repoLabel = 'Repository',
  // Shown in the repo-path box when nothing is selected. Pickers that do NOT
  // fall back to PortOS (e.g. sprite import, where the app IS the source)
  // override this — the default text would lie about what happens.
  emptyRepoText = 'using default PortOS context'
}) {
  const selectId = useId();
  const selectedApp = apps.find(app => app.id === value);
  const sortedApps = [...apps].sort((a, b) =>
    (a?.name || '').localeCompare(b?.name || '', undefined, { sensitivity: 'base' })
  );

  const content = (
    <div className="space-y-2">
      <select
        id={selectId}
        value={value}
        onChange={(event) => onChange?.(event.target.value)}
        className={selectClassName}
        aria-label={ariaLabel || label || placeholder}
      >
        {includeDefaultOption && <option value="">{placeholder}</option>}
        {sortedApps.map(app => (
          <option key={app.id} value={app.id}>{app.name}</option>
        ))}
      </select>

      {showRepoPath && (
        <div className="rounded-lg border border-port-border bg-port-bg/50 px-3 py-2 text-xs text-gray-400">
          {selectedApp ? (
            <div className="flex items-start gap-2">
              <AppIcon
                icon={selectedApp.icon || 'package'}
                appId={selectedApp.id}
                hasAppIcon={!!selectedApp.appIconPath}
                size={14}
                ariaLabel={selectedApp.name}
                className="mt-0.5 shrink-0 text-gray-400"
              />
              <div className="min-w-0">
                <div className="font-medium text-gray-200">{selectedApp.name}</div>
                <div className="truncate text-gray-500" title={selectedApp.repoPath || ''}>
                  {repoLabel}: {selectedApp.repoPath || 'No repo path'}
                </div>
              </div>
            </div>
          ) : (
            <div>{repoLabel}: {emptyRepoText}</div>
          )}
        </div>
      )}
    </div>
  );

  return (
    <div className={className}>
      {label ? (
        <>
          <label htmlFor={selectId} className="block text-xs text-gray-400">{label}</label>
          <div className="mt-1">{content}</div>
        </>
      ) : content}
    </div>
  );
}