fix: Fix action hint without name

Fix action hint without name

Change-Id: Ie1e88b2749399dbe0291d739e18a25aaaf0faaac
This commit is contained in:
Jingwei.Zhang 2021-08-25 13:29:55 +08:00
parent 1d4952cf60
commit f1c3df26a4
29 changed files with 78 additions and 49 deletions

View File

@ -175,6 +175,7 @@ export default class BaseForm extends React.Component {
}
get successText() {
if (this.instanceName) {
return firstUpperCase(
t('{action} successfully, instance: {name}.', {
action: this.name.toLowerCase(),
@ -182,13 +183,24 @@ export default class BaseForm extends React.Component {
})
);
}
return firstUpperCase(
t('{action} successfully.', {
action: this.name.toLowerCase(),
})
);
}
get errorText() {
if (this.instanceName) {
return t('Unable to {action}, instance: {name}.', {
action: this.name.toLowerCase(),
name: this.instanceName,
});
}
return t('Unable to {action}.', {
action: this.name.toLowerCase(),
});
}
get isSubmitting() {
const { isSubmitting = false } = this.state;

View File

@ -148,6 +148,7 @@ export default class BaseStepForm extends React.Component {
}
get successText() {
if (this.instanceName) {
return firstUpperCase(
t('{action} successfully, instance: {name}.', {
action: this.name.toLowerCase(),
@ -155,13 +156,24 @@ export default class BaseStepForm extends React.Component {
})
);
}
return firstUpperCase(
t('{action} successfully.', {
action: this.name.toLowerCase(),
})
);
}
get errorText() {
if (this.instanceName) {
return t('Unable to {action}, instance: {name}.', {
action: this.name.toLowerCase(),
name: this.instanceName,
});
}
return t('Unable to {action}.', {
action: this.name.toLowerCase(),
});
}
get isSubmitting() {
return (this.store && this.store.isSubmitting) || false;

View File

@ -89,12 +89,14 @@ export default class ConfirmAction {
unescape = (message) => unescapeHtml(message);
getNameOne = (data) => data.name;
getItemId = (data) => data.id;
getItemName = (data) => data.name || `- (${this.getItemId(data)})`;
getName = (data) =>
isArray(data)
? data.map((it) => this.getNameOne(it)).join(', ')
: this.getNameOne(data);
? data.map((it) => this.getItemName(it)).join(', ')
: this.getItemName(data);
// eslint-disable-next-line no-unused-vars
allowedCheckFunc = (data) => true;
@ -154,7 +156,14 @@ export default class ConfirmAction {
);
};
performErrorMsg = (data) => {
performErrorMsg = (data, isBatch) => {
if (isBatch) {
if (!this.messageHasItemName) {
return '';
}
const name = this.getName(data);
return t('instance: {name}.', { name });
}
if (!this.messageHasItemName) {
return t('You are not allowed to {action}.', {
action: this.actionNameDisplay || this.title,
@ -184,11 +193,17 @@ export default class ConfirmAction {
onSubmit = (data) => Promise.resolve();
getBatchPerformTitle() {
if (this.messageHasItemName) {
return t(
'There are resources that cannot {action} in the selected resources, such as:',
{ action: this.passiveAction.toLowerCase() }
);
}
return t(
'There are resources that cannot {action} in the selected resources.',
{ action: this.passiveAction.toLowerCase() }
);
}
perform = async (data) => {
if (isArray(data)) {
@ -208,7 +223,7 @@ export default class ConfirmAction {
failedItems.push(items[index]);
}
});
const errorMsg = this.unescape(this.performErrorMsg(failedItems));
const errorMsg = this.unescape(this.performErrorMsg(failedItems, true));
const title = this.getBatchPerformTitle();
const msg = (
<div>

View File

@ -70,7 +70,7 @@ export default class ModalAction extends BaseForm {
}
get instanceName() {
return this.item.name || this.values.name;
return (this.item || {}).name || (this.values || {}).name;
}
get isAsyncAction() {

View File

@ -238,7 +238,6 @@
"Click to show detail": "Click to show detail",
"Clone Volume": "Clone Volume",
"Clone volume": "Clone volume",
"Close": "Close",
"Close External Gateway": "Close External Gateway",
"Close all notifications.": "Close all notifications.",
"Close external gateway": "Close external gateway",
@ -1039,7 +1038,6 @@
"One entry per line(e.g. {ip})": "One entry per line(e.g. {ip})",
"Online Resize": "Online Resize",
"Only a MAC address or an OpenFlow based datapath_id of the switch are accepted in this field": "Only a MAC address or an OpenFlow based datapath_id of the switch are accepted in this field",
"Open": "Open",
"Open External Gateway": "Open External Gateway",
"Operating Status": "Operating Status",
"Operating System": "Operating System",
@ -1553,6 +1551,7 @@
"The {action} instruction has been issued, instance: {name}. \n You can wait for a few seconds to follow the changes of the list data or manually refresh the data to get the final display result.": "The {action} instruction has been issued, instance: {name}. \n You can wait for a few seconds to follow the changes of the list data or manually refresh the data to get the final display result.",
"The {action} instruction has been issued. \n You can wait for a few seconds to follow the changes of the list data or manually refresh the data to get the final display result.": "The {action} instruction has been issued. \n You can wait for a few seconds to follow the changes of the list data or manually refresh the data to get the final display result.",
"There are resources that cannot {action} in the selected resources, such as:": "There are resources that cannot {action} in the selected resources, such as:",
"There are resources that cannot {action} in the selected resources.": "There are resources that cannot {action} in the selected resources.",
"There are resources under the project and cannot be deleted.": "There are resources under the project and cannot be deleted.",
"This service will automatically query the configuration (CPU, memory, etc.) and mac address of the physical machine, and the ironic-inspector service will automatically register this information in the node information.": "This service will automatically query the configuration (CPU, memory, etc.) and mac address of the physical machine, and the ironic-inspector service will automatically register this information in the node information.",
"This will delete all child objects of the load balancer.": "This will delete all child objects of the load balancer.",
@ -1577,8 +1576,6 @@
"USER": "USER",
"UUID": "UUID",
"Ubuntu": "Ubuntu",
"Unable to batch {action} {name}.": "Unable to batch {action} {name}.",
"Unable to batch {action}, instance: {name}.": "Unable to batch {action}, instance: {name}.",
"Unable to create instance: batch creation is not supported when specifying IP.": "Unable to create instance: batch creation is not supported when specifying IP.",
"Unable to create instance: insufficient quota to create resources.": "Unable to create instance: insufficient quota to create resources.",
"Unable to create volume: insufficient quota to create resources.": "Unable to create volume: insufficient quota to create resources.",
@ -1854,6 +1851,7 @@
"ingress": "ingress",
"instance": "instance",
"instance snapshot": "instance snapshot",
"instance: {name}.": "instance: {name}.",
"instances": "instances",
"jump to the console": "jump to the console",
"keypair": "keypair",

View File

@ -238,7 +238,6 @@
"Click to show detail": "点击查看详情",
"Clone Volume": "克隆云硬盘",
"Clone volume": "克隆云硬盘",
"Close": "关闭",
"Close External Gateway": "关闭公网网关",
"Close all notifications.": "关闭所有消息提示",
"Close external gateway": "关闭公网网关",
@ -1039,7 +1038,6 @@
"One entry per line(e.g. {ip})": "每行一条(例如: {ip})",
"Online Resize": "在线修改配置",
"Only a MAC address or an OpenFlow based datapath_id of the switch are accepted in this field": "只可填写交换机的Mac地址或者交换机基于openflow的数据路径ID",
"Open": "开",
"Open External Gateway": "开启公网网关",
"Operating Status": "操作状态",
"Operating System": "操作系统",
@ -1553,6 +1551,7 @@
"The {action} instruction has been issued, instance: {name}. \n You can wait for a few seconds to follow the changes of the list data or manually refresh the data to get the final display result.": "{action}指令已下发,实例名称:{name}。 \n 您可等待几秒关注列表数据的变更或是手动刷新数据,以获取最终展示结果。",
"The {action} instruction has been issued. \n You can wait for a few seconds to follow the changes of the list data or manually refresh the data to get the final display result.": "{action}指令已下发。 \n 您可等待几秒关注列表数据的变更或是手动刷新数据,以获取最终展示结果。",
"There are resources that cannot {action} in the selected resources, such as:": "您选中的资源中有无法{action}的资源,如:",
"There are resources that cannot {action} in the selected resources.": "您选中的资源中有无法{action}的资源。",
"There are resources under the project and cannot be deleted.": "项目下存在资源,无法执行删除操作。",
"This service will automatically query the configuration (CPU, memory, etc.) and mac address of the physical machine, and the ironic-inspector service will automatically register this information in the node information.": "此服务将对在对物理机的配置CPU、内存等和 mac 地址进行自动查询, 并且 ironic-inspector 服务会将这些信息自动注册入节点信息中。",
"This will delete all child objects of the load balancer.": "这会删除所有LB下的资源",
@ -1577,8 +1576,6 @@
"USER": "用户",
"UUID": "",
"Ubuntu": "",
"Unable to batch {action} {name}.": "无法批量{action} {name}。",
"Unable to batch {action}, instance: {name}.": "无法批量{action},实例名称:{name}。",
"Unable to create instance: batch creation is not supported when specifying IP.": "无法创建云主机指定IP时不支持批量创建云主机。",
"Unable to create instance: insufficient quota to create resources.": "无法创建云主机:超过配额。",
"Unable to create volume: insufficient quota to create resources.": "无法创建云硬盘:超过配额。",
@ -1854,6 +1851,7 @@
"ingress": "入方向",
"instance": "云主机",
"instance snapshot": "云主机快照",
"instance: {name}.": "实例名称:{name}。",
"instances": "云主机",
"jump to the console": "跳转到控制台",
"keypair": "密钥",

View File

@ -42,7 +42,7 @@ export default class Delete extends ConfirmAction {
policy = 'baremetal:port:delete';
getNameOne = (data) => data.name || data.uuid;
getItemId = (data) => data.uuid;
allowedCheckFunc = () => true;

View File

@ -42,7 +42,7 @@ export default class Delete extends ConfirmAction {
policy = 'baremetal:portgroup:delete';
getNameOne = (data) => data.name || data.uuid;
getItemId = (data) => data.uuid;
allowedCheckFunc = () => true;

View File

@ -30,7 +30,7 @@ export default class ClearMaintenance extends ConfirmAction {
policy = 'baremetal:node:clear_maintenance';
getNameOne = (data) => data.name || data.uuid;
getItemId = (data) => data.uuid;
allowedCheckFunc = (item) => item.maintenance;

View File

@ -42,7 +42,7 @@ export default class Delete extends ConfirmAction {
policy = 'baremetal:node:delete';
getNameOne = (data) => data.name || data.uuid;
getItemId = (data) => data.uuid;
allowedCheckFunc = () => true;

View File

@ -31,7 +31,7 @@ export default class Inspect extends ConfirmAction {
policy = 'baremetal:node:set_provision_state';
getNameOne = (data) => data.name || data.uuid;
getItemId = (data) => data.uuid;
allowedCheckFunc = (item) => item.provision_state === 'manageable';

View File

@ -34,7 +34,7 @@ export default class PowerOn extends ConfirmAction {
policy = 'baremetal:node:set_power_state';
getNameOne = (data) => data.name || data.uuid;
getItemId = (data) => data.uuid;
allowedCheckFunc = (item) => item.power_state === 'power off';

View File

@ -34,7 +34,7 @@ export default class PowerOff extends ConfirmAction {
policy = 'baremetal:node:set_power_state';
getNameOne = (data) => data.name || data.uuid;
getItemId = (data) => data.uuid;
allowedCheckFunc = (item) => item.power_state === 'power on';

View File

@ -28,7 +28,7 @@ export default class EnableAction extends ConfirmAction {
return t('Enable');
}
getNameOne = (data) => data.host;
getItemName = (data) => data.host;
get actionName() {
return t('Enable compute host');

View File

@ -32,7 +32,7 @@ export default class Reset extends ConfirmAction {
return t('Reset To Initial Value');
}
getNameOne = (data) => data.key;
getItemName = (data) => data.key;
policy = 'skyline:system_admin';

View File

@ -36,7 +36,7 @@ export default class Enable extends ConfirmAction {
return t('enable cinder service');
}
getName = (data) => data.binary;
getItemName = (data) => data.binary;
policy = 'volume_extension:services:update';

View File

@ -28,7 +28,7 @@ export default class EnableAction extends ConfirmAction {
return t('Enable');
}
getName = (data) => data.host;
getItemName = (data) => data.host;
get actionName() {
return t('enable compute service');

View File

@ -36,7 +36,7 @@ export default class Disable extends ConfirmAction {
return t('disable neutron agent');
}
getName = (data) => data.binary;
getItemName = (data) => data.binary;
policy = 'update_agent';

View File

@ -36,7 +36,7 @@ export default class Enable extends ConfirmAction {
return t('enable neutron agent');
}
getName = (data) => data.binary;
getItemName = (data) => data.binary;
policy = 'update_agent';

View File

@ -38,7 +38,7 @@ export default class DeleteAction extends ConfirmAction {
policy = 'delete_floatingip_port_forwarding';
getNameOne = (data) => {
getItemName = (data) => {
const {
floating_ip_address,
external_port,

View File

@ -38,7 +38,7 @@ export default class Release extends ConfirmAction {
allowedCheckFunc = (item) =>
!_.isNull(item.fixed_ip_address) && item.status !== 'DOWN';
getNameOne = (data) => data.floating_ip_address;
getItemName = (data) => data.floating_ip_address;
onSubmit = (value) => globalFloatingIpsStore.disassociateFip(value);
}

View File

@ -41,7 +41,7 @@ export default class Release extends ConfirmAction {
policy = 'delete_floatingip';
getNameOne = (data) => data.floating_ip_address;
getItemName = (data) => data.floating_ip_address;
onChangeType(choosed, data) {
if (isArray(data)) {

View File

@ -38,7 +38,7 @@ export default class DeleteAction extends ConfirmAction {
policy = 'update_router';
getNameOne = (data) => {
getItemName = (data) => {
const { destination, nexthop } = data;
return `${destination}(${nexthop})`;
};

View File

@ -38,7 +38,7 @@ export default class DeleteAction extends ConfirmAction {
policy = 'delete_security_group_rule';
getNameOne = (item) => {
getItemName = (item) => {
if (item.name) {
return item.name;
}

View File

@ -37,7 +37,7 @@ export default class DeleteAction extends ConfirmAction {
return t('delete allowed address pair');
}
getNameOne = (data) => data.ip_address;
getItemName = (data) => data.ip_address;
policy = 'update_port';

View File

@ -40,7 +40,7 @@ export default class DeleteAction extends ConfirmAction {
return t('be released');
}
getNameOne = (data) => data.ip_address;
getItemName = (data) => data.ip_address;
policy = 'update_port';

View File

@ -36,8 +36,6 @@ export default class DeleteAction extends ConfirmAction {
return t('delete virtual adapter');
}
getNameOne = (data) => data.name || data.id;
policy = 'delete_port';
allowedCheckFunc = (item) => {

View File

@ -39,8 +39,6 @@ export default class Detach extends ConfirmAction {
policy = 'os_compute_api:os-attach-interfaces:delete';
getNameOne = (data) => data.name || data.id;
hasMoreInterfaces(instance) {
let count = 0;
const { addresses } = instance;

View File

@ -42,8 +42,6 @@ export default class DeleteAction extends ConfirmAction {
policy = 'volume:delete';
getNameOne = (data) => data.name || data.id;
canDelete = (item) =>
['available', 'error', 'error_extending'].indexOf(item.status) >= 0;