mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-18 18:04:17 +00:00
fix(ui): keep Skillshare-installed Pi plugins out of Pi packages
A plugin Skillshare installs from a Git source and binds only to Pi landed in the "Pi packages" list, which is meant for packages Pi installs itself (npm:/git: identifiers with no recorded source). The list now also requires that neither the package nor any binding has a source, so such plugins stay under "Managed by Skillshare". The Pi target's Extensions tab titled those same plugins by their local state path (local:.../skillshare-<hash>/content), which does not say which plugin it is. The server already returns the plugin name as managedBy; use it as the card title, keeping the path in the tooltip and details.
This commit is contained in:
@@ -105,6 +105,11 @@ describe('Pi target Extensions tab', () => {
|
||||
expect(screen.queryByText('Package default')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('names a package Skillshare installs by its plugin, not its state path', async () => {
|
||||
show(global({ packages: [{ ...global().packages[0], managedBy: 'superpowers' }] }));
|
||||
expect(await screen.findByRole('region', { name: 'superpowers' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('collapses a package to its header', async () => {
|
||||
const user = userEvent.setup();
|
||||
show(global());
|
||||
|
||||
@@ -149,7 +149,8 @@ const isOn = (row: PiExtensionRow, action?: PiExtensionAction) =>
|
||||
function PackageCard({ pkg, name, ownsRules, pending, set, t }: { pkg: PiExtensionPackage; name: string; ownsRules: boolean; pending: Record<string, PiExtensionAction>; set: SetAction; t: T }) {
|
||||
const [open, setOpen] = useState(true);
|
||||
const [details, setDetails] = useState(false);
|
||||
const title = pkg.identity || pkg.source;
|
||||
// A plugin Skillshare installs is a local path into its state directory: its name says which one.
|
||||
const title = pkg.managedBy || pkg.identity || pkg.source;
|
||||
const actionOf = (r: PiExtensionRow) => pending[keyOf(pkg.scope, pkg.index, r.path)];
|
||||
const on = pkg.rows.filter((r) => isOn(r, actionOf(r))).length;
|
||||
const locked = Boolean(pkg.readOnly) || (pkg.rows.length > 0 && pkg.rows.every((r) => !r.editable));
|
||||
|
||||
@@ -200,15 +200,22 @@ describe('PluginsPage', () => {
|
||||
{ target: 'omo', label: 'omo', project: false, operations: ['add', 'sync'], npm: true },
|
||||
{ target: 'codex', label: 'Codex', project: false, operations: ['add', 'sync'] },
|
||||
],
|
||||
packages: { demo: { bindings: { codex: { id: 'demo@market' } } }, driver: { bindings: { omo: { id: 'npm:@scope/driver' } } } },
|
||||
packages: {
|
||||
demo: { bindings: { codex: { id: 'demo@market' } } },
|
||||
driver: { bindings: { omo: { id: 'npm:@scope/driver' } } },
|
||||
// Skillshare installs this one from its source, even though only a Pi target has it.
|
||||
powers: { source: 'owner/powers', bindings: { omo: { id: 'local:/state/powers/content', source: 'owner/powers' } } },
|
||||
},
|
||||
hosts: [],
|
||||
});
|
||||
mount();
|
||||
const pi = (await screen.findByRole('heading', { name: 'plugins.piTitle' })).closest('section')!;
|
||||
const managed = screen.getByRole('heading', { name: 'plugins.managedTitle' }).closest('section')!;
|
||||
expect(pi).toHaveTextContent('driver');
|
||||
expect(pi).not.toHaveTextContent('powers');
|
||||
expect(managed).not.toHaveTextContent('driver');
|
||||
expect(managed).toHaveTextContent('demo');
|
||||
expect(managed).toHaveTextContent('powers');
|
||||
});
|
||||
it('offers an imported npm package to the other Pi targets, installing it from its identifier', async () => {
|
||||
vi.mocked(pluginsApi.list).mockResolvedValue({
|
||||
|
||||
@@ -135,12 +135,14 @@ export default function PluginsPage() {
|
||||
],
|
||||
});
|
||||
};
|
||||
// A package bound only to Pi targets is a Pi package: it gets its own list, in the same rows.
|
||||
// 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.
|
||||
const piTargets = new Set((data?.targetDefinitions ?? []).filter((d) => d.npm).map((d) => d.target));
|
||||
const names = Object.keys(data?.packages ?? {});
|
||||
const isPi = (name: string) => {
|
||||
const bound = Object.keys(data!.packages[name].bindings);
|
||||
return bound.length > 0 && bound.every((target) => piTargets.has(target));
|
||||
const pack = data!.packages[name];
|
||||
const bound = Object.entries(pack.bindings);
|
||||
return !pack.source && bound.length > 0 && bound.every(([target, b]) => piTargets.has(target) && !b?.source);
|
||||
};
|
||||
const piPackages = names.filter(isPi);
|
||||
const plugins = names.filter((name) => !isPi(name));
|
||||
|
||||
Reference in New Issue
Block a user