Commit 6f78a18f authored by Enrique Alcántara's avatar Enrique Alcántara

Merge branch '335710-devops-adoption-page-constantly-refreshes' into 'master'

DevOps Adoption - Reduce page refresh rate

See merge request gitlab-org/gitlab!69056
parents a792bf77 bb4867bd
......@@ -185,7 +185,6 @@ export default {
pollTableData() {
const shouldPoll = shouldPollTableData({
enabledNamespaces: this.devopsAdoptionEnabledNamespaces.nodes,
timestamp: this.devopsAdoptionEnabledNamespaces?.nodes[0]?.latestSnapshot?.recordedAt,
openModal: this.openModal,
});
......
import { isToday } from '~/lib/utils/datetime_utility';
/**
* A helper function which accepts the enabledNamespaces,
*
* @param {Object} params the enabledNamespaces data, timestamp and check for open modals
* @param {Object} params the enabledNamespaces data, and the check for open modals
*
* @return {Boolean} a boolean to determine if table data should be polled
*/
export const shouldPollTableData = ({ enabledNamespaces, timestamp, openModal }) => {
export const shouldPollTableData = ({ enabledNamespaces, openModal }) => {
if (openModal) {
return false;
} else if (!enabledNamespaces.length) {
......@@ -17,7 +15,6 @@ export const shouldPollTableData = ({ enabledNamespaces, timestamp, openModal })
const anyPendingEnabledNamespaces = enabledNamespaces.some(
(node) => node.latestSnapshot === null,
);
const dataNotRefreshedToday = !isToday(new Date(timestamp));
return anyPendingEnabledNamespaces || dataNotRefreshedToday;
return anyPendingEnabledNamespaces;
};
......@@ -4,18 +4,13 @@ import { devopsAdoptionNamespaceData } from '../mock_data';
describe('shouldPollTableData', () => {
const { nodes: pendingData } = devopsAdoptionNamespaceData;
const comepleteData = [pendingData[0]];
const mockDate = '2020-07-06T00:00:00.000Z';
const previousDay = '2020-07-05T00:00:00.000Z';
it.each`
scenario | enabledNamespaces | timestamp | openModal | expected
${'no namespaces data'} | ${[]} | ${mockDate} | ${false} | ${true}
${'no timestamp'} | ${comepleteData} | ${null} | ${false} | ${true}
${'open modal'} | ${comepleteData} | ${mockDate} | ${true} | ${false}
${'namespaces data, timestamp is today, modal is closed'} | ${comepleteData} | ${mockDate} | ${false} | ${false}
${'namespaces data, timestamp is yesterday, modal is closed'} | ${comepleteData} | ${previousDay} | ${false} | ${true}
${'namespaces data, timestamp is today, modal is open'} | ${comepleteData} | ${mockDate} | ${true} | ${false}
${'pending namespaces data, timestamp is today, modal is closed'} | ${pendingData} | ${mockDate} | ${false} | ${true}
scenario | enabledNamespaces | openModal | expected
${'no namespaces data'} | ${[]} | ${false} | ${true}
${'open modal'} | ${comepleteData} | ${true} | ${false}
${'pending namespaces data, modal is closed'} | ${pendingData} | ${false} | ${true}
${'pending namespaces data, modal is open'} | ${pendingData} | ${true} | ${false}
`('returns $expected when $scenario', ({ enabledNamespaces, timestamp, openModal, expected }) => {
expect(shouldPollTableData({ enabledNamespaces, timestamp, openModal })).toBe(expected);
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment