Allow cluster create and import locations to be overridden (#14041)

* Allow cluster create and import locations to be overridden

* Wire into home page

* Bug fix on home page

* Update type declaration
This commit is contained in:
Neil MacDougall 2025-04-08 08:49:10 +01:00 committed by GitHub
parent 467139b939
commit 5822b9e63c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 46 additions and 29 deletions

View File

@ -373,6 +373,11 @@ export interface ConfigureTypeOptions {
*/
customRoute?: Object;
/**
* Custom options vary pre resource type
*/
custom?: any;
/**
* Leaving these here for completeness but I don't think these should be advertised as useable to plugin creators.
*/

View File

@ -113,24 +113,32 @@ export default {
},
createLocation() {
return {
name: 'c-cluster-product-resource-create',
params: {
product: this.$store.getters['currentProduct'].name,
resource: this.resource
},
const options = this.$store.getters[`type-map/optionsFor`](this.resource)?.custom || {};
const params = {
product: this.$store.getters['currentProduct'].name,
resource: this.resource
};
const defaultLocation = {
name: 'c-cluster-product-resource-create',
params
};
return options.createLocation ? options.createLocation(params) : defaultLocation;
},
importLocation() {
return {
name: 'c-cluster-product-resource-create',
params: {
product: this.$store.getters['currentProduct'].name,
resource: this.resource
},
const options = this.$store.getters[`type-map/optionsFor`](this.resource)?.custom || {};
const params = {
product: this.$store.getters['currentProduct'].name,
resource: this.resource
};
const defaultLocation = {
name: 'c-cluster-product-resource-create',
params,
query: { [MODE]: _IMPORT }
};
return options.importLocation ? options.importLocation(params) : defaultLocation;
},
canImport() {

View File

@ -49,6 +49,21 @@ export default defineComponent({
mixins: [PageHeaderActions],
data() {
const options = this.$store.getters[`type-map/optionsFor`](CAPI.RANCHER_CLUSTER)?.custom || {};
const params = {
product: MANAGER,
cluster: BLANK_CLUSTER,
resource: CAPI.RANCHER_CLUSTER
};
const defaultCreateLocation = {
name: 'c-cluster-product-resource-create',
params,
};
const defaultImportLocation = {
...defaultCreateLocation,
query: { [MODE]: _IMPORT }
};
return {
HIDE_HOME_PAGE_CARDS,
fullVersion: getVersionInfo(this.$store).fullVersion,
@ -87,24 +102,9 @@ export default defineComponent({
},
},
createLocation: {
name: 'c-cluster-product-resource-create',
params: {
product: MANAGER,
cluster: BLANK_CLUSTER,
resource: CAPI.RANCHER_CLUSTER
},
},
createLocation: options.createLocation ? options.createLocation(params) : defaultCreateLocation,
importLocation: {
name: 'c-cluster-product-resource-create',
params: {
product: MANAGER,
cluster: BLANK_CLUSTER,
resource: CAPI.RANCHER_CLUSTER
},
query: { [MODE]: _IMPORT }
},
importLocation: options.importLocation ? options.importLocation(params) : defaultImportLocation,
headers: [
STATE,

View File

@ -107,6 +107,7 @@
// graphConfig: undefined -- Use this to pass along the graph configuration
// notFilterNamespace: undefined -- Define namespaces that do not need to be filtered
// localOnly: False -- Hide this type from the nav/search bar on downstream clusters
// custom: any - Custom options for a given type
// }
// )
// ignoreGroup(group): Never show group or any types in it
@ -524,6 +525,7 @@ export const getters = {
depaginate: false,
customRoute: undefined,
resourceEditMasthead: true,
custom: {},
};
return (schemaOrType, pagination) => {
@ -1729,6 +1731,8 @@ export const mutations = {
let obj = { ...options, match };
if ( idx >= 0 ) {
// Merge the custom data object - multiple configures will update existing rather than overwrite
obj.custom = Object.assign(state.typeOptions[idx].custom || {}, obj.custom || {});
obj = Object.assign(state.typeOptions[idx], obj);
state.typeOptions.splice(idx, 1, obj);
} else {