-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
266 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { stubPlus } from "cypress/support/stubs"; | ||
|
||
import { CONSENT_REPORTING_ROUTE } from "~/features/common/nav/v2/routes"; | ||
|
||
describe("Consent reporting", () => { | ||
beforeEach(() => { | ||
cy.login(); | ||
}); | ||
|
||
describe("access", () => { | ||
it("can access the consent reporting page", () => { | ||
stubPlus(true, { | ||
core_fides_version: "1.9.6", | ||
fidesplus_server: "healthy", | ||
fidesplus_version: "1.9.6", | ||
system_scanner: { | ||
enabled: false, | ||
cluster_health: null, | ||
cluster_error: null, | ||
}, | ||
dictionary: { | ||
enabled: false, | ||
service_health: null, | ||
service_error: null, | ||
}, | ||
tcf: { | ||
enabled: false, | ||
}, | ||
fides_cloud: { | ||
enabled: false, | ||
}, | ||
}); | ||
cy.visit(CONSENT_REPORTING_ROUTE); | ||
cy.getByTestId("consent-reporting"); | ||
}); | ||
it("can't access without plus", () => { | ||
stubPlus(false); | ||
cy.visit(CONSENT_REPORTING_ROUTE); | ||
cy.getByTestId("home-content"); | ||
}); | ||
}); | ||
|
||
describe("downloading reports", () => { | ||
beforeEach(() => { | ||
stubPlus(true, { | ||
core_fides_version: "1.9.6", | ||
fidesplus_server: "healthy", | ||
fidesplus_version: "1.9.6", | ||
system_scanner: { | ||
enabled: false, | ||
cluster_health: null, | ||
cluster_error: null, | ||
}, | ||
dictionary: { | ||
enabled: false, | ||
service_health: null, | ||
service_error: null, | ||
}, | ||
tcf: { | ||
enabled: false, | ||
}, | ||
fides_cloud: { | ||
enabled: false, | ||
}, | ||
}); | ||
cy.visit(CONSENT_REPORTING_ROUTE); | ||
}); | ||
it("can request a report", () => { | ||
cy.intercept({ | ||
url: "/api/v1/plus/consent_reporting*", | ||
method: "GET", | ||
}).as("getConsentReport"); | ||
cy.getByTestId("input-from-date").type("2023-11-01"); | ||
cy.getByTestId("input-to-date").type("2023-11-07"); | ||
cy.getByTestId("download-btn").click(); | ||
cy.wait("@getConsentReport"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
clients/admin-ui/src/features/consent-reporting/ConsentReporting.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { | ||
Button, | ||
HStack, | ||
Input, | ||
InputGroup, | ||
InputLeftAddon, | ||
useToast, | ||
} from "@fidesui/react"; | ||
import { useState } from "react"; | ||
|
||
import { getErrorMessage } from "~/features/common/helpers"; | ||
import { useLazyDownloadReportQuery } from "~/features/consent-reporting/consent-reporting.slice"; | ||
|
||
const ConsentReporting = () => { | ||
const [startDate, setStartDate] = useState<string>(""); | ||
const [endDate, setEndDate] = useState<string>(""); | ||
|
||
const toast = useToast(); | ||
|
||
const [downloadReportTrigger, { isLoading }] = useLazyDownloadReportQuery(); | ||
|
||
const handleDownloadClicked = async () => { | ||
const result = await downloadReportTrigger({ startDate, endDate }); | ||
if (result.isError) { | ||
const message = getErrorMessage( | ||
result.error, | ||
"A problem occurred while generating your consent report. Please try again." | ||
); | ||
toast({ status: "error", description: message }); | ||
} else { | ||
const a = document.createElement("a"); | ||
const csvBlob = new Blob([result.data], { type: "text/csv" }); | ||
a.href = window.URL.createObjectURL(csvBlob); | ||
a.download = `consent-reports.csv`; | ||
a.click(); | ||
} | ||
}; | ||
|
||
return ( | ||
<HStack gap={4} maxWidth="720px" data-testid="consent-reporting"> | ||
<InputGroup size="sm" flex={1}> | ||
<InputLeftAddon borderRadius="md">From</InputLeftAddon> | ||
<Input | ||
type="date" | ||
name="From" | ||
value={startDate} | ||
max={endDate || undefined} | ||
onChange={(e) => setStartDate(e.target.value)} | ||
borderRadius="md" | ||
data-testid="input-from-date" | ||
/> | ||
</InputGroup> | ||
<InputGroup size="sm" flex={1}> | ||
<InputLeftAddon borderRadius="md">To</InputLeftAddon> | ||
<Input | ||
type="date" | ||
name="To" | ||
value={endDate} | ||
min={startDate || undefined} | ||
onChange={(e) => setEndDate(e.target.value)} | ||
borderRadius="md" | ||
data-testid="input-to-date" | ||
/> | ||
</InputGroup> | ||
<Button | ||
onClick={handleDownloadClicked} | ||
isLoading={isLoading} | ||
colorScheme="primary" | ||
size="sm" | ||
data-testid="download-btn" | ||
> | ||
Download report | ||
</Button> | ||
</HStack> | ||
); | ||
}; | ||
|
||
export default ConsentReporting; |
49 changes: 49 additions & 0 deletions
49
clients/admin-ui/src/features/consent-reporting/consent-reporting.slice.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { baseApi } from "~/features/common/api.slice"; | ||
|
||
type DateRange = { | ||
startDate?: string; | ||
endDate?: string; | ||
}; | ||
|
||
export function convertDateRangeToSearchParams({ | ||
startDate, | ||
endDate, | ||
}: DateRange) { | ||
let startDateISO; | ||
if (startDate) { | ||
startDateISO = new Date(startDate); | ||
startDateISO.setUTCHours(0, 0, 0); | ||
} | ||
|
||
let endDateISO; | ||
if (endDate) { | ||
endDateISO = new Date(endDate); | ||
endDateISO.setUTCHours(0, 0, 0); | ||
} | ||
|
||
return { | ||
...(startDateISO ? { created_gt: startDateISO.toISOString() } : {}), | ||
...(endDateISO ? { created_lt: endDateISO.toISOString() } : {}), | ||
}; | ||
} | ||
|
||
export const consentReportingApi = baseApi.injectEndpoints({ | ||
endpoints: (build) => ({ | ||
downloadReport: build.query<any, DateRange>({ | ||
query: ({ startDate, endDate }) => { | ||
const params = { | ||
...convertDateRangeToSearchParams({ startDate, endDate }), | ||
download_csv: "true", | ||
}; | ||
return { | ||
url: "plus/consent_reporting", | ||
params, | ||
responseHandler: "content-type", | ||
}; | ||
}, | ||
providesTags: ["Consent Reporting"], | ||
}), | ||
}), | ||
}); | ||
|
||
export const { useLazyDownloadReportQuery } = consentReportingApi; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Box, Breadcrumb, BreadcrumbItem, Heading, Text } from "@fidesui/react"; | ||
import NextLink from "next/link"; | ||
import React from "react"; | ||
|
||
import Layout from "~/features/common/Layout"; | ||
import { CONSENT_REPORTING_ROUTE } from "~/features/common/nav/v2/routes"; | ||
import ConsentReporting from "~/features/consent-reporting/ConsentReporting"; | ||
|
||
const ConsentReportingPage = () => ( | ||
<Layout title="Configure consent"> | ||
<Box mb={4}> | ||
<Heading fontSize="2xl" fontWeight="semibold" mb={2} data-testid="header"> | ||
Configure consent | ||
</Heading> | ||
<Box> | ||
<Breadcrumb | ||
fontWeight="medium" | ||
fontSize="sm" | ||
color="gray.600" | ||
data-testid="breadcrumbs" | ||
> | ||
<BreadcrumbItem> | ||
<NextLink href={CONSENT_REPORTING_ROUTE}>Consent</NextLink> | ||
</BreadcrumbItem> | ||
<BreadcrumbItem color="complimentary.500"> | ||
<NextLink href="#">Reporting</NextLink> | ||
</BreadcrumbItem> | ||
</Breadcrumb> | ||
</Box> | ||
</Box> | ||
<Text fontSize="sm" mb={8} width={{ base: "100%", lg: "50%" }}> | ||
Download a CSV containing a report of consent preferences made by users on | ||
your sites. Select a date range below and click "Download | ||
report". Depending on the number of records in the date range you | ||
select, it may take several minutes to prepare the file after you click | ||
"Download report". | ||
</Text> | ||
<Box data-testid="consent"> | ||
<ConsentReporting /> | ||
</Box> | ||
</Layout> | ||
); | ||
|
||
export default ConsentReportingPage; |