Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vscode): Implement errors side panel in vscode extension #4512

Merged
merged 2 commits into from
Apr 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 36 additions & 19 deletions apps/vs-code-react/src/app/designer/DesignerCommandBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {
validateParameter,
updateParameterValidation,
openPanel,
useWorkflowParameterValidationErrors,
useAllSettingsValidationErrors,
useAllConnectionErrors,
} from '@microsoft/logic-apps-designer';
import type { RootState } from '@microsoft/logic-apps-designer';
import { RUN_AFTER_COLORS, isNullOrEmpty } from '@microsoft/logic-apps-shared';
Expand Down Expand Up @@ -38,6 +41,8 @@ export const DesignerCommandBar: React.FC<DesignerCommandBarProps> = ({ isRefres
)
);

const designerIsDirty = useIsDesignerDirty();

const { isLoading: isSaving, mutate: saveWorkflowMutate } = useMutation(async () => {
const designerState = DesignerStore.getState();
const { definition, parameters, connectionReferences } = await serializeBJSWorkflow(designerState, {
Expand Down Expand Up @@ -87,6 +92,11 @@ export const DesignerCommandBar: React.FC<DesignerCommandBarProps> = ({ isRefres
id: '+0ua83',
description: 'Button text for parameters',
}),
DESIGNER_ERRORS: intl.formatMessage({
defaultMessage: 'Errors',
id: 'ohOaXj',
description: 'Button text for errors',
}),
MONITORING_VIEW_REFRESH: intl.formatMessage({
defaultMessage: 'Refresh',
id: 'pr9GwA',
Expand All @@ -110,8 +120,6 @@ export const DesignerCommandBar: React.FC<DesignerCommandBarProps> = ({ isRefres
disableGrey: [{ color: 'rgb(121, 119, 117)' }, iconClass],
});

const designerIsDirty = useIsDesignerDirty();

const allInputErrors = useSelector((state: RootState) => {
return (Object.entries(state.operations.inputParameters) ?? []).filter(([_id, nodeInputs]) =>
Object.values(nodeInputs.parameterGroups).some((parameterGroup) =>
Expand All @@ -120,22 +128,20 @@ export const DesignerCommandBar: React.FC<DesignerCommandBarProps> = ({ isRefres
);
});

const allWorkflowParameterErrors = useSelector((state: RootState) => {
let validationErrorToShow = null;
for (const parameter of Object.entries(state.workflowParameters.validationErrors) ?? []) {
if (parameter?.[1]?.value) {
validationErrorToShow = {
name: state.workflowParameters.definitions[parameter[0]]?.name,
msg: parameter[1].value,
};
}
}
return validationErrorToShow;
});

const haveErrors = useMemo(() => allInputErrors.length > 0 || !!allWorkflowParameterErrors, [allInputErrors, allWorkflowParameterErrors]);
const haveInputErrors = allInputErrors.length > 0;
const allWorkflowParameterErrors = useWorkflowParameterValidationErrors();
const haveWorkflowParameterErrors = Object.keys(allWorkflowParameterErrors ?? {}).length > 0;
const allSettingsErrors = useAllSettingsValidationErrors();
const haveSettingsErrors = Object.keys(allSettingsErrors ?? {}).length > 0;
const allConnectionErrors = useAllConnectionErrors();
const haveConnectionErrors = Object.keys(allConnectionErrors ?? {}).length > 0;

const haveErrors = useMemo(
() => haveInputErrors || haveWorkflowParameterErrors || haveSettingsErrors || haveConnectionErrors,
[haveInputErrors, haveWorkflowParameterErrors, haveSettingsErrors, haveConnectionErrors]
);

const isSaveDisabled = isSaving || haveErrors || !designerIsDirty;
const isSaveDisabled = useMemo(() => isSaving || haveErrors || !designerIsDirty, [isSaving, haveErrors, designerIsDirty]);

const desingerItems: ICommandBarItemProps[] = [
{
Expand Down Expand Up @@ -166,7 +172,7 @@ export const DesignerCommandBar: React.FC<DesignerCommandBarProps> = ({ isRefres
return (
<>
{item.text}
{allWorkflowParameterErrors ? (
{haveWorkflowParameterErrors ? (
<div style={{ display: 'inline-block', marginLeft: 8 }}>
<TrafficLightDot fill={RUN_AFTER_COLORS[isDarkMode ? 'dark' : 'light']['FAILED']} />
</div>
Expand All @@ -176,6 +182,17 @@ export const DesignerCommandBar: React.FC<DesignerCommandBarProps> = ({ isRefres
},
onClick: () => !!dispatch(openPanel({ panelMode: 'WorkflowParameters' })),
},
{
key: 'errors',
disabled: !haveErrors,
text: Resources.DESIGNER_ERRORS,
ariaLabel: Resources.DESIGNER_ERRORS,
iconProps: {
iconName: haveErrors ? 'StatusErrorFull' : 'ErrorBadge',
style: haveErrors ? { color: RUN_AFTER_COLORS[isDarkMode ? 'dark' : 'light']['FAILED'] } : undefined,
},
onClick: () => !!dispatch(openPanel({ panelMode: 'Error' })),
},
];

const monitoringViewItems: ICommandBarItemProps[] = [
Expand Down Expand Up @@ -204,7 +221,7 @@ export const DesignerCommandBar: React.FC<DesignerCommandBarProps> = ({ isRefres
items={isMonitoringView ? monitoringViewItems : desingerItems}
ariaLabel="Use left and right arrow keys to navigate between commands"
styles={{
root: { borderBottom: `1px solid ${isDarkMode ? '#333333' : '#d6d6d6'}` },
root: { borderBottom: `1px solid ${isDarkMode ? '#333333' : '#d6d6d6'}`, padding: '0 20px' },
}}
/>
);
Expand Down
Loading