Skip to content

Commit

Permalink
fix: multiple scheduling enhancements
Browse files Browse the repository at this point in the history
- responsiveness
- automation object saving
- automation loading
- initial cron value fix
- textarea updates

JIRA: F1-437
risk: low
  • Loading branch information
scavnickyj committed Jul 3, 2024
1 parent 64057a3 commit 26961db
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ export class AutomationsQuery implements IAutomationsQuery {
...metaIncludeObj,
...filterObj,
...this.sort,
include: ["createdBy", "modifiedBy"],
include: [
"createdBy",
"modifiedBy",
"notificationChannel",
"recipients",
"exportDefinitions",
],
size: limit,
page: offset / limit,
}),
Expand Down Expand Up @@ -98,6 +104,6 @@ export class AutomationsQuery implements IAutomationsQuery {
allFilters.push(`${this.type}=isnull=false`);
}

return allFilters ? { filter: allFilters.join(";") } : {};
return allFilters.length > 0 ? { filter: allFilters.join(";") } : {};
};
}
18 changes: 17 additions & 1 deletion libs/sdk-ui-dashboard/src/model/react/useWorkspaceAutomations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ interface IUseWorkspaceAutomationsConfig
* Workspace to work with.
*/
workspace?: string;

/**
* Number of automations to get.
*
* Defaults to 100
*/
limit?: number;
}

/**
Expand All @@ -43,6 +50,7 @@ export function useWorkspaceAutomations(
onLoading,
onPending,
onSuccess,
limit = 100,
}: IUseWorkspaceAutomationsConfig,
dependencies?: any[],
): UseCancelablePromiseState<IAutomationMetadataObject[], any> {
Expand All @@ -52,7 +60,15 @@ export function useWorkspaceAutomations(
return useCancelablePromise(
{
promise: enable
? () => effectiveBackend.workspace(effectiveWorkspace).automations().getAutomations()
? () =>
effectiveBackend
.workspace(effectiveWorkspace)
.automations()
.getAutomationsQuery()
.withSize(limit)
.withSorting(["title,asc"])
.query()
.then((result) => result.items)
: undefined,
onCancel,
onError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,11 @@
"comment": "Title of a link to documentation",
"limit": 0
},
"dialogs.schedule.email.footer.title.short": {
"value": "Help",
"comment": "Title of a link to documentation",
"limit": 0
},
"dialogs.schedule.email.save": {
"value": "Save",
"comment": "Translate as imperative. It's caption of a button for saving scheduled mail",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { isExportDefinitionDashboardContent } from "@gooddata/sdk-model";
import { getTimezoneByIdentifier, TIMEZONE_DEFAULT } from "./utils/timezone.js";
import { DASHBOARD_TITLE_MAX_LENGTH } from "../../constants/index.js";
import parseISO from "date-fns/parseISO/index.js";
import { isMobileView } from "./utils/responsive.js";

const MAX_MESSAGE_LENGTH = 200;
const MAX_SUBJECT_LENGTH = 200;
Expand Down Expand Up @@ -96,6 +97,10 @@ export function ScheduledMailDialogRenderer(props: IScheduledEmailDialogProps) {
automation.schedule?.firstRun ?? normalizeTime(new Date(), undefined, 60).toISOString(),
);

const helpTextId = isMobileView()
? "dialogs.schedule.email.footer.title.short"
: "dialogs.schedule.email.footer.title";

// trigger the invariant only if the user tries to open the dialog
if (isVisible) {
invariant(
Expand Down Expand Up @@ -129,7 +134,7 @@ export function ScheduledMailDialogRenderer(props: IScheduledEmailDialogProps) {
footerLeftRenderer={() => (
<div className="gd-schedule-email-dialog-footer-link">
<Hyperlink
text={intl.formatMessage({ id: "dialogs.schedule.email.footer.title" })}
text={intl.formatMessage({ id: helpTextId })}
href=""
iconClass="gd-icon-circle-question"
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// (C) 2019-2024 GoodData Corporation
import * as React from "react";
import cx from "classnames";

import { isMobileView } from "../utils/responsive.js";
interface ITextareaOwnProps {
className: string;
hasError: boolean;
Expand Down Expand Up @@ -30,18 +28,11 @@ export class Textarea extends React.PureComponent<ITextareaProps, ITextareaState

constructor(props: ITextareaProps) {
super(props);
this.state = {
rows: isMobileView() ? 1 : props.rows,
};
}

public render() {
const { className, label, maxlength, placeholder, value } = this.props;
const { rows } = this.state;

const classNames = cx(`gd-input-component gd-textarea-component ${className}`, {
"gd-textarea-component-collapsed": rows === 1,
});
const { className, label, maxlength, placeholder, value, rows } = this.props;
const classNames = cx(`gd-input-component gd-textarea-component ${className}`);

return (
<div className={classNames}>
Expand All @@ -53,11 +44,8 @@ export class Textarea extends React.PureComponent<ITextareaProps, ITextareaState
placeholder={placeholder}
value={value}
rows={rows}
onBlur={this.onBlur}
onChange={this.onChange}
onFocus={this.onFocus}
/>
{rows === 1 ? this.renderCollapseIndicator() : null}
</label>
</div>
);
Expand All @@ -71,23 +59,7 @@ export class Textarea extends React.PureComponent<ITextareaProps, ITextareaState
});
};

private onBlur = (_e: React.FocusEvent<HTMLTextAreaElement>): void => {
if (isMobileView()) {
this.setState({ rows: 1 });
}
};

private onChange = (e: React.ChangeEvent<HTMLTextAreaElement>): void => {
this.props.onChange(e.target.value);
};

private onFocus = (_e: React.FocusEvent<HTMLTextAreaElement>): void => {
if (isMobileView()) {
this.setState({ rows: this.props.rows });
}
};

private renderCollapseIndicator = (): React.ReactNode => {
return <span className="gd-input-component-indicator">&#8943;</span>;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function newAutomationMetadataObjectDefinition({
}): IAutomationMetadataObjectDefinition {
const firstRun = parseISO(new Date().toISOString());
const normalizedFirstRun = normalizeTime(firstRun, undefined, 60);
const cron = getDefaultCronExpression(firstRun);
const cron = getDefaultCronExpression(normalizedFirstRun);

const automation: IAutomationMetadataObjectDefinition = {
type: "automation",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
// (C) 2019-2024 GoodData Corporation
import { useCallback } from "react";
import { ObjRef, IAutomationMetadataObject, IAutomationMetadataObjectDefinition } from "@gooddata/sdk-model";
import {
ObjRef,
IAutomationMetadataObject,
IAutomationMetadataObjectDefinition,
IAutomationSchedule,
} from "@gooddata/sdk-model";
import { useCreateScheduledEmail } from "./useCreateScheduledEmail.js";
import { useUpdateScheduledEmail } from "./useUpdateScheduledEmail.js";
import { IScheduledEmailDialogProps } from "../../types.js";
import { IntlShape, useIntl } from "react-intl";
import omit from "lodash/omit.js";

export function useSaveScheduledEmailToBackend(
automation: IAutomationMetadataObject | IAutomationMetadataObjectDefinition,
Expand Down Expand Up @@ -40,10 +46,10 @@ export function useSaveScheduledEmailToBackend(
);

const handleSaveScheduledEmail = (): void => {
if (automation.id) {
handleUpdateScheduledEmail(automation);
const sanitizedAutomation = sanitizeAutomation(automation, intl);
if (sanitizedAutomation.id) {
handleUpdateScheduledEmail(sanitizedAutomation);
} else {
const sanitizedAutomation = sanitizeAutomation(automation, intl);
handleCreateScheduledEmail(sanitizedAutomation);
}
};
Expand All @@ -62,5 +68,12 @@ function sanitizeAutomation(
if (!automation.title) {
automation.title = intl.formatMessage({ id: "dialogs.schedule.email.title.placeholder" });
}

// We want to omit the cronDescription as it a variable created on backend that cannot
// be overriden and BE has hard time handling it with each PUT
if (automation.schedule) {
automation.schedule = omit(automation.schedule, ["cronDescription"]) as IAutomationSchedule;
}

return automation;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
useDashboardSelector,
} from "../../../model/index.js";
import { messages } from "../../../locales.js";
import { isMobileView } from "../DefaultScheduledEmailDialog/utils/responsive.js";

/**
* @alpha
Expand Down Expand Up @@ -56,6 +57,10 @@ export const ScheduledEmailManagementDialog: React.FC<IScheduledEmailManagementD

const maxAutomationsReached = automations.length >= maxAutomations;

const helpTextId = isMobileView()
? "dialogs.schedule.email.footer.title.short"
: "dialogs.schedule.email.footer.title";

return (
<>
<Dialog
Expand Down Expand Up @@ -97,7 +102,7 @@ export const ScheduledEmailManagementDialog: React.FC<IScheduledEmailManagementD
<div className="gd-content-divider"></div>
<div className="gd-buttons">
<Hyperlink
text={intl.formatMessage({ id: "dialogs.schedule.email.footer.title" })}
text={intl.formatMessage({ id: helpTextId })}
href=""
iconClass="gd-icon-circle-question"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const ScheduledEmails: React.FC<IScheduledEmailsProps> = (props) => {

if (isLoading) {
return (
<div className="gd-loading-equalizer-wrap">
<div className="gd-loading-equalizer-wrap gd-scheduled-emails-message">
<div className="gd-loading-equalizer gd-loading-equalizer-fade">
<LoadingSpinner
className="large gd-loading-equalizer-spinner"
Expand Down
51 changes: 24 additions & 27 deletions libs/sdk-ui-dashboard/styles/scss/scheduled_mail.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ $horizontal-space: 10px;
$vertical-space: 20px;
$input-height: 28px;
$dialog-padding: 20px;
$min-content-height: 110px;

@mixin input-styles {
color: button-variables.$button-normal-color;
Expand Down Expand Up @@ -96,27 +97,12 @@ $dialog-padding: 20px;
}

.gd-input-field {
resize: vertical;
resize: none;
min-height: 30px;

@media #{kit-variables.$small-only} {
resize: none;
}
}

.gd-input-component-indicator {
position: absolute;
top: 10px;
right: 10px;
color: kit-variables.$gd-color-text;
font-size: 14px;
font-family: gdcustomfont, avenir, "Helvetica Neue", arial, sans-serif;
}
}

.gd-textarea-component-collapsed {
.gd-input-field {
overflow: hidden;
font-size: 13px;
font-style: normal;
font-weight: 400;
line-height: 15px;
}
}

Expand Down Expand Up @@ -364,7 +350,7 @@ $dialog-padding: 20px;
.gd-scheduled-email-management-dialog {
display: flex;
flex-direction: column;
width: 460px;
width: 540px;

@media #{kit-variables.$small-only} {
width: calc(100vw - 20px);
Expand All @@ -386,19 +372,17 @@ $dialog-padding: 20px;
}

.gd-scheduled-emails-content {
display: flex;
flex-direction: column;
flex: 1;
overflow-x: hidden;
width: calc(100% + 20px);
margin: 0 -20px 0 0;
padding: 10px 20px 20px 0;
padding: 10px 20px 10px 0;
min-height: 143px;
max-height: 455px;
max-height: 475px;
overflow-y: auto;

@media #{kit-variables.$small-only} {
max-height: none;
height: 100%;
}
}

Expand Down Expand Up @@ -434,10 +418,11 @@ $dialog-padding: 20px;
}

.gd-scheduled-emails-message {
height: 100%;
min-height: $min-content-height;
display: flex;
justify-content: center;
align-items: center;
flex: 1;
padding-top: 10px;
text-align: center;
color: kit-variables.$gd-color-state-blank;
Expand Down Expand Up @@ -569,6 +554,10 @@ $dialog-padding: 20px;
button {
margin: 5px;
}

.gd-hyperlink:hover {
text-decoration: none;
}
}

.gd-add-button {
Expand Down Expand Up @@ -881,6 +870,10 @@ $dialog-padding: 20px;
color: kit-variables.$gd-palette-primary-base;
text-decoration: none;
}

@media #{kit-variables.$small-only} {
display: block;
}
}

.gd-schedule-email-dialog-destination {
Expand Down Expand Up @@ -946,4 +939,8 @@ $dialog-padding: 20px;
display: inline-flex;
flex: 1;
justify-content: flex-start;

.gd-hyperlink:hover {
text-decoration: none;
}
}

0 comments on commit 26961db

Please sign in to comment.