Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin-catalog: Rework installed list to include all plugins #117

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 121 additions & 33 deletions plugin-catalog/src/components/plugins/InstalledList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,124 @@ interface Plugin {

export interface PurePluginInstalledListProps {
installedPlugins: Plugin[] | null;
otherInstalledPlugins: any[] | null;
error: string | null;
}

export function PurePluginInstalledList({ installedPlugins, error }: PurePluginInstalledListProps) {
export function PurePluginInstalledList({
installedPlugins,
otherInstalledPlugins,
error,
}: PurePluginInstalledListProps) {
return (
<SectionBox title="Installed" textAlign="center" paddingTop={2}>
{error ? (
<Typography>{`Error loading Installed plugins: ${error}`}</Typography>
) : (
<SimpleTable
columns={[
{
label: 'Name',
getter: plugin => (
<Box>
<Link
routeName="/plugin-catalog/:repoName/:pluginName"
params={{ repoName: plugin.repoName, pluginName: plugin.folderName }}
>
{plugin.pluginTitle}
</Link>
</Box>
),
},
{
label: 'Version',
getter: plugin => plugin.pluginVersion,
},
{
label: 'Repo',
getter: plugin => plugin.repoName,
},
{
label: 'Author',
getter: plugin => plugin.author,
},
]}
emptyMessage="No plugins installed"
data={installedPlugins || []}
/>
<Box
sx={{
display: 'flex',
flexDirection: 'column',
gap: 2,
}}
>
<Box
sx={{
display: 'flex',
flexDirection: 'column',
gap: 2,
alignItems: 'start',
}}
>
<Typography variant="h6" components="h2">
Installed from the Plugin Catalog
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The title of the section is already "Installed". So here we could just have Plugins from the Catalog.

</Typography>
<SimpleTable
columns={[
{
label: 'Name',
getter: plugin => (
<Box>
<Link
routeName="/plugin-catalog/:repoName/:pluginName"
params={{ repoName: plugin.repoName, pluginName: plugin.folderName }}
>
{plugin.pluginTitle}
</Link>
</Box>
),
},
{
label: 'Version',
getter: plugin => plugin.pluginVersion,
},
{
label: 'Repo',
getter: plugin => plugin.repoName,
},
{
label: 'Author',
getter: plugin => plugin.author,
},
]}
emptyMessage="No plugins installed"
data={installedPlugins || []}
/>
</Box>

<Box
sx={{
display: 'flex',
flexDirection: 'column',
gap: 2,
alignItems: 'start',
}}
>
<Typography variant="h6" components="h2">
Other Installed Plugins
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here we could use Other Plugins

</Typography>

<SimpleTable
columns={[
{
label: 'Name',
getter: otherInstalledPlugins => (
<Box>
<Link
routeName={`pluginDetails`}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lliteral is not replacing any var, so it may be "pluginDetails" instead (no {} needed either).

params={{ name: otherInstalledPlugins.name }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should (in a different commit) make sure that the names of plugins are separated into org+name. We can use the org as the author. See:
headlamp-k8s/headlamp#2572

>
{otherInstalledPlugins.name}
</Link>
</Box>
),
},
{
label: 'Version',
getter: otherInstalledPlugins => otherInstalledPlugins.version,
},
{
label: 'Repo',
getter: plugin => plugin.repoName,
},
{
label: 'Author',
getter: plugin => plugin.author,
},
]}
emptyMessage="No plugins installed"
data={otherInstalledPlugins || []}
/>
</Box>
</Box>
)}
</SectionBox>
);
}

export function PluginInstalledList() {
const [installedPlugins, setInstalledPlugins] = useState<Plugin[] | null>(null);
const [otherInstalledPlugins, setOtherInstalledPlugins] = useState<Plugin[] | null>(null);
const [error, setError] = useState<string | null>(null);

useEffect(() => {
Expand All @@ -81,8 +152,25 @@ export function PluginInstalledList() {
}
}

function fetchOtherInstalledPlugins() {
const storedPlugins = localStorage.getItem('headlampPluginSettings');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the correct way to get the plugins? I think there's currently an issue related to this, since it mentions plugins settings but we have the package.json stored there, although it's likely a bug.
See #this comment.

if (storedPlugins) {
const parsedPlugins = JSON.parse(storedPlugins);
setOtherInstalledPlugins(parsedPlugins);
} else {
setOtherInstalledPlugins([]);
}
}

fetchInstalledPlugins();
fetchOtherInstalledPlugins();
}, []);

return <PurePluginInstalledList installedPlugins={installedPlugins} error={error} />;
return (
<PurePluginInstalledList
installedPlugins={installedPlugins}
otherInstalledPlugins={otherInstalledPlugins}
error={error}
/>
);
}
Loading