Skip to content

Commit a9765bf

Browse files
committed
Making it so we can target detail page vs show configuration
Fixes #16179 Fixes #16189
1 parent 15235a6 commit a9765bf

File tree

6 files changed

+70
-5
lines changed

6 files changed

+70
-5
lines changed

docusaurus/extensions_versioned_docs/version-v2/api/tabs.md

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ _Arguments_
2424
| Key | Type | Description |
2525
|---|---|---|
2626
|`TabLocation.RESOURCE_DETAIL`| String | Location for a Tab on a Resource Detail page |
27+
|`TabLocation.RESOURCE_SHOW_CONFIGURATION`| String | Location for a Tab on a Resource Show Configuration |
2728

2829
<br/>
2930

30-
`when` Object admissable values:
31+
`when` Object admissible values:
3132

3233
`LocationConfig` as described above for the [LocationConfig object](./common#locationconfig).
3334

@@ -38,13 +39,13 @@ _Arguments_
3839

3940
![Tabs](../screenshots/add-tab.png)
4041

41-
`options` config object. Admissable parameters for the `options` with `'TabLocation.RESOURCE_DETAIL'` are:
42+
`options` config object. Admissible parameters for the `options` with `'TabLocation.RESOURCE_DETAIL'` are:
4243

4344
| Key | Type | Description |
4445
|---|---|---|
4546
|`name`| String | Query param name used in url when tab is active/clicked |
4647
|`label`| String | Text for the tab label |
47-
|`labelKey`| String | Same as "label" but allows for translation. Will superseed "label" |
48+
|`labelKey`| String | Same as "label" but allows for translation. Will supersede "label" |
4849
|`weight`| Int | Defines the order on which the tab is displayed in relation to other tabs in the component |
4950
|`showHeader`| Boolean | Whether the tab header is displayed or not |
5051
|`tooltip`| String | Tooltip message (on tab header) |
@@ -66,4 +67,38 @@ plugin.addTab(
6667
component: () => import('./MyTabComponent.vue')
6768
}
6869
);
70+
```
71+
72+
### TabLocation.RESOURCE_SHOW_CONFIGURATION options
73+
74+
![Tabs](../screenshots/add-tab-show-configuration.png)
75+
76+
`options` config object. Admissible parameters for the `options` with `'TabLocation.RESOURCE_SHOW_CONFIGURATION'` are:
77+
78+
| Key | Type | Description |
79+
|---|---|---|
80+
|`name`| String | Query param name used in url when tab is active/clicked |
81+
|`label`| String | Text for the tab label |
82+
|`labelKey`| String | Same as "label" but allows for translation. Will supersede "label" |
83+
|`weight`| Int | Defines the order on which the tab is displayed in relation to other tabs in the component |
84+
|`showHeader`| Boolean | Whether the tab header is displayed or not |
85+
|`tooltip`| String | Tooltip message (on tab header) |
86+
|`component`| Function | Component to be rendered as content on the tab |
87+
88+
Usage example:
89+
90+
```ts
91+
plugin.addTab(
92+
TabLocation.RESOURCE_SHOW_CONFIGURATION,
93+
{ resource: ['pod'] },
94+
{
95+
name: 'some-name',
96+
labelKey: 'plugin-examples.tab-label',
97+
label: 'some-label',
98+
weight: -5,
99+
showHeader: true,
100+
tooltip: 'this is a tooltip message',
101+
component: () => import('./MyTabComponent.vue')
102+
}
103+
);
69104
```
56.5 KB
Loading

shell/components/Drawer/ResourceDetailDrawer/composables.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useStore } from 'vuex';
22
import { getYaml } from '@shell/components/Drawer/ResourceDetailDrawer/helpers';
33
import { ConfigProps, YamlProps } from '@shell/components/Drawer/ResourceDetailDrawer/types';
4+
import { inject, provide } from 'vue';
45

56
export async function useDefaultYamlTabProps(resource: any): Promise<YamlProps> {
67
const yaml = await getYaml(resource);
@@ -27,3 +28,21 @@ export function useDefaultConfigTabProps(resource: any): ConfigProps | undefined
2728
resourceType: resource.type
2829
};
2930
}
31+
32+
const IS_IN_RESOURCE_DETAIL_DRAWER_KEY = 'isInResourceDetailDrawerKey';
33+
34+
/**
35+
* Used to add a provide method which will indicate to all ancestors that they're inside the ResourceDetailDrawer. This is useful because we show
36+
* config page components both independently and within the ResourceDetailDrawer and we sometimes want to distinguish between the two use cases.
37+
*/
38+
export function useResourceDetailDrawerProvider() {
39+
provide(IS_IN_RESOURCE_DETAIL_DRAWER_KEY, true);
40+
}
41+
42+
/**
43+
* A composable used to determine if the current component was instantiated as an ancestor of a ResourceDetailDrawer.
44+
* @returns true if the component is an ancestor of ResourceDetailDrawer, otherwise false
45+
*/
46+
export function useIsInResourceDetailDrawer() {
47+
return inject(IS_IN_RESOURCE_DETAIL_DRAWER_KEY, false);
48+
}

shell/components/Drawer/ResourceDetailDrawer/index.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useI18n } from '@shell/composables/useI18n';
44
import { useStore } from 'vuex';
55
import Tabbed from '@shell/components/Tabbed/index.vue';
66
import YamlTab, { Props as YamlProps } from '@shell/components/Drawer/ResourceDetailDrawer/YamlTab.vue';
7-
import { useDefaultConfigTabProps, useDefaultYamlTabProps } from '@shell/components/Drawer/ResourceDetailDrawer/composables';
7+
import { useDefaultConfigTabProps, useDefaultYamlTabProps, useResourceDetailDrawerProvider } from '@shell/components/Drawer/ResourceDetailDrawer/composables';
88
import ConfigTab from '@shell/components/Drawer/ResourceDetailDrawer/ConfigTab.vue';
99
import { computed, ref } from 'vue';
1010
import RcButton from '@components/RcButton/RcButton.vue';
@@ -54,6 +54,8 @@ const canEdit = computed(() => {
5454
return isConfig.value ? props.resource.canEdit : props.resource.canEditYaml;
5555
});
5656
57+
useResourceDetailDrawerProvider();
58+
5759
</script>
5860
<template>
5961
<Drawer

shell/components/Tabbed/index.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import findIndex from 'lodash/findIndex';
77
import { ExtensionPoint, TabLocation } from '@shell/core/types';
88
import { getApplicableExtensionEnhancements } from '@shell/core/plugin-helpers';
99
import Tab from '@shell/components/Tabbed/Tab';
10+
import { useIsInResourceDetailDrawer } from '@shell/components/Drawer/ResourceDetailDrawer/composables';
1011
1112
export default {
1213
name: 'Tabbed',
@@ -105,7 +106,8 @@ export default {
105106
},
106107
107108
data() {
108-
const extensionTabs = this.showExtensionTabs ? getApplicableExtensionEnhancements(this, ExtensionPoint.TAB, TabLocation.RESOURCE_DETAIL, this.$route, this, this.extensionParams) || [] : [];
109+
const location = this.isInResourceDetailDrawer ? TabLocation.RESOURCE_SHOW_CONFIGURATION : TabLocation.RESOURCE_DETAIL;
110+
const extensionTabs = this.showExtensionTabs ? getApplicableExtensionEnhancements(this, ExtensionPoint.TAB, location, this.$route, this, this.extensionParams) || [] : [];
109111
110112
const parsedExtTabs = extensionTabs.map((item) => {
111113
return {
@@ -133,6 +135,12 @@ export default {
133135
}
134136
},
135137
138+
setup() {
139+
const isInResourceDetailDrawer = useIsInResourceDetailDrawer();
140+
141+
return { isInResourceDetailDrawer };
142+
},
143+
136144
watch: {
137145
sortedTabs(tabs) {
138146
const {

shell/core/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export enum PanelLocation {
7979
/** Enum regarding tab locations that are extensible in the UI */
8080
export enum TabLocation {
8181
RESOURCE_DETAIL = 'tab', // eslint-disable-line no-unused-vars
82+
RESOURCE_SHOW_CONFIGURATION = 'resource-show-configuration', // eslint-disable-line no-unused-vars
8283
CLUSTER_CREATE_RKE2 = 'cluster-create-rke2', // eslint-disable-line no-unused-vars
8384
}
8485

0 commit comments

Comments
 (0)