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 panel "Add filter" bug #1610

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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 @@ -8,6 +8,7 @@ import {
useGridApiRef,
} from '@mui/x-data-grid-pro';
import { entries } from '@seedcompany/common';
import { merge } from 'lodash';
import { useMemo } from 'react';
import { extendSx } from '~/common';
import {
Expand All @@ -29,6 +30,7 @@ import {
ProgressReportsColumnMap,
ProgressReportsGrid,
ProgressReportsGridProps,
useProgressReportsDataGrid,
} from './ProgressReportsGrid';

const COLLAPSED_ROW_HEIGHT = 54;
Expand Down Expand Up @@ -116,18 +118,24 @@ export const ProgressReportsExpandedGrid = (
props: Omit<ProgressReportsGridProps, 'columns'>
) => {
const apiRef = useGridApiRef();

const { expanded, onMouseDown, onRowClick } = useExpandedSetup();

const slotProps = useMemo(
(): DataGridProps['slotProps'] => ({
row: {
onMouseDown,
},
}),
const dataGridProps = useProgressReportsDataGrid({
...props,
apiRef,
columns,
});

const mouseSlotProps = useMemo(
(): DataGridProps['slotProps'] => ({ row: { onMouseDown } }),
[onMouseDown]
);

const slotProps = useMemo(
() => merge({}, dataGridProps.slotProps, mouseSlotProps),
[dataGridProps.slotProps, mouseSlotProps]
);

return (
<ExpansionContext.Provider value={expanded}>
<ProgressReportsGrid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,40 @@ export type ProgressReportColumnMapShape = Record<

export const ExpansionMarker = 'expandable';

export const useProgressReportsDataGrid = ({
quarter,
...props
}: ProgressReportsGridProps) => {
const source = useMemo(() => {
return {
query: ProgressReportsDocument,
variables: {
input: {
filter: {
start: {
afterInclusive: quarter.startOf('quarter'),
},
end: {
beforeInclusive: quarter.endOf('quarter'),
},
},
},
},
listAt: 'progressReports',
initialInput: {
sort: 'status',
order: 'DESC',
},
} as const;
}, [quarter]);
const [dataGridProps] = useDataGridSource({
...source,
apiRef: props.apiRef,
});

return dataGridProps;
};

export const ProgressReportsColumnMap = {
project: {
headerName: 'Project',
Expand Down Expand Up @@ -179,32 +213,7 @@ export const ProgressReportsGrid = ({
quarter,
...props
}: ProgressReportsGridProps) => {
const source = useMemo(() => {
return {
query: ProgressReportsDocument,
variables: {
input: {
filter: {
start: {
afterInclusive: quarter.startOf('quarter'),
},
end: {
beforeInclusive: quarter.endOf('quarter'),
},
},
},
},
listAt: 'progressReports',
initialInput: {
sort: 'status',
order: 'DESC',
},
} as const;
}, [quarter]);
const [dataGridProps] = useDataGridSource({
...source,
apiRef: props.apiRef,
});
const dataGridProps = useProgressReportsDataGrid({ quarter, ...props });

const slots = useMemo(
() =>
Expand Down
Loading