Skip to content

Commit

Permalink
Code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
anderson-joyle committed Sep 13, 2024
1 parent 4a22843 commit 7b3d469
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 69 deletions.
56 changes: 56 additions & 0 deletions src/libraries/Microsoft.PowerFx.Core/App/IECSFlags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

namespace Microsoft.PowerFx.Core.App
{
internal interface IECSFlags
{
internal bool IsNewEnhancedComponentPropertiesFlightEnabled { get; }

internal bool IsComponentFunctionPropertyDataflowEnabled { get; }

internal bool IsCommentingImportExportEnabled { get; }

internal bool ShowPowerFxV1FeatureECSFlag { get; }

internal bool IsUpdateIfDelegationEnabled { get; }

internal bool EnableSecureSharedConnectionsByDefault { get; }

internal bool IsComponentResetBehaviorUpdated { get; }

internal bool IsPostCompLibImportAnalysisEnabled { get; }

internal bool IsLazyRecordLoadingEnabled { get; }

internal bool IsAsyncNodeDelegationEnabled { get; }

internal bool IsImpureNodeDelegationEnabled { get; }

internal bool IsDataflowAnalysisVisible { get; }

internal bool IsDataflowAnalysisEnabledForNewApps { get; }

internal bool IsDataflowAnalysisEnabledForAllApps { get; }

internal bool IsAsyncOnComponentFunctionProperties { get; }

internal bool IsCanvasComponentBehaviorPropertyCoercion { get; }

internal bool IsModernControlsOnByDefault { get; }

internal bool IsPowerFxFormulaBarCommentsToFxEnabledV2 { get; }

internal bool IsPowerFxFormulaBarCommentsToFxEnabledForNewApps { get; }

internal bool IsRemoveAllDelegationEnabled { get; }

internal bool IsEditInMCSECSEnabled { get; }

internal bool IsImperativeUdfEnabled { get; }

internal bool IsNL2FxReducedContextEnabled { get; }

internal bool IsProactiveControlRenameEnabled { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using System.Collections.Generic;

namespace Microsoft.PowerFx.Core.App
{
internal interface IExternalDocumentProperties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ protected override async Task<DValue<RecordValue>> PatchCoreAsync(RecordValue ba
/// <param name="mutationCopy">Should we make a copy of the found record, ahead of mutation.</param>///
/// <returns>A record instance within the current table. This record can then be updated.</returns>
/// <remarks>A derived class may override if there's a more efficient way to find the match than by linear scan.</remarks>
internal virtual async Task<RecordValue> FindAsync(RecordValue baseRecord, CancellationToken cancellationToken, bool mutationCopy = false)
protected virtual async Task<RecordValue> FindAsync(RecordValue baseRecord, CancellationToken cancellationToken, bool mutationCopy = false)
{
cancellationToken.ThrowIfCancellationRequested();

Expand Down
66 changes: 11 additions & 55 deletions src/libraries/Microsoft.PowerFx.Core/Texl/Builtins/Remove.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.PowerFx.Core.App;
using Microsoft.PowerFx.Core.App.ErrorContainers;
using Microsoft.PowerFx.Core.Binding;
using Microsoft.PowerFx.Core.Entities;
Expand All @@ -21,9 +21,6 @@
namespace Microsoft.PowerFx.Core.Texl.Builtins
{
// Remove(collection:*[], item1:![], item2:![], ..., ["All"])

// !!!TODO MOVE THIS TO src/Cloud/DocumentServer.Core/Document/Texl/Functions/Libraries/BuiltinFunctions.cs
//[RequiresErrorContext]
internal class RemoveFunction : BuiltinFunction, ISuggestionAwareFunction
{
public override bool ManipulatesCollections => true;
Expand Down Expand Up @@ -328,22 +325,6 @@ public override bool IsAsyncInvocation(CallNode callNode, TexlBinding binding)
return Arg0RequiresAsync(callNode, binding);
}

// !!!TODO MOVE THIS TO
// src/Cloud/DocumentServer.Core/Document/Texl/Functions/Libraries/BuiltinFunctions.cs and
// src/Cloud/DocumentServer.Core/Document/Publish/TryPushCustomJsExpressionHandlers.cs
//public static void PushCustomJsArgs(TexlFunction func, JsTranslator translator, TexlBinding binding, CallNode node, List<Fragment> argFragments)
//{
// Contracts.Assert(argFragments.Count >= 1);

// // If the "ALL" arg was not specified, inject an empty string arg instead.
// var args = node.Args.Children;

// if (argFragments.Count < 3 || !DType.String.Accepts(binding.GetType(args[argFragments.Count - 1]), exact: true, useLegacyDateTimeAccepts: false, usePowerFxV1CompatibilityRules: binding.Features.PowerFxV1CompatibilityRules))
// {
// argFragments.Add(translator.CreateFragment(PAStringBuilderConst.EmptyQuotes));
// }
//}

protected override bool RequiresPagedDataForParamCore(TexlNode[] args, int paramIndex, TexlBinding binding)
{
Contracts.AssertValue(args);
Expand All @@ -358,9 +339,6 @@ protected override bool RequiresPagedDataForParamCore(TexlNode[] args, int param
}

// Remove(collection:*[], source:*[], ["All"])
// !!!TODO MOVE THIS TO src/Cloud/DocumentServer.Core/Document/Texl/Functions/Libraries/BuiltinFunctions.cs
//[RequiresErrorContext]
//[TexlRuntimeNameOverride(Suffix = "All")]
internal class RemoveAllFunction : BuiltinFunction
{
public override bool ManipulatesCollections => true;
Expand Down Expand Up @@ -538,27 +516,6 @@ public override bool IsAsyncInvocation(CallNode callNode, TexlBinding binding)
return Arg0RequiresAsync(callNode, binding);
}

// !!!TODO MOVE THIS TO
// src/Cloud/DocumentServer.Core/Document/Texl/Functions/Libraries/BuiltinFunctions.cs and
// src/Cloud/DocumentServer.Core/Document/Publish/TryPushCustomJsExpressionHandlers.cs
//public static void PushCustomJsArgs(TexlFunction func, JsTranslator translator, TexlBinding binding, CallNode node, List<Fragment> argFragments)
//{
// Contracts.Assert(argFragments.Count >= 1);

// if (func.IsServerDelegatable(node, binding))
// {
// // If remove all is delegatable && the "ALL" arg was not specified, the translator handles it
// return;
// }

// // If the "ALL" arg was not specified, inject an empty string arg instead.
// var args = node.Args.Children;
// if (argFragments.Count < 3 || !DType.String.Accepts(binding.GetType(args[argFragments.Count - 1]), exact: true, useLegacyDateTimeAccepts: false, usePowerFxV1CompatibilityRules: binding.Features.PowerFxV1CompatibilityRules))
// {
// argFragments.Add(translator.CreateFragment(PAStringBuilderConst.EmptyQuotes));
// }
//}

public override bool IsServerDelegatable(CallNode callNode, TexlBinding binding)
{
Contracts.AssertValue(callNode);
Expand All @@ -569,18 +526,17 @@ public override bool IsServerDelegatable(CallNode callNode, TexlBinding binding)
return false;
}

// !!!TODO Check with PA team
// Use ECS flag as a guard.
//if (binding.Document != null)
//{
// if (binding.Document.Properties is DocumentProperties documentProperties)
// {
// if (!documentProperties.IsRemoveAllDelegationEnabled)
// {
// return false;
// }
// }
//}
if (binding.Document != null)
{
if (binding.Document.Properties is IECSFlags flags)
{
if (!flags.IsRemoveAllDelegationEnabled)
{
return false;
}
}
}

if (!binding.TryGetDataSourceInfo(callNode.Args.Children[0], out IExternalDataSource dataSource))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.PowerFx.Core.App.ErrorContainers;
using Microsoft.PowerFx.Core.Entities;
using Microsoft.PowerFx.Core.Errors;
using Microsoft.PowerFx.Core.IR;
using Microsoft.PowerFx.Core.Localization;
using Microsoft.PowerFx.Core.Types;
using Microsoft.PowerFx.Core.Types.Enums;
using Microsoft.PowerFx.Functions;
using Microsoft.PowerFx.Interpreter.Localization;
using Microsoft.PowerFx.Syntax;
using Microsoft.PowerFx.Types;

namespace Microsoft.PowerFx.Interpreter
Expand Down Expand Up @@ -75,7 +66,7 @@ public static async Task<FormulaValue> RemoveCore(FormulaType irContext, Formula
return arg0;
}

// If any of the argN (N>0) are an error, return the error.
// If any of the argN (N>0) is error, return the error.
foreach (var arg in args.Skip(1))
{
cancellationToken.ThrowIfCancellationRequested();
Expand All @@ -87,7 +78,7 @@ public static async Task<FormulaValue> RemoveCore(FormulaType irContext, Formula

if (arg is TableValue tableValue)
{
var errorRecord = tableValue.Rows.FirstOrDefault(row => row.IsError);
var errorRecord = tableValue.Rows.First(row => row.IsError);
if (errorRecord != null)
{
return errorRecord.Error;
Expand Down

0 comments on commit 7b3d469

Please sign in to comment.