diff --git a/package-lock.json b/package-lock.json index feee5e08..3e6ecce9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6296,9 +6296,9 @@ } }, "node_modules/get-func-name": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", - "integrity": "sha512-Hm0ixYtaSZ/V7C8FJrtZIuBBI+iSgL+1Aq82zSu8VQNB4S3Gk8e7Qs3VwBDJAhmRZcFqkl3tQu36g/Foh5I5ig==", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.2.tgz", + "integrity": "sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ==", "dev": true, "engines": { "node": "*" diff --git a/src/user/library/index.test.ts b/src/user/library/index.test.ts index 368c1874..04f7a1de 100644 --- a/src/user/library/index.test.ts +++ b/src/user/library/index.test.ts @@ -394,6 +394,7 @@ describe("edit form tests", () => { { "advertiserId": "12345", "createdAt": undefined, + "creativeInstanceId": "1", "id": "1234", "included": true, "name": "a creative", @@ -412,6 +413,7 @@ describe("edit form tests", () => { { "advertiserId": "12345", "createdAt": undefined, + "creativeInstanceId": "3", "id": "1235", "included": true, "name": "a different creative", @@ -450,6 +452,7 @@ describe("edit form tests", () => { { "advertiserId": "12345", "createdAt": undefined, + "creativeInstanceId": "1", "id": "1234", "included": true, "name": "a creative", @@ -468,6 +471,7 @@ describe("edit form tests", () => { { "advertiserId": "12345", "createdAt": undefined, + "creativeInstanceId": undefined, "id": "1235", "included": false, "name": "a different creative", @@ -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", @@ -559,10 +566,12 @@ describe("edit form tests", () => { { "creativeId": "1234", "creativeSetId": "22222", + "id": "1", }, ], "billingType": "cpm", "id": "22222", + "name": "22222", "oses": [ { "code": "1234", diff --git a/src/user/library/index.ts b/src/user/library/index.ts index 3e128a7e..df39e374 100644 --- a/src/user/library/index.ts +++ b/src/user/library/index.ts @@ -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, @@ -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 = { notification_all_v1: "Push Notification", @@ -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 ?? @@ -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 { @@ -156,6 +159,7 @@ function creativeList( return { ...validCreativeFields(c, advertiserId, included), createdAt: c.createdAt, + creativeInstanceId: included ? ad.id : undefined, }; }); }; @@ -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, })), diff --git a/src/user/views/adsManager/types/index.ts b/src/user/views/adsManager/types/index.ts index a04d8626..85753b97 100644 --- a/src/user/views/adsManager/types/index.ts +++ b/src/user/views/adsManager/types/index.ts @@ -61,6 +61,7 @@ export type Segment = { }; export type Creative = CreativeInput & { + creativeInstanceId?: string; id?: string; targetUrlValid?: string; state?: string;