diff --git a/CommonUI/src/Components/FullPageModal/FullPageModal.tsx b/CommonUI/src/Components/FullPageModal/FullPageModal.tsx index 35e8e151bc..4182e7c299 100644 --- a/CommonUI/src/Components/FullPageModal/FullPageModal.tsx +++ b/CommonUI/src/Components/FullPageModal/FullPageModal.tsx @@ -14,9 +14,13 @@ const FullPageModal: FunctionComponent = (
{ props.onClose && props.onClose(); }}> - +
- {props.children} +
{props.children}
); }; diff --git a/CommonUI/src/Components/ModelTable/ModelTable.tsx b/CommonUI/src/Components/ModelTable/ModelTable.tsx index 70e5b28ac3..cbab1744f1 100644 --- a/CommonUI/src/Components/ModelTable/ModelTable.tsx +++ b/CommonUI/src/Components/ModelTable/ModelTable.tsx @@ -38,6 +38,7 @@ import Navigation from '../../Utils/Navigation'; import Route from 'Common/Types/API/Route'; import BadDataException from 'Common/Types/Exception/BadDataException'; import Populate from '../../Utils/ModelAPI/Populate'; +import List from '../Table/List'; export interface ComponentProps { modelType: { new (): TBaseModel }; @@ -562,8 +563,116 @@ const ModelTable: Function = ( />) } - return ( - <> + const getList = (): ReactElement => { + return ( + ) => { + const query: Query = {}; + + for (const key in filterData) { + if ( + filterData[key] && + typeof filterData[key] === Typeof.String + ) { + query[key as keyof TBaseModel] = ( + filterData[key] || '' + ).toString(); + } + + if (typeof filterData[key] === Typeof.Boolean) { + query[key as keyof TBaseModel] = Boolean( + filterData[key] + ); + } + + if (filterData[key] instanceof Date) { + query[key as keyof TBaseModel] = + filterData[key]; + } + + if (filterData[key] instanceof Search) { + query[key as keyof TBaseModel] = + filterData[key]; + } + } + + setQuery(query); + }} + onSortChanged={(sortBy: string, sortOrder: SortOrder) => { + setSortBy(sortBy); + setSortOrder(sortOrder); + }} + singularLabel={model.singularName || 'Item'} + pluralLabel={model.pluralName || 'Items'} + error={error} + currentPageNumber={currentPageNumber} + isLoading={isLoading} + totalItemsCount={totalItemsCount} + data={BaseModel.toJSONObjectArray(data)} + id={props.id} + columns={tableColumns} + itemsOnPage={itemsOnPage} + disablePagination={props.disablePagination || false} + onNavigateToPage={async ( + pageNumber: number, + itemsOnPage: number + ) => { + setCurrentPageNumber(pageNumber); + setItemsOnPage(itemsOnPage); + }} + showFilter={showTableFilter} + noItemsMessage={props.noItemsMessage || ''} + onRefreshClick={() => { + fetchItems(); + }} + actionButtons={actionButtonSchema} + onActionEvent={(key: ActionType, item: JSONObject) => { + if (key === ActionType.Edit) { + setModalType(ModalType.Edit); + setShowModal(true); + setCurrentEditableItem(item); + } + + if (key === ActionType.Delete) { + setShowDeleteConfirmModal(true); + setCurrentDeleteableItem(item); + } + + if (key === ActionType.View) { + if (!props.currentPageRoute) { + throw new BadDataException( + 'Please populate curentPageRoute in ModelTable' + ); + } + Navigation.navigate( + new Route( + props.currentPageRoute.toString() + ).addRoute('/' + item['_id']) + ); + } + }} + />) + } + + const getCardComponent = (): ReactElement => { + + if (props.showAsList) { + return
+ {props.cardProps && + {getList()} + } + + {!props.cardProps && getList()} +
+ } + + + return
{props.cardProps && ( > {getTable()} } - + {!props.cardProps && getTable()} +
+ } + + return ( + <> + + + {getCardComponent()} {showModel ? ( diff --git a/CommonUI/src/Components/Table/List.tsx b/CommonUI/src/Components/Table/List.tsx index 0d02d7fd92..1ddf977960 100644 --- a/CommonUI/src/Components/Table/List.tsx +++ b/CommonUI/src/Components/Table/List.tsx @@ -1,7 +1,5 @@ import { JSONObject } from 'Common/Types/JSON'; import React, { FunctionComponent, ReactElement } from 'react'; -import TableBody from './TableBody'; -import TableHeader from './TableHeader'; import Columns from './Types/Columns'; import Pagination from './Pagination'; import SortOrder from 'Common/Types/Database/SortOrder'; @@ -10,6 +8,7 @@ import ActionButtonSchema, { ActionType } from './Types/ActionButtonSchema'; import Search from 'Common/Types/Database/Search'; import ErrorMessage from './ErrorMessage'; import TableLoader from './Loader'; +import ListBody from './ListBody'; export interface ComponentProps { data: Array; @@ -68,7 +67,7 @@ const List: FunctionComponent = ( } return ( - = ( +const ListBody: FunctionComponent = ( props: ComponentProps ): ReactElement => { return ( @@ -35,4 +35,4 @@ const TableBody: FunctionComponent = ( ); }; -export default TableBody; +export default ListBody; diff --git a/Dashboard/src/App.tsx b/Dashboard/src/App.tsx index f7cde2aff2..b2d67e5124 100644 --- a/Dashboard/src/App.tsx +++ b/Dashboard/src/App.tsx @@ -108,6 +108,7 @@ const App: FunctionComponent = () => { projects={projects} error={error} onProjectSelected={onProjectSelected} + selectedProject={selectedProject} > ; onProjectSelected: (project: Project) => void; } @@ -35,7 +40,7 @@ const DashboardHeader: FunctionComponent = ( projects={props.projects} onProjectSelected={props.onProjectSelected} /> - {}} /> + { }} />
= ( /> {showProjectInvitationModal && { - setShowProjectInvitationModal(false); + setShowProjectInvitationModal(false); }}> -
- -
+ + modelType={TeamPermission} + id="team-permission-table" + isDeleteable={true} + query={{ + userId: User.getUserId(), + hasAcceptedInvitation: false, + }} + isEditable={false} + isCreateable={false} + isViewable={false} + cardProps={{ + icon: IconProp.User, + title: 'Project Invitations', + description: + 'Here is a list of projects and teams you have been invited to.', + }} + noItemsMessage={ + 'No proejct or team invitations for you so far.' + } + showAsList={true} + columns={[ + { + field: { + projectId: true, + }, + title: 'Project', + type: FieldType.Text, + isFilterable: true, + }, + { + field: { + teamId: true, + }, + title: 'Team', + type: FieldType.Text, + }, + ]} + />
} ); diff --git a/Dashboard/src/Components/MasterPage/MasterPage.tsx b/Dashboard/src/Components/MasterPage/MasterPage.tsx index de37760649..9192a33684 100644 --- a/Dashboard/src/Components/MasterPage/MasterPage.tsx +++ b/Dashboard/src/Components/MasterPage/MasterPage.tsx @@ -9,6 +9,7 @@ export interface ComponentProps { children: ReactElement | Array; isLoading: boolean; projects: Array; + selectedProject: Project | null; error: string; onProjectSelected: (project: Project) => void; } @@ -21,6 +22,7 @@ const DashboardMasterPage: FunctionComponent = ( footer={