Skip to content

Commit

Permalink
updates on archived items
Browse files Browse the repository at this point in the history
  • Loading branch information
zotya committed Mar 10, 2023
1 parent 2fe898c commit 627225d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/components/Result/DatahubCardItem.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';

import { Label } from 'semantic-ui-react';
import { DateTime, StringList } from '@eeacms/search';
import { ResultContext } from '@eeacms/search';
import { Link } from 'react-router-dom';
Expand All @@ -16,9 +17,13 @@ const DatahubCardItem = (props) => {

const item = {
title: (
<Link to={result.href} title={result.title}>
{result.title}
</Link>
<>
<Link to={result.href} title={result.title}>
{result.title}
</Link>
{result.isNew && <Label className="new-item">New</Label>}
{result.isExpired && <Label className="archived-item">Archived</Label>}
</>
),
description: <ResultContext {...props} />,
preview_image_url: result.hasImage ? result.thumbUrl : undefined,
Expand Down
57 changes: 57 additions & 0 deletions src/config/facets.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,67 @@ import {
fixedRangeFacet,
histogramFacet,
makeRange,
booleanFacet,
} from '@eeacms/search';
import { dateRangeFacet } from '@eeacms/search';

export function getTodayWithTime() {
const d = new Date();
const month = d.getMonth() + 1;
const day = d.getDate();
const hour = d.getHours();
const minute = d.getMinutes();
const second = d.getSeconds();

const output = [
d.getFullYear(),
'-',
month < 10 ? '0' : '',
month,
'-',
day < 10 ? '0' : '',
day,
'T',
hour < 10 ? '0' : '',
hour,
':',
minute < 10 ? '0' : '',
minute,
':',
second < 10 ? '0' : '',
second,
'Z',
].join('');
return output;
}

const facets = [
booleanFacet(() => ({
field: 'IncludeArchived',
label: 'Include archived content',
id: 'archived-facet',
showInFacetsList: false,
showInSecondaryFacetsList: true,
isFilter: true, // filters don't need facet options to show up

// we want this to be applied by default
// when the facet is checked, then apply the `on` key:
off: {
constant_score: {
filter: {
bool: {
should: [
{ bool: { must_not: { exists: { field: 'expires' } } } },
// Functions should be supported in the buildFilters
{ range: { expires: { gte: getTodayWithTime() } } },
],
},
},
},
},
on: null,
})),

multiTermFacet({
field: 'instrument',
isFilterable: true,
Expand Down

0 comments on commit 627225d

Please sign in to comment.