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

ref(issue-views): Restructure issue views components #82593

Merged
merged 2 commits into from
Jan 3, 2025

Conversation

MichaelSun48
Copy link
Member

@MichaelSun48 MichaelSun48 commented Dec 27, 2024

This PR reorganizes some of the components and logic in IssueViews components. No visual or functional changes should are intended by these changes. If you see any in the preview, please lmk.

The biggest changes include:

  • Delete draggableTabBar.tsx component, redistribute it's parts to other components (detailed in the diff)
  • Create a new IssueViewTab component that contains the tab contents (title, ellipsis menu, etc.).
  • Rename draggableTabMenuButton.tsx to issueViewEllipsisMenu.tsx
  • Rename draggableTabs to views in customViewsHeader.tsx

Some reasoning:

  • DraggableTabBar sounds very redundant to and less clear than CustomViewsHeader and DraggableTabList. To me, CustomViewsHeader (soon to be renamed IssueViewsHeader) should be a specific implementation of DraggableTabList, which sounds like it should be reusable.
  • I'd like to have parity between product names and codebase names - hence why I'm changing "custom views" to "issue views" and "tabs" to views.

@MichaelSun48 MichaelSun48 requested a review from a team as a code owner December 27, 2024 19:43
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Dec 27, 2024
@MichaelSun48 MichaelSun48 changed the title Make component hierarchy not a complete dumpster fire ref(issue-views): Restructure issue views components Dec 27, 2024
Comment on lines 67 to 124
const handleNewViewsSaved: NewTabContext['onNewViewsSaved'] = useCallback<
NewTabContext['onNewViewsSaved']
>(
() => (newViews: NewView[]) => {
if (newViews.length === 0) {
return;
}
setNewViewActive(false);
const {label, query, saveQueryToView} = newViews[0];
const remainingNewViews: IssueView[] = newViews.slice(1)?.map(view => {
const newId = generateTempViewId();
const viewToTab: IssueView = {
id: newId,
key: newId,
label: view.label,
query: view.query,
querySort: IssueSortOptions.DATE,
unsavedChanges: view.saveQueryToView
? undefined
: [view.query, IssueSortOptions.DATE],
isCommitted: true,
};
return viewToTab;
});
let updatedTabs: IssueView[] = tabs.map(tab => {
if (tab.key === viewId) {
return {
...tab,
label,
query: saveQueryToView ? query : '',
querySort: IssueSortOptions.DATE,
unsavedChanges: saveQueryToView ? undefined : [query, IssueSortOptions.DATE],
isCommitted: true,
};
}
return tab;
});

if (remainingNewViews.length > 0) {
updatedTabs = [...updatedTabs, ...remainingNewViews];
}

dispatch({
type: 'SET_VIEWS',
views: updatedTabs,
syncViews: true,
updateQueryParams: {
newQueryParams: {query, sort: IssueSortOptions.DATE},
replace: true,
},
});
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[location, setNewViewActive, tabs, viewId]
);

useEffect(() => {
setOnNewViewsSaved(handleNewViewsSaved);
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved to IssueViews.tsx (context component)

This logic makes sure that the "save as view" and "save all" buttons on the new view page work properly.

Comment on lines -51 to -67
useHotkeys(
[
{
match: ['command+s', 'ctrl+s'],
includeInputs: true,
callback: () => {
if (tabs.find(tab => tab.key === tabListState?.selectedKey)?.unsavedChanges) {
dispatch({type: 'SAVE_CHANGES', syncViews: true});
addSuccessMessage(t('Changes saved to view'));
}
},
},
],
[dispatch, tabListState?.selectedKey, tabs]
);
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved to customViewsHeader.tsx

This logic controls the ctrl/cmd+s to save behavior

Comment on lines -218 to -279
<TabContentWrap>
<EditableTabTitle
label={tab.label}
isEditing={editingTabKey === tab.key}
setIsEditing={isEditing => setEditingTabKey(isEditing ? tab.key : null)}
onChange={newLabel =>
dispatch({type: 'RENAME_TAB', newLabel: newLabel.trim(), syncViews: true})
}
isSelected={
(tabListState && tabListState?.selectedKey === tab.key) ||
(!tabListState && tab.key === initialTabKey)
}
/>
{/* If tablistState isn't initialized, we want to load the elipsis menu
for the initial tab, that way it won't load in a second later
and cause the tabs to shift and animate on load.
*/}
{((tabListState && tabListState?.selectedKey === tab.key) ||
(!tabListState && tab.key === initialTabKey)) && (
<motion.div
// This stops the ellipsis menu from animating in on load (when tabListState isn't initialized yet),
// but enables the animation later on when switching tabs
initial={tabListState ? {opacity: 0} : false}
animate={{opacity: 1}}
transition={{delay: 0.1, duration: 0.1}}
>
<DraggableTabMenuButton
hasUnsavedChanges={!!tab.unsavedChanges}
menuOptions={makeMenuOptions(tab)}
aria-label={t(`%s Ellipsis Menu`, tab.label)}
/>
</motion.div>
)}
</TabContentWrap>
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved to its own component IssueViewTab.tsx

This contains the tab's content like the editable title and ellipsis menu


const TEMPORARY_TAB_KEY = 'temporary-tab';

export const generateTempViewId = () => `_${Math.random().toString().substring(2, 7)}`;
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved in from draggableTabBar.tsx - this is a general function used by a lot of components. It should live in the context component not some random component in the hierachy

Copy link

codecov bot commented Dec 30, 2024

Bundle Report

Changes will increase total bundle size by 68 bytes (0.0%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
app-webpack-bundle-array-push 32.18MB 68 bytes (0.0%) ⬆️

@MichaelSun48 MichaelSun48 force-pushed the msun/issueViews/reorganizeComponents branch from 90e2196 to 757cfc0 Compare January 3, 2025 15:40
@MichaelSun48 MichaelSun48 merged commit 39a0423 into master Jan 3, 2025
42 checks passed
@MichaelSun48 MichaelSun48 deleted the msun/issueViews/reorganizeComponents branch January 3, 2025 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants