Skip to content

Commit

Permalink
Add useMockableK8sWatchResource
Browse files Browse the repository at this point in the history
  • Loading branch information
rszwajko committed Sep 20, 2022
1 parent c82d110 commit b9e20c2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/Providers/ProvidersPage.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useMemo, useState } from 'react';
import { useTranslation } from 'src/internal/i18n';
import { ProviderResource } from 'src/internal/k8s';
import { useMockableK8sWatchResource } from 'src/utils/fetch';

import { MOCK_CLUSTER_PROVIDERS } from '@app/queries/mocks/providers.mock';
import { useK8sWatchResource } from '@openshift-console/dynamic-plugin-sdk';
import {
Button,
Level,
Expand All @@ -26,17 +26,11 @@ import { createMetaMatcher, Field } from './components/shared';
import { NAME, NAMESPACE, READY, TYPE, URL } from './components/shared';
import TableView from './components/TableView';

const isMock = process.env.DATA_SOURCE === 'mock';

const useProviders = ({ kind, namespace }) => {
const [providers, loaded, error] = isMock
? [MOCK_CLUSTER_PROVIDERS, true, false]
: useK8sWatchResource<ProviderResource[]>({
kind,
isList: true,
namespaced: true,
namespace,
});
const [providers, loaded, error] = useMockableK8sWatchResource(
{ kind, namespace },
MOCK_CLUSTER_PROVIDERS,
);

// const inventoryProvidersQuery = useInventoryProvidersQuery();
// providers.map(p => enhanceWithInventory(inventoryProvidersQuery))
Expand Down
17 changes: 17 additions & 0 deletions src/utils/fetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useK8sWatchResource } from '@openshift-console/dynamic-plugin-sdk';

const isMock = process.env.DATA_SOURCE === 'mock';

export function useMockableK8sWatchResource<T>(
{ kind, namespace },
mockData: T[] = [],
) {
return isMock
? [mockData, true, false]
: useK8sWatchResource<T[]>({
kind,
isList: true,
namespaced: true,
namespace,
});
}

0 comments on commit b9e20c2

Please sign in to comment.