saleor-dashboard/src/plugins/components/PluginsList/PluginsList.tsx
mmarkusik 19b8d30565
Feature - channels per plugin (#1093)
* Update schema

* Update queries, mutations, and types

* Add render with dividers util function

* Add plugin details channels card component

* Update plugin details to use channels

* Update stories

* Update plugin configuration type across the app, fix some other types, temporarily comment some things out in plugins list so types match"

* Update schema

* Update types

* Update plugins list to show channels and global statuses, add plugin channel status, update status label component

* Add render with dividers util function

* Comment out some stuff for types to match - temporary

* Add useChannelsSearchWithLoadMore util to imitate loading more from backend for channels list with load more

* Change filters logic to be able to display multiple fields in a field section and add it to plugins view

* Add scroll option to plugin availability popup on plugin list

* Fix plugin list page story

* Temporarily comment some stuff out, fix some types

* Add filters errors WIP

* Fix filters not updating list

* Add error handling to plugins list filters and filters in general

* Rename some components according to review

* Move useChannelsSearch and useChannelsSearchWithLoadMore to hooks, change some imports accordingly

* Fix imports

* Move render collection with dividers to a component, fix usages

* Replace channels with load more and search query to base channels query

* Change render with dividers function to take in a component instead of render function

* Update tests

* Extract messages

* Remove unnecessary imports

* Fix filters - autocomplete messing items order sometimes & some fields not working

* Update plugin update mutation variables - change channelId to channel

* fix failing tests

* Add test ids

* fix failing tests

* fix failing tests

* Rename misc.tsx to ts

* Remove usage of render collection with diviers, change it to CollectionWithDividers component

* Remove unnecessary imports

* Update messages ids

* Update snapshots

Co-authored-by: Karolina Rakoczy <rakoczy.karolina@gmail.com>
2021-05-11 15:58:09 +02:00

114 lines
3.5 KiB
TypeScript

import { makeStyles } from "@material-ui/core";
import TableBody from "@material-ui/core/TableBody";
import TableCell from "@material-ui/core/TableCell";
import TableFooter from "@material-ui/core/TableFooter";
import TableRow from "@material-ui/core/TableRow";
import EditIcon from "@material-ui/icons/Edit";
import ResponsiveTable from "@saleor/components/ResponsiveTable";
import Skeleton from "@saleor/components/Skeleton";
import TablePagination from "@saleor/components/TablePagination";
import { renderCollection } from "@saleor/misc";
import { PluginListUrlSortField } from "@saleor/plugins/urls";
import { ListProps, SortPage } from "@saleor/types";
import React from "react";
import { useIntl } from "react-intl";
import { Plugins_plugins_edges_node } from "../../types/Plugins";
import PluginChannelAvailabilityCell from "./PluginChannelAvailabilityCell";
import PluginChannelConfigurationCell from "./PluginChannelConfigurationCell";
import PluginListTableHead from "./PluginListTableHead";
export const useStyles = makeStyles(
() => ({
link: {
cursor: "pointer"
}
}),
{ name: "PluginsList" }
);
export interface PluginListProps
extends ListProps,
SortPage<PluginListUrlSortField> {
plugins: Plugins_plugins_edges_node[];
}
const totalColSpan = 10;
const PluginList: React.FC<PluginListProps> = props => {
const {
settings,
plugins,
disabled,
onNextPage,
pageInfo,
sort,
onRowClick,
onSort,
onUpdateListSettings,
onPreviousPage
} = props;
const classes = useStyles(props);
const intl = useIntl();
return (
<ResponsiveTable>
<PluginListTableHead sort={sort} onSort={onSort} />
<TableFooter>
<TableRow>
<TablePagination
colSpan={totalColSpan}
settings={settings}
hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}
onNextPage={onNextPage}
onUpdateListSettings={onUpdateListSettings}
hasPreviousPage={
pageInfo && !disabled ? pageInfo.hasPreviousPage : false
}
onPreviousPage={onPreviousPage}
/>
</TableRow>
</TableFooter>
<TableBody>
{renderCollection(
plugins,
plugin =>
plugin ? (
<TableRow
hover={!!plugin}
className={!!plugin ? classes.link : undefined}
onClick={plugin ? onRowClick(plugin.id) : undefined}
key={plugin ? plugin.id : "skeleton"}
>
<TableCell colSpan={5}>{plugin.name}</TableCell>
<PluginChannelConfigurationCell plugin={plugin} />
<PluginChannelAvailabilityCell plugin={plugin} />
<TableCell align="right">
<div onClick={plugin ? onRowClick(plugin.id) : undefined}>
<EditIcon />
</div>
</TableCell>
</TableRow>
) : (
<TableRow>
<TableCell colSpan={totalColSpan}>
<Skeleton />
</TableCell>
</TableRow>
),
() => (
<TableRow>
<TableCell colSpan={totalColSpan}>
{intl.formatMessage({
defaultMessage: "No plugins found"
})}
</TableCell>
</TableRow>
)
)}
</TableBody>
</ResponsiveTable>
);
};
PluginList.displayName = "PluginList";
export default PluginList;