From 75ed3e637c79d4f0f05b283c22760f56c6b44b8b Mon Sep 17 00:00:00 2001 From: Lim Zi Yang Date: Thu, 30 May 2024 20:24:46 +0800 Subject: [PATCH 1/5] refactor: update data type for get sr by id api response --- .../_hooks/use-org-service-requests.ts | 217 --------------- .../_hooks/use-service-request-info.tsx | 82 +----- .../_hooks/use-service-request-steps.tsx | 4 +- .../_hooks/use-service-requests.ts | 246 ------------------ ...-request.ts => use-service-request-dto.ts} | 14 +- frontend/src/lib/service.ts | 5 +- frontend/src/types/service-request.ts | 10 +- 7 files changed, 28 insertions(+), 550 deletions(-) rename frontend/src/hooks/{use-service-request.ts => use-service-request-dto.ts} (72%) diff --git a/frontend/src/app/(authenticated)/(main)/(admin)/admin-service-requests-dashboard/_hooks/use-org-service-requests.ts b/frontend/src/app/(authenticated)/(main)/(admin)/admin-service-requests-dashboard/_hooks/use-org-service-requests.ts index a978fb42..9bb95416 100644 --- a/frontend/src/app/(authenticated)/(main)/(admin)/admin-service-requests-dashboard/_hooks/use-org-service-requests.ts +++ b/frontend/src/app/(authenticated)/(main)/(admin)/admin-service-requests-dashboard/_hooks/use-org-service-requests.ts @@ -1,226 +1,9 @@ import { toast } from "@/components/ui/use-toast" import useOrganizationId from "@/hooks/use-organization-id" import { getAllServiceRequestForAdmin } from "@/lib/service" -import { FormFieldType, JsonFormComponents } from "@/types/json-form-components" -import { StepStatus } from "@/types/pipeline" -import { ServiceRequest, ServiceRequestStatus } from "@/types/service-request" import { useQuery } from "@tanstack/react-query" import { useMemo } from "react" -const DUMMY_PIPELINE_FORM: JsonFormComponents = { - fields: [ - { - name: "input", - title: "Input", - description: "", - type: FormFieldType.INPUT, - required: true, - placeholder: "Enter text...", - min_length: 1, - }, - { - name: "select", - title: "Select", - description: "", - type: FormFieldType.SELECT, - required: true, - placeholder: "Select an option", - options: ["Option 1", "Option 2", "Option 3"], - default: "Option 1", - }, - { - name: "checkbox", - title: "Checkbox", - description: "", - type: FormFieldType.CHECKBOXES, - options: ["Option 1", "Option 2", "Option 3"], - }, - ], -} - -const DUMMY_SERVICE_REQUESTS: ServiceRequest[] = [ - { - id: "1", - user_id: "123456", // DUMMY - pipeline_id: "65d48c02d62a1281c4f4ba3e", - pipeline_name: "Service 1", - pipeline_version: "0", - status: ServiceRequestStatus.PENDING, - created_on: "2024-02-21T19:50:01", - created_by: "User 1", - last_updated: "2024-02-21T19:50:01", - remarks: "", - pipeline: { - form: DUMMY_PIPELINE_FORM, - }, - form_data: {}, - first_step_name: "Approval", - steps: { - Approval: { - name: "Approval", - status: StepStatus.STEP_RUNNING, - next_step_name: "Create EC2", - }, - - "Create EC2": { - name: "Create EC2", - status: StepStatus.STEP_NOT_STARTED, - next_step_name: "", - }, - }, - }, - { - id: "2", - user_id: "123456", // DUMMY - pipeline_id: "65d48c02d62a1281c4f4ba3e", - pipeline_name: "Service 1", - pipeline_version: "0", - status: ServiceRequestStatus.PENDING, - created_on: "2024-02-21T18:50:01", - created_by: "User 2", - last_updated: "2024-02-21T18:50:01", - remarks: "", - pipeline: { - form: DUMMY_PIPELINE_FORM, - }, - first_step_name: "Approval", - form_data: {}, - steps: { - Approval: { - name: "Approval", - status: StepStatus.STEP_RUNNING, - next_step_name: "Create EC2", - }, - - "Create EC2": { - name: "Create EC2", - status: StepStatus.STEP_NOT_STARTED, - next_step_name: "", - }, - }, - }, - { - id: "3", - user_id: "123456", // DUMMY - pipeline_id: "65d48c02d62a1281c4f4ba3e", - pipeline_name: "Service 1", - pipeline_version: "0", - status: ServiceRequestStatus.PENDING, - created_on: "2024-02-21T17:00:00", - created_by: "User 3", - last_updated: "2024-02-21T17:00:00", - remarks: "", - pipeline: { - form: DUMMY_PIPELINE_FORM, - }, - first_step_name: "Approval", - form_data: {}, - steps: { - Approval: { - name: "Approval", - status: StepStatus.STEP_RUNNING, - next_step_name: "Create EC2", - }, - - "Create EC2": { - name: "Create EC2", - status: StepStatus.STEP_NOT_STARTED, - next_step_name: "", - }, - }, - }, - { - id: "4", - user_id: "123456", // DUMMY - pipeline_id: "65d48c02d62a1281c4f4ba3e", - pipeline_name: "Service 1", - pipeline_version: "0", - status: ServiceRequestStatus.FAILED, - created_on: "2024-02-21T00:00:00", - created_by: "User 4", - last_updated: "2024-02-21T00:00:00", - remarks: "", - pipeline: { - form: DUMMY_PIPELINE_FORM, - }, - first_step_name: "Approval", - form_data: {}, - steps: { - Approval: { - name: "Approval", - status: StepStatus.STEP_COMPLETED, - next_step_name: "Create EC2", - }, - - "Create EC2": { - name: "Create EC2", - status: StepStatus.STEP_RUNNING, - next_step_name: "", - }, - }, - }, - { - id: "5", - user_id: "123456", // DUMMY - pipeline_id: "65d48c02d62a1281c4f4ba3e", - pipeline_name: "Service 1", - pipeline_version: "0", - status: ServiceRequestStatus.FAILED, - created_on: "2024-02-20T00:00:00", - created_by: "User 1", - last_updated: "2024-02-20T00:00:00", - remarks: "", - pipeline: { - form: DUMMY_PIPELINE_FORM, - }, - first_step_name: "Approval", - form_data: {}, - steps: { - Approval: { - name: "Approval", - status: StepStatus.STEP_FAILED, - next_step_name: "Create EC2", - }, - - "Create EC2": { - name: "Create EC2", - status: StepStatus.STEP_NOT_STARTED, - next_step_name: "", - }, - }, - }, - { - id: "6", - user_id: "123456", // DUMMY - pipeline_id: "65d48c02d62a1281c4f4ba3e", - pipeline_name: "Service 1", - pipeline_version: "0", - status: ServiceRequestStatus.RUNNING, - created_on: "2024-02-10T00:00:00", - created_by: "User 2", - last_updated: "2024-02-10T00:00:00", - remarks: "", - pipeline: { - form: DUMMY_PIPELINE_FORM, - }, - first_step_name: "Approval", - form_data: {}, - steps: { - Approval: { - name: "Approval", - status: StepStatus.STEP_COMPLETED, - next_step_name: "Create EC2", - }, - - "Create EC2": { - name: "Create EC2", - status: StepStatus.STEP_RUNNING, - next_step_name: "", - }, - }, - }, -] - interface UseOrgServiceRequestsOptions { page: number pageSize: number diff --git a/frontend/src/app/(authenticated)/(main)/(non-admin)/service-request-info/[serviceRequestId]/_hooks/use-service-request-info.tsx b/frontend/src/app/(authenticated)/(main)/(non-admin)/service-request-info/[serviceRequestId]/_hooks/use-service-request-info.tsx index 945354a9..c168ec46 100644 --- a/frontend/src/app/(authenticated)/(main)/(non-admin)/service-request-info/[serviceRequestId]/_hooks/use-service-request-info.tsx +++ b/frontend/src/app/(authenticated)/(main)/(non-admin)/service-request-info/[serviceRequestId]/_hooks/use-service-request-info.tsx @@ -1,77 +1,8 @@ -import useServiceRequest from "@/hooks/use-service-request" +import useServiceRequestDTO from "@/hooks/use-service-request-dto" import { generateUiSchema } from "@/lib/rjsf-utils" import { convertServiceRequestFormToRJSFSchema } from "@/lib/rjsf-utils" -import { FormFieldType, JsonFormComponents } from "@/types/json-form-components" -import { StepStatus } from "@/types/pipeline" -import { ServiceRequest, ServiceRequestStatus } from "@/types/service-request" import { useMemo } from "react" -const DUMMY_PIPELINE_FORM: JsonFormComponents = { - fields: [ - { - name: "input", - title: "Input", - description: "", - type: FormFieldType.INPUT, - required: true, - placeholder: "Enter text...", - min_length: 1, - }, - { - name: "select", - title: "Select", - description: "", - type: FormFieldType.SELECT, - required: true, - placeholder: "Select an option", - options: ["Option 1", "Option 2", "Option 3"], - default: "Option 1", - }, - { - name: "checkbox", - title: "Checkbox", - description: "", - type: FormFieldType.CHECKBOXES, - options: ["Option 1", "Option 2", "Option 3"], - }, - ], -} - -const DUMMY_SR_FORM_DATA = { - input: "Input value", - select: "Item 1", - checkboxes: ["Item 1", "Item 2"], -} -const DUMMY_SERVICE_REQUEST: ServiceRequest = { - id: "1", - user_id: "123456", // DUMMY - pipeline_id: "65d48c02d62a1281c4f4ba3e", - pipeline_name: "Service 1", - pipeline_version: "0", - status: ServiceRequestStatus.NOT_STARTED, - created_by: "User 1", - created_on: "2024-02-21T19:50:01", - last_updated: "2024-02-21T19:50:01", - remarks: "Remarks", - pipeline: { - form: DUMMY_PIPELINE_FORM, - }, - form_data: DUMMY_SR_FORM_DATA, - first_step_name: "Approval", - steps: { - Approval: { - name: "Approval", - status: StepStatus.STEP_NOT_STARTED, - next_step_name: "Create EC2", - }, - "Create EC2": { - name: "Create EC2", - status: StepStatus.STEP_NOT_STARTED, - next_step_name: "", - }, - }, -} - interface UseServiceRequestInfoOptions { serviceRequestId: string } @@ -80,10 +11,9 @@ const useServiceRequestInfo = ({ serviceRequestId, }: UseServiceRequestInfoOptions) => { // TODO: Remove DUMMY_SERVICE_REQUEST when integrating with BE - const { serviceRequest = DUMMY_SERVICE_REQUEST, isServiceRequestLoading } = - useServiceRequest({ - serviceRequestId, - }) + const { serviceRequest, isServiceRequestLoading } = useServiceRequestDTO({ + serviceRequestId, + }) const uiSchema = useMemo( () => generateUiSchema(serviceRequest?.pipeline?.form), @@ -95,9 +25,9 @@ const useServiceRequestInfo = ({ ) return { - pipelineName: serviceRequest?.pipeline_name, + pipelineName: serviceRequest?.pipeline.name ?? "", pipelineDescription: "", - formData: serviceRequest?.form_data, + formData: serviceRequest?.service_request.form_data ?? {}, isServiceRequestLoading, uiSchema, rjsfSchema, diff --git a/frontend/src/app/(authenticated)/(main)/(non-admin)/service-request-logs/_hooks/use-service-request-steps.tsx b/frontend/src/app/(authenticated)/(main)/(non-admin)/service-request-logs/_hooks/use-service-request-steps.tsx index 42eb057f..7c09ebe9 100644 --- a/frontend/src/app/(authenticated)/(main)/(non-admin)/service-request-logs/_hooks/use-service-request-steps.tsx +++ b/frontend/src/app/(authenticated)/(main)/(non-admin)/service-request-logs/_hooks/use-service-request-steps.tsx @@ -1,4 +1,4 @@ -import useServiceRequest from "@/hooks/use-service-request" +import useServiceRequestDTO from "@/hooks/use-service-request-dto" import { createStepsFromObject } from "@/lib/utils" import { useEffect, useMemo, useState } from "react" @@ -8,7 +8,7 @@ type UseServiceRequestLogsOptions = { const useServiceRequestSteps = ({ serviceRequestId, }: UseServiceRequestLogsOptions) => { - const { serviceRequest, isServiceRequestLoading } = useServiceRequest({ + const { serviceRequest, isServiceRequestLoading } = useServiceRequestDTO({ serviceRequestId, }) diff --git a/frontend/src/app/(authenticated)/(main)/(non-admin)/your-service-request-dashboard/_hooks/use-service-requests.ts b/frontend/src/app/(authenticated)/(main)/(non-admin)/your-service-request-dashboard/_hooks/use-service-requests.ts index 54ad3548..862c140f 100644 --- a/frontend/src/app/(authenticated)/(main)/(non-admin)/your-service-request-dashboard/_hooks/use-service-requests.ts +++ b/frontend/src/app/(authenticated)/(main)/(non-admin)/your-service-request-dashboard/_hooks/use-service-requests.ts @@ -1,255 +1,9 @@ import { toast } from "@/components/ui/use-toast" import useOrganizationId from "@/hooks/use-organization-id" import { getAllServiceRequest } from "@/lib/service" -import { FormFieldType, JsonFormComponents } from "@/types/json-form-components" -import { StepStatus } from "@/types/pipeline" -import { ServiceRequest, ServiceRequestStatus } from "@/types/service-request" import { useQuery } from "@tanstack/react-query" import { useMemo } from "react" -const DUMMY_PIPELINE_FORM: JsonFormComponents = { - fields: [ - { - name: "input", - title: "Input", - description: "", - type: FormFieldType.INPUT, - required: true, - placeholder: "Enter text...", - min_length: 1, - }, - { - name: "select", - title: "Select", - description: "", - type: FormFieldType.SELECT, - required: true, - placeholder: "Select an option", - options: ["Option 1", "Option 2", "Option 3"], - default: "Option 1", - }, - { - name: "checkbox", - title: "Checkbox", - description: "", - type: FormFieldType.CHECKBOXES, - options: ["Option 1", "Option 2", "Option 3"], - }, - ], -} - -const DUMMY_SERVICE_REQUESTS: ServiceRequest[] = [ - { - id: "1", - user_id: "123456", // DUMMY - pipeline_id: "65d48c02d62a1281c4f4ba3e", - pipeline_name: "Service 1", - pipeline_version: "0", - status: ServiceRequestStatus.NOT_STARTED, - created_by: "User 1", - created_on: "2024-02-21T19:50:01", - last_updated: "2024-02-21T19:50:01", - remarks: "Remarks", - pipeline: { - form: DUMMY_PIPELINE_FORM, - }, - first_step_name: "Approval", - form_data: {}, - steps: { - Approval: { - name: "Approval", - status: StepStatus.STEP_NOT_STARTED, - next_step_name: "Create EC2", - }, - - "Create EC2": { - name: "Create EC2", - status: StepStatus.STEP_NOT_STARTED, - next_step_name: "", - }, - }, - }, - { - id: "2", - user_id: "123456", // DUMMY - pipeline_id: "65d48c02d62a1281c4f4ba3e", - pipeline_version: "0", - pipeline_name: "Service 1", - status: ServiceRequestStatus.PENDING, - created_by: "User 1", - created_on: "2024-02-21T18:50:01", - last_updated: "2024-02-21T18:50:01", - remarks: "Remarks", - pipeline: { - form: DUMMY_PIPELINE_FORM, - }, - first_step_name: "Approval", - form_data: {}, - steps: { - Approval: { - name: "Approval", - status: StepStatus.STEP_RUNNING, - next_step_name: "Create EC2", - }, - - "Create EC2": { - name: "Create EC2", - status: StepStatus.STEP_NOT_STARTED, - next_step_name: "", - }, - }, - }, - { - id: "3", - user_id: "123456", // DUMMY - pipeline_id: "65d48c02d62a1281c4f4ba3e", - pipeline_name: "Service 1", - pipeline_version: "0", - - status: ServiceRequestStatus.RUNNING, - created_by: "User 1", - created_on: "2024-02-21T17:00:00", - last_updated: "2024-02-21T17:00:00", - remarks: "Remarks", - pipeline: { - form: DUMMY_PIPELINE_FORM, - }, - first_step_name: "Approval", - form_data: {}, - steps: { - Approval: { - name: "Approval", - status: StepStatus.STEP_COMPLETED, - next_step_name: "Create EC2", - }, - - "Create EC2": { - name: "Create EC2", - status: StepStatus.STEP_RUNNING, - next_step_name: "", - }, - }, - }, - { - id: "4", - user_id: "123456", // DUMMY - pipeline_id: "65d48c02d62a1281c4f4ba3e", - pipeline_name: "Service 1", - pipeline_version: "0", - status: ServiceRequestStatus.COMPLETED, - created_by: "User 1", - created_on: "2024-02-21T00:00:00", - last_updated: "2024-02-21T00:00:00", - remarks: "", - pipeline: { - form: DUMMY_PIPELINE_FORM, - }, - first_step_name: "Approval", - form_data: {}, - steps: { - Approval: { - name: "Approval", - status: StepStatus.STEP_COMPLETED, - next_step_name: "Create EC2", - }, - - "Create EC2": { - name: "Create EC2", - status: StepStatus.STEP_COMPLETED, - next_step_name: "", - }, - }, - }, - { - id: "4", - user_id: "123456", // DUMMY - pipeline_id: "65d48c02d62a1281c4f4ba3e", - pipeline_name: "Service 1", - pipeline_version: "0", - status: ServiceRequestStatus.FAILED, - created_by: "User 1", - created_on: "2024-02-21T00:00:00", - last_updated: "2024-02-21T00:00:00", - remarks: "", - pipeline: { - form: DUMMY_PIPELINE_FORM, - }, - first_step_name: "Approval", - form_data: {}, - steps: { - Approval: { - name: "Approval", - status: StepStatus.STEP_FAILED, - next_step_name: "Create EC2", - }, - - "Create EC2": { - name: "Create EC2", - status: StepStatus.STEP_NOT_STARTED, - next_step_name: "", - }, - }, - }, - { - id: "5", - user_id: "123456", // DUMMY - pipeline_id: "65d48c02d62a1281c4f4ba3e", - pipeline_name: "Service 1", - pipeline_version: "0", - status: ServiceRequestStatus.FAILED, - created_by: "User 1", - created_on: "2024-02-20T00:00:00", - last_updated: "2024-02-20T00:00:00", - remarks: "", - pipeline: { - form: DUMMY_PIPELINE_FORM, - }, - first_step_name: "Approval", - form_data: {}, - steps: { - Approval: { - name: "Approval", - status: StepStatus.STEP_COMPLETED, - next_step_name: "Create EC2", - }, - - "Create EC2": { - name: "Create EC2", - status: StepStatus.STEP_FAILED, - next_step_name: "", - }, - }, - }, - { - id: "6", - user_id: "123456", // DUMMY - pipeline_id: "65d48c02d62a1281c4f4ba3e", - pipeline_name: "Service 1", - pipeline_version: "0", - status: ServiceRequestStatus.CANCELLED, - created_on: "2024-02-10T00:00:00", - last_updated: "2024-02-10T00:00:00", - remarks: "", - pipeline: { - form: DUMMY_PIPELINE_FORM, - }, - first_step_name: "Approval", - form_data: {}, - steps: { - Approval: { - name: "Approval", - status: StepStatus.STEP_FAILED, - next_step_name: "Create EC2", - }, - - "Create EC2": { - name: "Create EC2", - status: StepStatus.STEP_RUNNING, - next_step_name: "", - }, - }, - }, -] interface UseServiceRequestProps { page: number pageSize: number diff --git a/frontend/src/hooks/use-service-request.ts b/frontend/src/hooks/use-service-request-dto.ts similarity index 72% rename from frontend/src/hooks/use-service-request.ts rename to frontend/src/hooks/use-service-request-dto.ts index 7ee6ad47..92e2dc26 100644 --- a/frontend/src/hooks/use-service-request.ts +++ b/frontend/src/hooks/use-service-request-dto.ts @@ -1,19 +1,21 @@ import { toast } from "@/components/ui/use-toast" -import { getServiceRequest } from "@/lib/service" -import { ServiceRequest } from "@/types/service-request" +import { getServiceRequestDTO } from "@/lib/service" +import { ServiceRequestDTO } from "@/types/service-request" import { useEffect, useState } from "react" interface UseServiceRequestOptions { serviceRequestId: string } -const useServiceRequest = ({ serviceRequestId }: UseServiceRequestOptions) => { - const [serviceRequest, setServiceRequest] = useState() +const useServiceRequestDTO = ({ + serviceRequestId, +}: UseServiceRequestOptions) => { + const [serviceRequest, setServiceRequest] = useState() const [loading, setLoading] = useState(false) useEffect(() => { setLoading(true) - getServiceRequest(serviceRequestId) + getServiceRequestDTO(serviceRequestId) .then(setServiceRequest) .catch((err) => { console.log(err) @@ -32,4 +34,4 @@ const useServiceRequest = ({ serviceRequestId }: UseServiceRequestOptions) => { } } -export default useServiceRequest +export default useServiceRequestDTO diff --git a/frontend/src/lib/service.ts b/frontend/src/lib/service.ts index 7fc4fd25..e787088b 100644 --- a/frontend/src/lib/service.ts +++ b/frontend/src/lib/service.ts @@ -1,6 +1,7 @@ import { Pipeline } from "@/types/pipeline" import { ServiceRequest, + ServiceRequestDTO, ServiceRequestLogs, ServiceRequestSteps, } from "@/types/service-request" @@ -82,9 +83,9 @@ export async function getAllServiceRequestForAdmin( .then((res) => res.data) } -export async function getServiceRequest( +export async function getServiceRequestDTO( serviceRequestId: string -): Promise { +): Promise { return apiClient .get(`/service_request/${serviceRequestId}`) .then((res) => res.data) diff --git a/frontend/src/types/service-request.ts b/frontend/src/types/service-request.ts index 066e01cc..42c70f9a 100644 --- a/frontend/src/types/service-request.ts +++ b/frontend/src/types/service-request.ts @@ -49,7 +49,7 @@ type ServiceRequest = { first_step_name: string steps?: ServiceRequestSteps // TODO: To refactor in future when service request details is implemented - pipeline?: { form: JsonFormComponents } + pipeline?: { name: string; form: JsonFormComponents } } type ServiceRequestLogs = { @@ -59,12 +59,20 @@ type ServiceRequestLogs = { next_offset: number } +type ServiceRequestDTO = { + service_request: ServiceRequest + pipeline: { name: string; form: JsonFormComponents } + steps?: ServiceRequestSteps + first_step_name: string +} + export type { ServiceRequestForm, ServiceRequestStep, ServiceRequestSteps, ServiceRequest, ServiceRequestLogs, + ServiceRequestDTO, } export { ServiceRequestStatus } From 8f23d151b49a30054eb6cb946f091a189855666d Mon Sep 17 00:00:00 2001 From: Lim Zi Yang Date: Thu, 30 May 2024 20:25:43 +0800 Subject: [PATCH 2/5] chore: remove dummy json objects --- .../_hooks/use-service-request-form.ts | 31 ------------------- .../_hooks/use-service-request.ts | 31 ------------------- .../_hooks/use-service-request-info.tsx | 1 - 3 files changed, 63 deletions(-) diff --git a/frontend/src/app/(authenticated)/(main)/(non-admin)/service-catalog/[pipelineId]/_hooks/use-service-request-form.ts b/frontend/src/app/(authenticated)/(main)/(non-admin)/service-catalog/[pipelineId]/_hooks/use-service-request-form.ts index c8fd133c..27fdd3d0 100644 --- a/frontend/src/app/(authenticated)/(main)/(non-admin)/service-catalog/[pipelineId]/_hooks/use-service-request-form.ts +++ b/frontend/src/app/(authenticated)/(main)/(non-admin)/service-catalog/[pipelineId]/_hooks/use-service-request-form.ts @@ -14,37 +14,6 @@ interface UseServiceRequestFormOptions { pipelineId: string } -const DUMMY_PIPELINE_FORM: JsonFormComponents = { - fields: [ - { - name: "input", - title: "Input", - description: "", - type: FormFieldType.INPUT, - required: true, - placeholder: "Enter text...", - min_length: 1, - }, - { - name: "select", - title: "Select", - description: "", - type: FormFieldType.SELECT, - required: true, - placeholder: "Select an option", - options: ["Option 1", "Option 2", "Option 3"], - default: "Option 1", - }, - { - name: "checkbox", - title: "Checkbox", - description: "", - type: FormFieldType.CHECKBOXES, - options: ["Option 1", "Option 2", "Option 3"], - }, - ], -} - const useServiceRequestForm = ({ pipelineId, }: UseServiceRequestFormOptions) => { diff --git a/frontend/src/app/(authenticated)/(main)/(non-admin)/service-catalog/[pipelineId]/_hooks/use-service-request.ts b/frontend/src/app/(authenticated)/(main)/(non-admin)/service-catalog/[pipelineId]/_hooks/use-service-request.ts index 2a38c150..6e88bb36 100644 --- a/frontend/src/app/(authenticated)/(main)/(non-admin)/service-catalog/[pipelineId]/_hooks/use-service-request.ts +++ b/frontend/src/app/(authenticated)/(main)/(non-admin)/service-catalog/[pipelineId]/_hooks/use-service-request.ts @@ -13,37 +13,6 @@ interface UseServiceRequestFormOptions { pipelineId: string } -const DUMMY_SERVICE_REQUEST_FORM: JsonFormComponents = { - fields: [ - { - name: "input", - title: "Input", - description: "", - type: FormFieldType.INPUT, - required: true, - placeholder: "Enter text...", - min_length: 1, - }, - { - name: "select", - title: "Select", - description: "", - type: FormFieldType.SELECT, - required: true, - placeholder: "Select an option", - options: ["Option 1", "Option 2", "Option 3"], - default: "Option 1", - }, - { - name: "checkbox", - title: "Checkbox", - description: "", - type: FormFieldType.CHECKBOXES, - options: ["Option 1", "Option 2", "Option 3"], - }, - ], -} - const useServiceRequestForm = ({ pipelineId, }: UseServiceRequestFormOptions) => { diff --git a/frontend/src/app/(authenticated)/(main)/(non-admin)/service-request-info/[serviceRequestId]/_hooks/use-service-request-info.tsx b/frontend/src/app/(authenticated)/(main)/(non-admin)/service-request-info/[serviceRequestId]/_hooks/use-service-request-info.tsx index c168ec46..acc535ea 100644 --- a/frontend/src/app/(authenticated)/(main)/(non-admin)/service-request-info/[serviceRequestId]/_hooks/use-service-request-info.tsx +++ b/frontend/src/app/(authenticated)/(main)/(non-admin)/service-request-info/[serviceRequestId]/_hooks/use-service-request-info.tsx @@ -10,7 +10,6 @@ interface UseServiceRequestInfoOptions { const useServiceRequestInfo = ({ serviceRequestId, }: UseServiceRequestInfoOptions) => { - // TODO: Remove DUMMY_SERVICE_REQUEST when integrating with BE const { serviceRequest, isServiceRequestLoading } = useServiceRequestDTO({ serviceRequestId, }) From d2003df89841d52dd31fed255115f6dd1887d273 Mon Sep 17 00:00:00 2001 From: Lim Zi Yang Date: Thu, 30 May 2024 20:27:10 +0800 Subject: [PATCH 3/5] chore: remove completed TODOs --- .../_components/admin-service-request-actions.tsx | 1 - .../(admin)/admin-service-requests-dashboard/columns.tsx | 1 - frontend/src/components/layouts/data-table-pagination.tsx | 3 +-- frontend/src/types/service-request.ts | 3 --- 4 files changed, 1 insertion(+), 7 deletions(-) diff --git a/frontend/src/app/(authenticated)/(main)/(admin)/admin-service-requests-dashboard/_components/admin-service-request-actions.tsx b/frontend/src/app/(authenticated)/(main)/(admin)/admin-service-requests-dashboard/_components/admin-service-request-actions.tsx index b670630a..2e958277 100644 --- a/frontend/src/app/(authenticated)/(main)/(admin)/admin-service-requests-dashboard/_components/admin-service-request-actions.tsx +++ b/frontend/src/app/(authenticated)/(main)/(admin)/admin-service-requests-dashboard/_components/admin-service-request-actions.tsx @@ -66,7 +66,6 @@ export default function AdminServiceRequestActions({ disabled={serviceRequest.status !== ServiceRequestStatus.PENDING} onClick={() => setOpenRejectConfirmationDialog(true)} > - {/* TODO: Add on click logic*/} diff --git a/frontend/src/app/(authenticated)/(main)/(admin)/admin-service-requests-dashboard/columns.tsx b/frontend/src/app/(authenticated)/(main)/(admin)/admin-service-requests-dashboard/columns.tsx index 7509d357..12c012a8 100644 --- a/frontend/src/app/(authenticated)/(main)/(admin)/admin-service-requests-dashboard/columns.tsx +++ b/frontend/src/app/(authenticated)/(main)/(admin)/admin-service-requests-dashboard/columns.tsx @@ -85,7 +85,6 @@ export const orgServiceRequestColumns: ColumnDef[] = [ { - // TODO: Replace with actual approval action approveServiceRequest(serviceRequestId) .then(() => { toast({ diff --git a/frontend/src/components/layouts/data-table-pagination.tsx b/frontend/src/components/layouts/data-table-pagination.tsx index 870b902c..df7c4743 100644 --- a/frontend/src/components/layouts/data-table-pagination.tsx +++ b/frontend/src/components/layouts/data-table-pagination.tsx @@ -38,8 +38,7 @@ export function DataTablePagination({ - {/* TODO: remove 1 per page option once testing fully done */} - {[1, 10, 20, 30, 40, 50].map((pageSize) => ( + {[10, 20, 30, 40, 50].map((pageSize) => ( {pageSize} diff --git a/frontend/src/types/service-request.ts b/frontend/src/types/service-request.ts index 42c70f9a..8d428e34 100644 --- a/frontend/src/types/service-request.ts +++ b/frontend/src/types/service-request.ts @@ -41,14 +41,11 @@ type ServiceRequest = { pipeline_version: string status: ServiceRequestStatus created_on: string - // TODO: Make field mandatory once accounts are tag to service request - created_by?: string last_updated: string remarks: string form_data: ServiceRequestForm first_step_name: string steps?: ServiceRequestSteps - // TODO: To refactor in future when service request details is implemented pipeline?: { name: string; form: JsonFormComponents } } From 3c82f31983469513d74bbbefba690735bded6f8f Mon Sep 17 00:00:00 2001 From: Lim Zi Yang Date: Thu, 30 May 2024 20:38:10 +0800 Subject: [PATCH 4/5] refactor: update seeded sr form data --- backend/database/mongo_seed/main.go | 60 +++++++++++++++++++---------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/backend/database/mongo_seed/main.go b/backend/database/mongo_seed/main.go index 0474c5e8..e3e203ff 100644 --- a/backend/database/mongo_seed/main.go +++ b/backend/database/mongo_seed/main.go @@ -316,11 +316,9 @@ func main() { CreatedOn: time.Date(2024, time.January, 1, 1, 0, 0, 0, time.UTC), LastUpdated: time.Date(2024, time.January, 1, 1, 0, 0, 0, time.UTC), FormData: models.FormData{ - "param": "test_param", - "method": "get", - "key": "test_key", - "value": "test_value", - "token": "test_token", + "field1": "test sr 1", + "field2": "Option 1", + "field3": []string{"Option 1"}, }, } @@ -341,11 +339,9 @@ func main() { CreatedOn: time.Date(2024, time.January, 1, 1, 0, 0, 0, time.UTC), LastUpdated: time.Date(2024, time.January, 1, 1, 0, 0, 0, time.UTC), FormData: models.FormData{ - "param": "test_param", - "method": "post", - "key": "test_key", - "value": "test_value", - "token": "test_token", + "field1": "test sr 2", + "field2": "Option 2", + "field3": []string{"Option 1", "Option 2"}, }, } @@ -366,7 +362,9 @@ func main() { CreatedOn: time.Date(2024, time.January, 1, 1, 0, 0, 0, time.UTC), LastUpdated: time.Date(2024, time.January, 1, 1, 0, 0, 0, time.UTC), FormData: models.FormData{ - "param": "test_param", + "field1": "test sr 3", + "field2": "Option 3", + "field3": []string{"Option 1", "Option 2", "Option 3"}, }, } @@ -387,7 +385,9 @@ func main() { CreatedOn: time.Date(2024, time.January, 1, 1, 0, 0, 0, time.UTC), LastUpdated: time.Date(2024, time.January, 1, 1, 0, 0, 0, time.UTC), FormData: models.FormData{ - "param": "test_param", + "field1": "test sr 4", + "field2": "Option 1", + "field3": []string{"Option 2"}, }, } @@ -408,7 +408,9 @@ func main() { CreatedOn: time.Date(2024, time.January, 1, 1, 0, 0, 0, time.UTC), LastUpdated: time.Date(2024, time.January, 1, 1, 0, 0, 0, time.UTC), FormData: models.FormData{ - "param": "test_param", + "field1": "test sr 5", + "field2": "Option 1", + "field3": []string{"Option 2", "Option 3"}, }, } @@ -429,7 +431,9 @@ func main() { CreatedOn: time.Date(2024, time.January, 1, 1, 0, 0, 0, time.UTC), LastUpdated: time.Date(2024, time.January, 1, 1, 0, 0, 0, time.UTC), FormData: models.FormData{ - "param": "test_param", + "field1": "test sr 6", + "field2": "Option 1", + "field3": []string{"Option 3"}, }, } @@ -450,7 +454,9 @@ func main() { CreatedOn: time.Date(2024, time.January, 1, 1, 0, 0, 0, time.UTC), LastUpdated: time.Date(2024, time.January, 1, 1, 0, 0, 0, time.UTC), FormData: models.FormData{ - "param": "test_param", + "field1": "test sr 7", + "field2": "Option 1", + "field3": []string{}, }, } @@ -471,7 +477,9 @@ func main() { CreatedOn: time.Date(2024, time.January, 1, 1, 0, 0, 0, time.UTC), LastUpdated: time.Date(2024, time.January, 1, 1, 0, 0, 0, time.UTC), FormData: models.FormData{ - "param": "test_param", + "field1": "test sr 8", + "field2": "Option 1", + "field3": []string{"Option 1"}, }, } @@ -492,7 +500,9 @@ func main() { CreatedOn: time.Date(2024, time.January, 1, 1, 0, 0, 0, time.UTC), LastUpdated: time.Date(2024, time.January, 1, 1, 0, 0, 0, time.UTC), FormData: models.FormData{ - "param": "test_param", + "field1": "test sr 9", + "field2": "Option 1", + "field3": []string{"Option 1"}, }, } @@ -513,7 +523,9 @@ func main() { CreatedOn: time.Date(2024, time.January, 1, 1, 0, 0, 0, time.UTC), LastUpdated: time.Date(2024, time.January, 1, 1, 0, 0, 0, time.UTC), FormData: models.FormData{ - "param": "test_param", + "field1": "test sr 10", + "field2": "Option 1", + "field3": []string{"Option 1"}, }, } @@ -534,7 +546,9 @@ func main() { CreatedOn: time.Date(2024, time.January, 1, 1, 0, 0, 0, time.UTC), LastUpdated: time.Date(2024, time.January, 1, 1, 0, 0, 0, time.UTC), FormData: models.FormData{ - "param": "test_param", + "field1": "test sr 11", + "field2": "Option 1", + "field3": []string{"Option 1"}, }, } @@ -555,7 +569,9 @@ func main() { CreatedOn: time.Date(2024, time.January, 1, 1, 0, 0, 0, time.UTC), LastUpdated: time.Date(2024, time.January, 1, 1, 0, 0, 0, time.UTC), FormData: models.FormData{ - "param": "test_param", + "field1": "test sr 12", + "field2": "Option 1", + "field3": []string{"Option 1"}, }, } @@ -576,7 +592,9 @@ func main() { CreatedOn: time.Date(2024, time.January, 1, 1, 0, 0, 0, time.UTC), LastUpdated: time.Date(2024, time.January, 1, 1, 0, 0, 0, time.UTC), FormData: models.FormData{ - "param": "test_param", + "field1": "test sr 13", + "field2": "Option 1", + "field3": []string{"Option 1"}, }, } From 5af34e9115547e3a212a1a7acf3038213730a5c5 Mon Sep 17 00:00:00 2001 From: Lim Zi Yang Date: Thu, 30 May 2024 20:41:10 +0800 Subject: [PATCH 5/5] fix: flickering of admin features --- .../src/app/(authenticated)/(main)/(admin)/layout.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/frontend/src/app/(authenticated)/(main)/(admin)/layout.tsx b/frontend/src/app/(authenticated)/(main)/(admin)/layout.tsx index d63d9a80..54440a5b 100644 --- a/frontend/src/app/(authenticated)/(main)/(admin)/layout.tsx +++ b/frontend/src/app/(authenticated)/(main)/(admin)/layout.tsx @@ -12,9 +12,12 @@ interface AdminLayoutProps { export default function AdminLayout({ children }: AdminLayoutProps) { const { isAdmin } = useUserMemberships() - return isAdmin ? ( - {children} - ) : ( - + return ( + isAdmin !== undefined && + (isAdmin ? ( + {children} + ) : ( + + )) ) }