From d005541a81659e774cdb7d70cf632b5b9b0ee206 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Tue, 19 Jul 2022 10:07:09 +0100 Subject: [PATCH] add labels --- CommonServer/Services/LabelService.ts | 10 ++++ CommonServer/Utils/StartServer.ts | 8 +-- CommonUI/src/Components/Card/Card.tsx | 5 +- .../{ModalTable.tsx => ModelTable.tsx} | 15 +++-- CommonUI/src/Components/Table/Pagination.tsx | 20 +++++-- CommonUI/src/Components/Table/Table.tsx | 57 +++++++++++++++++-- CommonUI/src/Styles/Custom/utils/Utils.scss | 10 ++++ Dashboard/src/Pages/Settings/APIKeys.tsx | 2 +- Dashboard/src/Pages/Settings/Labels.tsx | 3 +- DashboardAPI/Index.ts | 31 +++++++++- 10 files changed, 139 insertions(+), 22 deletions(-) create mode 100644 CommonServer/Services/LabelService.ts rename CommonUI/src/Components/ModelTable/{ModalTable.tsx => ModelTable.tsx} (92%) diff --git a/CommonServer/Services/LabelService.ts b/CommonServer/Services/LabelService.ts new file mode 100644 index 0000000000..479c25bd55 --- /dev/null +++ b/CommonServer/Services/LabelService.ts @@ -0,0 +1,10 @@ +import PostgresDatabase from '../Infrastructure/PostgresDatabase'; +import Model from 'Common/Models/Label'; +import DatabaseService from './DatabaseService'; + +export class Service extends DatabaseService { + public constructor(postgresDatabase?: PostgresDatabase) { + super(Model, postgresDatabase); + } +} +export default new Service(); diff --git a/CommonServer/Utils/StartServer.ts b/CommonServer/Utils/StartServer.ts index 2866d55c1e..a781cc9e25 100644 --- a/CommonServer/Utils/StartServer.ts +++ b/CommonServer/Utils/StartServer.ts @@ -123,19 +123,19 @@ const init: Function = async (appName: string): Promise => { ); app.post('*', (_req: ExpressRequest, res: ExpressResponse) => { - res.status(404).json({ error: 'API not found' }); + res.status(404).json({ error: '404 - Not Found.' }); }); app.put('*', (_req: ExpressRequest, res: ExpressResponse) => { - res.status(404).json({ error: 'API not found' }); + res.status(404).json({ error: '404 - Not Found.' }); }); app.delete('*', (_req: ExpressRequest, res: ExpressResponse) => { - res.status(404).json({ error: 'API not found' }); + res.status(404).json({ error: '404 - Not Found.' }); }); app.get('*', (_req: ExpressRequest, res: ExpressResponse) => { - res.status(404).json({ error: 'API not found' }); + res.status(404).json({ error: '404 - Not Found.' }); }); // await OpenTelemetrySDK.start(); diff --git a/CommonUI/src/Components/Card/Card.tsx b/CommonUI/src/Components/Card/Card.tsx index a2d6a6f982..5faf87c6a2 100644 --- a/CommonUI/src/Components/Card/Card.tsx +++ b/CommonUI/src/Components/Card/Card.tsx @@ -1,10 +1,11 @@ -import React, { FunctionComponent, ReactElement } from 'react'; +import React, { CSSProperties, FunctionComponent, ReactElement } from 'react'; export interface ComponentProps { title: string; description: string; buttons?: Array; children?: Array | ReactElement; + cardBodyStyle?: CSSProperties } const Card: FunctionComponent = ( @@ -27,7 +28,7 @@ const Card: FunctionComponent = (
{props.buttons}
{props.children && ( -
{props.children}
+
{props.children}
)} diff --git a/CommonUI/src/Components/ModelTable/ModalTable.tsx b/CommonUI/src/Components/ModelTable/ModelTable.tsx similarity index 92% rename from CommonUI/src/Components/ModelTable/ModalTable.tsx rename to CommonUI/src/Components/ModelTable/ModelTable.tsx index e357b30da0..6bd86ce04e 100644 --- a/CommonUI/src/Components/ModelTable/ModalTable.tsx +++ b/CommonUI/src/Components/ModelTable/ModelTable.tsx @@ -35,7 +35,7 @@ enum ModalType { Create, Edit } -const ModalTable: Function = ( +const ModelTable: Function = ( props: ComponentProps ): ReactElement => { @@ -44,7 +44,7 @@ const ModalTable: Function = ( const [data, setData] = useState>([]); const [currentPageNumber, setCurrentPageNumber] = useState(1); - const [totalItemsCount, setTotalItemsCount] = useState(1); + const [totalItemsCount, setTotalItemsCount] = useState(0); const [isLoading, setIsLaoding] = useState(false); const [error, setError] = useState(''); const [showModel, setShowModal] = useState(false); @@ -111,12 +111,15 @@ const ModalTable: Function = ( } fetchItems(); + }, []); return ( <> - + ( onNavigateToPage={(pageNumber: number) => { setCurrentPageNumber(pageNumber); }} + onRefreshClick={() => { + fetchItems(); + }} /> @@ -148,6 +154,7 @@ const ModalTable: Function = ( fields: props.createFormFields || [], formType: ModalType.Create ? FormType.Create : FormType.Update, }} + /> ) : ( <> @@ -156,4 +163,4 @@ const ModalTable: Function = ( ); }; -export default ModalTable; +export default ModelTable; diff --git a/CommonUI/src/Components/Table/Pagination.tsx b/CommonUI/src/Components/Table/Pagination.tsx index 7196e3df42..251f32a471 100644 --- a/CommonUI/src/Components/Table/Pagination.tsx +++ b/CommonUI/src/Components/Table/Pagination.tsx @@ -7,22 +7,32 @@ export interface ComponentProps { onNavigateToPage: (pageNumber: number) => void; isLoading: boolean; isError: boolean; + singularLabel: string; + pluralLabel: string; } const Pagination: FunctionComponent = ( props: ComponentProps ): ReactElement => { - const isPreviousDisabled: boolean = props.currentPageNumber === 1; - const isNextDisabled: boolean = props.currentPageNumber * props.itemsOnPage < props.totalItemsCount; + const isPreviousDisabled: boolean = (props.currentPageNumber === 1 || props.isLoading || props.isError); + const isNextDisabled: boolean = ( + props.currentPageNumber * props.itemsOnPage < props.totalItemsCount + || props.isLoading || props.isError + ); + const isCurrentPageButtonDisabled: boolean = props.isLoading || props.isError; return (
- +

{props.totalItemsCount} {props.totalItemsCount > 1 ? props.pluralLabel : props.singularLabel}

-
+ + + + + ) } if (props.error) { - return (

{props.error}

) + return ( + + + + + + ) + } + + if (props.data.length === 0) { + return ( + + + + + + ) } return ( = ( /> {getTablebody()} = ( isDeleteable={true} isEditable={true} isCreateable={true} + itemsOnPage={10} cardProps={{ title: 'Labels', description: diff --git a/DashboardAPI/Index.ts b/DashboardAPI/Index.ts index 84ffd0ba58..74623cb8d9 100755 --- a/DashboardAPI/Index.ts +++ b/DashboardAPI/Index.ts @@ -26,6 +26,28 @@ import EmailVerificationTokenService, { Service as EmailVerificationTokenServiceType, } from 'CommonServer/Services/EmailVerificationTokenService'; +import Team from 'Common/Models/Team'; +import TeamService, { + Service as TeamServiceType, +} from 'CommonServer/Services/TeamService'; + +import TeamMember from 'Common/Models/TeamMember'; +import TeamMemberService, { + Service as TeamMemberServiceType, +} from 'CommonServer/Services/TeamMemberService'; + +import TeamPermission from 'Common/Models/TeamPermission'; +import TeamPermissionService, { + Service as TeamPermissionServiceType, +} from 'CommonServer/Services/TeamPermissionService'; + +import Label from 'Common/Models/Label'; +import LabelService, { + Service as LabelServiceType, +} from 'CommonServer/Services/LabelService'; + + + const app: ExpressApplication = Express.getExpressApp(); const APP_NAME: string = 'api'; @@ -39,7 +61,14 @@ app.use( ).getRouter() ); app.use(new BaseAPI(Probe, ProbeService).getRouter()); -app.use(new BaseAPI(Probe, ProbeService).getRouter()); + + +app.use(new BaseAPI(Team, TeamService).getRouter()); +app.use(new BaseAPI(TeamMember, TeamMemberService).getRouter()); +app.use(new BaseAPI(TeamPermission, TeamPermissionService).getRouter()); + +app.use(new BaseAPI(Label, LabelService).getRouter()); + app.use( new BaseAPI( EmailVerificationToken,
+
+ +
+
+

{props.error}
{props.onRefreshClick ? { + if (props.onRefreshClick) { + props.onRefreshClick(); + } + }} className="underline primary-on-hover">Refresh? : <>}

+
+

No {props.singularLabel.toLocaleLowerCase()}

+