I think it would be a good idea to have better code editor and user defined functions/macros or what ever the name, to make the code inside PowerApps more readable and reuseable. It is errorprone to write long nested strings of commands inside a simple multiline textbox.
For example this is OnSelect code of a button on an app I'm developing. I'll try to explain how to make it more readable below.
If(CreateNew=true,Collect('[dbo].[AssignmentPermit]',{SafetyManagementPlanId: SafetyManagementPlanGallery.Selected.Id, Title: PermitTitleTextInput.Text, TargetName: PermitTargetNameTextInput.Text, Identifier: PermitIdentifierTextInput.Text, SafetyManagementAuthorizerName: PermitSafetyManagementAuthorizerNameTextInput.Text, SafetyManagementAuthorizerPhone: PermitSafetyManagementAuthorizerPhoneTextInput.Text, PermittedCompany: PermitPermittedCompanyTextInput.Text, PermittedContactName: PermitPermittedContactNameTextInput.Text, PermittedContactPhone: PermitPermittedContactPhoneTextInput.Text, AdditionalInformation: PermitAdditionalInformationTextInput.Text}),Patch('[dbo].[AssignmentPermit]',First(Filter('[dbo].[AssignmentPermit]',Id=AssignmentPermitId)),{Title:PermitTitleTextInput.Text,TargetName: PermitTargetNameTextInput.Text, Identifier: PermitIdentifierTextInput.Text, SafetyManagementAuthorizerName: PermitSafetyManagementAuthorizerNameTextInput.Text, SafetyManagementAuthorizerPhone: PermitSafetyManagementAuthorizerPhoneTextInput.Text, PermittedCompany: PermitPermittedCompanyTextInput.Text, PermittedContactName: PermitPermittedContactNameTextInput.Text, PermittedContactPhone: PermitPermittedContactPhoneTextInput.Text, AdditionalInformation: PermitAdditionalInformationTextInput.Text}));If(CreateNew=true,UpdateContext({CreateNew:false,AssignmentPermitId:Last(Filter('[dbo].[AssignmentPermit]',SafetyManagementPlanId=SafetyManagementPlanGallery.Selected.Id)).Id}))
Identing as a way of making code readable, what I would like to have is ability to switch line editor to auto-ident mode.
If( CreateNew=true, Collect( '[dbo].[AssignmentPermit]', { SafetyManagementPlanId: SafetyManagementPlanGallery.Selected.Id, Title: PermitTitleTextInput.Text, TargetName: PermitTargetNameTextInput.Text, Identifier: PermitIdentifierTextInput.Text, SafetyManagementAuthorizerName: PermitSafetyManagementAuthorizerNameTextInput.Text, SafetyManagementAuthorizerPhone: PermitSafetyManagementAuthorizerPhoneTextInput.Text, PermittedCompany: PermitPermittedCompanyTextInput.Text, PermittedContactName: PermitPermittedContactNameTextInput.Text, PermittedContactPhone: PermitPermittedContactPhoneTextInput.Text, AdditionalInformation: PermitAdditionalInformationTextInput.Text } ), Patch( '[dbo].[AssignmentPermit]', First( Filter( '[dbo].[AssignmentPermit]', Id=AssignmentPermitId) ), { Title:PermitTitleTextInput.Text, TargetName: PermitTargetNameTextInput.Text, Identifier: PermitIdentifierTextInput.Text, SafetyManagementAuthorizerName: PermitSafetyManagementAuthorizerNameTextInput.Text, SafetyManagementAuthorizerPhone: PermitSafetyManagementAuthorizerPhoneTextInput.Text, PermittedCompany: PermitPermittedCompanyTextInput.Text, PermittedContactName: PermitPermittedContactNameTextInput.Text, PermittedContactPhone: PermitPermittedContactPhoneTextInput.Text, AdditionalInformation: PermitAdditionalInformationTextInput.Text } ) ); If( CreateNew=true, UpdateContext( { CreateNew:false, AssignmentPermitId:Last( Filter( '[dbo].[AssignmentPermit]', SafetyManagementPlanId=SafetyManagementPlanGallery.Selected.Id ) ).Id } ) )
Commenting would be nice feature as well - I don't know if you have it already, I might have just overlooked it.
Reuseability of code could be real user defined functions or simply code blocks.
1. Define reuseable code block MyCodeBlock1. This is simple, not a real function as it does not need parameters. It simply functions as its code would be right there where it is inserted.
Title: PermitTitleTextInput.Text, TargetName: PermitTargetNameTextInput.Text, Identifier: PermitIdentifierTextInput.Text, SafetyManagementAuthorizerName: PermitSafetyManagementAuthorizerNameTextInput.Text, SafetyManagementAuthorizerPhone: PermitSafetyManagementAuthorizerPhoneTextInput.Text, PermittedCompany: PermitPermittedCompanyTextInput.Text, PermittedContactName: PermitPermittedContactNameTextInput.Text, PermittedContactPhone: PermitPermittedContactPhoneTextInput.Text, AdditionalInformation: PermitAdditionalInformationTextInput.Text
2. So the original code would be like this.
If(
CreateNew=true,
Collect(
'[dbo].[AssignmentPermit]',
{
SafetyManagementPlanId: SafetyManagementPlanGallery.Selected.Id,
ReuseCode(MyCodeBlock1)
}
),
Patch(
'[dbo].[AssignmentPermit]',
First(
Filter(
'[dbo].[AssignmentPermit]',
Id=AssignmentPermitId)
),
{
ReuseCode(MyCodeBlock1)
}
)
);
If(
CreateNew=true,
UpdateContext(
{
CreateNew:false,
AssignmentPermitId:Last(
Filter(
'[dbo].[AssignmentPermit]',
SafetyManagementPlanId=SafetyManagementPlanGallery.Selected.Id
)
).Id
}
)
Well. Just a few ideas there.
Cheers,
Olli