Skip to content

[PROD RELEASE] - Reduce complexity #1027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 159 commits into
base: master
Choose a base branch
from
Open

[PROD RELEASE] - Reduce complexity #1027

wants to merge 159 commits into from

Conversation

kkartunov
Copy link
Collaborator

Includes work on:

  • Copilot portal
  • Bugs & Fixes for served apps
  • Review app initial code base
  • Admin app initial code base

vas3a and others added 30 commits January 13, 2025 17:42
PM-505 Fix default values on onboarding form
PM-579 QR feedback on copilot request form
V5 challenge management

const onApplied: () => void = useCallback(() => {
mutate(`${copilotBaseUrl}/copilots/opportunity/${opportunityId}/applications`)
mutate(`${copilotBaseUrl}/copilots/opportunity/${opportunityId}`)

Choose a reason for hiding this comment

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

Consider adding error handling for the mutate function to ensure that any issues during the mutation process are properly managed. This will help in maintaining the robustness of the application.

isCopilot
&& copilotApplications
&& copilotApplications.length === 0
&& opportunity?.status === 'active' ? applyCopilotOpportunityButton : undefined

Choose a reason for hiding this comment

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

Consider using optional chaining (?.) for opportunity?.status to avoid potential runtime errors if opportunity is undefined.

&& copilotApplications.length === 0
&& opportunity?.status === 'active' ? applyCopilotOpportunityButton : undefined
}
infoComponent={(isCopilot && !(copilotApplications

Choose a reason for hiding this comment

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

The condition for infoComponent is complex and could benefit from being extracted into a well-named variable or function to improve readability.

<span
className={styles.appliedText}
>
{`Applied on ${textFormatDateLocaleShortString(new Date(application.createdAt))}`}

Choose a reason for hiding this comment

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

Ensure that textFormatDateLocaleShortString handles invalid dates gracefully, as application.createdAt might not always be a valid date string.


.textCaps {
text-transform: capitalize;
}

Choose a reason for hiding this comment

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

It is recommended to ensure that files end with a newline character to avoid potential issues with some tools and systems that expect a newline at the end of files.

* @param request
* @returns
*/
export const applyCopilotOpportunity = async (opportunityId: number, request?: {

Choose a reason for hiding this comment

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

The request parameter is now optional, but the function implementation does not handle the case where request might be undefined. Consider adding a check to handle this scenario to avoid potential runtime errors.

@@ -54,7 +54,6 @@

.react-responsive-modal-closeButton {
top: $sp-5;
padding: $sp-1;
border-radius: 50%;

Choose a reason for hiding this comment

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

Removing the padding from the .react-responsive-modal-closeButton might affect the button's click area and visual appearance. Consider verifying the impact on usability and design consistency across different screen sizes and devices.

opportunityId: string,
handle?: string,
userId: number,
status: CopilotApplicationStatus,

Choose a reason for hiding this comment

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

Consider adding a default value for the status property to ensure that all instances of CopilotApplication have a defined status. This can help prevent potential issues where the status might be unintentionally left undefined.

import styles from './styles.module.scss'

const CopilotApplicationAction = (copilotApplication: CopilotApplication): JSX.Element => {
const { opportunityId }: {opportunityId?: string} = useParams<{ opportunityId?: string }>()

Choose a reason for hiding this comment

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

Consider adding PropTypes or TypeScript interfaces to ensure that the copilotApplication prop is validated and has the expected shape.

}
}, [opportunityId, copilotApplication])
return (
<div onClick={onClick} className={styles.actionWrapper}>

Choose a reason for hiding this comment

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

Using onClick on a div can be problematic for accessibility. Consider using a button element or adding appropriate ARIA roles and keyboard event handlers to ensure the component is accessible.

},
{
label: 'Actions',
propertyName: '',

Choose a reason for hiding this comment

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

The propertyName is currently an empty string. If this is intentional, consider adding a brief explanation in the documentation or code comments to clarify its purpose. If not, ensure that the correct property name is provided.

* @returns
*/
export const assignCopilotOpportunity = async (
opportunityId: string,

Choose a reason for hiding this comment

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

Consider using consistent parameter types for opportunityId across functions. In applyCopilotOpportunity, opportunityId is a number, while in assignCopilotOpportunity, it is a string. This inconsistency may lead to confusion or errors.


const CopilotApplicationAction = (
copilotApplication: CopilotApplication,
allCopilotApplications: CopilotApplication[],

Choose a reason for hiding this comment

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

Consider renaming allCopilotApplications to copilotApplications for consistency and clarity, as the prefix 'all' might be redundant.

): JSX.Element => {
const { opportunityId }: {opportunityId?: string} = useParams<{ opportunityId?: string }>()
const isInvited = useMemo(
() => allCopilotApplications.findIndex(item => item.status === CopilotApplicationStatus.INVITED) > -1,

Choose a reason for hiding this comment

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

The use of findIndex here is to check for the existence of an invited application. Consider using some instead for better readability: allCopilotApplications.some(item => item.status === CopilotApplicationStatus.INVITED).

}

{
!isInvited && copilotApplication.status === CopilotApplicationStatus.PENDING && (

Choose a reason for hiding this comment

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

Consider adding a check to ensure isInvited is defined and of the expected type before using it in the condition. This can help prevent potential runtime errors if isInvited is undefined or not a boolean.

<TableRow
key={getKey(index)}
data={sorted}
allRows={sortedData}

Choose a reason for hiding this comment

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

Consider renaming allRows to a more descriptive name that indicates its purpose or contents, as sortedData is already used and might cause confusion.

@@ -11,63 +15,97 @@ interface TableCellProps<T> {
readonly data: T
readonly index: number
readonly propertyName?: string
readonly renderer?: (data: T) => JSX.Element | undefined
readonly className?: string
readonly renderer?: (data: T, allRows?: ReadonlyArray<T>) => JSX.Element | undefined

Choose a reason for hiding this comment

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

The renderer function signature has been updated to include an optional allRows parameter. Ensure that all implementations of this function are updated accordingly to handle this new parameter, even if it's not used.

readonly showExpandIndicator?: boolean
readonly isExpanded?: boolean
readonly colSpan?: number
allRows?: ReadonlyArray<T>

Choose a reason for hiding this comment

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

The allRows property has been added to the TableCellProps interface. Verify that this property is correctly passed and utilized in the component logic where necessary.

case 'action':
case 'element':
case 'numberElement':
data = props.renderer?.(props.data, props.allRows)

Choose a reason for hiding this comment

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

The renderer function now takes an additional argument props.allRows. Ensure that all implementations of renderer are updated to handle this new parameter appropriately, and verify that it does not introduce any unintended side effects.

{...col}
data={props.data}
index={props.index}
allRows={props.allRows}

Choose a reason for hiding this comment

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

Consider verifying if allRows is necessary for the component's functionality. If it is not used within the component, it might be better to remove it to reduce complexity.

[allCopilotApplications],
)
const onClick = useCallback(async () => {
if (copilotApplication.status !== CopilotApplicationStatus.PENDING || isInvited) {

Choose a reason for hiding this comment

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

The condition copilotApplication.status !== CopilotApplicationStatus.PENDING || isInvited may cause the function to return early if isInvited is true, regardless of the copilotApplication.status. Ensure this logic aligns with the intended behavior, as it changes the original condition which only checked copilotApplication.status. Consider if additional checks or restructuring are needed to maintain the desired functionality.

)
}
{activeTab === CopilotDetailsTabViews.details && <OpportunityDetails opportunity={opportunity} />}
{activeTab === CopilotDetailsTabViews.applications && isAdminOrPM && opportunity && (

Choose a reason for hiding this comment

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

Consider checking if opportunity is defined earlier in the logic to avoid repeating this check in multiple places. This could help reduce complexity and improve readability.

if (
copilotApplication.status !== CopilotApplicationStatus.PENDING
|| isInvited
|| copilotApplication.opportunityStatus !== 'active'

Choose a reason for hiding this comment

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

Consider using a constant or enum for the string 'active' to avoid magic strings and improve maintainability.

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.

10 participants