Skip to content

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

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

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
136 changes: 133 additions & 3 deletions plugin-catalog/src/components/plugins/InstalledList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { Link, SectionBox, SimpleTable } from '@kinvolk/headlamp-plugin/lib/Comm
import { Typography } from '@mui/material';
import { Box } from '@mui/material';
import { useEffect, useState } from 'react';
import { useSelector } from 'react-redux';

// this will need to import the store from the main project after everything is merged in from the refactor

interface Plugin {
pluginName: string;
Expand All @@ -17,16 +20,21 @@ 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"
paddingTop={2}
headerProps={{
noPadding: false, headerStyle: 'subsection' ,
noPadding: false, headerStyle: 'subsection',
actions: [
<Link routeName="plugins">Go to all installed plugins</Link>,
]
Expand Down Expand Up @@ -70,16 +78,120 @@ export function PurePluginInstalledList({ installedPlugins, error }: PurePluginI
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
</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
</Typography>

<SimpleTable
columns={[
{
label: 'Name',
getter: otherInstalledPlugins => (
<Box>
<Link
routeName={`pluginDetails`}
params={{ name: otherInstalledPlugins.name }}
>
{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 mainPlugins = useTypedSelector(state => state.plugins.PluginSettings);

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

const pluginInfo = useSelector((state: any) => state.plugins.pluginSettings);

console.log("WORKING", pluginInfo);

useEffect(() => {
async function fetchInstalledPlugins() {
try {
Expand All @@ -95,8 +207,26 @@ 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