I'm using a actionsheet in react native and need it to generate an alert once a button is clicked. The buttons are in the array provided under the BUTTONS variable. The code is shown below:
const BUTTONS = [
{ text: "SMS", icon: "chatboxes", iconColor: "#2c8ef4" },
{ text: "Email", icon: "analytics", iconColor: "#f42ced" },
{ text: "Push Notification", icon: "aperture", iconColor: "#ea943b" },
{ text: "Delete", icon: "trash", iconColor: "#fa213b" },
{ text: "Cancel", icon: "close", iconColor: "#25de5b" }
];
const DESTRUCTIVE_INDEX = 3;
const CANCEL_INDEX = 4;
return(
...
ActionSheet.show(
{
options: BUTTONS,
cancelButtonIndex: CANCEL_INDEX,
destructiveButtonIndex: DESTRUCTIVE_INDEX,
title: "How do you want to receive your notification"
},
buttonIndex => {
setSheet({ clicked: BUTTONS[buttonIndex] });
}
)
Related
Hi I've implemented one simple shortcut to get data from input but after submitting the view I couldn't get the response payload or it cannot update the view to acknowledge user. following is my simple code.
const { App } = require("#slack/bolt");
const app = new App({
token: process.env.BOT_TOKEN,
socketMode: true,
signingSecret: process.env.SIGNIGN_SECRET,
appToken: process.env.APP_TOKEN,
});
app.shortcut({ callback_id: 'open_modal', type: 'message_action' }, async ({ shortcut, ack, client }) => {
try {
await ack();
console.log("Ack:")
const result = await client.views.open({
trigger_id: shortcut.trigger_id,
callback_id: "new-task-modal",
view: {
type: "modal",
title: {
type: "plain_text",
text: "My App",
},
submit: {
type: "plain_text",
text: "Submit",
emoji: true,
},
close: {
type: "plain_text",
text: "Cancel",
},
blocks: [
{
"type": "input",
"element": {
"type": "plain_text_input",
"action_id": "plain_text_input-action"
},
"label": {
"type": "plain_text",
"text": "Label",
"emoji": true
}
}
],
},
});
} catch (error) {
console.log(error);
}
});
app.view({ callback_id: 'new-task-modal', type: 'message_action' }, async({ shortcut, ack, view, body }) => {
try {
console.log("New task modal",view.state.values );
await ack();
let result = await client.views.update({
view_id: body.view.id,
view: {
type: "modal",
title: {
type: "plain_text",
text: "My App",
emoji: true,
},
close: {
type: "plain_text",
text: "Cancel",
},
blocks: [
{
type: "section",
text: {
type: "plain_text",
text: "This is a plain text section block.",
emoji: true,
},
},
],
}
});
} catch (error) {
console.log(error)
}
})
app.shortcut() function works fine and create one view but after submitting that view it couldn't hit to app.view() function to update the view so is there any way to update the current view.
The callback_id in the client.views.open call should be under the view field, not on the root level.
const result = await client.views.open({
trigger_id: shortcut.trigger_id,
- callback_id: "new-task-modal",
view: {
+ callback_id: "new-task-modal",
type: "modal",
title: {
type: "plain_text",
text: "My App",
},
...
I am getting the following error when trying to pass data to material ui table, the table isnt displayed and it crash. Cannot modify '', the object is protected and can only be modified by using an action.
im using typescript and mobx state tree
setTreasurers: flow(function* () {
return self.treasurerData = yield getAllTreasurers();
})
var showTreasurerData = userStore.getTreasurerData
const cloneSheeps = [...showTreasurerData];
return (
<div>
<MaterialTable
title="Tesoreros"
columns={[
{ title: "Email", field: "email" },
{ title: "Cuit", field: "cuit" },
{
title: "Verificado",
field: "verified",
},
]}
data={cloneSheeps}
options={{
sorting: true,
actionsColumnIndex: -1
}}
localization={
{ header: { actions: 'Acciones' } }
}
actions={
[
{
position: "auto",
icon: "done",
tooltip: "Enable User",
onClick: (event, user) => {
var isVerified = true;
ManageTreasurerVerification(user, isVerified)
},
},
{
icon: "cancel",
tooltip: "Disable User",
onClick: (event, user) => {
var isVerified = false;
ManageTreasurerVerification(user, isVerified)
},
},
]}
/>
I'm trying to use SweetAlert 2.1.2 with the following configuration:
swal({
title: "My Event Title",
text: "My event message",
icon: "warning",
html: true,
closeOnClickOutside: true,
content: {
element: "input",
attributes: {
placeholder: "User text",
type: "input"
}
},
buttons: {
cancelMove: {
text: "Cancel",
value: "c"
},
sendConfirm: {
text: "Yes, continue",
value: "s"
},
}
},
function(value) {
switch (value) {
case "cancelMove":
swal("Move cancelled");
break;
case "sendConfirm":
swal("Sending confirmation ...");
break;
default:
swal("Good bye!!!");
}
});
But, I'm not getting the expected results of a text input and two buttons:
I think I'm following their configuration steps correctly. But, obviously I'm not.
During button clicking with its defined value you're passing in value this button value. I mean cancelMove sends value = c and sendConfirm sends value = s.
Also use .then( instead of }, function(.
Working snippet below:
swal({
title: "My Event Title",
text: "My event message",
icon: "warning",
html: true,
closeOnClickOutside: true,
content: {
element: "input",
attributes: {
placeholder: "User text",
type: "input"
}
},
buttons: {
cancelMove: {
text: "Cancel",
value: "c"
},
sendConfirm: {
text: "Yes, continue",
value: "s"
},
}
}).then((value)=>{
switch (value) {
case "c":
swal("Move cancelled");
break;
case "s":
swal("Sending confirmation ...");
break;
default:
swal("Good bye!!!");
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<a href={LinkMappingUtility.getMappedWebUiLink('/#/dashboard')}
data-id="0"
className="nav-menu-item"
autoFocus="true">
{menuItem({ linkTitle: translate('sbDashboard', currentLanguage), icon: 'swn-home-icon' })}
this is the anchor tag inside that i have menu item text and i want the text in enzyme
My Code is :
test('all menu items display the correct text', () => {
const allMenuItemText = [
{ linkTitle: 'Dashboard', icon: 'swn-home-icon' },
{ linkTitle: 'Alerts', icon: 'swn-alerts-icon' },
{ linkTitle: 'Contact Management', icon: 'swn-home-icon'},
{ linkTitle: 'Reporting', icon: 'swn-home-icon' },
{ linkTitle: 'Solutions', icon: 'swn-home-icon' },
{ linkTitle: 'Integrations', icon: 'swn-home-icon' },
{ linkTitle: 'Account Settings', icon: 'swn-home-icon'},
{ linkTitle: 'Support & Training', icon: 'swn-home-icon' }
];
wrapper.find('.nav-menu-item').forEach((node, index) => {
expect(node.text()).toEqual(allMenuItemText[index].linkTitle);
})
output : here i am getting the empty string in return
I'm guessing just a typo, you meant to use a class selector?
// tag selector
wrapper.find('nav-menu-item') ...
// class selector
wrapper.find('.nav-menu-item') ...
Have you tried selecting the link title - the anchor tag is difficult to select in the testing library - so if you select the link title you are clicking it may work
const anchorTag = wrapper.find("my-link-title");
expect(anchorTag).toHaveAttribute("href", "https://url-test-1#");
I use this context menu for a right click on table:tr elements:
http://www.downloadjavascripts.com/list/javasitelll99/Details.aspx
It works fine! and I defined a function for action handling.
var option = { width: 150, items: [
{ text: "Edit", icon: "public/images/sample-css/wi0126-16.gif", alias: "1-1", action: menuAction },
{ text: "Activate", icon: "public/images/sample-css/ac0036-16.gif", alias: "1-2", action: menuAction },
//this is normal menu item, menuAction will be called if this item is clicked on
{ text: "Deactivate", icon: "public/images/sample-css/ei0021-16.gif", alias: "1-3", action: menuAction },
//this is a split line
{ type: "splitLine" },
//this is a parent item, which has some sub-menu items
{ text: "Delete", icon: "public/images/sample-css/ei0021-16.gif", alias: "1-3", action: menuAction },
{ type: "splitLine" },
{ text: "Item Four", icon: "public/images/sample-css/wi0124-16.gif", alias: "1-5", action: menuAction },
{ text: "Group Three", icon: "public/images/sample-css/wi0062-16.gif", alias: "1-6", type: "group", width: 180, items: [
{ text: "Item One", icon: "public/images/sample-css/wi0096-16.gif", alias: "4-1", action: menuAction },
{ text: "Item Two", icon: "public/images/sample-css/wi0122-16.gif", alias: "4-2", action: menuAction }
]
}
]
};
function menuAction(){
alert(this.data.alias);
}
But, now I want to get the id of the clicked table:tr element.
How to get it?
var myElementId;
var option = { ...
onShow: applyrule,
onContextMenu: BeforeContextMenu
};
function menuAction() {
alert(myElementId);
}
function applyrule(menu) {
myElementId = this.id
}
Assuming that tableId is the id of your table this function should help you:
function getIdOfRowByIndex(tableId, rowIndex) {
return document.getElementById(tableId).rows[rowIndex].id;
}
If you have a tr element, then this function should help you:
function getIdOfRow(trElement) {
return trElement.id;
}
You can use jQuery to simplify your tasks, but these functions are technology-agnostic to help those who do not want/can use jQuery too.