-
Notifications
You must be signed in to change notification settings - Fork 73
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
Basic consent reporting UI #4488
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ff7fd91
scaffold consent reporting UI
jpople fc5c0ab
Merge branch 'main' into jpople/prod-1434/consent-reporting-ui
jpople bf7b732
update to use correct URL for query
jpople a3feb5c
improvements to query, update with final copy, add Cypress tests
jpople 717fa31
fix 'controlled component' error message
jpople 691e76b
update changelog
jpople 51dd7aa
Merge branch 'main' into jpople/prod-1434/consent-reporting-ui
jpople 7b4eeae
fix error handling
jpople 9edc69e
Merge branch 'jpople/prod-1434/consent-reporting-ui' of https://githu…
jpople c16ffd1
Merge branch 'main' into jpople/prod-1434/consent-reporting-ui
jpople File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error results are JSON objects with a |
||
}; | ||
}, | ||
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; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The actual download had to be moved out of the slice file to be able to handle errors.