Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/dataController/platform.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ export interface IGetAllPlatform {
orgId: number
}
export interface ICreatePlatform {
platformName: string
platformNames: string[]
createdBy: number
projectId?: null | number
orgId: number
}

Expand Down
11 changes: 10 additions & 1 deletion app/db/dao/platform.dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {eq} from 'drizzle-orm/sql'
import {logger, LogType} from '~/utils/logger'
import {dbClient} from '../client'
import {errorHandling} from './utils'
import {ORG_ID} from '@route/utils/constants'

const PlatformDao = {
getAllPlatform: async ({orgId}: IGetAllPlatform) => {
Expand All @@ -26,8 +27,16 @@ const PlatformDao = {
}
},
createPlatform: async (param: ICreatePlatform) => {

try {
return await dbClient.insert(platform).values(param)
const insertData = param.platformNames.map((platformName) => ({
platformName: platformName?.trim(),
orgId: param.orgId ?? ORG_ID,
projectId: param.projectId,
createdBy: param.createdBy,
}))
const data = await dbClient.insert(platform).values(insertData)
return data
} catch (error: any) {
// FOR DEV PURPOSES
logger({
Expand Down
61 changes: 61 additions & 0 deletions app/routes/api/v1/addPlatforms.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {ActionFunctionArgs} from '@remix-run/node'
import {z} from 'zod'
import {getUserAndCheckAccess} from '~/routes/utilities/checkForUserAndAccess'
import {
errorResponseHandler,
responseHandler,
} from '~/routes/utilities/responseHandler'
import {API} from '../../utilities/api'
import {getRequestParams} from '../../utilities/utils'
import PlatformController from '@controllers/platform.controller'
import {ORG_ID} from '@route/utils/constants'

const AddPlatformsSchema = z.object({
platforms: z
.array(
z.string().min(1, {message: 'Each Platform must be a non-empty string'}),
)
.min(1, {message: 'At least one platform is required'}),
projectId: z.number().gt(0),
})

type AddPlatformsType = z.infer<typeof AddPlatformsSchema>

export const action = async ({request}: ActionFunctionArgs) => {
try {
if (request.headers.get('content-type') !== 'application/json') {
return responseHandler({
error: 'Invalid content type, expected application/json',
status: 400,
})
}

const user = await getUserAndCheckAccess({
request,
resource: API.AddPlatforms,
})
const orgID = ORG_ID
const data = await getRequestParams<AddPlatformsType>(request, AddPlatformsSchema)

const resp = await PlatformController.createPlatform({
projectId: data.projectId,
platformNames: data.platforms,
createdBy: user?.userId ?? 0,
orgId: orgID
})

if (resp) {
return responseHandler({
data: {message: `${resp[0].affectedRows} platform(s) added`},
status: 201,
})
} else {
return responseHandler({
error: 'Error adding platforms due to duplicate entries',
status: 400,
})
}
} catch (error: any) {
return errorResponseHandler(error)
}
}
3 changes: 3 additions & 0 deletions app/routes/utilities/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export enum API {
AddProjects = 'api/v1/project/create',
AddRun = 'api/v1/run/create',
AddSquads = 'api/v1/project/add-squads',
AddPlatforms = 'api/v1/project/add-platforms',
AddTest = 'api/v1/test/create',
AddTestBulk = 'api/v1/test/bulk-add',
AddToken = 'api/v1/token/generate',
Expand Down Expand Up @@ -68,6 +69,7 @@ export const API_RESOLUTION_PATHS = {
[API.AddProjects]: 'routes/api/v1/createProjects.ts',
[API.AddRun]: 'routes/api/v1/createRun.ts',
[API.AddSquads]: 'routes/api/v1/addSquads.ts',
[API.AddPlatforms]: 'routes/api/v1/addPlatforms.ts',
[API.AddTest]: 'routes/api/v1/createTest.ts',
[API.AddTestBulk]: 'routes/api/v1/bulkAddTest.ts',
[API.AddToken]: 'routes/api/v1/generateToken.ts',
Expand Down Expand Up @@ -171,4 +173,5 @@ export const ApiToTypeMap: {
[API.UpdateUserRole]: ApiTypes.PUT,
[API.AddSection]: ApiTypes.POST,
[API.EditSection]: ApiTypes.PUT,
[API.AddPlatforms]: ApiTypes.POST
}
2 changes: 1 addition & 1 deletion app/screens/RunTestList/AddResultDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const AddResultDialog = ({
width: 'min-96',
backgroundColor: getStatusColor(currStatus as TestStatusType),
fontWeight: 500,
color: currStatus === TestStatusType.Blocked ? 'white' : 'black',
color: getStatusTextColor(currStatus as TestStatusType),
}}>
{currStatus}
<ChevronDown size={22} strokeWidth={2} className="ml-2" />
Expand Down
27 changes: 27 additions & 0 deletions app/screens/TestList/ProjectActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum Actions {
AddLabel = 'Label',
AddSquad = 'Squad',
CreateRun = 'Run',
AddPlatform = 'Platform',
}

const ACTION_ITEMS: {
Expand All @@ -45,6 +46,10 @@ const ACTION_ITEMS: {
id: 4,
action: Actions.CreateRun,
},
{
id: 5,
action: Actions.AddPlatform
}
]

export const ProjectActions = () => {
Expand All @@ -57,6 +62,8 @@ export const ProjectActions = () => {
const [addSquadDialog, setAddSquadDialog] = useState<boolean>(false)
const [addLabelDialog, setAddLabelDialog] = useState<boolean>(false)
const [addRunDialog, setAddRunDialog] = useState<boolean>(false)
const [addPlatformDialog, setAddPlatformDialog] = useState<boolean>(false)


useEffect(() => {
if (saveChanges.data?.error === null) {
Expand Down Expand Up @@ -110,6 +117,7 @@ export const ProjectActions = () => {
if (action === Actions.AddLabel) setAddLabelDialog(true)
else if (action === Actions.AddSquad) setAddSquadDialog(true)
else if (action === Actions.CreateRun) setAddRunDialog(true)
else if (action === Actions.AddPlatform) setAddPlatformDialog(true)
else if (action === Actions.AddTest)
navigate(`/project/${projectId}/tests/createTest`, {}, e)
}
Expand Down Expand Up @@ -159,6 +167,19 @@ export const ProjectActions = () => {
})
}

const handleSaveChangesPlatforms = (value: string) => {
const platforms = value
.split(',')
.map((val) => val.trim())
.filter((val) => val !== '')
const postData = {platforms, projectId}
saveChanges.submit(postData, {
method: 'POST',
action: `/${API.AddPlatforms}`,
encType: 'application/json',
})
}

return (
<div>
<DropdownMenu open={actionDD} onOpenChange={setActionDD}>
Expand Down Expand Up @@ -199,6 +220,12 @@ export const ProjectActions = () => {
state={addSquadDialog}
setState={setAddSquadDialog}
/>
<AddSquadsLabelsDialog
heading={Actions.AddPlatform}
handleSaveChanges={handleSaveChangesPlatforms}
state={addPlatformDialog}
setState={setAddPlatformDialog}
/>
<AddSquadsLabelsDialog
heading={Actions.CreateRun}
handleSaveChanges={handleSaveChangesRuns}
Expand Down
2 changes: 2 additions & 0 deletions app/services/rbac/rbacPolicyGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ export function generateRbacPolicy(): IRbacPolicy[] {
action = ApiTypes.GET
break


case API.AddLabels:
case API.AddSquads:
case API.AddTestBulk:
case API.AddRun:
case API.AddPlatforms:
case API.AddTest:
case API.AddSection:
role = AccessType.USER
Expand Down