Skip to content

Commit

Permalink
Pass start and end dates to filter component. Closes #2646.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Apr 10, 2024
1 parent 09a75ec commit 6973b2b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/app/(main)/reports/[reportId]/FilterParameters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export function FilterParameters() {
<FilterSelectForm
websiteId={websiteId}
fields={fields.filter(({ name }) => !filters.find(f => f.name === name))}
startDate={dateRange?.startDate}
endDate={dateRange?.endDate}
onChange={handleAdd}
/>
</PopupForm>
Expand Down
6 changes: 4 additions & 2 deletions src/app/(main)/reports/[reportId]/FilterSelectForm.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import { useState } from 'react';
import FieldSelectForm from './FieldSelectForm';
import FieldFilterEditForm from './FieldFilterEditForm';
import { useDateRange } from 'components/hooks';

export interface FilterSelectFormProps {
websiteId?: string;
fields: any[];
startDate?: Date;
endDate?: Date;
onChange?: (filter: { name: string; type: string; operator: string; value: string }) => void;
allowFilterSelect?: boolean;
}

export default function FilterSelectForm({
websiteId,
fields,
startDate,
endDate,
onChange,
allowFilterSelect,
}: FilterSelectFormProps) {
const [field, setField] = useState<{ name: string; label: string; type: string }>();
const [{ startDate, endDate }] = useDateRange(websiteId);

if (!field) {
return <FieldSelectForm fields={fields} onSelect={setField} showType={false} />;
Expand Down
5 changes: 4 additions & 1 deletion src/app/(main)/websites/[websiteId]/WebsiteFilterButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import classNames from 'classnames';
import { Button, Icon, Icons, Popup, PopupTrigger, Text } from 'react-basics';
import PopupForm from 'app/(main)/reports/[reportId]/PopupForm';
import FilterSelectForm from 'app/(main)/reports/[reportId]/FilterSelectForm';
import { useFields, useMessages, useNavigation } from 'components/hooks';
import { useFields, useMessages, useNavigation, useDateRange } from 'components/hooks';
import { OPERATOR_PREFIXES } from 'lib/constants';
import styles from './WebsiteFilterButton.module.css';

Expand All @@ -16,6 +16,7 @@ export function WebsiteFilterButton({
const { formatMessage, labels } = useMessages();
const { renderUrl, router } = useNavigation();
const { fields } = useFields();
const [{ startDate, endDate }] = useDateRange(websiteId);

const handleAddFilter = ({ name, operator, value }) => {
const prefix = OPERATOR_PREFIXES[operator];
Expand All @@ -38,6 +39,8 @@ export function WebsiteFilterButton({
<FilterSelectForm
websiteId={websiteId}
fields={fields}
startDate={startDate}
endDate={endDate}
onChange={value => {
handleAddFilter(value);
close();
Expand Down

0 comments on commit 6973b2b

Please sign in to comment.