Skip to content

Commit 2265bd4

Browse files
committed
handle bundle release availabililty resolution
1 parent b3d833a commit 2265bd4

File tree

3 files changed

+103
-9
lines changed

3 files changed

+103
-9
lines changed

lib/components/Citation/DataProductCitation/Service.js

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,24 @@ var useViewState = function useViewState(state, props) {
342342

343343
if (hasLatestRelease && (0, _typeUtil.exists)(baseProduct)) {
344344
hasLatestReleaseBundle = _BundleService.default.isProductInBundle(bundlesContext, latestReleaseObject.release, baseProduct.productCode);
345+
} // Determine if the bundle product has data for the specified release.
346+
347+
348+
var isBundleProductInRelease = true;
349+
350+
if (hasBundleProduct && hasSpecifiedRelease && !isAppliedReleaseLatestNonProv) {
351+
var _bundleProduct;
352+
353+
var bundleHasRelease = (_bundleProduct = bundleProduct) === null || _bundleProduct === void 0 ? void 0 : _bundleProduct.releases.find(function (r) {
354+
return r.release === appliedRenderedReleaseTag;
355+
});
356+
isBundleProductInRelease = (0, _typeUtil.exists)(bundleHasRelease);
345357
} // Determine if the citable product should be the bundle container product
346358
// or the currently specified product.
359+
// eslint-disable-next-line max-len
347360

348361

349-
var citableBaseProduct = hasBundleProduct ? bundleProduct : baseProduct; // Determine the product to use for citing within the applicable release
362+
var citableBaseProduct = hasBundleProduct && isBundleProductInRelease ? bundleProduct : baseProduct; // Determine the product to use for citing within the applicable release
350363
// and within the context of bundles.
351364

352365
var citableReleaseProduct = null;
@@ -357,6 +370,7 @@ var useViewState = function useViewState(state, props) {
357370
if (!hasSpecifiedRelease && !hasLatestReleaseBundle) {
358371
citableReleaseProduct = baseProduct;
359372
} else {
373+
// Has a specified release, or if not, has latest release bundle.
360374
// When a bundled product code is available for the given release,
361375
// get the product for the parent code and release.
362376
// Otherwise, the citable product is the current product for the specified
@@ -383,7 +397,22 @@ var useViewState = function useViewState(state, props) {
383397
} // Determine if there's a valid product to generate the citation with.
384398

385399

386-
var hasValidProduct = (0, _typeUtil.exists)(citableBaseProduct); // Determine the overall citation display status.
400+
var hasValidProduct = (0, _typeUtil.exists)(citableBaseProduct);
401+
var hasValidReleaseProduct = (0, _typeUtil.exists)(citableReleaseProduct); // Verify identified release product is in the applied release.
402+
403+
var isCitableReleaseProductInRelease = false; // If looking at latest release non provisional, consider in release.
404+
405+
if (isAppliedReleaseLatestNonProv) {
406+
isCitableReleaseProductInRelease = true;
407+
} else if (hasValidReleaseProduct) {
408+
var _citableReleaseProduc;
409+
410+
var productHasRelease = (_citableReleaseProduc = citableReleaseProduct) === null || _citableReleaseProduc === void 0 ? void 0 : _citableReleaseProduc.releases.find(function (r) {
411+
return r.release === appliedRenderedReleaseTag;
412+
});
413+
isCitableReleaseProductInRelease = (0, _typeUtil.exists)(productHasRelease);
414+
} // Determine the overall citation display status.
415+
387416

388417
var appliedStatus = status;
389418
var displayType = _ViewState.DisplayType.CONDITIONAL;
@@ -402,8 +431,15 @@ var useViewState = function useViewState(state, props) {
402431
// not show a release citation, show not available display state.
403432
displayType = _ViewState.DisplayType.NOT_AVAILABLE;
404433
} else if (hasAppliedReleaseDoi) {
405-
if ((0, _typeUtil.exists)(citableReleaseProduct)) {
406-
displayType = _ViewState.DisplayType.RELEASE;
434+
if (hasValidReleaseProduct) {
435+
// If the identified release product doesn't have data in the
436+
// release and we're viewing a specific release, report
437+
// as not available for that release.
438+
if (!isCitableReleaseProductInRelease) {
439+
displayType = _ViewState.DisplayType.NOT_AVAILABLE;
440+
} else {
441+
displayType = _ViewState.DisplayType.RELEASE;
442+
}
407443
} else {
408444
// If the component is ready and a release was specified but
409445
// failed to resolve the appropriate citable release product,
@@ -418,14 +454,18 @@ var useViewState = function useViewState(state, props) {
418454
// a special case, render as not available.
419455
displayType = _ViewState.DisplayType.NOT_AVAILABLE;
420456
}
457+
} else if (!isCitableReleaseProductInRelease) {
458+
// If the detected citable release product is not in the applied
459+
// release, then consider the display as provisional.
460+
displayType = _ViewState.DisplayType.PROVISIONAL;
421461
} else if (!hasLatestRelease || hideLatestReleaseCitation || disableConditional) {
422462
// If display is determined to be conditional, but we haven't identified
423463
// a valid latest release or it's set to hide the citation for that
424464
// release, then display as provisional.
425465
// If an override has been presented by the component, also
426466
// display as provisional.
427467
displayType = _ViewState.DisplayType.PROVISIONAL;
428-
} else if (!hasValidProduct || !(0, _typeUtil.exists)(citableReleaseProduct)) {
468+
} else if (!hasValidProduct || !hasValidReleaseProduct) {
429469
// If the component is ready and the display state is conditional
430470
// and a valid product and release product were not found, error state.
431471
appliedStatus = _State.ContextStatus.ERROR;

src/lib_components/components/Citation/DataProductCitation/Service.ts

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,18 @@ const useViewState = (
383383
(baseProduct as ContextDataProduct).productCode,
384384
);
385385
}
386+
// Determine if the bundle product has data for the specified release.
387+
let isBundleProductInRelease: boolean = true;
388+
if (hasBundleProduct && hasSpecifiedRelease && !isAppliedReleaseLatestNonProv) {
389+
const bundleHasRelease: Undef<DataProductRelease> = bundleProduct?.releases.find(
390+
(r: DataProductRelease): boolean => r.release === appliedRenderedReleaseTag,
391+
);
392+
isBundleProductInRelease = exists(bundleHasRelease);
393+
}
386394
// Determine if the citable product should be the bundle container product
387395
// or the currently specified product.
388-
const citableBaseProduct: Nullable<ContextDataProduct> = hasBundleProduct
396+
// eslint-disable-next-line max-len
397+
const citableBaseProduct: Nullable<ContextDataProduct> = hasBundleProduct && isBundleProductInRelease
389398
? bundleProduct
390399
: baseProduct;
391400
// Determine the product to use for citing within the applicable release
@@ -397,6 +406,7 @@ const useViewState = (
397406
if (!hasSpecifiedRelease && !hasLatestReleaseBundle) {
398407
citableReleaseProduct = baseProduct;
399408
} else {
409+
// Has a specified release, or if not, has latest release bundle.
400410
// When a bundled product code is available for the given release,
401411
// get the product for the parent code and release.
402412
// Otherwise, the citable product is the current product for the specified
@@ -424,6 +434,18 @@ const useViewState = (
424434
}
425435
// Determine if there's a valid product to generate the citation with.
426436
const hasValidProduct: boolean = exists(citableBaseProduct);
437+
const hasValidReleaseProduct: boolean = exists(citableReleaseProduct);
438+
// Verify identified release product is in the applied release.
439+
let isCitableReleaseProductInRelease: boolean = false;
440+
// If looking at latest release non provisional, consider in release.
441+
if (isAppliedReleaseLatestNonProv) {
442+
isCitableReleaseProductInRelease = true;
443+
} else if (hasValidReleaseProduct) {
444+
const productHasRelease: Undef<DataProductRelease> = citableReleaseProduct?.releases.find(
445+
(r: DataProductRelease): boolean => r.release === appliedRenderedReleaseTag,
446+
);
447+
isCitableReleaseProductInRelease = exists(productHasRelease);
448+
}
427449
// Determine the overall citation display status.
428450
let appliedStatus: ContextStatus = status;
429451
let displayType: DisplayType = DisplayType.CONDITIONAL;
@@ -441,8 +463,15 @@ const useViewState = (
441463
// not show a release citation, show not available display state.
442464
displayType = DisplayType.NOT_AVAILABLE;
443465
} else if (hasAppliedReleaseDoi) {
444-
if (exists(citableReleaseProduct)) {
445-
displayType = DisplayType.RELEASE;
466+
if (hasValidReleaseProduct) {
467+
// If the identified release product doesn't have data in the
468+
// release and we're viewing a specific release, report
469+
// as not available for that release.
470+
if (!isCitableReleaseProductInRelease) {
471+
displayType = DisplayType.NOT_AVAILABLE;
472+
} else {
473+
displayType = DisplayType.RELEASE;
474+
}
446475
} else {
447476
// If the component is ready and a release was specified but
448477
// failed to resolve the appropriate citable release product,
@@ -457,14 +486,18 @@ const useViewState = (
457486
// a special case, render as not available.
458487
displayType = DisplayType.NOT_AVAILABLE;
459488
}
489+
} else if (!isCitableReleaseProductInRelease) {
490+
// If the detected citable release product is not in the applied
491+
// release, then consider the display as provisional.
492+
displayType = DisplayType.PROVISIONAL;
460493
} else if (!hasLatestRelease || hideLatestReleaseCitation || disableConditional) {
461494
// If display is determined to be conditional, but we haven't identified
462495
// a valid latest release or it's set to hide the citation for that
463496
// release, then display as provisional.
464497
// If an override has been presented by the component, also
465498
// display as provisional.
466499
displayType = DisplayType.PROVISIONAL;
467-
} else if (!hasValidProduct || !exists(citableReleaseProduct)) {
500+
} else if (!hasValidProduct || !hasValidReleaseProduct) {
468501
// If the component is ready and the display state is conditional
469502
// and a valid product and release product were not found, error state.
470503
appliedStatus = ContextStatus.ERROR;

src/lib_components/components/Citation/StyleGuide.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import ActionCreator from './DataProductCitation/Actions';
2929
import ComponentErrorBoundary from '../Error/ComponentErrorBoundary';
3030
import DataProductCitation from './DataProductCitation';
3131
import DataProductCitationContext from './DataProductCitation/Context';
32+
import DataProductCitationService from './DataProductCitation/Service';
3233
import DataProductCitationView from './DataProductCitation/View';
3334
import NeonApi from '../NeonApi';
3435
import NeonContext from '../NeonContext/NeonContext';
@@ -38,6 +39,10 @@ import ReleaseService from '../../service/ReleaseService';
3839
import Theme from '../Theme/Theme';
3940
import { Release } from '../../types/internal';
4041
import { isStringNonEmpty } from '../../util/typeUtil';
42+
import {
43+
DataProductCitationViewProps,
44+
DataProductCitationViewState,
45+
} from './DataProductCitation/ViewState';
4146

4247
const useStyles = makeStyles((theme) => ({
4348
divider: {
@@ -217,6 +222,13 @@ const DataProductCitationDemo = (): JSX.Element => {
217222
neonContextState,
218223
stateReleases,
219224
);
225+
const viewState: DataProductCitationViewState = DataProductCitationService.useViewState(
226+
stateCtx,
227+
DataProductCitationView.defaultProps as DataProductCitationViewProps,
228+
);
229+
const {
230+
releaseObject: appliedCitationReleaseObject,
231+
}: DataProductCitationViewState = viewState;
220232
// eslint-disable-next-line max-len
221233
const citationDispatch = DataProductCitationContext.useDataProductCitationContextDispatch() as Dispatch<any>;
222234
const fetchAllProducts$ = (NeonGraphQL.getAllDataProducts() as Observable<AjaxResponse>).pipe(
@@ -358,6 +370,15 @@ const DataProductCitationDemo = (): JSX.Element => {
358370
onChange={handleReleaseChange}
359371
/>
360372
</Grid>
373+
<Grid item xs={12}>
374+
<Typography variant="subtitle2" className={classes.title}>
375+
The citation context will determine the applied release based
376+
on the available releases for the product, release, and bundle.
377+
<br />
378+
{`Applied Release: ${appliedCitationReleaseObject?.release}`}
379+
</Typography>
380+
<Divider className={classes.divider} />
381+
</Grid>
361382
<Grid item xs={12}>
362383
<DataProductCitationView />
363384
</Grid>

0 commit comments

Comments
 (0)