From 73a03fbfc87df72fe631b15c13c7d583ae4c3669 Mon Sep 17 00:00:00 2001 From: ronronscelestes Date: Fri, 13 Aug 2021 12:38:21 +0200 Subject: [PATCH] integrated DS + deleteOne, updateOne --- .../src/pages/Webhooks/ListView/index.js | 243 ++++++++++++++---- 1 file changed, 187 insertions(+), 56 deletions(-) diff --git a/packages/core/admin/admin/src/pages/Webhooks/ListView/index.js b/packages/core/admin/admin/src/pages/Webhooks/ListView/index.js index f52fc13a5e..f5f288a15a 100644 --- a/packages/core/admin/admin/src/pages/Webhooks/ListView/index.js +++ b/packages/core/admin/admin/src/pages/Webhooks/ListView/index.js @@ -6,30 +6,43 @@ import React, { useEffect, useReducer, useRef, useState } from 'react'; import { useHistory, useLocation } from 'react-router-dom'; -import { Header, List } from '@buffetjs/custom'; -import { Button } from '@buffetjs/core'; import { Plus } from '@buffetjs/icons'; -import { omit } from 'lodash'; import { useIntl } from 'react-intl'; import { request, - ListButton, PopUpWarning, useRBAC, LoadingIndicatorPage, EmptyState, useNotification, } from '@strapi/helper-plugin'; -import adminPermissions from '../../../permissions'; -import PageTitle from '../../../components/SettingsPageTitle'; -import { ListRow } from '../../../components/Webhooks'; -import Wrapper from './Wrapper'; + +import { HeaderLayout, Layout, ContentLayout } from '@strapi/parts/Layout'; +import { Row } from '@strapi/parts/Row'; +import { Box } from '@strapi/parts/Box'; +import { IconButton } from '@strapi/parts/IconButton'; +import { BaseCheckbox } from '@strapi/parts/BaseCheckbox'; +import { Table, Thead, Tr, Th, Tbody, Td, TFooter } from '@strapi/parts/Table'; +import { Text, TableLabel } from '@strapi/parts/Text'; +import { Button } from '@strapi/parts/Button'; +import { VisuallyHidden } from '@strapi/parts/VisuallyHidden'; +import { Switch } from '@strapi/parts/Switch'; +import AddIcon from '@strapi/icons/AddIcon'; +import EditIcon from '@strapi/icons/EditIcon'; +import DeleteIcon from '@strapi/icons/DeleteIcon'; import reducer, { initialState } from './reducer'; +import PageTitle from '../../../components/SettingsPageTitle'; +import adminPermissions from '../../../permissions'; function ListView() { const { isLoading, - allowedActions: { canCreate, canRead, canUpdate, canDelete }, + allowedActions: { + canCreate, + canRead, + // canUpdate, + // canDelete, + }, } = useRBAC(adminPermissions.settings.webhooks); const toggleNotification = useNotification(); const isMounted = useRef(true); @@ -101,30 +114,30 @@ function ListView() { // List props const rowsCount = webhooks.length; - const titleLabel = `${ - rowsCount > 1 - ? formatMessage({ id: 'Settings.webhooks.title' }) - : formatMessage({ id: 'Settings.webhooks.singular' }) - }`; - const title = `${rowsCount} ${titleLabel}`; + // const titleLabel = `${ + // rowsCount > 1 + // ? formatMessage({ id: 'Settings.webhooks.title' }) + // : formatMessage({ id: 'Settings.webhooks.singular' }) + // }`; + // const title = `${rowsCount} ${titleLabel}`; /* eslint-disable indent */ - const deleteButtonProps = canDelete - ? { - color: 'delete', - disabled: !(webhooksToDelete.length > 0), - label: formatMessage({ id: 'app.utils.delete' }), - onClick: () => setShowModal(true), - type: 'button', - } - : null; + // const deleteButtonProps = canDelete + // ? { + // color: 'delete', + // disabled: !(webhooksToDelete.length > 0), + // label: formatMessage({ id: 'app.utils.delete' }), + // onClick: () => setShowModal(true), + // type: 'button', + // } + // : null; /* eslint-enable indent */ - const listProps = { - title, - button: deleteButtonProps, - items: webhooks, - }; + // const listProps = { + // title, + // button: deleteButtonProps, + // items: webhooks, + // }; const fetchData = async () => { try { @@ -151,6 +164,7 @@ function ListView() { }; const handleChange = (value, id) => { + // console.log(value, id); dispatch({ type: 'SET_WEBHOOKS_TO_DELETE', value, @@ -224,10 +238,10 @@ function ListView() { id, }); }; - + console.log(webhooks); const handleEnabledChange = async (value, id) => { + // console.log(!value) const webhookIndex = getWebhookIndex(id); - const initialWebhookProps = webhooks[webhookIndex]; const keys = [webhookIndex, 'isEnabled']; @@ -276,29 +290,106 @@ function ListView() { } return ( - + -
- {canRead && ( -
+ (canCreate ? handleGoTo('create') : {})} startIcon={}> + {headerProps.actions[0].label} + + )} + /> + + + <> {rowsCount > 0 ? ( - { - return ( - - ); - }} - /> + (canCreate ? handleGoTo('create') : {})} icon={}> + Add another field to this collection type + + )} + > + + + + + + + + + + + {webhooks.map(webhook => ( + + + + + + + + ))} + +
+ + + name + + url + + status + + actions +
+ handleChange(value, webhook.id)} + id={`Select ${webhook.id}`} + name={`Select ${webhook.name}`} + /> + + + {webhook.name} + + + {webhook.url} + + + handleEnabledChange(webhook.isEnabled, webhook.id)} + visibleLabels + /> + + + + { + handleGoTo(webhook.id); + }} + label="Edit" + icon={} + noBorder + /> + + { + handleDeleteClick(webhook.id); + }} + label="Delete" + icon={} + noBorder + /> + + +
) : ( )} - {canCreate &&
- )} + + setShowModal(!showModal)} popUpWarningType="danger" onConfirm={handleConfirmDelete} /> - + ); } export default ListView; + +// TO KEEP AS EXEMPLE UNTIL WE KNOW HOW TO DEAL WITH EVENTS AND FUNCTIONS DEFINED IN THIS COMPONENT + +// {canRead && ( +// <> +// {rowsCount > 0 ? +// ( +// { +// return ( +// +// ); +// }} +// /> +// ) : ( +// +// )} +// {canCreate &&