Related
I implemented a slack bot with um field of type input(multi_users_select). I would like to remove defaults apps from the list select?
{
type: 'input',
element: {
type: 'multi_users_select',
action_id: input.actionId,
initial_users: input.initial_users,
},
label: {
type: 'plain_text',
text: input.text,
emoji: input.emoji,
},
};
Instead of type: 'multi_users_select' use "type": "multi_conversations_select" with filter as shown below to get only users in your workspace.
You can copy and paste the below code in block-kit builder to test on your own.
https://app.slack.com/block-kit-builder/
{
"title": {
"type": "plain_text",
"text": "Blocker-Bot"
},
"submit": {
"type": "plain_text",
"text": "Submit"
},
"type": "modal",
"callback_id": "custom_time_select",
"private_metadata": "private-data",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Test block with multi conversations select"
},
"accessory": {
"type": "multi_conversations_select",
"placeholder": {
"type": "plain_text",
"text": "Select conversations",
"emoji": true
},
"filter": {
"include": [
"im"
],
"exclude_bot_users": true
},
"action_id": "multi_conversations_select-action"
}
}
]
}
Update 05-Jul-21
Included various other types of select users without bots/apps
{
"type": "modal",
"title": {
"type": "plain_text",
"text": "My App",
"emoji": true
},
"submit": {
"type": "plain_text",
"text": "Submit",
"emoji": true
},
"close": {
"type": "plain_text",
"text": "Cancel",
"emoji": true
},
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Conversations type Select user"
},
"accessory": {
"type": "conversations_select",
"placeholder": {
"type": "plain_text",
"text": "Select a user",
"emoji": true
},
"filter": {
"include": [
"im"
],
"exclude_bot_users": true
},
"action_id": "users_select-action"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Multi Conversations type Select users"
},
"accessory": {
"type": "multi_conversations_select",
"placeholder": {
"type": "plain_text",
"text": "Select conversations",
"emoji": true
},
"filter": {
"include": [
"im"
],
"exclude_bot_users": true
},
"action_id": "multi_conversations_select-action"
}
},
{
"type": "input",
"element": {
"type": "multi_conversations_select",
"placeholder": {
"type": "plain_text",
"text": "Select users",
"emoji": true
},
"filter": {
"include": [
"im"
],
"exclude_bot_users": true
},
"action_id": "multi_users_select-action"
},
"label": {
"type": "plain_text",
"text": "Input type Select users",
"emoji": true
}
}
]
}
Currently, filtering is available for conversations select menu or conversations multi select menu.
https://api.slack.com/reference/block-kit/composition-objects#filter_conversations
May be you can write to feedback#slack.com and they can log it for future releases.
I am working on a nested state. And after a certain event(on form submit), I want to reset the form input field to the initial state, and also its flags(for a controlled component). But I am not able to that.
My initial State looks like this:
state = {
orderForm: {
name: {
elementType: "input",
elementConfig: {
type: "text",
placeholder: "Your Name",
},
value: "",
validation: {
required: true,
},
valid: false,
},
address: {
elementType: "input",
elementConfig: {
type: "text",
placeholder: "Your Address",
},
value: "",
validation: {
required: true,
},
valid: false,
touched: false,
},
email: {
elementType: "input",
elementConfig: {
type: "text",
placeholder: "Your Email",
},
value: "",
validation: {
required: true,
},
valid: false,
touched: false,
},
mobile: {
elementType: "input",
elementConfig: {
type: "text",
placeholder: "Your Phone",
},
value: "",
validation: {
required: true,
length: true,
},
valid: false,
touched: false,
},
addressType: {
elementType: "select",
elementConfig: {
options: [
{ value: "home", displayValue: "Residental" },
{ value: "office", displayValue: "Commerical" },
],
},
value: "home",
validation: {
required: false,
},
valid: true,
},
},
formIsValid: false,
};
And when I submit my it looks like,
{
"orderForm": {
"name": {
"elementType": "input",
"elementConfig": {
"type": "text",
"placeholder": "Your Name"
},
"value": "abc",
"validation": {
"required": true
},
"valid": true,
"touched": true
},
"address": {
"elementType": "input",
"elementConfig": {
"type": "text",
"placeholder": "Your Address"
},
"value": "123 - xyz",
"validation": {
"required": true
},
"valid": true,
"touched": true
},
"email": {
"elementType": "input",
"elementConfig": {
"type": "text",
"placeholder": "Your Email"
},
"value": "a#bc.com",
"validation": {
"required": true
},
"valid": true,
"touched": true
},
"mobile": {
"elementType": "input",
"elementConfig": {
"type": "text",
"placeholder": "Your Phone"
},
"value": "1234567890",
"validation": {
"required": true,
"length": true
},
"valid": true,
"touched": true
},
"addressType": {
"elementType": "select",
"elementConfig": {
"options": [
{
"value": "home",
"displayValue": "Residental"
},
{
"value": "office",
"displayValue": "Commerical"
}
]
},
"value": "office",
"validation": {
"required": false
},
"valid": true,
"touched": true
}
},
"formIsValid": true
}
So I tried this method, which I tried to reset it using the previous state but I am not able to do it. I know I can do it by storing it in a variable see link but don't want to use this. And using the Spread operator for making copies for each is too much tedious.
my method which I tried, it's not working.
this.setState(
(prevState) => {
const orderForm = [...prevState.orderForm];
return { orderForm };
},
() => {this.props.history.push("/orders")}
);
I know there could be better way to that. And I don't want to use any helper library.
Thank you.
Will this work,
this.setState(prevState=>({
return {
...prevState,
// spread your initial state.
}),()=>console.log(your state));
Now there can be different scenarios, I don't if your state is at your component level or at redux level. But in both ways you can access your initial state. If it's at component level, it's pretty easy.
If you're using redux, then you can make use of Selectors and get your initial state as props from your redux or any other state management library you're using.
I have an API which returns response in the format
[
{"id": 12345,
"value": "some_string",
"practice_id": "12344"},
{"id": 12346,
"value": "some_other_string",
"practice_id": "12345"},
]
I am testing that the response validates a specific JSON-Schema, and my schema test is
response.body.should.have.schema({
type: 'array',
required: ['id', 'value', 'practice_id'],
properties: {
id: {
type: 'number',
},
value: {
type: 'string',
},
practice_id: {
type: 'string',
minLength: 5,
}
}
});
The issue is that the test passes even if I change the type of id to string or change the value of practice_id to number, which is not correct.
What am I doing wrong here? I am using Postman-BDD to validate the responses.
I guess your schema should be more like this:
{
"type": "array",
"items":
{
"required":
[
"id",
"value",
"practice_id"
],
"properties":
{
"id":
{
"type": "number"
},
"value":
{
"type": "string"
},
"practice_id":
{
"type": "string",
"minLength": 5
}
}
}
}
You are missing the "items" keywords to actually define the content of the array. And this schema also gives an error in JSONBuddy on validating some sample data:
I have a dataset that looks like this:
Valid Example Data
{
type: "step",
label: "Step 1",
fields: [
// An optional field
{
type: "email",
label: "Your Email"
},
// A field that is required and can be either amount|preset
{
type: "amount",
label: "Amount"
},
// A field that is required and can be either credit_card|ach
{
type: "credit_card",
label: "Credit Card"
}
]
}
The fields array can contain many objects of various types. The above example would be valid.
Invalid Example Data
{
type: "step",
label: "Step 1",
fields: [
{
type: "email",
label: "Your Email"
},
{
type: "credit_card",
label: "Credit Card"
}
]
}
This should error as it does not include an object of type amount or presets
Validation Rules
In order to be valid, fields needs to contain 2 objects.
1 of them must be of either { type: "amount" } or { type: "presets" }
1 of them must be of either { type: "credit_card" } or { type: "ach" }
Any combination of the 2 would make fields be valid.
JSON Schema
Here is my (failing) JSON Schema:
{
"title": "step",
"type": "object",
"properties": {
"type": {
"title": "type",
"type": "string"
},
"label": {
"title": "label",
"type": "string"
},
"fields": {
"title": "fields",
"description": "Array of fields",
"type": "array",
"additionalItems": true,
"minItems": 1,
"items": {
"type": "object",
"anyOf": [
{ "properties": { "type": { "enum": ["amount", "preset"] } } },
{ "properties": { "type": { "enum": ["credit_card", "ach"] } } }
],
"properties": {
"type": {
"type": "string",
}
}
},
}
},
"required": ["type", "label", "fields"]
}
Here is the JSON Schema Validation Reference
I think between contains, anyOf, allOf, oneOf, and enum I should be able to do this?
Put the following in your /properties/fields schema. That expresses the constraints you need. Remove /properties/fields/items/anyOf (it's wrong) and /properties/fields/additionalItems (it doesn't do anything).
"allOf": [
{
"contains": {
"properties": { "type": { "enum": ["amount", "presets"] } }
}
},
{
"contains": {
"properties": { "type": { "enum": ["credit_card", "ach"] } }
}
}
]
How can i bind my child data in one column?
I want to write "Technology,Economy,Life" in same column and same row. But i think i need to loop in "Category". How can i do this, any idea?
My Data:
{
"ParentId": "00000000-0000-0000-0000-000000000000",
"Title": null,
"UserGroupModel": null,
"EntityAccessData": [
{
"EntityTitle": "User",
"Access": {
"Id": "59d0c6f7-8f93-497a-854d-bdd4a42ade94",
"Title": "Can Delete"
},
"Category": [
{
"Id": "00000000-0000-0000-0000-000000000000",
"Title": "Technology"
},
{
"Id": "00000000-0000-0000-0000-000000000000",
"Title": "Economy"
},
{
"Id": "00000000-0000-0000-0000-000000000000",
"Title": "Life"
}
],
"HasAccess": true
},
{
"EntityTitle": "UserGroup",
"Access": {
"Id": "7c65be44-11b0-4cf4-9104-0ad999e7e280",
"Title": "Can Edit"
},
"Category": [
{
"Id": "00000000-0000-0000-0000-000000000000",
"Title": "Technology"
},
{
"Id": "00000000-0000-0000-0000-000000000000",
"Title": "Economy"
},
{
"Id": "00000000-0000-0000-0000-000000000000",
"Title": "Life"
}
],
"HasAccess": true
}
]
}
My Script:
$("#grid").kendoGrid({
dataSource: {
type: "json",
transport: {
read: "/getData" },
schema: {
data: "EntityAccessData"
},
group: [{
field: "EntityTitle"
}],
},
columns: [
{
field: "Access.Id",
title: "ID"
},
{
field: "Access.Title",
title: "Access title"
},
{
field: "HasAccess",
title: "has access"
},
{
field: "Category.Title", // ***wrong***
title: "Category"
},
]
});
Define the schema as follow:
schema: {
data : "EntityAccessData",
model: {
CategoryTitle: function () {
var category = [];
$.each(this.Category, function(idx, elem) {
category.push(elem.Title);
});
return category.join(",");
}
}
},
Where I add an additional field CategoryTitle that is the result of joining the Title of the Category array and then define the column as:
{
field: "CategoryTitle()",
title: "Category"
}