mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
refactor(ui): use the keyed-text helper where the rule was still inline
Two places still wrote out 'translate the backend key, else show its text' by hand next to keyedText, so the rule had three copies. The Pi package test also rebuilt the set of Pi targets for every package on every render; it is now built once per inventory, as before the flow moved out of the page. Refs #446
This commit is contained in:
@@ -3,6 +3,7 @@ import { pluginsApi, targetMap, type PluginBinding, type PluginDiscovery, type P
|
||||
import { Check, ChevronDown, ChevronRight, Search, X } from 'lucide-react';
|
||||
import AgentIcon from '../AgentIcon';
|
||||
import { agentReasons } from './agentReasons';
|
||||
import { keyedText } from './outcomeText';
|
||||
import SourceHint from './SourceHint';
|
||||
import { pluginErrorMessage } from './pluginError';
|
||||
import PluginDocsLink from './PluginDocsLink';
|
||||
@@ -165,7 +166,7 @@ export default function PluginAddDialog({ onClose, onPreview, initialSource = ''
|
||||
<span className={`ss-chk rad self-start mt-0.5 ${name === c.name ? 'on' : ''}`} />
|
||||
<span className="flex min-w-0 flex-1 flex-col gap-0.5">
|
||||
<span className="flex items-center gap-2"><span className="font-mono font-semibold">{c.name}</span>{c.version && <span className="ss-tag">{c.version}</span>}</span>
|
||||
{(c.problem || c.description) && <span className={`text-[13px] ${c.problem ? 'text-bad' : 'text-ink-2'}`}>{c.problemKey ? t(c.problemKey, c.problemArgs, c.problem) : c.problem || c.description}</span>}
|
||||
{(c.problem || c.description) && <span className={`text-[13px] ${c.problem ? 'text-bad' : 'text-ink-2'}`}>{keyedText(t, c.problemKey, c.problem, c.problemArgs) || c.description}</span>}
|
||||
{c.components.length > 0 && <span className="text-xs text-ink-3">{c.components.join(' · ')}</span>}
|
||||
</span>
|
||||
<span className="ss-stack" aria-hidden="true">{c.targets.map((target) => <span key={target} className="ss-at"><AgentIcon target={target} size={13} /></span>)}</span>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { PluginCandidate, PluginTarget, PluginTargetDefinition } from '../../api/plugins';
|
||||
import type { useT } from '../../i18n';
|
||||
import { keyedText } from './outcomeText';
|
||||
|
||||
type T = ReturnType<typeof useT>;
|
||||
|
||||
@@ -8,10 +9,10 @@ export function agentReasons(candidate: PluginCandidate | undefined, definitions
|
||||
return (Object.keys(definitions) as PluginTarget[]).map((target) => {
|
||||
const definition = definitions[target];
|
||||
const info = candidate?.targetInfo?.[target];
|
||||
const reason = (info?.problemKey ? t(info.problemKey, info.problemArgs, info.problem) : info?.problem)
|
||||
const reason = keyedText(t, info?.problemKey, info?.problem, info?.problemArgs)
|
||||
|| (!candidate?.targets.includes(target) ? t('plugins.unsupported')
|
||||
: isProjectMode && !definition.project ? t('plugins.globalOnly')
|
||||
: !definition.operations.includes('add') ? (definition.reasonKey ? t(definition.reasonKey, undefined, definition.reason) : definition.reason) || t('plugins.unsupported')
|
||||
: !definition.operations.includes('add') ? keyedText(t, definition.reasonKey, definition.reason) || t('plugins.unsupported')
|
||||
: '');
|
||||
return { target, definition, reason };
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { act, renderHook } from '@testing-library/react';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { pluginsApi, type PluginInventory, type PluginPlan } from '../../api/plugins';
|
||||
import { changedRuns, failureText, isPiPackage, reviewChanges, syncTodo, updatesFound, updatesLeft, usePluginsFlow } from './pluginsFlow';
|
||||
import { changedRuns, failureText, piPackageTest, reviewChanges, syncTodo, updatesFound, updatesLeft, usePluginsFlow } from './pluginsFlow';
|
||||
|
||||
vi.mock('../../api/plugins', async (importOriginal) => ({ ...await importOriginal<typeof import('../../api/plugins')>(), pluginsApi: { preview: vi.fn(), apply: vi.fn() } }));
|
||||
|
||||
@@ -167,7 +167,7 @@ describe('plugins flow rules', () => {
|
||||
expect(syncTodo(undefined)).toEqual([]);
|
||||
});
|
||||
it('calls a package Pi installs itself, bound only to Pi targets, a Pi package', () => {
|
||||
expect(['demo', 'driver', 'powers', 'unbound', 'gone'].filter((name) => isPiPackage(inventory, name))).toEqual(['driver']);
|
||||
expect(['demo', 'driver', 'powers', 'unbound', 'gone'].filter(piPackageTest(inventory))).toEqual(['driver']);
|
||||
});
|
||||
it('splits a preview into what it changes and what it leaves alone, with the version each has', () => {
|
||||
const { active, idle } = reviewChanges(plan('r', { action: 'update' }, { action: 'noop' }, { name: 'driver', target: 'omo', action: 'noop', binding: { id: 'npm:@scope/driver', version: '3.0.0' } }), inventory);
|
||||
|
||||
@@ -46,13 +46,15 @@ export function syncTodo(inventory?: PluginInventory) {
|
||||
* A package Pi installs itself (no source Skillshare copies from) and bound only to Pi targets
|
||||
* is a Pi package: it gets its own list, in the same rows. A plugin Skillshare installs stays above.
|
||||
*/
|
||||
export function isPiPackage(inventory: PluginInventory | undefined, name: string) {
|
||||
// A run can name a package config no longer has, such as one it just removed.
|
||||
const pack = inventory?.packages[name];
|
||||
if (!pack) return false;
|
||||
export function piPackageTest(inventory: PluginInventory | undefined) {
|
||||
const piTargets = new Set((inventory?.targetDefinitions ?? []).filter((d) => d.npm).map((d) => d.target));
|
||||
const bound = Object.entries(pack.bindings);
|
||||
return !pack.source && bound.length > 0 && bound.every(([target, b]) => piTargets.has(target) && !b?.source);
|
||||
return (name: string) => {
|
||||
// A run can name a package config no longer has, such as one it just removed.
|
||||
const pack = inventory?.packages[name];
|
||||
if (!pack) return false;
|
||||
const bound = Object.entries(pack.bindings);
|
||||
return !pack.source && bound.length > 0 && bound.every(([target, b]) => piTargets.has(target) && !b?.source);
|
||||
};
|
||||
}
|
||||
|
||||
export function installedVersion(inventory: PluginInventory | undefined, name: string, target: string) {
|
||||
@@ -140,6 +142,6 @@ export function usePluginsFlow({ t, inventory, refresh, onPreviewed }: {
|
||||
todo: syncTodo(inventory),
|
||||
...reviewChanges(review?.plan, inventory),
|
||||
changed: changedRuns(t, outcomes),
|
||||
isPi: (name: string) => isPiPackage(inventory, name),
|
||||
isPi: piPackageTest(inventory),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user