-
Notifications
You must be signed in to change notification settings - Fork 334
Expand file tree
/
Copy pathMasthead.vue
More file actions
281 lines (245 loc) · 7.17 KB
/
Masthead.vue
File metadata and controls
281 lines (245 loc) · 7.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<script>
import { mapGetters } from 'vuex';
import Favorite from '@shell/components/nav/Favorite';
import TypeDescription from '@shell/components/TypeDescription';
import { RcButton } from '@components/RcButton';
import { get } from '@shell/utils/object';
import { AS, _YAML } from '@shell/config/query-params';
import ResourceLoadingIndicator from './ResourceLoadingIndicator';
import TabTitle from '@shell/components/TabTitle';
/**
* Resource List Masthead component.
*/
export default {
name: 'MastheadResourceList',
components: {
Favorite,
RcButton,
TypeDescription,
ResourceLoadingIndicator,
TabTitle
},
props: {
resource: {
type: String,
required: true,
},
favoriteResource: {
type: String,
default: null
},
schema: {
type: Object,
default: null,
},
typeDisplay: {
type: String,
default: null,
},
isCreatable: {
type: Boolean,
default: null,
},
isYamlCreatable: {
type: Boolean,
default: null,
},
createLocation: {
type: Object,
default: null,
},
yamlCreateLocation: {
type: Object,
default: null,
},
createButtonLabel: {
type: String,
default: null
},
loadResources: {
type: Array,
default: () => []
},
loadIndeterminate: {
type: Boolean,
default: false
},
showIncrementalLoadingIndicator: {
type: Boolean,
default: false
},
/**
* Inherited global identifier prefix for tests
* Define a term based on the parent component to avoid conflicts on multiple components
*/
componentTestid: {
type: String,
default: 'masthead'
}
},
data() {
const params = { ...this.$route.params };
// Determine if the current product has a topLevelProduct defined, and if so,
// use that for the formRoute instead of the current route's product.
// This allows resources from extensions (new product registration) to use the correct route for creation,
// which may be different from the route of the resource list.
let currPluginName = '';
let formRoute;
let overrideCreateLocationByExtension = false;
const plugins = this.$extension.getPlugins();
Object.keys(plugins).forEach((key) => {
if (plugins[key].productNames.includes(this.$store.getters['productId'])) {
currPluginName = key;
}
});
// the flag "topLevelProduct" only exists in the V2 product registration model
// same for the flag "startRouteWithProduct", we want to make sure both flags are true before we change the route structure
if (currPluginName && plugins[currPluginName]?.topLevelProduct && plugins[currPluginName]?.startRouteWithProduct) {
// override create route for extension resource lists
formRoute = { name: `${ this.$route.name }-create`, params: { ...params, product: this.$store.getters['productId'] } };
overrideCreateLocationByExtension = true;
} else {
// this was the original logic before the topLevelProduct override was added
formRoute = { name: `${ this.$route.name }-create`, params };
}
const hasEditComponent = this.$store.getters['type-map/hasCustomEdit'](this.resource);
const yamlRoute = {
name: `${ this.$route.name }-create`,
params,
query: { [AS]: _YAML },
};
return {
overrideCreateLocationByExtension,
formRoute,
yamlRoute,
hasEditComponent,
};
},
computed: {
get,
...mapGetters(['isExplorer', 'currentCluster']),
resourceName() {
if (this.schema) {
return this.$store.getters['type-map/labelFor'](this.schema);
}
return this.resource;
},
_typeDisplay() {
if ( this.typeDisplay !== null) {
return this.typeDisplay;
}
if ( !this.schema ) {
return '?';
}
return this.$store.getters['type-map/labelFor'](this.schema, 99);
},
_isYamlCreatable() {
if ( this.isYamlCreatable !== null) {
return this.isYamlCreatable;
}
return this.schema && this._isCreatable && this.$store.getters['type-map/optionsFor'](this.resource).canYaml;
},
_isCreatable() {
// Does not take into account hasEditComponent, such that _isYamlCreatable works
if ( this.isCreatable !== null) {
return this.isCreatable;
}
// blocked-post means you can post through norman, but not through steve.
if ( this.schema && this.schema?.collectionMethods && !this.schema?.collectionMethods.find((x) => ['blocked-post', 'post'].includes(x.toLowerCase())) ) {
return false;
}
return this.$store.getters['type-map/optionsFor'](this.resource).isCreatable;
},
_createLocation() {
return this.overrideCreateLocationByExtension ? this.formRoute : this.createLocation || this.formRoute;
},
_yamlCreateLocation() {
return this.yamlCreateLocation || this.yamlRoute;
},
_createButtonlabel() {
const overrideLabel = this.$store.getters['type-map/optionsFor'](this.resource).listCreateButtonLabelKey;
if (overrideLabel) {
return this.t(overrideLabel);
}
return this.createButtonLabel || this.t('resourceList.head.create');
},
}
};
</script>
<template>
<header class="with-subheader">
<slot name="typeDescription">
<TypeDescription :resource="resource" />
</slot>
<div class="title">
<h1 class="m-0">
<TabTitle>{{ _typeDisplay }}</TabTitle> <Favorite
v-if="isExplorer"
:resource="favoriteResource || resource"
/>
</h1>
<ResourceLoadingIndicator
v-if="showIncrementalLoadingIndicator"
:resources="loadResources"
:indeterminate="loadIndeterminate"
/>
</div>
<div class="sub-header">
<slot name="subHeader">
<!--Slot content-->
</slot>
</div>
<div class="actions-container">
<slot name="actions">
<div class="actions">
<slot name="extraActions" />
<slot name="createButton">
<RcButton
v-if="hasEditComponent && _isCreatable"
variant="primary"
size="large"
:data-testid="componentTestid+'-create'"
:to="_createLocation"
>
{{ _createButtonlabel }}
</RcButton>
<RcButton
v-else-if="_isYamlCreatable"
variant="primary"
size="large"
:data-testid="componentTestid+'-create-yaml'"
:to="_yamlCreateLocation"
>
{{ t("resourceList.head.createFromYaml") }}
</RcButton>
</slot>
</div>
</slot>
</div>
</header>
</template>
<style lang="scss" scoped>
.title {
align-items: center;
display: flex;
h1 {
margin: 0;
}
}
header {
margin-bottom: 20px;
}
header.with-subheader {
grid-template-areas:
'type-banner type-banner'
'title actions'
'sub-header sub-header'
'state-banner state-banner';
}
.sub-header {
grid-area: sub-header;
a {
display: inline-block;
}
}
</style>