Skip to content

Commit

Permalink
Replace catalog/refresh call with catalog/load
Browse files Browse the repository at this point in the history
  • Loading branch information
jordojordo committed Feb 29, 2024
1 parent fed54c9 commit 538bbe5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 45 deletions.
48 changes: 11 additions & 37 deletions pkg/kubewarden/components/Dashboard/DashboardView.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<script>
import { mapGetters } from 'vuex';
import isEmpty from 'lodash/isEmpty';
import semver from 'semver';
import isEmpty from 'lodash/isEmpty';
import { CATALOG, POD, WORKLOAD_TYPES } from '@shell/config/types';
import { KUBERNETES, CATALOG as CATALOG_ANNOTATIONS } from '@shell/config/labels-annotations';
import { CATALOG, POD } from '@shell/config/types';
import { CATALOG as CATALOG_ANNOTATIONS } from '@shell/config/labels-annotations';
import { REPO_TYPE, REPO, CHART, VERSION } from '@shell/config/query-params';
import { SHOW_PRE_RELEASE } from '@shell/store/prefs';
import { allHash } from '@shell/utils/promise';
import ResourceManager from '@shell/mixins/resource-manager';
import ConsumptionGauge from '@shell/components/ConsumptionGauge';
import Loading from '@shell/components/Loading';
Expand All @@ -25,8 +24,6 @@ export default {
Card, ConsumptionGauge, DefaultsBanner, Loading
},
mixins: [ResourceManager],
async fetch() {
const hash = {};
const types = [
Expand All @@ -44,10 +41,10 @@ export default {
}
await allHash(hash);
await this.$store.dispatch('catalog/refresh');
this.secondaryResourceData = this.secondaryResourceDataConfig();
this.resourceManagerFetchSecondaryResources(this.secondaryResourceData);
if ( isEmpty(this.charts) ) {
await this.$store.dispatch('catalog/load');
}
},
data() {
Expand All @@ -57,12 +54,7 @@ export default {
return {
DASHBOARD_HEADERS,
colorStops,
controllerDeployment: null,
deployments: null,
psPods: [],
secondaryResourceData: this.secondaryResourceDataConfig(),
colorStops
};
},
Expand Down Expand Up @@ -185,8 +177,8 @@ export default {
return this.getPolicyGauges(this.namespacedPolicies);
},
version() {
return this.controllerDeployment?.metadata?.labels?.['app.kubernetes.io/version'];
appVersion() {
return this.controllerApp?.spec?.chart?.metadata?.appVersion;
},
upgradeAvailable() {
Expand Down Expand Up @@ -241,24 +233,6 @@ export default {
},
methods: {
secondaryResourceDataConfig() {
return {
namespace: this.controllerDeployment?.metadata?.namespace,
data: {
[WORKLOAD_TYPES.DEPLOYMENT]: {
applyTo: [
{
var: 'controllerDeployment',
parsingFunc: (data) => {
return data.find(deploy => deploy?.metadata?.labels?.[KUBERNETES.MANAGED_NAME] === KUBEWARDEN_CHARTS.CONTROLLER);
}
}
]
}
}
};
},
getPolicyGauges(type) {
if ( !isEmpty(type) ) {
return type?.reduce((policy, neu) => {
Expand Down Expand Up @@ -379,9 +353,9 @@ export default {
{{ t('kubewarden.dashboard.intro') }}
</h1>
<div v-if="version" class="head-version-container">
<div v-if="appVersion" class="head-version-container">
<div class="head-version bg-primary mr-10">
{{ t('kubewarden.dashboard.upgrade.appVersion') }}: {{ version }}
{{ t('kubewarden.dashboard.upgrade.appVersion') }}: {{ appVersion }}
</div>
<div
v-if="upgradeAvailable"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default {
export const policyServerPod: any = {
id: 'cattle-kubewarden-system/policy-server-default-7f59869c46-wjg4v',
type: 'pod',
apiVersion: 'v1',
Expand Down
10 changes: 3 additions & 7 deletions tests/unit/components/Dashboard/DashboardView.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import DefaultsBanner from '@kubewarden/components/DefaultsBanner';
import ConsumptionGauge from '@shell/components/ConsumptionGauge';

import DEFAULTS_APP from '@tests/unit/_templates_/defaultsApp';
import PS_POD from '@tests/unit/_templates_/policyServerPod';

describe('component: DashboardView', () => {
const commonMocks = {
Expand All @@ -30,7 +29,6 @@ describe('component: DashboardView', () => {
controllerChart: () => null,
defaultsApp: () => DEFAULTS_APP,
hideBannerDefaults: () => false,
policyServerPods: () => [PS_POD],
globalPolicies: () => [],
namespacedPolicies: () => [],
version: () => '1.25',
Expand Down Expand Up @@ -134,15 +132,13 @@ describe('component: DashboardView', () => {
];

const wrapper = createWrapper({
data() {
return { psPods: pods };
},
stubs: { DefaultsBanner: { template: '<span />' } }
computed: { policyServerPods: () => pods },
stubs: { DefaultsBanner: { template: '<span />' } }
});

const gauges = wrapper.findAllComponents(ConsumptionGauge);

expect(gauges.at(0).props().capacity).toStrictEqual([PS_POD].length as Number);
expect(gauges.at(0).props().capacity).toStrictEqual(pods.length as Number);
expect(gauges.at(0).props().used).toStrictEqual(1 as Number);
});

Expand Down

0 comments on commit 538bbe5

Please sign in to comment.