Skip to content

Commit

Permalink
fix: archive fix (#1176)
Browse files Browse the repository at this point in the history
* fix: archive fix

* fix: PR requests
  • Loading branch information
kiram15 authored Feb 23, 2024
1 parent e480802 commit c0dd344
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { useContext, useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import { NEW_ARCHIVED_CONTENT_ALERT_DISMISSED_COOKIE_NAME } from './data/constants';
import { EnterpriseAppContext } from '../EnterpriseApp/EnterpriseAppContextProvider';
import { enterpriseCurationActions, isArchivedContent } from '../EnterpriseApp/data/enterpriseCurationReducer';
import { enterpriseCurationActions } from '../EnterpriseApp/data/enterpriseCurationReducer';
import { isArchivedContent } from '../../utils';

const ContentHighlightArchivedAlert = ({ open, onClose }) => {
const [archivedContentLocalStorage, setArchivedContentLocalStorage] = useState({});
Expand Down
14 changes: 13 additions & 1 deletion src/components/ContentHighlights/ContentHighlightSetCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useNavigate } from 'react-router-dom';

import { ROUTE_NAMES } from '../EnterpriseApp/data/constants';
import { useContentHighlightsContext } from './data/hooks';
import { makePlural } from '../../utils';

const ContentHighlightSetCard = ({
imageCapSrc,
Expand All @@ -14,6 +15,7 @@ const ContentHighlightSetCard = ({
isPublished,
enterpriseSlug,
itemCount,
archivedItemCount,
onClick,
}) => {
const navigate = useNavigate();
Expand All @@ -30,6 +32,15 @@ const ContentHighlightSetCard = ({
openStepperModal();
};

const cardItemText = () => {
let returnString = '';
returnString += makePlural(itemCount, 'item');
if (archivedItemCount > 0) {
returnString += ` : ${makePlural(archivedItemCount, 'archived item')}`;
}
return returnString;
};

return (
<Card
isClickable
Expand All @@ -39,7 +50,7 @@ const ContentHighlightSetCard = ({
<Card.ImageCap src={imageCapSrc} srcAlt="" />
<Card.Header title={title} />
<Card.Section>
{itemCount} items
{cardItemText()}
</Card.Section>
</Card>
);
Expand All @@ -51,6 +62,7 @@ ContentHighlightSetCard.propTypes = {
enterpriseSlug: PropTypes.string.isRequired,
isPublished: PropTypes.bool.isRequired,
itemCount: PropTypes.number.isRequired,
archivedItemCount: PropTypes.number.isRequired,
imageCapSrc: PropTypes.string.isRequired,
onClick: PropTypes.func.isRequired,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { connect } from 'react-redux';
import { sendEnterpriseTrackEvent } from '@edx/frontend-enterprise-utils';
import ContentHighlightCardItem from './ContentHighlightCardItem';
import {
COURSE_RUN_STATUSES,
DEFAULT_ERROR_MESSAGE,
HIGHLIGHTS_CARD_GRID_COLUMN_SIZES,
MAX_CONTENT_ITEMS_PER_HIGHLIGHT_SET,
Expand All @@ -17,6 +16,7 @@ import { generateAboutPageUrl } from './data/utils';
import EVENT_NAMES from '../../eventTracking';
import { features } from '../../config';
import DeleteArchivedHighlightsDialogs from './DeleteArchivedHighlightsDialogs';
import { isArchivedContent } from '../../utils';

const ContentHighlightsCardItemsContainer = ({
enterpriseId, enterpriseSlug, isLoading, highlightedContent, updateHighlightSet,
Expand Down Expand Up @@ -44,16 +44,8 @@ const ContentHighlightsCardItemsContainer = ({

if (FEATURE_HIGHLIGHTS_ARCHIVE_MESSAGING) {
for (let i = 0; i < highlightedContent.length; i++) {
const {
courseRunStatuses,
} = highlightedContent[i];
if (courseRunStatuses) {
// a course is only archived if all of its runs are archived
if (courseRunStatuses?.every(status => status === COURSE_RUN_STATUSES.archived)) {
archivedContent.push(highlightedContent[i]);
} else {
activeContent.push(highlightedContent[i]);
}
if (isArchivedContent(highlightedContent[i])) {
archivedContent.push(highlightedContent[i]);
} else {
activeContent.push(highlightedContent[i]);
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/ContentHighlights/HighlightSetSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ const HighlightSetSection = ({
isPublished,
highlightedContentUuids,
cardImageUrl,
archivedContentCount,
}) => (
<ContentHighlightSetCard
key={uuid}
title={title}
highlightSetUUID={uuid}
isPublished={isPublished}
itemCount={highlightedContentUuids.length}
archivedItemCount={archivedContentCount}
imageCapSrc={cardImageUrl}
onClick={() => trackClickEvent({
uuid, title, isPublished, highlightedContentUuids,
Expand Down
20 changes: 2 additions & 18 deletions src/components/EnterpriseApp/data/enterpriseCurationReducer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { logError } from '@edx/frontend-platform/logging';
import { NEW_ARCHIVED_CONTENT_ALERT_DISMISSED_COOKIE_NAME, COURSE_RUN_STATUSES } from '../../ContentHighlights/data/constants';
import { NEW_ARCHIVED_CONTENT_ALERT_DISMISSED_COOKIE_NAME } from '../../ContentHighlights/data/constants';
import { isArchivedContent } from '../../../utils';

export const initialReducerState = {
isLoading: true,
Expand Down Expand Up @@ -71,23 +72,6 @@ function getHighlightSetsFromState(state) {
return state.enterpriseCuration?.highlightSets || [];
}

/**
* Helper function to determine if a content is archived.
*
* @param {Object} content
* @returns {Boolean}
*/
export function isArchivedContent(content) {
const { courseRunStatuses } = content;

if (!courseRunStatuses) {
return false;
}

const ARCHIVABLE_STATUSES = [COURSE_RUN_STATUSES.archived, COURSE_RUN_STATUSES.unpublished];
return courseRunStatuses.every(status => ARCHIVABLE_STATUSES.includes(status));
}

/**
* Helper function to determine if there is a new archived content in a highlight set
*
Expand Down
2 changes: 1 addition & 1 deletion src/components/settings/SettingsLMSTab/ExistingCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const ExistingCard = ({
getStatus,
}) => {
const location = useLocation();
const pathname = location.pathname;
const { pathname } = location;
const redirectPath = pathname.endsWith('/') ? pathname : `${pathname}/`;
const [showDeleteModal, setShowDeleteModal] = useState(false);
const isEdxStaff = getAuthenticatedUser().administrator;
Expand Down
2 changes: 1 addition & 1 deletion src/data/services/EnterpriseDataApiService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
import { snakeCaseObject } from '@edx/frontend-platform/utils';

import store from '../store';
import { configuration, features } from '../../config';
import { configuration } from '../../config';

class EnterpriseDataApiService {
// TODO: This should access the data-api through the gateway instead of direct
Expand Down
34 changes: 34 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import CornerstoneIcon from './icons/CSOD.png';
import DegreedIcon from './icons/Degreed.png';
import MoodleIcon from './icons/Moodle.png';
import SAPIcon from './icons/SAP.svg';
import { COURSE_RUN_STATUSES } from './components/ContentHighlights/data/constants';

import LmsApiService from './data/services/LmsApiService';

Expand Down Expand Up @@ -447,6 +448,37 @@ function getActiveTableColumnFilters(columns) {
})).filter(filter => !!filter.filterValue);
}

/**
* Helper to transform a string into a plural form based on a number.
*
* @returns A string with the number and the plural form of the string.
*/
function makePlural(num, string) {
const stringEndings = ['s', 'x', 'z'];
if (num > 1 || num === 0) {
if (stringEndings.includes(string.charAt(string.length - 1))) {
return `${num} ${string}es`;
}
return `${num} ${string}s`;
}
return `${num} ${string}`;
}

/**
* Helper function to determine if a content is archived.
*
* @param {Object} content (can be program, course, or pathway)
* @returns {Boolean}
*/
function isArchivedContent(content) {
const { courseRunStatuses } = content;
if (!courseRunStatuses) {
return false;
}
const ARCHIVABLE_STATUSES = [COURSE_RUN_STATUSES.archived, COURSE_RUN_STATUSES.unpublished];
return courseRunStatuses.every(status => ARCHIVABLE_STATUSES.includes(status));
}

export {
camelCaseDict,
camelCaseDictArray,
Expand Down Expand Up @@ -484,4 +516,6 @@ export {
isAssignableSubsidyAccessPolicyType,
getActiveTableColumnFilters,
queryCacheOnErrorHandler,
makePlural,
isArchivedContent,
};

0 comments on commit c0dd344

Please sign in to comment.