Skip to content

Commit

Permalink
Merge pull request #1294 from brave/master
Browse files Browse the repository at this point in the history
Production Release 2024-08-05
  • Loading branch information
IanKrieger authored Aug 5, 2024
2 parents 5a482ec + 2eb52df commit 065a465
Show file tree
Hide file tree
Showing 26 changed files with 2,716 additions and 2,819 deletions.
56 changes: 17 additions & 39 deletions src/components/Conversion/ConversionDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { Conversion } from "@/user/views/adsManager/types";
import { FormikErrors } from "formik";
import { ReviewField } from "@/user/views/adsManager/views/advanced/components/review/components/ReviewField";
import _ from "lodash";
import { msg } from "@lingui/macro";
import { useLingui } from "@lingui/react";
import { FormikErrors } from "formik";

interface Props {
conversions: Conversion[];
convErrors?: FormikErrors<Conversion>[] | string[] | string;
conversion?: Conversion;
convErrors?: FormikErrors<Conversion>;
}

export function ConversionDisplay({ conversions, convErrors }: Props) {
export function ConversionDisplay({ conversion, convErrors }: Props) {
const { _: lingui } = useLingui();
if (conversions.length === 0) {
if (!conversion) {
return (
<ReviewField
caption={msg`Conversion`}
Expand All @@ -21,39 +20,18 @@ export function ConversionDisplay({ conversions, convErrors }: Props) {
);
}

function extractConversionError(
idx: number,
field: keyof Conversion,
): string | undefined {
const errorObj = convErrors?.[idx];

if (!errorObj) {
return undefined;
}

if (_.isString(errorObj)) {
return errorObj;
}

return errorObj[field];
}

return (
<>
{conversions.map((c, idx) => (
<div key={idx}>
<ReviewField
caption={msg`Conversion URL Pattern`}
value={c.urlPattern}
error={extractConversionError(idx, "urlPattern")}
/>
<ReviewField
caption={msg`Conversion Observation Window`}
value={`${c.observationWindow} days`}
error={extractConversionError(idx, "observationWindow")}
/>
</div>
))}
</>
<div>
<ReviewField
caption={msg`Conversion URL Pattern`}
value={conversion.urlPattern}
error={convErrors?.urlPattern}
/>
<ReviewField
caption={msg`Conversion Observation Window`}
value={`${conversion.observationWindow} days`}
error={convErrors?.observationWindow}
/>
</div>
);
}
10 changes: 8 additions & 2 deletions src/components/Location/LocationPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,26 @@ import { ActiveGeocodesDocument, GeocodeInput } from "@/graphql-client/graphql";
import { useLingui } from "@lingui/react";
import { msg, Trans } from "@lingui/macro";
import { useQuery } from "@apollo/client";
import { useIsEdit } from "@/form/FormikHelpers";

const icon = <CheckBoxOutlineBlankIcon fontSize="small" />;
const checkedIcon = <CheckBoxIcon fontSize="small" />;

export const LocationPicker = () => {
const { data } = useQuery(ActiveGeocodesDocument);
const sorted = _.sortBy(data?.geocodes ?? [], "code");
const { isDraft } = useIsEdit();
const { data } = useQuery(ActiveGeocodesDocument, { skip: !isDraft });
const sorted = _.sortBy(
(data?.geocodes ?? []).filter((c) => c.code !== "OTHER"),
"code",
);
const [formProps, meta, helper] = useField<GeocodeInput[]>("geoTargets");
const errorMessage = meta.error;
const { _: lingui } = useLingui();

return (
<Autocomplete
sx={{ mt: 2 }}
disabled={!isDraft}
limitTags={20}
getLimitTagsText={(count) => <Trans>+{count} more</Trans>}
multiple
Expand Down
21 changes: 8 additions & 13 deletions src/components/Segment/SegmentPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ interface Props {

export const SegmentPicker = ({ idx }: Props) => {
const { data } = useQuery(SegmentsDocument);
const activeSegments = [...(data?.segments?.data ?? [])].sort((a, b) => {
if (a.name === "Untargeted" || b.name === "Untargeted") return 1;
return a.name.toLowerCase().localeCompare(b.name.toLowerCase());
});
const activeSegments = [...(data?.segments?.data ?? [])]
.filter((s) => s.code !== "Svp7l-zGN")
.sort((a, b) => {
return a.name.toLowerCase().localeCompare(b.name.toLowerCase());
});
const { _: lingui } = useLingui();

const [, targetMeta] = useField<boolean>(`adSets.${idx}.isNotTargeting`);
Expand All @@ -34,12 +35,9 @@ export const SegmentPicker = ({ idx }: Props) => {

useEffect(() => {
if (targetMeta.value) {
// eslint-disable-next-line lingui/no-unlocalized-strings
helper.setValue([{ code: "Svp7l-zGN", name: "Untargeted" }]);
helper.setValue([]);
} else {
const onlyUntargeted =
meta.value.length === 1 && meta.value[0].code === "Svp7l-zGN";
helper.setValue(onlyUntargeted ? [] : meta.value);
helper.setValue(meta.value);
}
}, [targetMeta.value]);

Expand All @@ -61,10 +59,7 @@ export const SegmentPicker = ({ idx }: Props) => {
disableCloseOnSelect
autoHighlight
groupBy={(option) => {
const name = option.name.split("-")[0];
// eslint-disable-next-line lingui/no-unlocalized-strings
if (name === "Untargeted") return "General";
return name;
return option.name.split("-")[0];
}}
getOptionLabel={(option) => segmentNameWithNoDash(option.name)}
renderOption={(props, option, { selected }) => (
Expand Down
14 changes: 12 additions & 2 deletions src/graphql-client/gql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 065a465

Please sign in to comment.