@rancher/shell 3.0.10 → 3.0.12-rc.1
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.
- package/assets/styles/base/_mixins.scss +31 -0
- package/assets/styles/base/_variables.scss +2 -0
- package/assets/styles/themes/_modern.scss +6 -5
- package/assets/translations/en-us.yaml +12 -9
- package/assets/translations/zh-hans.yaml +0 -3
- package/chart/__tests__/rancher-backup-index.test.ts +248 -0
- package/chart/rancher-backup/index.vue +41 -2
- package/components/BrandImage.vue +6 -5
- package/components/ConsumptionGauge.vue +12 -4
- package/components/DynamicContent/DynamicContentIcon.vue +3 -2
- package/components/EmptyProductPage.vue +76 -0
- package/components/ExplorerProjectsNamespaces.vue +1 -4
- package/components/LazyImage.vue +2 -1
- package/components/Resource/Detail/Card/Scaler.vue +4 -4
- package/components/Resource/Detail/CopyToClipboard.vue +1 -2
- package/components/Resource/Detail/Metadata/KeyValueRow.vue +9 -3
- package/components/Resource/Detail/TitleBar/__tests__/__snapshots__/index.test.ts.snap +31 -0
- package/components/Resource/Detail/TitleBar/__tests__/index.test.ts +45 -1
- package/components/Resource/Detail/TitleBar/index.vue +1 -1
- package/components/Resource/Detail/ViewOptions/__tests__/__snapshots__/index.test.ts.snap +9 -0
- package/components/Resource/Detail/ViewOptions/__tests__/index.test.ts +62 -0
- package/components/Resource/Detail/ViewOptions/index.vue +2 -1
- package/components/ResourceList/Masthead.vue +25 -2
- package/components/SideNav.vue +13 -0
- package/components/Tabbed/index.vue +6 -0
- package/components/__tests__/ConsumptionGauge.test.ts +31 -0
- package/components/__tests__/PromptModal.test.ts +2 -0
- package/components/fleet/FleetClusters.vue +1 -0
- package/components/fleet/__tests__/FleetClusters.test.ts +71 -0
- package/components/form/NodeScheduling.vue +17 -3
- package/components/form/PrivateRegistry.vue +69 -0
- package/components/form/ProjectMemberEditor.vue +0 -10
- package/components/form/__tests__/PrivateRegistry.test.ts +133 -0
- package/components/formatter/WorkloadHealthScale.vue +3 -1
- package/components/nav/Group.vue +26 -3
- package/components/nav/Header.vue +32 -7
- package/components/nav/TopLevelMenu.helper.ts +7 -79
- package/components/nav/TopLevelMenu.vue +15 -1
- package/components/nav/__tests__/TopLevelMenu.helper.test.ts +2 -53
- package/config/pagination-table-headers.js +8 -1
- package/config/private-label.js +2 -1
- package/config/product/apps.js +3 -1
- package/config/product/auth.js +1 -0
- package/config/product/backup.js +1 -0
- package/config/product/compliance.js +1 -1
- package/config/product/explorer.js +25 -6
- package/config/product/fleet.js +1 -0
- package/config/product/gatekeeper.js +1 -0
- package/config/product/istio.js +1 -0
- package/config/product/logging.js +1 -0
- package/config/product/longhorn.js +2 -1
- package/config/product/manager.js +1 -0
- package/config/product/monitoring.js +1 -0
- package/config/product/navlinks.js +1 -0
- package/config/product/neuvector.js +2 -1
- package/config/product/settings.js +1 -0
- package/config/product/uiplugins.js +1 -0
- package/core/__tests__/extension-manager-impl.test.js +187 -2
- package/core/__tests__/plugin-products-helpers.test.ts +454 -0
- package/core/__tests__/plugin-products.test.ts +3219 -0
- package/core/extension-manager-impl.js +34 -3
- package/core/plugin-helpers.ts +31 -0
- package/core/plugin-products-base.ts +375 -0
- package/core/plugin-products-extending.ts +44 -0
- package/core/plugin-products-helpers.ts +262 -0
- package/core/plugin-products-top-level.ts +66 -0
- package/core/plugin-products-type-guards.ts +33 -0
- package/core/plugin-products.ts +50 -0
- package/core/plugin-types.ts +222 -0
- package/core/plugin.ts +45 -10
- package/core/productDebugger.js +48 -0
- package/core/types.ts +95 -11
- package/detail/__tests__/__snapshots__/fleet.cattle.io.bundle.test.ts.snap +52 -0
- package/detail/__tests__/fleet.cattle.io.bundle.test.ts +171 -0
- package/detail/__tests__/node.test.ts +83 -0
- package/detail/fleet.cattle.io.bundle.vue +21 -34
- package/detail/management.cattle.io.oidcclient.vue +2 -1
- package/detail/node.vue +1 -0
- package/dialog/ExtensionCatalogInstallDialog.vue +1 -1
- package/dialog/InstallExtensionDialog.vue +6 -27
- package/dialog/UninstallExistingExtensionDialog.vue +141 -0
- package/dialog/UninstallExtensionDialog.vue +4 -26
- package/dialog/__tests__/UninstallExistingExtensionDialog.test.ts +114 -0
- package/edit/__tests__/fleet.cattle.io.gitrepo.test.ts +1 -0
- package/edit/catalog.cattle.io.clusterrepo.vue +17 -3
- package/edit/cloudcredential.vue +2 -1
- package/edit/monitoring.coreos.com.alertmanagerconfig/receiverConfig.vue +11 -6
- package/edit/provisioning.cattle.io.cluster/__tests__/Ingress.test.ts +176 -0
- package/edit/provisioning.cattle.io.cluster/index.vue +5 -4
- package/edit/provisioning.cattle.io.cluster/rke2.vue +4 -1
- package/edit/provisioning.cattle.io.cluster/shared.ts +4 -2
- package/edit/provisioning.cattle.io.cluster/tabs/Basics.vue +6 -0
- package/edit/provisioning.cattle.io.cluster/tabs/Ingress.vue +7 -2
- package/edit/secret/generic.vue +1 -0
- package/edit/secret/index.vue +2 -1
- package/edit/service.vue +2 -14
- package/list/management.cattle.io.feature.vue +7 -1
- package/list/provisioning.cattle.io.cluster.vue +0 -50
- package/list/workload.vue +11 -4
- package/mixins/brand.js +2 -1
- package/mixins/resource-fetch.js +12 -3
- package/models/catalog.cattle.io.clusterrepo.js +9 -0
- package/models/cluster.x-k8s.io.machinedeployment.js +8 -3
- package/models/management.cattle.io.authconfig.js +2 -1
- package/models/management.cattle.io.cluster.js +4 -3
- package/models/monitoring.coreos.com.receiver.js +11 -6
- package/models/pod.js +18 -0
- package/models/provisioning.cattle.io.cluster.js +2 -2
- package/models/workload.js +20 -2
- package/package.json +5 -6
- package/pages/c/_cluster/apps/charts/AppChartCardFooter.vue +0 -1
- package/pages/c/_cluster/apps/charts/index.vue +3 -8
- package/pages/c/_cluster/apps/charts/install.vue +8 -9
- package/pages/c/_cluster/istio/index.vue +4 -2
- package/pages/c/_cluster/longhorn/index.vue +2 -1
- package/pages/c/_cluster/monitoring/index.vue +2 -2
- package/pages/c/_cluster/neuvector/index.vue +2 -1
- package/pages/c/_cluster/settings/brand.vue +4 -4
- package/pages/c/_cluster/settings/performance.vue +0 -5
- package/pages/c/_cluster/uiplugins/PluginInfoPanel.vue +2 -1
- package/pages/c/_cluster/uiplugins/__tests__/index.test.ts +231 -13
- package/pages/c/_cluster/uiplugins/index.vue +145 -38
- package/plugins/dashboard-store/__tests__/resource-class.test.ts +1 -0
- package/plugins/dashboard-store/actions.js +3 -2
- package/plugins/dashboard-store/resource-class.js +62 -6
- package/plugins/plugin.js +16 -0
- package/plugins/steve/steve-pagination-utils.ts +8 -2
- package/plugins/steve/subscribe.js +29 -4
- package/rancher-components/RcButton/RcButton.vue +3 -3
- package/rancher-components/RcButtonSplit/RcButtonSplit.test.ts +253 -0
- package/rancher-components/RcButtonSplit/RcButtonSplit.vue +158 -0
- package/rancher-components/RcButtonSplit/index.ts +1 -0
- package/scripts/test-plugins-build.sh +4 -4
- package/scripts/typegen.sh +13 -1
- package/store/__tests__/type-map.test.ts +84 -24
- package/store/type-map.js +42 -3
- package/tsconfig.paths.json +1 -0
- package/types/resources/pod.ts +18 -0
- package/types/shell/index.d.ts +8506 -2908
- package/types/store/dashboard-store.types.ts +5 -0
- package/types/store/pagination.types.ts +6 -0
- package/utils/__tests__/require-asset.test.ts +98 -0
- package/utils/async.ts +1 -5
- package/utils/axios.js +1 -4
- package/utils/brand.ts +3 -1
- package/utils/dynamic-importer.js +3 -2
- package/utils/favicon.js +4 -3
- package/utils/pagination-utils.ts +1 -1
- package/utils/require-asset.ts +95 -0
- package/utils/uiplugins.ts +12 -16
- package/utils/validators/__tests__/private-registry.test.ts +76 -0
- package/utils/validators/private-registry.ts +28 -0
- package/vue.config.js +4 -3
- package/components/HarvesterServiceAddOnConfig.vue +0 -207
|
@@ -1358,7 +1358,35 @@ export default class Resource {
|
|
|
1358
1358
|
return window.$globalApp.$router;
|
|
1359
1359
|
}
|
|
1360
1360
|
|
|
1361
|
+
get isProdRegistrationV2TopLevelProductResoure() {
|
|
1362
|
+
// this is the logic to determine if the resource is top level product or not
|
|
1363
|
+
// changes c-cluster-product-resource to product-c-cluster-resource
|
|
1364
|
+
// this is for the new extension product registration model
|
|
1365
|
+
let currPluginName = '';
|
|
1366
|
+
const plugins = this.$extension.getPlugins();
|
|
1367
|
+
|
|
1368
|
+
Object.keys(plugins).forEach((key) => {
|
|
1369
|
+
if (plugins[key].productNames.includes(this.$rootGetters['productId'])) {
|
|
1370
|
+
currPluginName = key;
|
|
1371
|
+
}
|
|
1372
|
+
});
|
|
1373
|
+
|
|
1374
|
+
// the flag "topLevelProduct" only exists in the V2 product registration model
|
|
1375
|
+
return plugins[currPluginName]?.topLevelProduct || false;
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1361
1378
|
get listLocation() {
|
|
1379
|
+
if (this.isProdRegistrationV2TopLevelProductResoure) {
|
|
1380
|
+
return {
|
|
1381
|
+
name: `${ this.$rootGetters['productId'] }-c-cluster-resource`,
|
|
1382
|
+
params: {
|
|
1383
|
+
product: this.$rootGetters['productId'],
|
|
1384
|
+
cluster: this.$rootGetters['clusterId'],
|
|
1385
|
+
resource: this.type,
|
|
1386
|
+
}
|
|
1387
|
+
};
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1362
1390
|
return {
|
|
1363
1391
|
name: `c-cluster-product-resource`,
|
|
1364
1392
|
params: {
|
|
@@ -1375,6 +1403,20 @@ export default class Resource {
|
|
|
1375
1403
|
|
|
1376
1404
|
const id = this.id?.replace(/.*\//, '');
|
|
1377
1405
|
|
|
1406
|
+
if (this.isProdRegistrationV2TopLevelProductResoure) {
|
|
1407
|
+
return {
|
|
1408
|
+
name: `${ this.$rootGetters['productId'] }-c-cluster-resource${ schema?.attributes?.namespaced ? '-namespace' : '' }-id`,
|
|
1409
|
+
params: {
|
|
1410
|
+
product: this.$rootGetters['productId'],
|
|
1411
|
+
cluster: this.$rootGetters['clusterId'],
|
|
1412
|
+
resource: this.type,
|
|
1413
|
+
namespace: isNamespaced && this.metadata?.namespace ? this.metadata.namespace : undefined,
|
|
1414
|
+
id,
|
|
1415
|
+
}
|
|
1416
|
+
};
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
// normal cluster scoped resource route as we know
|
|
1378
1420
|
return {
|
|
1379
1421
|
name: `c-cluster-product-resource${ schema?.attributes?.namespaced ? '-namespace' : '' }-id`,
|
|
1380
1422
|
params: {
|
|
@@ -1935,6 +1977,25 @@ export default class Resource {
|
|
|
1935
1977
|
|
|
1936
1978
|
get _glance() {
|
|
1937
1979
|
const type = this.parentNameOverride || this.$rootGetters['type-map/labelFor'](this.schema);
|
|
1980
|
+
let toRoute = null;
|
|
1981
|
+
|
|
1982
|
+
if (this.isProdRegistrationV2TopLevelProductResoure) {
|
|
1983
|
+
toRoute = {
|
|
1984
|
+
name: `${ this.$rootGetters['productId'] }-c-cluster-resource-id`,
|
|
1985
|
+
params: {
|
|
1986
|
+
product: this.$rootGetters['currentProduct']?.id,
|
|
1987
|
+
cluster: this.$rootGetters['currentCluster']?.id,
|
|
1988
|
+
resource: this.type,
|
|
1989
|
+
}
|
|
1990
|
+
};
|
|
1991
|
+
} else {
|
|
1992
|
+
toRoute = {
|
|
1993
|
+
name: `c-cluster-product-resource-id`,
|
|
1994
|
+
product: this.$rootGetters['currentProduct']?.id,
|
|
1995
|
+
cluster: this.$rootGetters['currentCluster']?.id,
|
|
1996
|
+
resource: this.type
|
|
1997
|
+
};
|
|
1998
|
+
}
|
|
1938
1999
|
|
|
1939
2000
|
return [
|
|
1940
2001
|
{
|
|
@@ -1958,12 +2019,7 @@ export default class Resource {
|
|
|
1958
2019
|
label: this.t('component.resource.detail.glance.namespace'),
|
|
1959
2020
|
formatter: this.$rootGetters['currentProduct']?.id && this.$rootGetters['currentCluster']?.id ? 'Link' : undefined,
|
|
1960
2021
|
formatterOpts: {
|
|
1961
|
-
to:
|
|
1962
|
-
name: `c-cluster-product-resource-id`,
|
|
1963
|
-
product: this.$rootGetters['currentProduct']?.id,
|
|
1964
|
-
cluster: this.$rootGetters['currentCluster']?.id,
|
|
1965
|
-
resource: this.type
|
|
1966
|
-
},
|
|
2022
|
+
to: toRoute,
|
|
1967
2023
|
row: {},
|
|
1968
2024
|
options: { internal: true }
|
|
1969
2025
|
},
|
package/plugins/plugin.js
CHANGED
|
@@ -3,6 +3,8 @@ import { allHashSettled } from '@shell/utils/promise';
|
|
|
3
3
|
import { shouldNotLoadPlugin, UI_PLUGIN_BASE_URL } from '@shell/config/uiplugins';
|
|
4
4
|
import { getKubeVersionData, getVersionData } from '@shell/config/version';
|
|
5
5
|
import versions from '@shell/utils/versions';
|
|
6
|
+
import { listProducts, loadProduct } from '@shell/utils/dynamic-importer';
|
|
7
|
+
import { Plugin as UIPlugin } from '@shell/core/plugin';
|
|
6
8
|
|
|
7
9
|
export default async function(context) {
|
|
8
10
|
if (process.env.excludeOperatorPkg === 'true') {
|
|
@@ -43,6 +45,20 @@ export default async function(context) {
|
|
|
43
45
|
try {
|
|
44
46
|
const res = await allHashSettled(fetches);
|
|
45
47
|
|
|
48
|
+
// Allow legacy products in shell/config/product to be loaded as if they came from an extension (if migrated to use $init)
|
|
49
|
+
for (const product of listProducts()) {
|
|
50
|
+
const impl = await loadProduct(product);
|
|
51
|
+
|
|
52
|
+
if (impl?.$init) {
|
|
53
|
+
const p = new UIPlugin(product);
|
|
54
|
+
|
|
55
|
+
impl.$init(p);
|
|
56
|
+
|
|
57
|
+
context.$plugin._add(product, p);
|
|
58
|
+
context.$plugin.applyPlugin(p);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
46
62
|
// Initialize the built-in extensions now - this is now done here so that built-in extensions get the same, correct environment data (version etc)
|
|
47
63
|
context.$extension.loadBuiltinExtensions();
|
|
48
64
|
|
|
@@ -23,6 +23,7 @@ import { PaginationSettingsStores } from '@shell/types/resources/settings';
|
|
|
23
23
|
import paginationUtils from '@shell/utils/pagination-utils';
|
|
24
24
|
import { KubeLabelSelector, KubeLabelSelectorExpression } from '@shell/types/kube/kube-api';
|
|
25
25
|
import { parseField } from '@shell/utils/sort';
|
|
26
|
+
import { POD_LAST_RESTART_FIELD, POD_RESTART_FIELD } from '@shell/types/resources/pod';
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* This is a workaround for a ts build issue found in check-plugins-build.
|
|
@@ -240,6 +241,8 @@ class StevePaginationUtils extends NamespaceProjectFilters {
|
|
|
240
241
|
[POD]: [
|
|
241
242
|
{ field: 'spec.containers.image' },
|
|
242
243
|
{ field: 'spec.nodeName' },
|
|
244
|
+
{ field: POD_RESTART_FIELD },
|
|
245
|
+
{ field: POD_LAST_RESTART_FIELD },
|
|
243
246
|
],
|
|
244
247
|
[MANAGEMENT.NODE]: [
|
|
245
248
|
{ field: 'status.nodeName' },
|
|
@@ -514,6 +517,10 @@ class StevePaginationUtils extends NamespaceProjectFilters {
|
|
|
514
517
|
}
|
|
515
518
|
}
|
|
516
519
|
|
|
520
|
+
if (opt.includeAssociatedData) {
|
|
521
|
+
params.push('includeAssociatedData=true');
|
|
522
|
+
}
|
|
523
|
+
|
|
517
524
|
// Note - There is a `limit` property that is by default 100,000. This can be disabled by using `limit=-1`,
|
|
518
525
|
// but we shouldn't be fetching any pages big enough to exceed the default
|
|
519
526
|
|
|
@@ -766,8 +773,7 @@ export const PAGINATION_SETTINGS_STORE_DEFAULTS: PaginationSettingsStores = {
|
|
|
766
773
|
{ resource: CAPI.RANCHER_CLUSTER, context: ['side-bar'] },
|
|
767
774
|
{ resource: MANAGEMENT.CLUSTER, context: ['side-bar'] },
|
|
768
775
|
{ resource: CATALOG.APP, context: ['branding'] },
|
|
769
|
-
SECRET
|
|
770
|
-
CAPI.MACHINE_SET
|
|
776
|
+
SECRET
|
|
771
777
|
],
|
|
772
778
|
generic: false,
|
|
773
779
|
}
|
|
@@ -131,11 +131,17 @@ const isWaitingForDestroy = (storeName, store) => {
|
|
|
131
131
|
};
|
|
132
132
|
|
|
133
133
|
const waitForSettingsSchema = (storeName, store) => {
|
|
134
|
-
return waitFor(
|
|
134
|
+
return waitFor(
|
|
135
|
+
() => isWaitingForDestroy(storeName, store) || !!store.getters['management/byId'](SCHEMA, MANAGEMENT.SETTING),
|
|
136
|
+
'management settings schema to be available'
|
|
137
|
+
);
|
|
135
138
|
};
|
|
136
139
|
|
|
137
140
|
const waitForSettings = (storeName, store) => {
|
|
138
|
-
return waitFor(
|
|
141
|
+
return waitFor(
|
|
142
|
+
() => isWaitingForDestroy(storeName, store) || !!store.getters['management/byId'](MANAGEMENT.SETTING, SETTING.UI_PERFORMANCE),
|
|
143
|
+
'UI performance settings to be available'
|
|
144
|
+
);
|
|
139
145
|
};
|
|
140
146
|
|
|
141
147
|
const isAdvancedWorker = (ctx) => {
|
|
@@ -195,8 +201,20 @@ export async function createWorker(store, ctx) {
|
|
|
195
201
|
};
|
|
196
202
|
}
|
|
197
203
|
|
|
198
|
-
|
|
199
|
-
|
|
204
|
+
try {
|
|
205
|
+
await waitForSettingsSchema(storeName, store);
|
|
206
|
+
await waitForSettings(storeName, store);
|
|
207
|
+
} catch (e) {
|
|
208
|
+
// Clean up the mock worker and abort so callers are not permanently blocked.
|
|
209
|
+
if (store.$workers[storeName]?.destroy) {
|
|
210
|
+
store.$workers[storeName].destroy();
|
|
211
|
+
} else {
|
|
212
|
+
delete store.$workers[storeName];
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
|
|
200
218
|
if (store.$workers[storeName].waitingForDestroy()) {
|
|
201
219
|
store.$workers[storeName].destroy();
|
|
202
220
|
|
|
@@ -382,6 +400,13 @@ const sharedActions = {
|
|
|
382
400
|
if (!this.$workers[getters.storeName]) {
|
|
383
401
|
await createWorker(this, ctx);
|
|
384
402
|
}
|
|
403
|
+
|
|
404
|
+
// createWorker cleans up and returns early when schema/settings are unavailable.
|
|
405
|
+
// Guard against calling postMessage on a non-existent worker.
|
|
406
|
+
if (!this.$workers[getters.storeName]) {
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
|
|
385
410
|
const options = { parseJSON: false };
|
|
386
411
|
const csrf = rootGetters['cookies/get']({ key: CSRF, options });
|
|
387
412
|
|
|
@@ -253,7 +253,7 @@ button {
|
|
|
253
253
|
&.btn-small {
|
|
254
254
|
//:not(.btn-sm) is being used to make the style more specific to override global styles. We may want to get rid of those styles at some point.
|
|
255
255
|
&, &:not(.btn-sm) {
|
|
256
|
-
line-height:
|
|
256
|
+
line-height: 140%;
|
|
257
257
|
font-size: 12px;
|
|
258
258
|
min-height: 24px;
|
|
259
259
|
|
|
@@ -265,7 +265,7 @@ button {
|
|
|
265
265
|
&.btn-medium {
|
|
266
266
|
//:not(.btn-sm) is being used to make the style more specific to override global styles. We may want to get rid of those styles at some point.
|
|
267
267
|
&, &:not(.btn-sm) {
|
|
268
|
-
line-height:
|
|
268
|
+
line-height: 140%;
|
|
269
269
|
font-size: 14px;
|
|
270
270
|
min-height: 32px;
|
|
271
271
|
|
|
@@ -277,7 +277,7 @@ button {
|
|
|
277
277
|
&.btn-large {
|
|
278
278
|
// This is the default size brought by the global button styling
|
|
279
279
|
&, &:not(.btn-sm) {
|
|
280
|
-
line-height:
|
|
280
|
+
line-height: 140%;
|
|
281
281
|
font-size: 16px;
|
|
282
282
|
min-height: 40px;
|
|
283
283
|
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { mount } from '@vue/test-utils';
|
|
2
|
+
import { defineComponent } from 'vue';
|
|
3
|
+
import RcButtonSplit from './RcButtonSplit.vue';
|
|
4
|
+
import { ButtonVariant, ButtonSize } from '@components/RcButton/types';
|
|
5
|
+
|
|
6
|
+
// v-dropdown is provided by floating-vue and must be mocked in unit tests.
|
|
7
|
+
// The default slot is the trigger anchor; the popper slot is the dropdown content.
|
|
8
|
+
const vDropdownMock = defineComponent({
|
|
9
|
+
template: `
|
|
10
|
+
<div>
|
|
11
|
+
<slot />
|
|
12
|
+
<slot name="popper" />
|
|
13
|
+
</div>
|
|
14
|
+
`,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const globalConfig = { global: { components: { 'v-dropdown': vDropdownMock } } };
|
|
18
|
+
|
|
19
|
+
// RcButton and RcDropdownTrigger both use single-root attribute inheritance, so
|
|
20
|
+
// the class added to the component falls through to the rendered <button> element.
|
|
21
|
+
// Selectors like '.rc-button-split-action' refer directly to the <button> element.
|
|
22
|
+
|
|
23
|
+
describe('rcButtonSplit.vue', () => {
|
|
24
|
+
it('renders the main action button', () => {
|
|
25
|
+
const wrapper = mount(RcButtonSplit, globalConfig);
|
|
26
|
+
|
|
27
|
+
expect(wrapper.find('.rc-button-split-action').exists()).toBe(true);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('renders the dropdown trigger', () => {
|
|
31
|
+
const wrapper = mount(RcButtonSplit, globalConfig);
|
|
32
|
+
|
|
33
|
+
expect(wrapper.find('.rc-button-split-trigger').exists()).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('emits click when the main action button is clicked', async() => {
|
|
37
|
+
const wrapper = mount(RcButtonSplit, globalConfig);
|
|
38
|
+
|
|
39
|
+
await wrapper.find('.rc-button-split-action').trigger('click');
|
|
40
|
+
|
|
41
|
+
expect(wrapper.emitted('click')).toHaveLength(1);
|
|
42
|
+
expect(wrapper.emitted('click')![0][0]).toBeInstanceOf(MouseEvent);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('does not emit click when the dropdown trigger is clicked', async() => {
|
|
46
|
+
const wrapper = mount(RcButtonSplit, globalConfig);
|
|
47
|
+
|
|
48
|
+
await wrapper.find('.rc-button-split-trigger').trigger('click');
|
|
49
|
+
|
|
50
|
+
expect(wrapper.emitted('click')).toBeUndefined();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('variant prop', () => {
|
|
54
|
+
it.each([
|
|
55
|
+
['primary', 'variant-primary'],
|
|
56
|
+
['secondary', 'variant-secondary'],
|
|
57
|
+
['tertiary', 'variant-tertiary'],
|
|
58
|
+
] as [ButtonVariant, string][])('applies %s variant class to the action button', (variant, className) => {
|
|
59
|
+
const wrapper = mount(RcButtonSplit, { ...globalConfig, props: { variant } });
|
|
60
|
+
|
|
61
|
+
expect(wrapper.find('.rc-button-split-action').classes()).toContain(className);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it.each([
|
|
65
|
+
['primary', 'variant-primary'],
|
|
66
|
+
['secondary', 'variant-secondary'],
|
|
67
|
+
['tertiary', 'variant-tertiary'],
|
|
68
|
+
] as [ButtonVariant, string][])('applies %s variant class to the dropdown trigger button', (variant, className) => {
|
|
69
|
+
const wrapper = mount(RcButtonSplit, { ...globalConfig, props: { variant } });
|
|
70
|
+
|
|
71
|
+
expect(wrapper.find('.rc-button-split-trigger').classes()).toContain(className);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('size prop', () => {
|
|
76
|
+
it.each([
|
|
77
|
+
['small', 'btn-small'],
|
|
78
|
+
['medium', 'btn-medium'],
|
|
79
|
+
['large', 'btn-large'],
|
|
80
|
+
] as [ButtonSize, string][])('applies %s size class to the action button', (size, className) => {
|
|
81
|
+
const wrapper = mount(RcButtonSplit, { ...globalConfig, props: { size } });
|
|
82
|
+
|
|
83
|
+
expect(wrapper.find('.rc-button-split-action').classes()).toContain(className);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it.each([
|
|
87
|
+
['small', 'btn-small'],
|
|
88
|
+
['medium', 'btn-medium'],
|
|
89
|
+
['large', 'btn-large'],
|
|
90
|
+
] as [ButtonSize, string][])('applies %s size class to the dropdown trigger button', (size, className) => {
|
|
91
|
+
const wrapper = mount(RcButtonSplit, { ...globalConfig, props: { size } });
|
|
92
|
+
|
|
93
|
+
expect(wrapper.find('.rc-button-split-trigger').classes()).toContain(className);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe('slots', () => {
|
|
98
|
+
it('renders default slot content in the main button', () => {
|
|
99
|
+
const wrapper = mount(RcButtonSplit, {
|
|
100
|
+
...globalConfig,
|
|
101
|
+
slots: { default: 'Save' },
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
expect(wrapper.find('.rc-button-split-action').text()).toContain('Save');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('renders before slot content in the main button', () => {
|
|
108
|
+
const wrapper = mount(RcButtonSplit, {
|
|
109
|
+
...globalConfig,
|
|
110
|
+
slots: {
|
|
111
|
+
default: 'Save',
|
|
112
|
+
before: '<span class="before-content">Before</span>',
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
expect(wrapper.find('.rc-button-split-action .before-content').exists()).toBe(true);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('renders after slot content in the main button', () => {
|
|
120
|
+
const wrapper = mount(RcButtonSplit, {
|
|
121
|
+
...globalConfig,
|
|
122
|
+
slots: {
|
|
123
|
+
default: 'Save',
|
|
124
|
+
after: '<span class="after-content">After</span>',
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
expect(wrapper.find('.rc-button-split-action .after-content').exists()).toBe(true);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('renders dropdownCollection slot content', () => {
|
|
132
|
+
const wrapper = mount(RcButtonSplit, {
|
|
133
|
+
...globalConfig,
|
|
134
|
+
slots: { dropdownCollection: '<div class="dropdown-item-test">Item 1</div>' },
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
expect(wrapper.find('.dropdown-item-test').exists()).toBe(true);
|
|
138
|
+
expect(wrapper.find('.dropdown-item-test').text()).toStrictEqual('Item 1');
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('dropdown trigger has aria-haspopup="menu" attribute', () => {
|
|
143
|
+
const wrapper = mount(RcButtonSplit, globalConfig);
|
|
144
|
+
|
|
145
|
+
expect(wrapper.find('.rc-button-split-trigger').attributes('aria-haspopup')).toBe('menu');
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('emits update:open when dropdown open state changes', async() => {
|
|
149
|
+
const wrapper = mount(RcButtonSplit, globalConfig);
|
|
150
|
+
|
|
151
|
+
await wrapper.findComponent({ name: 'RcDropdown' }).vm.$emit('update:open', true);
|
|
152
|
+
|
|
153
|
+
expect(wrapper.emitted('update:open')).toHaveLength(1);
|
|
154
|
+
expect(wrapper.emitted('update:open')![0]).toStrictEqual([true]);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('applies default variant "primary" when no variant is provided', () => {
|
|
158
|
+
const wrapper = mount(RcButtonSplit, globalConfig);
|
|
159
|
+
|
|
160
|
+
expect(wrapper.find('.rc-button-split-action').classes()).toContain('variant-primary');
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('applies default size "medium" when no size is provided', () => {
|
|
164
|
+
const wrapper = mount(RcButtonSplit, globalConfig);
|
|
165
|
+
|
|
166
|
+
expect(wrapper.find('.rc-button-split-action').classes()).toContain('btn-medium');
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe('aria label props', () => {
|
|
170
|
+
it('ariaLabel is applied to the action button', () => {
|
|
171
|
+
const wrapper = mount(RcButtonSplit, { ...globalConfig, props: { ariaLabel: 'Save document' } });
|
|
172
|
+
|
|
173
|
+
expect(wrapper.find('.rc-button-split-action').attributes('aria-label')).toBe('Save document');
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('ariaLabel is absent from the trigger button', () => {
|
|
177
|
+
const wrapper = mount(RcButtonSplit, { ...globalConfig, props: { ariaLabel: 'Save document' } });
|
|
178
|
+
|
|
179
|
+
expect(wrapper.find('.rc-button-split-trigger').attributes('aria-label')).toBeUndefined();
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('ariaLabelTrigger is applied to the trigger button', () => {
|
|
183
|
+
const wrapper = mount(RcButtonSplit, { ...globalConfig, props: { ariaLabelTrigger: 'More save options' } });
|
|
184
|
+
|
|
185
|
+
expect(wrapper.find('.rc-button-split-trigger').attributes('aria-label')).toBe('More save options');
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('ariaLabelTrigger is absent from the action button', () => {
|
|
189
|
+
const wrapper = mount(RcButtonSplit, { ...globalConfig, props: { ariaLabelTrigger: 'More save options' } });
|
|
190
|
+
|
|
191
|
+
expect(wrapper.find('.rc-button-split-action').attributes('aria-label')).toBeUndefined();
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('ariaLabelDropdown is forwarded to RcDropdown', () => {
|
|
195
|
+
const wrapper = mount(RcButtonSplit, { ...globalConfig, props: { ariaLabelDropdown: 'Save actions' } });
|
|
196
|
+
|
|
197
|
+
expect(wrapper.findComponent({ name: 'RcDropdown' }).props('ariaLabel')).toBe('Save actions');
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
describe('items prop', () => {
|
|
202
|
+
const items = [
|
|
203
|
+
{ id: 'draft', label: 'Save as Draft' },
|
|
204
|
+
{ id: 'template', label: 'Save as Template' },
|
|
205
|
+
{ id: 'discard', label: 'Discard Changes' },
|
|
206
|
+
];
|
|
207
|
+
|
|
208
|
+
it('renders an RcDropdownItem for each entry in items', () => {
|
|
209
|
+
const wrapper = mount(RcButtonSplit, { ...globalConfig, props: { items } });
|
|
210
|
+
|
|
211
|
+
const dropdownItems = wrapper.findAllComponents({ name: 'RcDropdownItem' });
|
|
212
|
+
|
|
213
|
+
expect(dropdownItems).toHaveLength(3);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('renders each item\'s label text', () => {
|
|
217
|
+
const wrapper = mount(RcButtonSplit, { ...globalConfig, props: { items } });
|
|
218
|
+
|
|
219
|
+
const dropdownItems = wrapper.findAllComponents({ name: 'RcDropdownItem' });
|
|
220
|
+
|
|
221
|
+
expect(dropdownItems[0].text()).toContain('Save as Draft');
|
|
222
|
+
expect(dropdownItems[1].text()).toContain('Save as Template');
|
|
223
|
+
expect(dropdownItems[2].text()).toContain('Discard Changes');
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('emits select with the item id when a prop item is clicked', async() => {
|
|
227
|
+
const wrapper = mount(RcButtonSplit, { ...globalConfig, props: { items } });
|
|
228
|
+
|
|
229
|
+
await wrapper.findAllComponents({ name: 'RcDropdownItem' })[0].trigger('click');
|
|
230
|
+
|
|
231
|
+
expect(wrapper.emitted('select')).toHaveLength(1);
|
|
232
|
+
expect(wrapper.emitted('select')![0]).toStrictEqual(['draft']);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('does not emit select when no items prop is provided', async() => {
|
|
236
|
+
const wrapper = mount(RcButtonSplit, globalConfig);
|
|
237
|
+
|
|
238
|
+
expect(wrapper.emitted('select')).toBeUndefined();
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it('renders both prop items and dropdownCollection slot content when both are supplied', () => {
|
|
242
|
+
const wrapper = mount(RcButtonSplit, {
|
|
243
|
+
...globalConfig,
|
|
244
|
+
props: { items: [{ id: 'draft', label: 'Save as Draft' }] },
|
|
245
|
+
slots: { dropdownCollection: '<div class="slot-item">Slot Item</div>' },
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
expect(wrapper.findAllComponents({ name: 'RcDropdownItem' })).toHaveLength(1);
|
|
249
|
+
expect(wrapper.find('.slot-item').exists()).toBe(true);
|
|
250
|
+
expect(wrapper.find('.slot-item').text()).toStrictEqual('Slot Item');
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
});
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* A split button that combines a primary action button with a dropdown trigger
|
|
4
|
+
* for secondary actions.
|
|
5
|
+
*
|
|
6
|
+
* Example:
|
|
7
|
+
*
|
|
8
|
+
* <rc-button-split variant="primary" @click="doAction" @update:open="onOpen">
|
|
9
|
+
* Save
|
|
10
|
+
* <template #dropdownCollection>
|
|
11
|
+
* <rc-dropdown-item @click="doOtherAction">Save as Draft</rc-dropdown-item>
|
|
12
|
+
* </template>
|
|
13
|
+
* </rc-button-split>
|
|
14
|
+
*/
|
|
15
|
+
import { RcButton } from '@components/RcButton';
|
|
16
|
+
import { RcDropdown, RcDropdownItem, RcDropdownTrigger } from '@components/RcDropdown';
|
|
17
|
+
import RcIcon from '@components/RcIcon/RcIcon.vue';
|
|
18
|
+
import { ButtonVariant, ButtonSize, IconProps } from '@components/RcButton/types';
|
|
19
|
+
import type { Placement } from 'floating-vue';
|
|
20
|
+
|
|
21
|
+
type RcButtonSplitVariant = Exclude<ButtonVariant, 'link' | 'ghost' | 'multiAction'>;
|
|
22
|
+
|
|
23
|
+
type RcButtonSplitItem = {
|
|
24
|
+
id: string;
|
|
25
|
+
label: string;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
type RcButtonSplitProps = {
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
variant?: RcButtonSplitVariant;
|
|
31
|
+
size?: ButtonSize;
|
|
32
|
+
ariaLabel?: string;
|
|
33
|
+
ariaLabelTrigger?: string;
|
|
34
|
+
ariaLabelDropdown?: string;
|
|
35
|
+
placement?: Placement;
|
|
36
|
+
distance?: number;
|
|
37
|
+
items?: RcButtonSplitItem[];
|
|
38
|
+
} & IconProps;
|
|
39
|
+
|
|
40
|
+
withDefaults(
|
|
41
|
+
defineProps<RcButtonSplitProps>(),
|
|
42
|
+
{
|
|
43
|
+
disabled: false,
|
|
44
|
+
variant: 'primary',
|
|
45
|
+
size: 'medium',
|
|
46
|
+
ariaLabel: undefined,
|
|
47
|
+
ariaLabelTrigger: undefined,
|
|
48
|
+
ariaLabelDropdown: undefined,
|
|
49
|
+
placement: 'bottom-end',
|
|
50
|
+
distance: undefined,
|
|
51
|
+
items: undefined,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const emit = defineEmits<{
|
|
55
|
+
click: [event: MouseEvent];
|
|
56
|
+
'update:open': [open: boolean];
|
|
57
|
+
select: [id: string];
|
|
58
|
+
}>();
|
|
59
|
+
</script>
|
|
60
|
+
|
|
61
|
+
<template>
|
|
62
|
+
<RcDropdown
|
|
63
|
+
:aria-label="ariaLabelDropdown"
|
|
64
|
+
:placement="placement"
|
|
65
|
+
:distance="distance"
|
|
66
|
+
@update:open="emit('update:open', $event)"
|
|
67
|
+
>
|
|
68
|
+
<div class="rc-button-split">
|
|
69
|
+
<RcButton
|
|
70
|
+
class="rc-button-split-action"
|
|
71
|
+
:aria-label="ariaLabel"
|
|
72
|
+
:disabled="disabled"
|
|
73
|
+
:variant="variant"
|
|
74
|
+
:size="size"
|
|
75
|
+
:left-icon="leftIcon"
|
|
76
|
+
:right-icon="rightIcon"
|
|
77
|
+
@click="emit('click', $event)"
|
|
78
|
+
>
|
|
79
|
+
<template
|
|
80
|
+
v-if="$slots.before"
|
|
81
|
+
#before
|
|
82
|
+
>
|
|
83
|
+
<slot name="before" />
|
|
84
|
+
</template>
|
|
85
|
+
<slot />
|
|
86
|
+
<template
|
|
87
|
+
v-if="$slots.after"
|
|
88
|
+
#after
|
|
89
|
+
>
|
|
90
|
+
<slot name="after" />
|
|
91
|
+
</template>
|
|
92
|
+
</RcButton>
|
|
93
|
+
|
|
94
|
+
<RcDropdownTrigger
|
|
95
|
+
class="rc-button-split-trigger"
|
|
96
|
+
:aria-label="ariaLabelTrigger"
|
|
97
|
+
:disabled="disabled"
|
|
98
|
+
:variant="variant"
|
|
99
|
+
:size="size"
|
|
100
|
+
>
|
|
101
|
+
<RcIcon
|
|
102
|
+
type="chevron-down"
|
|
103
|
+
size="inherit"
|
|
104
|
+
/>
|
|
105
|
+
</RcDropdownTrigger>
|
|
106
|
+
</div>
|
|
107
|
+
|
|
108
|
+
<template #dropdownCollection>
|
|
109
|
+
<RcDropdownItem
|
|
110
|
+
v-for="item in items"
|
|
111
|
+
:key="item.id"
|
|
112
|
+
@click="emit('select', item.id)"
|
|
113
|
+
>
|
|
114
|
+
{{ item.label }}
|
|
115
|
+
</RcDropdownItem>
|
|
116
|
+
<slot name="dropdownCollection" />
|
|
117
|
+
</template>
|
|
118
|
+
</RcDropdown>
|
|
119
|
+
</template>
|
|
120
|
+
|
|
121
|
+
<style lang="scss" scoped>
|
|
122
|
+
.rc-button-split {
|
|
123
|
+
display: inline-flex;
|
|
124
|
+
|
|
125
|
+
// Round only the outer left edge of the main button
|
|
126
|
+
:deep(.rc-button-split-action) {
|
|
127
|
+
border-top-right-radius: 0;
|
|
128
|
+
border-bottom-right-radius: 0;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Round only the outer right edge of the trigger button; narrow padding
|
|
132
|
+
:deep(button.rc-button-split-trigger) {
|
|
133
|
+
border-top-left-radius: 0;
|
|
134
|
+
border-bottom-left-radius: 0;
|
|
135
|
+
padding-left: 8px;
|
|
136
|
+
padding-right: 8px;
|
|
137
|
+
min-width: unset;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
:deep(button.btn-small.rc-button-split-trigger) {
|
|
141
|
+
padding-left: 4px;
|
|
142
|
+
padding-right: 4px;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Primary: semi-transparent right border as separator
|
|
146
|
+
:deep(.rc-button-split-trigger.variant-primary),
|
|
147
|
+
:deep(.rc-button-split-trigger.variant-secondary),
|
|
148
|
+
:deep(.rc-button-split-trigger.variant-tertiary) {
|
|
149
|
+
border-left: 1px solid rgba(255, 255, 255, 0.3);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Link/Ghost: subtle separator
|
|
153
|
+
:deep(.rc-button-split-action.variant-link),
|
|
154
|
+
:deep(.rc-button-split-action.variant-ghost) {
|
|
155
|
+
border-right: 1px solid var(--border);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
</style>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as RcButtonSplit } from './RcButtonSplit.vue';
|