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

fix: keep change request type in table #8849

Merged
merged 1 commit into from
Nov 25, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface IChangeRequestTableProps {

const defaultSort: SortingRule<string> & {
columns?: string[];
type?: 'open' | 'closed';
} = { id: 'createdAt', desc: true };

const StyledTabContainer = styled('div')({
Expand Down Expand Up @@ -76,6 +77,12 @@ export const ChangeRequestsTabs = ({
const { value: storedParams, setValue: setStoredParams } =
createLocalStorage(`${projectId}:ProjectChangeRequest`, defaultSort);

const initialChangeRequestType =
searchParams.get('type') || storedParams.type;
const [changeRequestType, setChangeRequestType] = useState<
'open' | 'closed'
>(initialChangeRequestType === 'closed' ? 'closed' : 'open');

const [openChangeRequests, closedChangeRequests] = useMemo(() => {
const open = changeRequests.filter(
(changeRequest) =>
Expand All @@ -97,14 +104,16 @@ export const ChangeRequestsTabs = ({
{
title: 'Change requests',
data: openChangeRequests,
type: 'open' as const,
},
{
title: 'Closed',
data: closedChangeRequests,
type: 'closed' as const,
},
];

const [activeTab, setActiveTab] = useState(0);
const activeTab =
tabs.find((tab) => tab.type === changeRequestType) || tabs[0];

const columns = useMemo(
() => [
Expand Down Expand Up @@ -193,7 +202,7 @@ export const ChangeRequestsTabs = ({
data: searchedData,
getSearchText,
getSearchContext,
} = useSearch(columns, searchValue, tabs[activeTab]?.data);
} = useSearch(columns, searchValue, activeTab?.data);

const data = useMemo(
() => (loading ? featuresPlaceholder : searchedData),
Expand Down Expand Up @@ -259,6 +268,7 @@ export const ChangeRequestsTabs = ({
if (searchValue) {
tableState.search = searchValue;
}
tableState.type = changeRequestType;

setSearchParams(tableState, {
replace: true,
Expand All @@ -267,9 +277,10 @@ export const ChangeRequestsTabs = ({
...params,
id: sortBy[0].id,
desc: sortBy[0].desc || false,
type: changeRequestType,
}));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [loading, sortBy, searchValue, setSearchParams]);
}, [loading, sortBy, searchValue, setSearchParams, changeRequestType]);

return (
<PageContent
Expand All @@ -281,18 +292,20 @@ export const ChangeRequestsTabs = ({
titleElement={
<StyledTabContainer>
<Tabs
value={tabs[activeTab]?.title}
value={activeTab?.title}
indicatorColor='primary'
textColor='primary'
variant='scrollable'
allowScrollButtonsMobile
>
{tabs.map((tab, index) => (
{tabs.map((tab) => (
<StyledTabButton
key={tab.title}
label={`${tab.title} (${tab.data.length})`}
value={tab.title}
onClick={() => setActiveTab(index)}
onClick={() =>
setChangeRequestType(tab.type)
}
/>
))}
</Tabs>
Expand Down
Loading