dashboard-shell-shell 1.0.1000000091 → 1.0.1000000092

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/list/workload.vue +188 -0
  2. package/package.json +1 -1
package/list/workload.vue CHANGED
@@ -0,0 +1,188 @@
1
+ <script>
2
+ import ResourceTable from '@shell/components/ResourceTable';
3
+ import {
4
+ WORKLOAD_TYPES, SCHEMA, NODE, POD, LIST_WORKLOAD_TYPES
5
+ } from '@shell/config/types';
6
+ import ResourceFetch from '@shell/mixins/resource-fetch';
7
+ import PaginatedResourceTable from '@shell/components/PaginatedResourceTable';
8
+ import { harvesterhci2cloud, cloud2harvesterhci } from '@shell/utils/router'
9
+
10
+ const workloadSchema = {
11
+ id: 'workload',
12
+ type: SCHEMA,
13
+ attributes: {
14
+ kind: 'Workload',
15
+ namespaced: true
16
+ },
17
+ metadata: { name: 'workload' },
18
+ };
19
+
20
+ const $loadingResources = ($route, $store) => {
21
+ const allowedResources = [];
22
+
23
+ Object.values(LIST_WORKLOAD_TYPES).forEach((type) => {
24
+ // You may not have RBAC to see some of the types
25
+ if ($store.getters['cluster/schemaFor'](type) ) {
26
+ allowedResources.push(type);
27
+ }
28
+ });
29
+
30
+ const allTypes = $route.params.resource === workloadSchema.id;
31
+
32
+ return {
33
+ loadResources: allTypes ? allowedResources : [$route.params.resource],
34
+ loadIndeterminate: allTypes,
35
+ };
36
+ };
37
+
38
+ export default {
39
+ name: 'ListWorkload',
40
+ components: { ResourceTable, PaginatedResourceTable },
41
+ mixins: [ResourceFetch],
42
+
43
+ props: {
44
+ useQueryParamsForSimpleFiltering: {
45
+ type: Boolean,
46
+ default: false
47
+ }
48
+ },
49
+
50
+ async fetch() {
51
+ if (this.paginationEnabled) {
52
+ return;
53
+ }
54
+
55
+ if (this.allTypes && this.loadResources.length) {
56
+ this.$initializeFetchData(this.loadResources[0], this.loadResources);
57
+ } else {
58
+ this.$initializeFetchData(this.$route.params.resource);
59
+ }
60
+
61
+ try {
62
+ const schema = this.$store.getters[`cluster/schemaFor`](NODE);
63
+
64
+ if (schema) {
65
+ // Used for shell/components/formatter/Endpoints.vue (too see column page needs to be wide and per page setting 25 or under)
66
+ this.$fetchType(NODE);
67
+ }
68
+ } catch {}
69
+
70
+ this.loadHeathResources();
71
+
72
+ if ( this.allTypes ) {
73
+ this.resources = await Promise.all(this.loadResources.map((allowed) => {
74
+ return this.$fetchType(allowed, this.loadResources);
75
+ }));
76
+ } else {
77
+ const type = this.$route.params.resource;
78
+
79
+ if ( this.$store.getters['cluster/schemaFor'](type) ) {
80
+ const resource = await this.$fetchType(type);
81
+
82
+ this.resources = [resource];
83
+ }
84
+ }
85
+ },
86
+
87
+ data() {
88
+ // Ensure these are set on load (to determine if the NS filter is required) rather than too late on `fetch`
89
+ const { loadResources, loadIndeterminate } = $loadingResources(this.$route, this.$store);
90
+
91
+ const { params:{ resource: type } } = this.$route;
92
+ const allTypes = this.$route.params.resource === workloadSchema.id;
93
+ const schema = type !== workloadSchema.id ? this.$store.getters['cluster/schemaFor'](type) : workloadSchema;
94
+ const paginationEnabled = !allTypes && this.$store.getters[`cluster/paginationEnabled`]?.({ id: type });
95
+
96
+ return {
97
+ allTypes,
98
+ schema,
99
+ paginationEnabled,
100
+ resources: [],
101
+ loadResources,
102
+ loadIndeterminate
103
+ };
104
+ },
105
+
106
+ computed: {
107
+ filteredRows() {
108
+ const out = [];
109
+
110
+ for ( const typeRows of this.resources ) {
111
+ if ( !typeRows ) {
112
+ continue;
113
+ }
114
+
115
+ for ( const row of typeRows ) {
116
+ if (!this.allTypes || !row.ownedByWorkload) {
117
+ out.push(row);
118
+ }
119
+ }
120
+ }
121
+
122
+ return out;
123
+ },
124
+
125
+ headers() {
126
+ return this.$store.getters['type-map/headersFor'](this.schema, false);
127
+ }
128
+ },
129
+
130
+ // All of the resources that we will load that we need for the loading indicator
131
+ $loadingResources($route, $store) {
132
+ return $loadingResources($route, $store);
133
+ },
134
+
135
+ methods: {
136
+ loadHeathResources() {
137
+ // See https://github.com/rancher/dashboard/issues/10417, health comes from selectors applied locally to all pods (bad)
138
+ if (this.paginationEnabled) {
139
+ return;
140
+ }
141
+
142
+ // Fetch these in the background to populate workload health
143
+ if ( this.allTypes ) {
144
+ this.$fetchType(POD);
145
+ this.$fetchType(WORKLOAD_TYPES.JOB);
146
+ } else {
147
+ const type = this.$route.params.resource;
148
+
149
+ if (type === WORKLOAD_TYPES.JOB || type === POD) {
150
+ // Ignore job and pods (we're fetching this anyway, plus they contain their own state)
151
+ return;
152
+ }
153
+
154
+ if (type === WORKLOAD_TYPES.CRON_JOB) {
155
+ this.$fetchType(WORKLOAD_TYPES.JOB);
156
+ } else {
157
+ this.$fetchType(POD);
158
+ }
159
+ }
160
+ }
161
+ },
162
+
163
+ typeDisplay() {
164
+ // Used by shell/components/ResourceList/index.vue to override list title (usually found via schema, which doesn't exist for this virtual type)
165
+ return this.$store.getters['type-map/labelFor'](this.schema || workloadSchema, 99);
166
+ },
167
+ };
168
+ </script>
169
+
170
+ <template>
171
+ <div>
172
+ <PaginatedResourceTable
173
+ v-if="paginationEnabled"
174
+ :schema="schema"
175
+ :use-query-params-for-simple-filtering="useQueryParamsForSimpleFiltering"
176
+ />
177
+ <ResourceTable
178
+ v-else
179
+ :loading="$fetchState.pending"
180
+ :schema="schema"
181
+ :headers="headers"
182
+ :rows="filteredRows"
183
+ :overflow-y="true"
184
+ :use-query-params-for-simple-filtering="useQueryParamsForSimpleFiltering"
185
+ :force-update-live-and-delayed="forceUpdateLiveAndDelayed"
186
+ />
187
+ </div>
188
+ </template>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dashboard-shell-shell",
3
- "version": "1.0.1000000091",
3
+ "version": "1.0.1000000092",
4
4
  "description": "Rancher Dashboard Shell",
5
5
  "repository": "https://github.com/rancherlabs/dashboard",
6
6
  "license": "Apache-2.0",