diff --git a/src/components/ItemList.svelte b/src/components/ItemList.svelte
index d22cda3be..813388b40 100644
--- a/src/components/ItemList.svelte
+++ b/src/components/ItemList.svelte
@@ -10,7 +10,7 @@
import Label from "./Label.svelte";
import { filterUncollectedItems } from "../state/filter";
- import { isExpired } from "../state/metrics";
+ import { isExpired, isRemoved } from "../state/items";
import { pageState, updateURLState } from "../state/stores";
let DEFAULT_ITEMS_PER_PAGE = 20;
@@ -21,7 +21,7 @@
export let showFilter = true;
- let filteredItems = items.filter((item) => !isExpired(item.expires));
+ let filteredItems = items.filter((item) => !isExpired(item));
let pagedItems;
let paginated = true;
let search;
@@ -189,9 +189,9 @@
/>
{/each}
{/if}
- {#if !item.in_source}
+ {#if isRemoved(item)}
- {:else if isExpired(item.expires)}
+ {:else if isExpired(item)}
{/if}
{#if item.deprecated}
diff --git a/src/pages/MetricDetail.svelte b/src/pages/MetricDetail.svelte
index c1368719e..48dca5e73 100644
--- a/src/pages/MetricDetail.svelte
+++ b/src/pages/MetricDetail.svelte
@@ -20,7 +20,7 @@
import { pageTitle, pageState, updateURLState } from "../state/stores";
import { getBigQueryURL } from "../state/urls";
- import { isExpired } from "../state/metrics";
+ import { isExpired, isRemoved } from "../state/items";
export let params;
@@ -78,12 +78,12 @@
{#await metricDataPromise then metric}
- {#if !metric.in_source}
+ {#if isRemoved(metric)}
- {:else if isExpired(metric.expires)}
+ {:else if isExpired(metric)}
items.filter(
- (item) => showUncollected || (!isExpired(item.expires) && item.in_source)
+ (item) => showUncollected || (!isExpired(item) && !isRemoved(item))
);
diff --git a/src/state/items.js b/src/state/items.js
new file mode 100644
index 000000000..c89dec405
--- /dev/null
+++ b/src/state/items.js
@@ -0,0 +1,12 @@
+export const isRemoved = (item) => {
+ // only consider an item expired if it has an in_source property
+ // and it is false
+ return item.in_source === false;
+};
+
+export const isExpired = (item) => {
+ if (item.expires === "never" || item.expires === undefined) {
+ return false;
+ }
+ return new Date() > new Date(item.expires);
+};
diff --git a/src/state/metrics.js b/src/state/metrics.js
deleted file mode 100644
index 4b7625f43..000000000
--- a/src/state/metrics.js
+++ /dev/null
@@ -1,6 +0,0 @@
-export const isExpired = (expiryDate) => {
- if (expiryDate === "never" || expiryDate === undefined) {
- return false;
- }
- return new Date() > new Date(expiryDate);
-};
diff --git a/tests/state.items.test.js b/tests/state.items.test.js
new file mode 100644
index 000000000..0a1c40d89
--- /dev/null
+++ b/tests/state.items.test.js
@@ -0,0 +1,25 @@
+import { isExpired, isRemoved } from "../src/state/items";
+
+describe("checking if a date has expired", () => {
+ it("returns True if input is 'never' or undefined", () => {
+ expect(isExpired({ expires: "never" }) || isExpired({})).toEqual(false);
+ });
+ it("returns True if input is a date from the past", () => {
+ expect(isExpired({ expires: "2021-01-01" })).toEqual(true);
+ });
+ it("returns False if input is a date from the future", () => {
+ expect(isExpired({ expires: "3021-01-01" })).toEqual(false);
+ });
+});
+
+describe("isRemoved works as expected", () => {
+ it("returns true if in_source is false", () => {
+ expect(isRemoved({ in_source: false })).toEqual(true);
+ });
+ it("returns false if in_source is undefined", () => {
+ expect(isRemoved({})).toEqual(false);
+ });
+ it("returns false if in_source is true", () => {
+ expect(isRemoved({ in_source: true })).toEqual(false);
+ });
+});
diff --git a/tests/state.metrics.test.js b/tests/state.metrics.test.js
deleted file mode 100644
index f5ebae697..000000000
--- a/tests/state.metrics.test.js
+++ /dev/null
@@ -1,13 +0,0 @@
-import { isExpired } from "../src/state/metrics";
-
-describe("checking if a date has expired", () => {
- it("returns True if input is 'never' or undefined", () => {
- expect(isExpired("never") || isExpired(undefined)).toEqual(false);
- });
- it("returns True if input is a date from the past", () => {
- expect(isExpired("2021-01-01")).toEqual(true);
- });
- it("returns False if input is a date from the future", () => {
- expect(isExpired("3021-01-01")).toEqual(false);
- });
-});