Skip to content

Commit

Permalink
Merge pull request #5571 from gooddata/SHA_master
Browse files Browse the repository at this point in the history
fix: schedule list dashboard / widget name, starts field
  • Loading branch information
hackerstanislav authored Nov 19, 2024
2 parents e3c6b47 + 72fa8dd commit dc94779
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import { convertUserIdentifier } from "./UsersConverter.js";
import { cloneWithSanitizedIds } from "./IdSanitization.js";
import isEmpty from "lodash/isEmpty.js";

type MetadataObjectDefinition = {
widget?: string;
title?: string;
filters?: FilterContextItem[];
};

export const convertExportDefinitionMdObject = (
exportDefinitionOut: JsonApiExportDefinitionOutWithLinks,
included: JsonApiExportDefinitionOutIncludes[] = [],
Expand Down Expand Up @@ -72,7 +78,7 @@ export const convertInlineExportDefinitionMdObject = (
id,
uri: id,
ref: idRef(id, "exportDefinition"),
title: "",
title: (exportDefinitionOut.requestPayload.metadata as MetadataObjectDefinition).title ?? "",
description: "",
tags: [],
requestPayload: request,
Expand All @@ -86,7 +92,7 @@ const convertExportDefinitionRequestPayload = (
exportRequest: VisualExportRequest | TabularExportRequest,
): IExportDefinitionRequestPayload => {
if (isTabularRequest(exportRequest)) {
const { widget } = (exportRequest.metadata as { widget?: string }) ?? {};
const { widget } = (exportRequest.metadata as MetadataObjectDefinition) ?? {};

const filters = exportRequest.visualizationObjectCustomFilters as IFilter[];
const filtersObj = filters ? { filters: filters.map(cloneWithSanitizedIds) } : {};
Expand All @@ -113,7 +119,7 @@ const convertExportDefinitionRequestPayload = (
...settingsObj,
};
} else {
const filters = (exportRequest.metadata as any)?.filters as FilterContextItem[];
const filters = (exportRequest.metadata as MetadataObjectDefinition)?.filters;
const filtersObj = filters ? { filters } : {};

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,14 @@ export function convertAutomation(

const tabularExports = exportDefinitions
?.filter((ed) => isExportDefinitionVisualizationObjectRequestPayload(ed.requestPayload))
.map((ed) => ({ requestPayload: convertExportDefinitionRequestPayload(ed.requestPayload) }));
.map((ed) => ({
requestPayload: convertExportDefinitionRequestPayload(ed.requestPayload, ed.title),
}));
const visualExports = exportDefinitions
?.filter((ed) => isExportDefinitionDashboardRequestPayload(ed.requestPayload))
.map((ed) => ({ requestPayload: convertExportDefinitionRequestPayload(ed.requestPayload) }));
.map((ed) => ({
requestPayload: convertExportDefinitionRequestPayload(ed.requestPayload, ed.title),
}));

const attributes = omitBy(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,29 @@ export const convertExportDefinitionMdObjectDefinition = (
title,
description,
tags,
requestPayload: convertExportDefinitionRequestPayload(requestPayload),
requestPayload: convertExportDefinitionRequestPayload(requestPayload, title),
},
},
};
};

export const convertExportDefinitionRequestPayload = (
exportRequest: IExportDefinitionRequestPayload,
title?: string,
): TabularExportRequest | VisualExportRequest => {
if (isExportDefinitionDashboardRequestPayload(exportRequest)) {
const { filters, dashboard } = exportRequest.content;
const metadataObj = exportRequest.content.filters ? { metadata: { filters } } : {};
const isMetadataFilled = title || exportRequest.content.filters;
const metadataObj = {
...(isMetadataFilled
? {
metadata: {
...(exportRequest.content.filters ? { filters } : {}),
...(title ? { title } : {}),
},
}
: {}),
};

return {
fileName: exportRequest.fileName,
Expand All @@ -63,6 +74,7 @@ export const convertExportDefinitionRequestPayload = (
},
metadata: {
widget,
...(title ? { title } : {}),
},
} as TabularExportRequest;
};
Expand Down
4 changes: 2 additions & 2 deletions libs/sdk-ui-kit/api/sdk-ui-kit.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4170,7 +4170,7 @@ export interface ITimepickerOwnProps {
// (undocumented)
skipNormalizeTime?: boolean;
// (undocumented)
time: Date;
time: Date | null;
// (undocumented)
timeAnchor?: number;
// (undocumented)
Expand Down Expand Up @@ -4429,7 +4429,7 @@ export class MultiSelectListItem extends PureComponent<IMultiSelectListItemProps
export const NoData: React_2.FC<INoDataProps>;

// @internal
export function normalizeTime(time: Date, date?: Date, timeAnchor?: number): Date;
export function normalizeTime(time?: Date, date?: Date, timeAnchor?: number): Date;

// @internal (undocumented)
export const NumericInput: React_2.FC<INumericInputProps>;
Expand Down
2 changes: 1 addition & 1 deletion libs/sdk-ui-kit/src/Datepicker/Datepicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class WrappedDatePicker extends React.PureComponent<DatePickerProps, IDat
const { props } = this;

if (props.date > nextProps.date || props.date < nextProps.date) {
const selectedDate = this.updateDate(nextProps.date);
const selectedDate = this.updateDate(nextProps.date || new Date());
this.setState({ selectedDate });
this.setState({ monthDate: selectedDate });
this.setState({ inputValue: formatDate(selectedDate, props.dateFormat) });
Expand Down
13 changes: 6 additions & 7 deletions libs/sdk-ui-kit/src/RecurrenceForm/DateTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ import { DEFAULT_DROPDOWN_ZINDEX, MAX_VISIBLE_TIME_ITEMS_COUNT, TIME_ANCHOR } fr

interface IDateTimeProps {
label: string;
date: Date;
date: Date | null;
locale?: string;
timezone?: string;
weekStart?: WeekStart;
dateFormat?: string;
timeFormat?: string;
onDateChange: (date: Date) => void;
onDateChange: (date: Date | null, valid: boolean) => void;
}

export const DateTime: React.FC<IDateTimeProps> = (props) => {
const { label, date, dateFormat, locale, timezone, onDateChange, weekStart, timeFormat } = props;

const handleDateChange = (selectedDate: Date) => {
const handleDateChange = (selectedDate: Date | null) => {
const newDate = normalizeTime(date, selectedDate, TIME_ANCHOR);
onDateChange(newDate);
onDateChange(newDate, !!selectedDate);
};

const handleTimeChange = (selectedTime: Date) => {
const handleTimeChange = (selectedTime: Date | null) => {
const newDate = normalizeTime(selectedTime, date, TIME_ANCHOR);
onDateChange(newDate);
onDateChange(newDate, !!selectedTime);
};

return (
Expand All @@ -40,7 +40,6 @@ export const DateTime: React.FC<IDateTimeProps> = (props) => {
dateFormat={dateFormat}
locale={locale}
placeholder={dateFormat}
resetOnInvalidValue={true}
onChange={handleDateChange}
weekStart={weekStart}
/>
Expand Down
8 changes: 6 additions & 2 deletions libs/sdk-ui-kit/src/RecurrenceForm/RecurrenceForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@ const RecurrenceFormCore: React.FC<IRecurrenceFormProps> = (props) => {
);

const onDateChange = useCallback(
(date: Date) => {
(date: Date, valid: boolean) => {
setDateValue(date);
const newExpression = constructCronExpression(date, recurrenceType, cronExpression, weekStart);
onChange(newExpression, date, isCronExpressionValid(newExpression, allowHourlyRecurrence));
onChange(
newExpression,
date,
valid && isCronExpressionValid(newExpression, allowHourlyRecurrence),
);
},
[cronExpression, onChange, recurrenceType, weekStart, allowHourlyRecurrence],
);
Expand Down
2 changes: 1 addition & 1 deletion libs/sdk-ui-kit/src/Timepicker/Timepicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export { normalizeTime, formatTime };
* @internal
*/
export interface ITimepickerOwnProps {
time: Date;
time: Date | null;
className?: string;
maxVisibleItemsCount?: number;
onChange?: (selectedTime: Date) => void;
Expand Down
12 changes: 6 additions & 6 deletions libs/sdk-ui-kit/src/Timepicker/utils/timeUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ export function updateTime(h: number, m: number, date?: Date): Date {
return selectedTime;
}

function getNormalizedHourAndMinute(time: Date, timeAnchor = TIME_ANCHOR) {
function getNormalizedHourAndMinute(time?: Date, timeAnchor = TIME_ANCHOR) {
let h: number;
let m: number;
const hours = time.getHours();
const minutes = time.getMinutes();
const hours = time?.getHours() ?? 0;
const minutes = time?.getMinutes() ?? 0;

// Do not shift time if it is exactly on the new hour (0 == 60 when timeAnchor is 60)
if (minutes === 0 && timeAnchor === 60) {
return { hours, minutes: 0 };
}

if (time.getMinutes() < timeAnchor) {
if (minutes < timeAnchor) {
h = hours;
m = timeAnchor;
} else {
Expand All @@ -56,7 +56,7 @@ function getNormalizedHourAndMinute(time: Date, timeAnchor = TIME_ANCHOR) {
* return 8:00 if time is 7:35
* return 0:00 if time is 23:45
*/
export function normalizeTime(time: Date, date?: Date, timeAnchor = TIME_ANCHOR): Date {
export function normalizeTime(time?: Date, date?: Date, timeAnchor = TIME_ANCHOR): Date {
const { hours, minutes } = getNormalizedHourAndMinute(time, timeAnchor);
return updateTime(hours, minutes, date);
return updateTime(hours, minutes, date || time);
}

0 comments on commit dc94779

Please sign in to comment.