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: include id if available #907

Merged
merged 4 commits into from
Sep 28, 2023
Merged
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
6 changes: 3 additions & 3 deletions package-lock.json

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

9 changes: 9 additions & 0 deletions src/user/library/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ describe("edit form tests", () => {
{
"advertiserId": "12345",
"createdAt": undefined,
"creativeInstanceId": "1",
"id": "1234",
"included": true,
"name": "a creative",
Expand All @@ -412,6 +413,7 @@ describe("edit form tests", () => {
{
"advertiserId": "12345",
"createdAt": undefined,
"creativeInstanceId": "3",
"id": "1235",
"included": true,
"name": "a different creative",
Expand Down Expand Up @@ -450,6 +452,7 @@ describe("edit form tests", () => {
{
"advertiserId": "12345",
"createdAt": undefined,
"creativeInstanceId": "1",
"id": "1234",
"included": true,
"name": "a creative",
Expand All @@ -468,6 +471,7 @@ describe("edit form tests", () => {
{
"advertiserId": "12345",
"createdAt": undefined,
"creativeInstanceId": undefined,
"id": "1235",
"included": false,
"name": "a different creative",
Expand Down Expand Up @@ -532,14 +536,17 @@ describe("edit form tests", () => {
{
"creativeId": "1234",
"creativeSetId": "11111",
"id": "1",
},
{
"creativeId": "1235",
"creativeSetId": "11111",
"id": "3",
},
],
"billingType": "cpm",
"id": "11111",
"name": "11111",
"oses": [
{
"code": "1234",
Expand All @@ -559,10 +566,12 @@ describe("edit form tests", () => {
{
"creativeId": "1234",
"creativeSetId": "22222",
"id": "1",
},
],
"billingType": "cpm",
"id": "22222",
"name": "22222",
"oses": [
{
"code": "1234",
Expand Down
10 changes: 8 additions & 2 deletions src/user/library/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
UpdateCampaignInput,
} from "graphql/types";
import { CampaignFragment } from "graphql/campaign.generated";
import { AdFragment } from "graphql/ad-set.generated";
import { AdFragment, AdSetFragment } from "graphql/ad-set.generated";
import {
AdSetForm,
Billing,
Expand All @@ -18,6 +18,7 @@ import {
import _ from "lodash";
import BigNumber from "bignumber.js";
import { CreativeFragment } from "graphql/creative.generated";
import moment from "moment";

const TYPE_CODE_LOOKUP: Record<string, string> = {
notification_all_v1: "Push Notification",
Expand Down Expand Up @@ -90,6 +91,8 @@ export function editCampaignValues(
campaign: CampaignFragment,
advertiserId: string,
): CampaignForm {
const sort = (a: AdSetFragment, b: AdSetFragment) =>
moment(a.createdAt).valueOf() - moment(b.createdAt).valueOf();
const ads: AdFragment[] = _.flatMap(campaign.adSets, "ads");

const billingType = (_.head(campaign.adSets)?.billingType ??
Expand All @@ -99,7 +102,7 @@ export function editCampaignValues(

return {
id: campaign.id,
adSets: campaign.adSets.map((adSet) => {
adSets: [...campaign.adSets].sort(sort).map((adSet) => {
const seg = adSet.segments ?? ([] as Segment[]);

return {
Expand Down Expand Up @@ -156,6 +159,7 @@ function creativeList(
return {
...validCreativeFields(c, advertiserId, included),
createdAt: c.createdAt,
creativeInstanceId: included ? ad.id : undefined,
};
});
};
Expand Down Expand Up @@ -217,11 +221,13 @@ export function transformEditForm(
id: adSet.id,
billingType: form.billingType,
price: transformPrice(form),
name: adSet.name,
segments: adSet.segments.map((v) => ({ code: v.code, name: v.name })),
oses: adSet.oses.map((v) => ({ code: v.code, name: v.name })),
ads: adSet.creatives
.filter((c) => c.included)
.map((ad) => ({
id: ad.creativeInstanceId,
creativeId: ad.id,
creativeSetId: adSet.id,
})),
Expand Down
1 change: 1 addition & 0 deletions src/user/views/adsManager/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export type Segment = {
};

export type Creative = CreativeInput & {
creativeInstanceId?: string;
id?: string;
targetUrlValid?: string;
state?: string;
Expand Down