2023-01-16 09:45:12 +00:00
|
|
|
|
import { AppManifestTableDisplay } from "@dashboard/apps/components/AppManifestTableDisplay/AppManifestTableDisplay";
|
|
|
|
|
import { InstallWithManifestFormButton } from "@dashboard/apps/components/InstallWithManifestFormButton";
|
|
|
|
|
import { appUrl, createAppInstallUrl } from "@dashboard/apps/urls";
|
|
|
|
|
import { isAppInTunnel } from "@dashboard/apps/utils";
|
|
|
|
|
import CardTitle from "@dashboard/components/CardTitle";
|
|
|
|
|
import { IconButton } from "@dashboard/components/IconButton";
|
|
|
|
|
import { TableButtonWrapper } from "@dashboard/components/TableButtonWrapper/TableButtonWrapper";
|
|
|
|
|
import TableRowLink from "@dashboard/components/TableRowLink";
|
|
|
|
|
import { AppListItemFragment } from "@dashboard/graphql";
|
|
|
|
|
import useNavigator from "@dashboard/hooks/useNavigator";
|
|
|
|
|
import { renderCollection } from "@dashboard/misc";
|
|
|
|
|
import { ListProps } from "@dashboard/types";
|
2023-01-12 08:19:13 +00:00
|
|
|
|
import { Card, TableBody, TableCell, Typography } from "@material-ui/core";
|
|
|
|
|
import { ResponsiveTable, SettingsIcon } from "@saleor/macaw-ui";
|
2022-10-13 15:13:08 +00:00
|
|
|
|
import React, { useCallback } from "react";
|
2022-10-20 11:35:31 +00:00
|
|
|
|
import { FormattedMessage } from "react-intl";
|
2020-07-22 10:54:15 +00:00
|
|
|
|
|
|
|
|
|
import { useStyles } from "../../styles";
|
2022-05-31 15:18:15 +00:00
|
|
|
|
import { AppPermissions } from "../AppPermissions/AppPermissions";
|
2020-07-22 10:54:15 +00:00
|
|
|
|
import AppsSkeleton from "../AppsSkeleton";
|
|
|
|
|
|
|
|
|
|
export interface InstalledAppsProps extends ListProps {
|
2022-12-15 13:51:05 +00:00
|
|
|
|
appsList: AppListItemFragment[];
|
2023-01-12 08:19:13 +00:00
|
|
|
|
onSettingsClick: (id: string) => void;
|
2022-10-20 11:35:31 +00:00
|
|
|
|
displayQuickManifestButton?: boolean;
|
|
|
|
|
title: string;
|
2020-07-22 10:54:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const InstalledApps: React.FC<InstalledAppsProps> = ({
|
|
|
|
|
appsList,
|
2023-01-12 08:19:13 +00:00
|
|
|
|
onSettingsClick,
|
2022-10-20 11:35:31 +00:00
|
|
|
|
title,
|
|
|
|
|
displayQuickManifestButton = false,
|
2020-07-22 10:54:15 +00:00
|
|
|
|
...props
|
|
|
|
|
}) => {
|
|
|
|
|
const classes = useStyles(props);
|
2022-10-13 15:13:08 +00:00
|
|
|
|
const navigate = useNavigator();
|
|
|
|
|
|
|
|
|
|
const navigateToAppInstallPage = useCallback(
|
|
|
|
|
(url: string) => {
|
|
|
|
|
navigate(createAppInstallUrl(url));
|
|
|
|
|
},
|
|
|
|
|
[navigate],
|
|
|
|
|
);
|
2022-05-31 15:18:15 +00:00
|
|
|
|
|
2020-07-22 10:54:15 +00:00
|
|
|
|
return (
|
2022-01-28 12:34:20 +00:00
|
|
|
|
<Card className={classes.apps}>
|
|
|
|
|
<CardTitle
|
2022-10-20 11:35:31 +00:00
|
|
|
|
title={title}
|
2022-10-13 15:13:08 +00:00
|
|
|
|
toolbar={
|
2022-10-20 11:35:31 +00:00
|
|
|
|
displayQuickManifestButton ? (
|
|
|
|
|
<InstallWithManifestFormButton
|
|
|
|
|
onSubmitted={navigateToAppInstallPage}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
undefined
|
|
|
|
|
)
|
2022-10-13 15:13:08 +00:00
|
|
|
|
}
|
2022-01-28 12:34:20 +00:00
|
|
|
|
/>
|
|
|
|
|
<ResponsiveTable>
|
2020-07-22 10:54:15 +00:00
|
|
|
|
<TableBody>
|
|
|
|
|
{renderCollection(
|
|
|
|
|
appsList,
|
|
|
|
|
(app, index) =>
|
|
|
|
|
app ? (
|
2022-05-06 08:59:55 +00:00
|
|
|
|
<TableRowLink
|
2022-12-15 13:51:05 +00:00
|
|
|
|
key={app.id}
|
2020-07-22 10:54:15 +00:00
|
|
|
|
className={classes.tableRow}
|
2022-12-15 13:51:05 +00:00
|
|
|
|
href={appUrl(app.id)}
|
2020-07-22 10:54:15 +00:00
|
|
|
|
>
|
|
|
|
|
<TableCell className={classes.colName}>
|
|
|
|
|
<span data-tc="name" className={classes.appName}>
|
2022-12-15 13:51:05 +00:00
|
|
|
|
{app.name}
|
2020-07-22 10:54:15 +00:00
|
|
|
|
</span>
|
2022-12-15 13:51:05 +00:00
|
|
|
|
{app.manifestUrl && isAppInTunnel(app.manifestUrl) ? (
|
2022-10-20 11:35:31 +00:00
|
|
|
|
<Typography variant="caption">
|
|
|
|
|
<FormattedMessage
|
|
|
|
|
defaultMessage="(TUNNEL - DEVELOPMENT)"
|
|
|
|
|
id="QdQ9z7"
|
|
|
|
|
/>
|
|
|
|
|
</Typography>
|
|
|
|
|
) : null}
|
2020-07-22 10:54:15 +00:00
|
|
|
|
</TableCell>
|
2022-10-20 11:35:31 +00:00
|
|
|
|
|
2020-07-22 10:54:15 +00:00
|
|
|
|
<TableCell className={classes.colAction}>
|
2022-12-15 13:51:05 +00:00
|
|
|
|
{app.manifestUrl && (
|
|
|
|
|
<AppManifestTableDisplay manifestUrl={app.manifestUrl} />
|
2022-04-27 10:41:03 +00:00
|
|
|
|
)}
|
2022-12-29 12:51:54 +00:00
|
|
|
|
<AppPermissions permissions={app.permissions || []} />
|
2022-05-13 11:04:16 +00:00
|
|
|
|
<TableButtonWrapper>
|
|
|
|
|
<IconButton
|
|
|
|
|
variant="secondary"
|
|
|
|
|
color="primary"
|
2023-01-12 08:19:13 +00:00
|
|
|
|
onClick={() => onSettingsClick(app.id)}
|
2022-05-13 11:04:16 +00:00
|
|
|
|
>
|
2023-01-12 08:19:13 +00:00
|
|
|
|
<SettingsIcon />
|
2022-05-13 11:04:16 +00:00
|
|
|
|
</IconButton>
|
|
|
|
|
</TableButtonWrapper>
|
2020-07-22 10:54:15 +00:00
|
|
|
|
</TableCell>
|
2022-05-06 08:59:55 +00:00
|
|
|
|
</TableRowLink>
|
2020-07-22 10:54:15 +00:00
|
|
|
|
) : (
|
|
|
|
|
<AppsSkeleton key={index} />
|
|
|
|
|
),
|
|
|
|
|
() => (
|
2022-10-27 10:58:17 +00:00
|
|
|
|
<TableRowLink className={classes.tableRow}>
|
2020-07-22 10:54:15 +00:00
|
|
|
|
<TableCell className={classes.colName}>
|
|
|
|
|
<Typography className={classes.text} variant="body2">
|
|
|
|
|
<FormattedMessage
|
2022-05-05 07:54:28 +00:00
|
|
|
|
id="9tgY4G"
|
2020-07-22 10:54:15 +00:00
|
|
|
|
defaultMessage="You don’t have any installed apps in your dashboard"
|
|
|
|
|
description="apps content"
|
|
|
|
|
/>
|
|
|
|
|
</Typography>
|
|
|
|
|
</TableCell>
|
2022-10-27 10:58:17 +00:00
|
|
|
|
</TableRowLink>
|
2022-06-21 09:36:55 +00:00
|
|
|
|
),
|
2020-07-22 10:54:15 +00:00
|
|
|
|
)}
|
|
|
|
|
</TableBody>
|
2022-01-28 12:34:20 +00:00
|
|
|
|
</ResponsiveTable>
|
|
|
|
|
</Card>
|
2020-07-22 10:54:15 +00:00
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
InstalledApps.displayName = "InstalledApps";
|
|
|
|
|
export default InstalledApps;
|