Skip to content

Commit

Permalink
fix: Resolve unknown badge type (#3607)
Browse files Browse the repository at this point in the history
* Resolve unknown badge type

* PR correction

* PR correction

* PR Correction

* Force update replicas

* PR correction

* PR correction

* PR correction

* PR correction

* PR correction
  • Loading branch information
KonradPietocha authored Jan 24, 2025
1 parent f274d8c commit 251bd6f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/components/Extensibility/ExtensibilityDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
} from './helpers';
import { useJsonata } from './hooks/useJsonata';
import CustomResource from 'resources/CustomResourceDefinitions/CustomResources.details';
import { useSetRecoilState } from 'recoil';
import { resourcesConditions } from 'state/resourceConditionsAtom';

export const ExtensibilityDetailsCore = ({
resMetaData,
Expand All @@ -28,6 +30,7 @@ export const ExtensibilityDetailsCore = ({
headerActions,
}) => {
const { t, widgetT, exists } = useGetTranslation();
const setResourcesConditions = useSetRecoilState(resourcesConditions);
const { urlPath, resource, features, description: resourceDescription } =
resMetaData?.general ?? {};
let { disableEdit, disableDelete } = features?.actions || {};
Expand Down Expand Up @@ -78,6 +81,7 @@ export const ExtensibilityDetailsCore = ({
const general = resMetaData?.general || {};

const prepareVisibility = (def, resource) => {
setResourcesConditions(resource.status);
const [visible, error] = jsonata(def.visibility, { resource }, true);
return { visible, error };
};
Expand Down
27 changes: 25 additions & 2 deletions src/components/Extensibility/contexts/DataSources.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import pluralize from 'pluralize';
import { createContext, useEffect, useRef, FC } from 'react';
import { createContext, useEffect, useRef, FC, useState } from 'react';
import { useRecoilValue } from 'recoil';

import { useFetch } from 'shared/hooks/BackendAPI/useFetch';
import { useObjectState } from 'shared/useObjectState';
import jp from 'jsonpath';
import { jsonataWrapper } from '../helpers/jsonataWrapper';
import { activeNamespaceIdState } from 'state/activeNamespaceIdAtom';
import { resourcesConditions } from 'state/resourceConditionsAtom';

export interface Resource {
metadata: {
Expand Down Expand Up @@ -83,10 +84,29 @@ export const DataSourcesContextProvider: FC<Props> = ({
// refetch intervals
const intervals = useRef<ReturnType<typeof setTimeout>[]>([]);
const fallbackNamespace = useRecoilValue(activeNamespaceIdState);
const stateConditions = useRecoilValue(resourcesConditions);
const [refetchSource, setRefetchSource] = useState('');

const findUpdatedName = (conditionsArr: string[], storeArr: string[]) => {
return conditionsArr.find(item => storeArr.includes(item));
};

// clear timeouts on component unmount
// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect(() => () => intervals.current.forEach(clearInterval), []);
useEffect(
() => () => {
const updatedSourceName = findUpdatedName(
Object.keys(stateConditions),
Object.keys(store),
);
if (updatedSourceName && !refetchSource) {
setRefetchSource(updatedSourceName);
}
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[stateConditions, refetchSource],
);

const buildUrl = (
dataSource: DataSource,
Expand Down Expand Up @@ -179,6 +199,7 @@ export const DataSourcesContextProvider: FC<Props> = ({
const dataSource = dataSources[dataSourceName];

if (
refetchSource === dataSourceName ||
!dataSourcesDict.current[dataSourceName] ||
dataSourcesDict.current[dataSourceName].rootName !==
resource?.metadata?.name ||
Expand All @@ -205,7 +226,9 @@ export const DataSourcesContextProvider: FC<Props> = ({
REFETCH_INTERVAL,
),
);

if (refetchSource) {
setRefetchSource('reFetched');
}
return firstFetch;
} else if (store?.[dataSourceName]?.loading) {
return store?.[dataSourceName]?.firstFetch;
Expand Down
8 changes: 8 additions & 0 deletions src/state/resourceConditionsAtom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { atom, RecoilState } from 'recoil';

const defaultValue: [] = [];

export const resourcesConditions: RecoilState<[]> = atom<[]>({
key: 'resourcesConditions',
default: defaultValue,
});

0 comments on commit 251bd6f

Please sign in to comment.