Skip to content

Conversation

adityathebe
Copy link
Member

resolves: #2641

image

Copy link

netlify bot commented Oct 6, 2025

Deploy Preview for flanksource-demo-stable ready!

Name Link
🔨 Latest commit b5ff926
🔍 Latest deploy log https://app.netlify.com/projects/flanksource-demo-stable/deploys/68e3bcaa56799a000869e34f
😎 Deploy Preview https://deploy-preview-2642--flanksource-demo-stable.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

netlify bot commented Oct 6, 2025

Deploy Preview for clerk-saas-ui ready!

Name Link
🔨 Latest commit b5ff926
🔍 Latest deploy log https://app.netlify.com/projects/clerk-saas-ui/deploys/68e3bcaa4c4cb600089fcd11
😎 Deploy Preview https://deploy-preview-2642--clerk-saas-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

vercel bot commented Oct 6, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
aws-preview Ready Ready Preview Oct 6, 2025 1:03pm
flanksource-ui Ready Ready Preview Oct 6, 2025 1:03pm

@adityathebe adityathebe requested a review from moshloop October 6, 2025 09:11
Copy link

netlify bot commented Oct 6, 2025

Deploy Preview for goofy-euclid-75956c ready!

Name Link
🔨 Latest commit b5ff926
🔍 Latest deploy log https://app.netlify.com/projects/goofy-euclid-75956c/deploys/68e3bcaaefb01200082789bc
😎 Deploy Preview https://deploy-preview-2642--goofy-euclid-75956c.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds email display in the people picker to distinguish duplicate names and enhances permission editing by fetching full permission details. Also restructures permission resource/object fields and updates default subject selection logic.

  • Show email alongside person name in dropdown options.
  • Fetch full permission data on edit and refactor resource/object field names (e.g. config_object, playbook_object).
  • Adjust subject type initialization and resource selection UI logic.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/components/Permissions/PermissionsTable.tsx Switch to new *_object fields and add contextual labels for displayed related objects.
src/components/Permissions/ManagePermissions/Forms/PermissionSubjectControls.tsx Change default subject to Person and add effect to initialize subject_type.
src/components/Permissions/ManagePermissions/Forms/PermissionForm.tsx Add fetch-on-edit logic, spinner state, and refactor to use permissionData abstraction.
src/components/Permissions/ManagePermissions/Forms/FormikPermissionSelectResourceFields.tsx Add dynamic initial tab selection based on existing form values.
src/components/Forms/Formik/FormikPeopleDropdown.tsx Display person email beside name in dropdown.
src/api/types/permissions.ts Strongly type object field and introduce explicit *_object fields and selector typing.
src/api/services/permissions.ts Add fetchPermissionById helper.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

export async function fetchPermissionById(id: string) {
const response = await IncidentCommander.get<PermissionTable[]>(
`/permissions?id=eq.${id}`
);
Copy link
Preview

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the API returns an empty array or an error scenario masked as a 200 with no rows, this returns undefined silently, causing the edit flow to proceed as if creating a new permission. Consider validating the response and throwing (or returning a rejected promise) when no record is found: e.g. if (!response.data.length) throw new Error('Permission not found'); so the UI can show an error state instead of falling back to 'Add'.

Suggested change
);
);
if (!response.data || response.data.length === 0) {
throw new Error('Permission not found');
}

Copilot uses AI. Check for mistakes.

);

// Use fetched data if editing, otherwise use provided data
const permissionData = permissionId ? fetchedPermission : data;
Copy link
Preview

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the fetch completes with an error or returns no record, fetchedPermission will be undefined and permissionData becomes undefined, causing the form to treat an edit as a creation (title, submit path) and potentially insert a duplicate. Use the stable permissionId or original data as a fallback (e.g. const permissionData = permissionId ? fetchedPermission ?? data : data) and gate add vs update logic on permissionId, not permissionData?.id.

Suggested change
const permissionData = permissionId ? fetchedPermission : data;
const permissionData = permissionId ? (fetchedPermission ?? data) : data;

Copilot uses AI. Check for mistakes.

Comment on lines +264 to 267
if (!permissionData?.id) {
return add({
...v
} as PermissionTable);
Copy link
Preview

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relying on permissionData?.id to choose add vs update can misclassify an edit when permissionData failed to load; this will attempt an add instead of update. Use the original permissionId prop (or a separate flag like !!permissionId) to decide the branch, ensuring failed fetches do not create duplicates.

Copilot uses AI. Check for mistakes.

@adityathebe adityathebe merged commit ef6f249 into main Oct 6, 2025
16 of 18 checks passed
@adityathebe adityathebe deleted the fix/person-dropdown-email-display branch October 6, 2025 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Person Selector must distinguish people with the same name
1 participant