mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2026-11-15 13:26:15 +08:00
chore(deps): bump @rancher/shell to 3.0.14 (#1208)
* chore(deps): bump @rancher/shell to 3.0.14 3.0.14 resolves [[name]] tokens in translations from values registered as l10n globals, which the standalone UI needs to pick the product name. Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com> * fix: save cloud-config template edits with @rancher/shell 3.0.14 The YamlEditor of shell 3.0.14 no longer emits onChanges, so editing a template saved its old cloud config. Copy the text from update:value, which both shell versions emit. Jest transforms @replit/codemirror-vim-core, an ESM-only dependency of the new YamlEditor, like the dashboard does. Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com> * fix: keep the YAML editor heights with CodeMirror 6 The min-height rules targeted the CodeMirror 5 element, so the editors shrank to their text. Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com> * fix: reject IP ranges the network settings don't support The CIDR check of @rancher/shell 3.0.14 also accepts short forms such as 10.1/16, extra parts and IPv6, so the VM migration, RWX and storage network settings saved them. Use a strict IPv4 CIDR check of our own. Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com> * fix: keep the look of the file selector buttons The FileSelector of @rancher/shell 3.0.14 no longer takes button classes and renders a medium secondary button. Pass the variant and size that match the previous primary and secondary buttons. Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com> * fix: keep Enter in a migration wizard field on the same step The Wizard of @rancher/shell 3.0.14 renders its step headers as submit buttons, so Enter in a text field clicked the first one and jumped back to step 1. Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com> * fix: show the created message after a restore, upgrade or upload Since @rancher/shell 3.0.14, save() no longer shows the message for resources with a generated name; callers show it with notifyGeneratedName(). Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com> * refactor: fold the logging output buffer with the CodeMirror 6 helpers The YAML editor of @rancher/shell 3.0.14 is CodeMirror 6, and its CodeMirror 5 methods are deprecated. Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com> * fix: keep the shell's table views off in standalone @rancher/shell 3.0.14 turns its table views on for every list in the standalone UI, as the server has no ui-configurable-tables feature and the default is on. The table views drop the filters the lists put in the table header, which also left the Images list empty. Add the feature, disabled, to the management store in standalone only. Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com> * fix: reject zero-padded octets in IP ranges Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com> --------- Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com>
This commit is contained in:
@@ -128,6 +128,7 @@ export default {
|
||||
|
||||
try {
|
||||
await proxyResource.save();
|
||||
proxyResource.notifyGeneratedName?.();
|
||||
|
||||
this.cancel();
|
||||
} catch (err) {
|
||||
|
||||
@@ -19,7 +19,8 @@ export default {
|
||||
<div class="row mb-20">
|
||||
<div class="col span-12">
|
||||
<FileSelector
|
||||
class="btn btn-sm bg-primary mb-10"
|
||||
variant="primary"
|
||||
class="mb-10"
|
||||
:label="t('generic.readFromFile')"
|
||||
@selected="onKeySelected"
|
||||
/>
|
||||
|
||||
@@ -191,7 +191,8 @@ export default {
|
||||
>
|
||||
<div class="col span-12">
|
||||
<FileSelector
|
||||
class="btn btn-sm bg-primary mb-10"
|
||||
variant="primary"
|
||||
class="mb-10"
|
||||
:label="t('generic.readFromFile')"
|
||||
@selected="onKeySelected"
|
||||
/>
|
||||
@@ -213,9 +214,7 @@ $yaml-height: 540px;
|
||||
:deep() .yaml-editor{
|
||||
flex: 1;
|
||||
min-height: $yaml-height;
|
||||
& .code-mirror .CodeMirror {
|
||||
position: initial;
|
||||
height: auto;
|
||||
& .code-mirror .cm-editor {
|
||||
min-height: $yaml-height;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { LabeledInput } from '@components/Form/LabeledInput';
|
||||
import LabeledSelect from '@shell/components/form/LabeledSelect.vue';
|
||||
import { RadioGroup } from '@components/Form/Radio';
|
||||
import ArrayList from '@shell/components/form/ArrayList';
|
||||
import { isValidCIDR } from '@shell/utils/validators/cidr';
|
||||
import { isValidCIDR } from '@pkg/harvester/utils/regular';
|
||||
import { _EDIT } from '@shell/config/query-params';
|
||||
import { Banner } from '@components/Banner';
|
||||
import { allHash } from '@shell/utils/promise';
|
||||
|
||||
@@ -62,7 +62,8 @@ export default {
|
||||
<div class="chooseFile">
|
||||
<FileSelector
|
||||
:include-file-name="true"
|
||||
class="btn btn-sm bg-primary mr-20"
|
||||
variant="primary"
|
||||
class="mr-20"
|
||||
label="Choose File"
|
||||
@selected="onKeySelectedCa('publicCertificate', $event)"
|
||||
/>
|
||||
@@ -80,7 +81,8 @@ export default {
|
||||
<div class="chooseFile">
|
||||
<FileSelector
|
||||
:include-file-name="true"
|
||||
class="btn btn-sm bg-primary mr-20"
|
||||
variant="primary"
|
||||
class="mr-20"
|
||||
label="Choose File"
|
||||
@selected="onKeySelectedCa('privateKey', $event)"
|
||||
/>
|
||||
@@ -98,7 +100,8 @@ export default {
|
||||
<div class="chooseFile">
|
||||
<FileSelector
|
||||
:include-file-name="true"
|
||||
class="btn btn-sm bg-primary mr-20"
|
||||
variant="primary"
|
||||
class="mr-20"
|
||||
label="Choose File"
|
||||
@selected="onKeySelectedCa('ca', $event)"
|
||||
/>
|
||||
|
||||
@@ -3,7 +3,7 @@ import { LabeledInput } from '@components/Form/LabeledInput';
|
||||
import LabeledSelect from '@shell/components/form/LabeledSelect.vue';
|
||||
import { RadioGroup } from '@components/Form/Radio';
|
||||
import ArrayList from '@shell/components/form/ArrayList';
|
||||
import { isValidCIDR } from '@shell/utils/validators/cidr';
|
||||
import { isValidCIDR } from '@pkg/harvester/utils/regular';
|
||||
import { _EDIT } from '@shell/config/query-params';
|
||||
import { Banner } from '@components/Banner';
|
||||
import Tip from '@shell/components/Tip';
|
||||
|
||||
@@ -5,7 +5,7 @@ import { RadioGroup } from '@components/Form/Radio';
|
||||
import { Banner } from '@components/Banner';
|
||||
import ArrayList from '@shell/components/form/ArrayList';
|
||||
import { allHash } from '@shell/utils/promise';
|
||||
import { isValidCIDR } from '@shell/utils/validators/cidr';
|
||||
import { isValidCIDR } from '@pkg/harvester/utils/regular';
|
||||
import { NODE } from '@shell/config/types';
|
||||
import { _EDIT } from '@shell/config/query-params';
|
||||
import { HCI } from '../../types';
|
||||
|
||||
@@ -59,6 +59,8 @@ import { ADD_ONS } from './harvester-map';
|
||||
import { registerAddonSideNav } from '../utils/dynamic-nav';
|
||||
import { setVendor } from '@shell/config/private-label';
|
||||
import { createCssVars } from '@shell/utils/color';
|
||||
import { CONFIGURABLE_TABLES } from '@shell/store/features';
|
||||
import { tableViewsOffFeature } from '../utils/table-views';
|
||||
|
||||
const TEMPLATE = HCI.VM_VERSION;
|
||||
const MONITORING_GROUP = 'Monitoring & Logging::Monitoring';
|
||||
@@ -156,6 +158,17 @@ export function init($plugin, store) {
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
// Keep the shell's table views off: they drop the filters the lists put in the table header
|
||||
store.watch(
|
||||
(_state, getters) => getters['management/byId'](MANAGEMENT.FEATURE, CONFIGURABLE_TABLES),
|
||||
(feature) => {
|
||||
if (!feature) {
|
||||
store.dispatch('management/load', { data: tableViewsOffFeature() });
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
}
|
||||
|
||||
product({
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
import { mount } from '@vue/test-utils';
|
||||
import { _CREATE, _EDIT, _VIEW } from '@shell/config/query-params';
|
||||
import YamlEditor from '@shell/components/YamlEditor';
|
||||
import { HCI } from '@pkg/harvester/config/labels-annotations';
|
||||
import HarvesterEditCloudTemplate from '../harvesterhci.io.cloudtemplate.vue';
|
||||
|
||||
const OLD_CONFIG = '#cloud-config\npassword: old\n';
|
||||
const NEW_CONFIG = '#cloud-config\npassword: new\n';
|
||||
|
||||
// A cloud-config template as the store gives it, `save` records what would be sent to the API
|
||||
function cloudTemplate({ isNew = false } = {}) {
|
||||
const value = {
|
||||
type: 'configmap',
|
||||
metadata: {
|
||||
name: 'tpl',
|
||||
namespace: 'default',
|
||||
...(isNew ? {} : { labels: { [HCI.CLOUD_INIT]: 'user' } }),
|
||||
},
|
||||
data: isNew ? undefined : { cloudInit: OLD_CONFIG },
|
||||
$dispatch: jest.fn(),
|
||||
save: () => Promise.resolve(),
|
||||
saved: [],
|
||||
};
|
||||
|
||||
jest.spyOn(value, 'save').mockImplementation(() => {
|
||||
value.saved.push(JSON.parse(JSON.stringify({ metadata: value.metadata, data: value.data })));
|
||||
|
||||
return Promise.resolve();
|
||||
});
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
// The real shell YamlEditor, with only its CodeMirror editor stubbed, so the events the form listens to are the
|
||||
// ones the shell emits
|
||||
function mountForm(mode, value) {
|
||||
return mount(HarvesterEditCloudTemplate, {
|
||||
props: { value, mode },
|
||||
global: {
|
||||
stubs: {
|
||||
CruResource: { template: '<div><slot /></div>' },
|
||||
Tabbed: { template: '<div><slot /></div>' },
|
||||
Tab: { template: '<div><slot /></div>' },
|
||||
NameNsDescription: true,
|
||||
LabeledSelect: true,
|
||||
CodeMirror: {
|
||||
name: 'CodeMirror', template: '<div />', emits: ['onInput', 'onReady', 'validationChanged']
|
||||
},
|
||||
FileDiff: true,
|
||||
},
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'prefs/get': jest.fn(),
|
||||
'type-map/isSpoofed': () => false,
|
||||
currentStore: () => 'harvester',
|
||||
'harvester/schemaFor': () => ({ linkFor: () => '/v1/harvester/configmaps' }),
|
||||
'i18n/t': (key) => key,
|
||||
},
|
||||
},
|
||||
$router: { replace: jest.fn() },
|
||||
$route: {
|
||||
name: 'c-cluster-product-resource-id', params: {}, query: {}
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// What a user typing in the editor does: CodeMirror reports the new text to the YamlEditor
|
||||
async function typeInEditor(wrapper, text) {
|
||||
wrapper.findComponent(YamlEditor).findComponent({ name: 'CodeMirror' }).vm.$emit('onInput', text);
|
||||
await wrapper.vm.$nextTick();
|
||||
}
|
||||
|
||||
describe('component: HarvesterEditCloudTemplate', () => {
|
||||
it('should save the edited cloud config when editing a template', async() => {
|
||||
const value = cloudTemplate();
|
||||
const wrapper = mountForm(_EDIT, value);
|
||||
|
||||
await typeInEditor(wrapper, NEW_CONFIG);
|
||||
await wrapper.vm.save(jest.fn());
|
||||
|
||||
expect(value.save).toHaveBeenCalledTimes(1);
|
||||
expect(value.saved[0].data).toStrictEqual({ cloudInit: NEW_CONFIG });
|
||||
});
|
||||
|
||||
it('should keep the template type label when editing a template', async() => {
|
||||
const value = cloudTemplate();
|
||||
const wrapper = mountForm(_EDIT, value);
|
||||
|
||||
await typeInEditor(wrapper, NEW_CONFIG);
|
||||
await wrapper.vm.save(jest.fn());
|
||||
|
||||
expect(value.saved[0].metadata.labels).toStrictEqual({ [HCI.CLOUD_INIT]: 'user' });
|
||||
});
|
||||
|
||||
it('should save the last text when the cloud config is edited several times', async() => {
|
||||
const value = cloudTemplate();
|
||||
const wrapper = mountForm(_EDIT, value);
|
||||
|
||||
await typeInEditor(wrapper, '#cloud-config\n');
|
||||
await typeInEditor(wrapper, NEW_CONFIG);
|
||||
await wrapper.vm.save(jest.fn());
|
||||
|
||||
expect(value.saved[0].data).toStrictEqual({ cloudInit: NEW_CONFIG });
|
||||
});
|
||||
|
||||
it('should save the cloud config unchanged when only saving a template', async() => {
|
||||
const value = cloudTemplate();
|
||||
const wrapper = mountForm(_EDIT, value);
|
||||
|
||||
await wrapper.vm.save(jest.fn());
|
||||
|
||||
expect(value.saved[0].data).toStrictEqual({ cloudInit: OLD_CONFIG });
|
||||
});
|
||||
|
||||
it('should save the cloud config and the template type when creating a template', async() => {
|
||||
const value = cloudTemplate({ isNew: true });
|
||||
const wrapper = mountForm(_CREATE, value);
|
||||
|
||||
await typeInEditor(wrapper, NEW_CONFIG);
|
||||
await wrapper.vm.save(jest.fn());
|
||||
|
||||
expect(value.save).toHaveBeenCalledWith({ url: '/v1/harvester/configmaps' });
|
||||
expect(value.saved[0]).toStrictEqual({
|
||||
metadata: {
|
||||
name: 'tpl', namespace: 'default', labels: { [HCI.CLOUD_INIT]: 'user' }
|
||||
},
|
||||
data: { cloudInit: NEW_CONFIG },
|
||||
});
|
||||
});
|
||||
|
||||
it('should show the template cloud config in the editor when viewing a template', () => {
|
||||
const value = cloudTemplate();
|
||||
const wrapper = mountForm(_VIEW, value);
|
||||
|
||||
expect(wrapper.findComponent(YamlEditor).props('value')).toBe(OLD_CONFIG);
|
||||
expect(value.data).toStrictEqual({ cloudInit: OLD_CONFIG });
|
||||
});
|
||||
});
|
||||
@@ -59,8 +59,8 @@ export default {
|
||||
},
|
||||
|
||||
methods: {
|
||||
update() {
|
||||
this.value.data = { cloudInit: this.config };
|
||||
update(config) {
|
||||
this.value.data = { cloudInit: config };
|
||||
},
|
||||
|
||||
updateBeforeSave() {
|
||||
@@ -119,7 +119,7 @@ export default {
|
||||
:mode="mode"
|
||||
class="yaml-editor"
|
||||
:editor-mode="mode === 'view' ? 'VIEW_CODE' : 'EDIT_CODE'"
|
||||
@onChanges="update"
|
||||
@update:value="update"
|
||||
/>
|
||||
</div>
|
||||
</Tab>
|
||||
@@ -133,9 +133,7 @@ export default {
|
||||
:deep() .yaml-editor{
|
||||
flex: 1;
|
||||
min-height: $yaml-height;
|
||||
& .code-mirror .CodeMirror {
|
||||
position: initial;
|
||||
height: auto;
|
||||
& .code-mirror .cm-editor {
|
||||
min-height: $yaml-height;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,8 @@ export default {
|
||||
<div class="header mb-20">
|
||||
<FileSelector
|
||||
v-if="isCreate"
|
||||
class="btn btn-sm bg-primary mt-10"
|
||||
variant="primary"
|
||||
class="mt-10"
|
||||
:label="t('generic.readFromFile')"
|
||||
accept=".pub"
|
||||
@selected="onKeySelected"
|
||||
|
||||
@@ -16,6 +16,8 @@ import isEmpty from 'lodash/isEmpty';
|
||||
import jsyaml from 'js-yaml';
|
||||
import { createYaml } from '@shell/utils/create-yaml';
|
||||
import YamlEditor, { EDITOR_MODES } from '@shell/components/YamlEditor';
|
||||
import { foldAllComments } from '@components/RcCodeMirror';
|
||||
import { unfoldCode } from '@codemirror/language';
|
||||
import { FLOW_TYPE } from '../config/harvester-map';
|
||||
|
||||
const LOGGING_EVENT = 'Logging/Event';
|
||||
@@ -172,10 +174,9 @@ export default {
|
||||
});
|
||||
}
|
||||
},
|
||||
onYamlEditorReady(cm) {
|
||||
cm.getMode().fold = 'yamlcomments';
|
||||
cm.execCommand('foldAll');
|
||||
cm.execCommand('unfold');
|
||||
onYamlEditorReady(view) {
|
||||
foldAllComments(view);
|
||||
unfoldCode(view);
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
@@ -173,6 +173,7 @@ export default {
|
||||
|
||||
try {
|
||||
await proxyResource.save();
|
||||
proxyResource.notifyGeneratedName?.();
|
||||
buttonCb(true);
|
||||
|
||||
this.$router.push({
|
||||
|
||||
@@ -299,6 +299,7 @@ export default {
|
||||
|
||||
const res = await this.value.save();
|
||||
|
||||
res.notifyGeneratedName?.();
|
||||
res.uploadImage(file);
|
||||
|
||||
buttonCb(true);
|
||||
|
||||
@@ -172,6 +172,7 @@ export default {
|
||||
|
||||
try {
|
||||
await proxyResource.save();
|
||||
proxyResource.notifyGeneratedName?.();
|
||||
buttonCb(true);
|
||||
|
||||
this.$router.push({
|
||||
|
||||
+1
-1
@@ -157,7 +157,7 @@ $yaml-height: 200px;
|
||||
flex: 1;
|
||||
min-height: $yaml-height;
|
||||
|
||||
& .code-mirror .CodeMirror {
|
||||
& .code-mirror .cm-editor {
|
||||
min-height: $yaml-height;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,7 +289,7 @@ $yaml-height: 350px;
|
||||
flex: 1;
|
||||
min-height: $yaml-height;
|
||||
|
||||
& .code-mirror .CodeMirror {
|
||||
& .code-mirror .cm-editor {
|
||||
min-height: $yaml-height;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -333,7 +333,7 @@ $xml-height: 350px;
|
||||
min-height: $xml-height;
|
||||
font-family: monospace;
|
||||
|
||||
& .code-mirror .CodeMirror {
|
||||
& .code-mirror .cm-editor {
|
||||
min-height: $xml-height;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,6 +232,7 @@ export default {
|
||||
this.imageValue.spec.targetStorageClassName = 'longhorn-static';
|
||||
|
||||
res = await this.imageValue.save();
|
||||
res.notifyGeneratedName?.();
|
||||
|
||||
this.value.spec.image = res.id;
|
||||
}
|
||||
@@ -253,6 +254,7 @@ export default {
|
||||
this.value.metadata.annotations = { [HCI_ANNOTATIONS.SKIP_SINGLE_REPLICA_DETACHED_VOL]: JSON.stringify(this.skipSingleReplicaDetachedVol) };
|
||||
}
|
||||
await this.value.save();
|
||||
this.value.notifyGeneratedName?.();
|
||||
this.done();
|
||||
buttonCb(true);
|
||||
} catch (e) {
|
||||
@@ -290,6 +292,7 @@ export default {
|
||||
|
||||
const res = await this.imageValue.save();
|
||||
|
||||
res.notifyGeneratedName?.();
|
||||
this.uploadImageId = res.id;
|
||||
this.uploadController = new AbortController();
|
||||
|
||||
|
||||
@@ -210,7 +210,8 @@ export default {
|
||||
<FileSelector
|
||||
:byte-limit="20000"
|
||||
:read-as-data-url="true"
|
||||
class="role-secondary"
|
||||
variant="secondary"
|
||||
size="large"
|
||||
:label="t('branding.logos.uploadLight')"
|
||||
:mode="mode"
|
||||
@error="setError"
|
||||
@@ -233,7 +234,8 @@ export default {
|
||||
<FileSelector
|
||||
:byte-limit="20000"
|
||||
:read-as-data-url="true"
|
||||
class="role-secondary"
|
||||
variant="secondary"
|
||||
size="large"
|
||||
:label="t('branding.logos.uploadDark')"
|
||||
:mode="mode"
|
||||
@error="setError"
|
||||
@@ -274,7 +276,8 @@ export default {
|
||||
<FileSelector
|
||||
:byte-limit="20000"
|
||||
:read-as-data-url="true"
|
||||
class="role-secondary"
|
||||
variant="secondary"
|
||||
size="large"
|
||||
:label="t('branding.favicon.upload')"
|
||||
:mode="mode"
|
||||
@error="setError"
|
||||
|
||||
@@ -12,6 +12,7 @@ import { PRODUCT_NAME } from '@pkg/harvester/config/harvester';
|
||||
import { currentRouter, currentRoute } from '@pkg/harvester/utils/router';
|
||||
import { decodeSecretValue } from '@pkg/harvester/utils/forklift';
|
||||
import { HCI } from '@pkg/harvester/types';
|
||||
import { preventImplicitSubmit } from '@pkg/harvester/utils/wizard';
|
||||
|
||||
const store = useStore();
|
||||
const route = currentRoute();
|
||||
@@ -258,6 +259,7 @@ init();
|
||||
:title="wizardTitle"
|
||||
finish-mode="finish"
|
||||
class="wizard"
|
||||
@keydown.enter.capture="preventImplicitSubmit"
|
||||
@cancel="onCancel"
|
||||
@finish="onFinish"
|
||||
>
|
||||
|
||||
@@ -10,6 +10,7 @@ import ReviewMigrationStep from '@pkg/harvester/components/vm-migration/ReviewMi
|
||||
import { PRODUCT_NAME } from '@pkg/harvester/config/harvester';
|
||||
import { currentRouter } from '@pkg/harvester/utils/router';
|
||||
import { exceptionToErrorsArray, stringify } from '@shell/utils/error';
|
||||
import { preventImplicitSubmit } from '@pkg/harvester/utils/wizard';
|
||||
|
||||
const store = useStore();
|
||||
const { t } = useI18n(store);
|
||||
@@ -269,6 +270,7 @@ const onCancel = () => {
|
||||
finish-mode="finish"
|
||||
finish-button-mode="createAndStart"
|
||||
class="wizard"
|
||||
@keydown.enter.capture="preventImplicitSubmit"
|
||||
@cancel="onCancel"
|
||||
@finish="onFinish"
|
||||
>
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { isValidCIDR } from '../regular';
|
||||
|
||||
describe('isValidCIDR', () => {
|
||||
it.each([
|
||||
'10.0.0.0/16',
|
||||
'192.168.1.0/24',
|
||||
'0.0.0.0/0',
|
||||
'255.255.255.255/32',
|
||||
'172.16.100.9/12',
|
||||
])('should accept the IPv4 CIDR %s', (cidr) => {
|
||||
expect(isValidCIDR(cidr)).toBe(true);
|
||||
});
|
||||
|
||||
it.each([
|
||||
['a short form', '10.1/16'],
|
||||
['a single number', '10/8'],
|
||||
['an integer address', '167772160/8'],
|
||||
['a hex address', '0x0a.0.0.0/8'],
|
||||
['an extra part', '10.0.0.0/24/1'],
|
||||
['an IPv6 range', 'fd00::/64'],
|
||||
['an IPv4-mapped IPv6 range', '::ffff:10.0.0.0/120'],
|
||||
['a prefix over 32', '10.0.0.0/33'],
|
||||
['an octet over 255', '10.0.0.256/24'],
|
||||
['zero-padded octets', '010.001.000.000/16'],
|
||||
['a zero-padded octet', '192.168.001.0/24'],
|
||||
['a zero-padded prefix', '10.0.0.0/08'],
|
||||
['no prefix', '10.0.0.0'],
|
||||
['an empty value', ''],
|
||||
])('should reject %s (%s)', (_, cidr) => {
|
||||
expect(isValidCIDR(cidr)).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
import Feature from '@shell/models/management.cattle.io.feature';
|
||||
import { MANAGEMENT } from '@shell/config/types';
|
||||
import { CONFIGURABLE_TABLES } from '@shell/store/features';
|
||||
import { tableViewsOffFeature } from '../table-views';
|
||||
|
||||
describe('tableViewsOffFeature', () => {
|
||||
it('should be the table views feature of the management store', () => {
|
||||
const feature = tableViewsOffFeature();
|
||||
|
||||
expect(feature.type).toBe(MANAGEMENT.FEATURE);
|
||||
expect(feature.id).toBe(CONFIGURABLE_TABLES);
|
||||
});
|
||||
|
||||
it('should be read as disabled by the shell', () => {
|
||||
const feature = new Feature(tableViewsOffFeature(), {
|
||||
getters: {}, rootGetters: {}, dispatch: jest.fn(), rootState: {}
|
||||
});
|
||||
|
||||
expect(feature.enabled).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
import { preventImplicitSubmit } from '../wizard';
|
||||
|
||||
function keydown(target) {
|
||||
return { target, preventDefault: jest.fn() };
|
||||
}
|
||||
|
||||
describe('preventImplicitSubmit', () => {
|
||||
it('should stop Enter in a text field from submitting the wizard', () => {
|
||||
const event = keydown(document.createElement('input'));
|
||||
|
||||
preventImplicitSubmit(event);
|
||||
|
||||
expect(event.preventDefault).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should leave Enter in a dropdown alone, which uses it to pick an option', () => {
|
||||
const select = document.createElement('div');
|
||||
const input = document.createElement('input');
|
||||
|
||||
select.className = 'v-select';
|
||||
select.appendChild(input);
|
||||
|
||||
const event = keydown(input);
|
||||
|
||||
preventImplicitSubmit(event);
|
||||
|
||||
expect(event.preventDefault).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it.each(['textarea', 'button'])('should leave Enter on a %s alone', (tag) => {
|
||||
const event = keydown(document.createElement(tag));
|
||||
|
||||
preventImplicitSubmit(event);
|
||||
|
||||
expect(event.preventDefault).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,13 @@
|
||||
|
||||
/**
|
||||
* IPv4 CIDR such as 10.0.0.0/16. Unlike the shell's isValidCIDR since 3.0.14, it rejects the short forms
|
||||
* (10.1/16), extra parts (10.0.0.0/24/1), zero-padded octets (010.0.0.0/8) and IPv6, which the network settings
|
||||
* don't support
|
||||
*/
|
||||
export function isValidCIDR(cidr) {
|
||||
return /^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\/(3[0-2]|[12]?[0-9])$/.test(cidr || '');
|
||||
}
|
||||
|
||||
export function isValidMac(value) {
|
||||
return /^[A-Fa-f0-9]{2}(-[A-Fa-f0-9]{2}){5}$|^[A-Fa-f0-9]{2}(:[A-Fa-f0-9]{2}){5}$/.test(value);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { MANAGEMENT } from '@shell/config/types';
|
||||
import { CONFIGURABLE_TABLES } from '@shell/store/features';
|
||||
|
||||
/**
|
||||
* The shell's table views feature (@rancher/shell 3.0.14), disabled, for the management store. Standalone Harvester
|
||||
* has no such feature on the server, so the shell uses its default, on, and every list gets the table views, which
|
||||
* drop the filters the lists put in the table header. Only kept in the store, nothing is saved.
|
||||
*/
|
||||
export function tableViewsOffFeature() {
|
||||
return {
|
||||
id: CONFIGURABLE_TABLES,
|
||||
type: MANAGEMENT.FEATURE,
|
||||
metadata: { name: CONFIGURABLE_TABLES },
|
||||
spec: { value: false },
|
||||
status: {
|
||||
default: true, dynamic: true, lockedValue: null
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Keydown (capture) handler for a wizard. The shell's Wizard renders its step headers as buttons without a type
|
||||
* since 3.0.14, so they are submit buttons: Enter in a text field submits the form by clicking the first one,
|
||||
* which jumps back to step 1. Dropdowns are left alone, they use Enter to pick an option.
|
||||
*/
|
||||
export function preventImplicitSubmit(event) {
|
||||
const target = event?.target;
|
||||
|
||||
if (target?.tagName === 'INPUT' && !target.closest('.v-select')) {
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user