Skip to content
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

Refactoring show page #7838

Merged
merged 5 commits into from
Oct 18, 2024
Merged

Refactoring show page #7838

merged 5 commits into from
Oct 18, 2024

Conversation

FelixMalfait
Copy link
Member

@FelixMalfait FelixMalfait commented Oct 18, 2024

@ehconitin following your question I did a quick refactoring of the show page - we can push it much further but it would be better to start from this code than from main

Edit: I will merge to avoid conflicts, this is very far from perfect but still much better than the mess we had before

@FelixMalfait FelixMalfait marked this pull request as ready for review October 18, 2024 22:29
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This pull request refactors the show page components, focusing on improving code organization and readability. The changes introduce new components and hooks for better data management and action handling.

  • Introduced new FieldsCard and SummaryCard components for improved modularity in the show page
  • Created custom hooks useRecordShowContainerActions, useRecordShowContainerData, and useRecordShowContainerTabs for centralized data fetching and state management
  • Refactored ShowPageRightContainer into ShowPageSubContainer for enhanced flexibility and structure
  • Updated TimelineCreateButtonGroup to use the new TAB_LIST_COMPONENT_ID from ShowPageSubContainer
  • Exported SingleTabProps type from TabList component for broader use in the application

9 file(s) reviewed, 27 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +70 to +76
const inlineRelationFieldMetadataItems = relationFieldMetadataItems?.filter(
(fieldMetadataItem) =>
(objectNameSingular === CoreObjectNameSingular.Note &&
fieldMetadataItem.name === 'noteTargets') ||
(objectNameSingular === CoreObjectNameSingular.Task &&
fieldMetadataItem.name === 'taskTargets'),
);
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider extracting this filter logic into a separate function for better readability and reusability

Comment on lines +118 to +122
activityObjectNameSingular={
objectNameSingular as
| CoreObjectNameSingular.Note
| CoreObjectNameSingular.Task
}
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Type assertion may not be safe. Consider using a type guard or refactoring to avoid the need for assertion

| CoreObjectNameSingular.Note
| CoreObjectNameSingular.Task
}
activity={recordFromStore as Task | Note}
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Type assertion here might be unsafe. Consider adding a type guard or refactoring to ensure type safety

Comment on lines +34 to 38
const tabs = useRecordShowContainerTabs(
loading,
objectNameSingular as CoreObjectNameSingular,
isInRightDrawer,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Casting objectNameSingular to CoreObjectNameSingular may cause runtime errors if the value doesn't match the enum

</ShowPageLeftContainer>
<ShowPageRightContainer
<ShowPageSubContainer
tabs={tabs}
targetableObject={{
id: objectRecordId,
targetObjectNameSingular: objectMetadataItem?.nameSingular,
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Optional chaining on objectMetadataItem may lead to undefined value for targetObjectNameSingular

Comment on lines +34 to +35
const shouldDisplayCalendarTab = isCompanyOrPerson;
const shouldDisplayEmailsTab = isCompanyOrPerson;
Copy link
Contributor

Choose a reason for hiding this comment

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

style: These variables have the same value. Consider combining them into a single variable

const shouldDisplayCalendarTab = isCompanyOrPerson;
const shouldDisplayEmailsTab = isCompanyOrPerson;

return [
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider extracting this array into a separate constant or function to improve readability

Comment on lines +63 to +67
hide:
targetObjectNameSingular === CoreObjectNameSingular.Note ||
targetObjectNameSingular === CoreObjectNameSingular.Task ||
isWorkflow ||
isWorkflowVersion,
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Tasks and Notes tabs have identical hide conditions. Consider refactoring to reduce duplication

Comment on lines +84 to 93
type ShowPageSubContainerProps = {
tabs: SingleTabProps[];
targetableObject: Pick<
ActivityTargetableObject,
'targetObjectNameSingular' | 'id'
>;
timeline?: boolean;
tasks?: boolean;
notes?: boolean;
emails?: boolean;
fieldsBox?: JSX.Element;
summaryCard?: JSX.Element;
isInRightDrawer?: boolean;
loading: boolean;
isNewRightDrawerItemLoading?: boolean;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

style: consider adding JSDoc comments to describe the purpose of this component and its props

objectRecordId={targetableObject.id}
/>
);

const renderActiveTabContent = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

style: renderActiveTabContent function is quite long and complex, consider extracting some logic into separate functions for better maintainability

@FelixMalfait FelixMalfait merged commit c285f0a into main Oct 18, 2024
13 checks passed
@FelixMalfait FelixMalfait deleted the refacto-show-page branch October 18, 2024 22:39
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.

1 participant