Skip to content

Commit

Permalink
Update query names, handle formatting (#110)
Browse files Browse the repository at this point in the history
* update query names

* handle null deliverable types

* make dateFormat function available to detail block

* remove unused function

* remove console log messages
  • Loading branch information
mdickson-adbe authored Jun 5, 2024
1 parent 4764101 commit fcc7312
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
13 changes: 8 additions & 5 deletions blocks/gmo-program-details/gmo-program-details.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { decorateIcons, readBlockConfig } from '../../scripts/lib-franklin.js';
import { getQueryVariable } from '../../scripts/shared.js';
import { executeQuery } from '../../scripts/graphql.js';
import { resolveMappings, filterArray, getProductMapping, checkBlankString } from '../../scripts/shared-program.js';
import { resolveMappings, filterArray, getProductMapping, checkBlankString, dateFormat } from '../../scripts/shared-program.js';
import { getBaseConfigPath } from '../../scripts/site-config.js';
import { searchAsset } from '../../scripts/assets.js';

Expand Down Expand Up @@ -376,7 +376,10 @@ async function buildTable(jsonResponse) {
const deliverableList = jsonResponse.data.deliverableList.items;
const programKpi = jsonResponse.data.programList?.items.primaryKpi;
const rows = document.createElement('div');
const uniqueCategories = getUniqueItems(deliverableList, 'deliverableType');
// we want the 'null' deliverableType to be part of this set for filtering
const uniqueCatSet = new Set();
deliverableList.forEach(object => { uniqueCatSet.add(object['deliverableType']) })
const uniqueCategories = Array.from(uniqueCatSet);
let emptyCategory = false;
uniqueCategories.forEach(async (category) => {
// build header row
Expand Down Expand Up @@ -466,8 +469,8 @@ async function buildTableRow(deliverableJson, kpi, createHidden) {
const status = (deliverableJson.deliverableStatusUpdate == null) ? "Not Available" : deliverableJson.deliverableStatusUpdate + "%";
const statusPct = (deliverableJson.deliverableStatusUpdate == null) ? "0%" : deliverableJson.deliverableStatusUpdate + "%";
dataRow.innerHTML = `
<div class='property table-column column1 deliverable-name'>${deliverableJson.deliverableName}</div>
<div class='property table-column column2 deliverable-type'>${typeLabel}</div>
<div class='property table-column column1 deliverable-name'>${checkBlankString(deliverableJson.deliverableName)}</div>
<div class='property table-column column2 deliverable-type'>${checkBlankString(typeLabel)}</div>
<div class='property table-column column3 platforms'></div>
<div class='property table-column column4 review-link'>
<a href="${deliverableJson.reviewLink}" class="campaign-link" target="_blank">Review Link</a>
Expand All @@ -487,7 +490,7 @@ async function buildTableRow(deliverableJson, kpi, createHidden) {
</div>
</div>
<div class='property table-column column8 date-wrapper'>
<div class='completion-date'>${checkBlankString(deliverableJson.taskCompletionDate)}</div>
<div class='completion-date'>${dateFormat(deliverableJson.taskCompletionDate)}</div>
${deliverableJson.previousTaskCompletionDate ? '<div class="revised-date">Revised from ' + deliverableJson.previousTaskCompletionDate + '</div> ': ""}
</div>
<div class='property table-column column9'>${checkBlankString(deliverableJson.driver)}</div>
Expand Down
7 changes: 1 addition & 6 deletions blocks/gmo-program-list/gmo-program-list.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readBlockConfig } from '../../scripts/lib-franklin.js';
import { decorateIcons } from '../../scripts/lib-franklin.js';
import { graphqlAllCampaignsFilter, graphqlCampaignCount, generateFilterJSON } from '../../scripts/graphql.js';
import { getProductMapping, checkBlankString, statusMapping } from '../../scripts/shared-program.js'
import { getProductMapping, checkBlankString, statusMapping, dateFormat } from '../../scripts/shared-program.js'
import { getBaseConfigPath } from '../../scripts/site-config.js';
import { searchAsset } from '../../scripts/assets.js';

Expand Down Expand Up @@ -485,9 +485,4 @@ function sortColumn(dir, property) {
sortArray.forEach(({ row }, index) => {
container.appendChild(row);
});
}

function dateFormat(dateString) {
const formattedDate = dateString ? dateString.split('T')[0] : 'Not Available';
return formattedDate;
}
4 changes: 2 additions & 2 deletions scripts/graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function graphqlQueryNameList(queryNameList) {
}

export async function graphqlCampaignCount(filter = {}) {
const queryName = 'getCampaignNameFilter';
const queryName = 'getTotalPrograms';
const encodedSemiColon = encodeURIComponent(';');
const encodedFilter = encodeURIComponent(JSON.stringify(filter));
const graphqlEndpoint = `${baseApiUrl}/${projectId}/${queryName}${encodedSemiColon}filter=${encodedFilter}`;
Expand Down Expand Up @@ -103,7 +103,7 @@ export async function graphqlAllCampaignsFilter(first,cursor,filter) {
}

export async function graphqlCampaignByName(campaignName) {
const queryName = 'getCampaignNames';
const queryName = 'getCampaignNamesFilter';
const encodedCampaignName = encodeURIComponent(campaignName);
const encodedSemiColon = encodeURIComponent(';');
//persisted query URLs have to be encoded together with the first semicolon
Expand Down
5 changes: 5 additions & 0 deletions scripts/shared-program.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ export function checkBlankString(string, notAvailableText = 'Not Available') {
return string;
}
}

export function dateFormat(dateString) {
const formattedDate = dateString ? dateString.split('T')[0] : 'Not Available';
return formattedDate;
}

0 comments on commit fcc7312

Please sign in to comment.