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

kup-activity-timeline: sorting and grouping changes #2062

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 10 additions & 1 deletion packages/ketchup-showcase/src/mock/activityTimeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14408,7 +14408,16 @@ const defaultData = {

export const mockedProps = {
dateColumn: 'XXDATA',
sortOrder: 'desc',
sort: [
{
column: 'XXDATA',
sortMode: 'A',
},
{
column: 'XXORA',
sortMode: 'D',
},
],
timeColumn: 'XXORA',
data: defaultData,
};
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ export default {
try: 'field',
},
{
prop: 'sortOrder',
description: 'Order for sorting',
type: 'KupDatesOrder',
default: 'desc',
try: 'field',
prop: 'sort',
description: 'Defines the current sorting options',
type: 'SortObject',
isArray: true,
default: '[]',
try: 'json',
},
{
prop: 'timeColumn',
Expand Down
11 changes: 10 additions & 1 deletion packages/ketchup/src/assets/activity-timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -14422,7 +14422,16 @@ const props = {
},
dateColumn: 'XXDATA',
timeColumn: 'XXORA',
sortOrder: 'asc',
sort: [
{
column: 'XXDATA',
sortMode: 'A',
},
{
column: 'XXORA',
sortMode: 'D',
},
],
};

if (props) {
Expand Down
16 changes: 6 additions & 10 deletions packages/ketchup/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { HTMLStencilElement, JSXBase } from "@stencil/core/internal";
import { KupAccordionData, KupAccordionItemSelectedEventPayload } from "./components/kup-accordion/kup-accordion-declarations";
import { GenericObject, KupComponentSizing, KupEventPayload } from "./types/GenericTypes";
import { KupCommand, KupDataCell, KupDataColumn, KupDataDataset, KupDataNewColumnOptions, KupDataNewColumnTypes, KupDataNode, KupDataRowAction } from "./managers/kup-data/kup-data-declarations";
import { KupDatesOrder } from "./managers/kup-dates/kup-dates-declarations";
import { GroupLabelDisplayMode, GroupObject, KupDatatableClickEventPayload, KupDatatableColumnMenuEventPayload, KupDatatableColumnMoveEventPayload, KupDatatableColumnRemoveEventPayload, KupDataTableDataset, KupDatatableDeleteRowEventPayload, KupDatatableHistoryEventPayload, KupDataTableInsertMode, KupDatatableInsertRowEventPayload, KupDatatableLoadMoreClickEventPayload, KupDataTableRow, KupDatatableRowActionItemClickEventPayload, KupDatatableRowSelectedEventPayload, LoadMoreMode as LoadMoreMode1, PaginatorPos, SelectionMode, ShowGrid, SortObject, TotalsMap } from "./components/kup-data-table/kup-data-table-declarations";
import { KupActivityTimelineClickEventPayload } from "./components/kup-activity-timeline/kup-activity-timeline-declarations";
import { ItemsDisplayMode, KupListEventPayload, KupListNode, KupListRole } from "./components/kup-list/kup-list-declarations";
import { KupAutocompleteEventPayload, KupAutocompleteIconClickEventPayload } from "./components/kup-autocomplete/kup-autocomplete-declarations";
Expand All @@ -30,7 +30,6 @@ import { KupColorPickerEventPayload } from "./components/kup-color-picker/kup-co
import { KupComboboxEventPayload, KupComboboxIconClickEventPayload } from "./components/kup-combobox/kup-combobox-declarations";
import { KupGanttPlannerProps, KupPlannerBarDisplayProps, KupPlannerBarTask, KupPlannerCalendarProps, KupPlannerClickEventPayload, KupPlannerEventOption, KupPlannerEventPayload, KupPlannerGanttEvent, KupPlannerGanttProps, KupPlannerGanttRow, KupPlannerGanttTask, KupPlannerGanttTaskN, KupPlannerItemDetail, KupPlannerPhase, KupPlannerSwitcherProps, KupPlannerTask, KupPlannerTaskGanttContentProps, KupPlannerTaskGanttProps, KupPlannerTaskItemProps, KupPlannerTaskListProps, KupPlannerTaskType, KupPlannerUnloadEventPayload, KupPlannerViewMode, PlannerProps } from "./components/kup-planner/kup-planner-declarations";
import { KupDashboardEventPayload, KupDataDashboard } from "./components/kup-dashboard/kup-dashboard-declarations";
import { GroupLabelDisplayMode, GroupObject, KupDatatableClickEventPayload, KupDatatableColumnMenuEventPayload, KupDatatableColumnMoveEventPayload, KupDatatableColumnRemoveEventPayload, KupDataTableDataset, KupDatatableDeleteRowEventPayload, KupDatatableHistoryEventPayload, KupDataTableInsertMode, KupDatatableInsertRowEventPayload, KupDatatableLoadMoreClickEventPayload, KupDataTableRow, KupDatatableRowActionItemClickEventPayload, KupDatatableRowSelectedEventPayload, LoadMoreMode as LoadMoreMode1, PaginatorPos, SelectionMode, ShowGrid, SortObject, TotalsMap } from "./components/kup-data-table/kup-data-table-declarations";
import { GenericFilter, KupGlobalFilterMode } from "./utils/filters/filters-declarations";
import { KupDatePickerEventPayload } from "./components/kup-date-picker/kup-date-picker-declarations";
import { KupDialogAutoCenter, KupDialogHeader, KupDialogModal } from "./components/kup-dialog/kup-dialog-declarations";
Expand Down Expand Up @@ -66,7 +65,7 @@ import { KupTypographyListClickEventPayload, KupTypographyListIconClickEventPayl
export { KupAccordionData, KupAccordionItemSelectedEventPayload } from "./components/kup-accordion/kup-accordion-declarations";
export { GenericObject, KupComponentSizing, KupEventPayload } from "./types/GenericTypes";
export { KupCommand, KupDataCell, KupDataColumn, KupDataDataset, KupDataNewColumnOptions, KupDataNewColumnTypes, KupDataNode, KupDataRowAction } from "./managers/kup-data/kup-data-declarations";
export { KupDatesOrder } from "./managers/kup-dates/kup-dates-declarations";
export { GroupLabelDisplayMode, GroupObject, KupDatatableClickEventPayload, KupDatatableColumnMenuEventPayload, KupDatatableColumnMoveEventPayload, KupDatatableColumnRemoveEventPayload, KupDataTableDataset, KupDatatableDeleteRowEventPayload, KupDatatableHistoryEventPayload, KupDataTableInsertMode, KupDatatableInsertRowEventPayload, KupDatatableLoadMoreClickEventPayload, KupDataTableRow, KupDatatableRowActionItemClickEventPayload, KupDatatableRowSelectedEventPayload, LoadMoreMode as LoadMoreMode1, PaginatorPos, SelectionMode, ShowGrid, SortObject, TotalsMap } from "./components/kup-data-table/kup-data-table-declarations";
export { KupActivityTimelineClickEventPayload } from "./components/kup-activity-timeline/kup-activity-timeline-declarations";
export { ItemsDisplayMode, KupListEventPayload, KupListNode, KupListRole } from "./components/kup-list/kup-list-declarations";
export { KupAutocompleteEventPayload, KupAutocompleteIconClickEventPayload } from "./components/kup-autocomplete/kup-autocomplete-declarations";
Expand All @@ -88,7 +87,6 @@ export { KupColorPickerEventPayload } from "./components/kup-color-picker/kup-co
export { KupComboboxEventPayload, KupComboboxIconClickEventPayload } from "./components/kup-combobox/kup-combobox-declarations";
export { KupGanttPlannerProps, KupPlannerBarDisplayProps, KupPlannerBarTask, KupPlannerCalendarProps, KupPlannerClickEventPayload, KupPlannerEventOption, KupPlannerEventPayload, KupPlannerGanttEvent, KupPlannerGanttProps, KupPlannerGanttRow, KupPlannerGanttTask, KupPlannerGanttTaskN, KupPlannerItemDetail, KupPlannerPhase, KupPlannerSwitcherProps, KupPlannerTask, KupPlannerTaskGanttContentProps, KupPlannerTaskGanttProps, KupPlannerTaskItemProps, KupPlannerTaskListProps, KupPlannerTaskType, KupPlannerUnloadEventPayload, KupPlannerViewMode, PlannerProps } from "./components/kup-planner/kup-planner-declarations";
export { KupDashboardEventPayload, KupDataDashboard } from "./components/kup-dashboard/kup-dashboard-declarations";
export { GroupLabelDisplayMode, GroupObject, KupDatatableClickEventPayload, KupDatatableColumnMenuEventPayload, KupDatatableColumnMoveEventPayload, KupDatatableColumnRemoveEventPayload, KupDataTableDataset, KupDatatableDeleteRowEventPayload, KupDatatableHistoryEventPayload, KupDataTableInsertMode, KupDatatableInsertRowEventPayload, KupDatatableLoadMoreClickEventPayload, KupDataTableRow, KupDatatableRowActionItemClickEventPayload, KupDatatableRowSelectedEventPayload, LoadMoreMode as LoadMoreMode1, PaginatorPos, SelectionMode, ShowGrid, SortObject, TotalsMap } from "./components/kup-data-table/kup-data-table-declarations";
export { GenericFilter, KupGlobalFilterMode } from "./utils/filters/filters-declarations";
export { KupDatePickerEventPayload } from "./components/kup-date-picker/kup-date-picker-declarations";
export { KupDialogAutoCenter, KupDialogHeader, KupDialogModal } from "./components/kup-dialog/kup-dialog-declarations";
Expand Down Expand Up @@ -200,10 +198,9 @@ export namespace Components {
*/
"setProps": (props: GenericObject) => Promise<void>;
/**
* Order for sorting.
* @default 'desc'
* Defines the current sorting options.
*/
"sortOrder": KupDatesOrder;
"sort": Array<SortObject>;
/**
* Columns containing times.
* @default null
Expand Down Expand Up @@ -5821,10 +5818,9 @@ declare namespace LocalJSX {
*/
"onKup-activitytimeline-ready"?: (event: KupActivityTimelineCustomEvent<KupEventPayload>) => void;
/**
* Order for sorting.
* @default 'desc'
* Defines the current sorting options.
*/
"sortOrder"?: KupDatesOrder;
"sort"?: Array<SortObject>;
/**
* Columns containing times.
* @default null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ export interface KupActivityTimelineData {
}

export interface KupActivityTimelineActivity {
time: string;
columns: KupActivityTimelineData[];
}

export interface KupActivityTimelineDatapoint {
date: string;
time: string;
activities: KupActivityTimelineActivity[];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import {
} from './kup-activity-timeline-declarations';
import { FImage } from '../../f-components/f-image/f-image';
import { getCellValueForDisplay } from '../../utils/cell-utils';
import { KupDatesOrder } from '../../managers/kup-dates/kup-dates-declarations';
import { SortObject } from '../kup-data-table/kup-data-table-declarations';
import { sortRows } from '../kup-data-table/kup-data-table-helper';

@Component({
tag: 'kup-activity-timeline',
Expand Down Expand Up @@ -71,10 +72,9 @@ export class KupActivityTimeline {
@Prop() dateColumn: string;

/**
* Order for sorting.
* @default 'desc'
* Defines the current sorting options.
*/
@Prop() sortOrder: KupDatesOrder = KupDatesOrder.DESC;
@Prop() sort: Array<SortObject> = [];

/**
* Columns containing times.
Expand Down Expand Up @@ -158,81 +158,48 @@ export class KupActivityTimeline {
/*-------------------------------------------------*/

#toTimeline(data: KupDataDataset): KupActivityTimelineDatapoint[] {
const columns = data.columns;
const rows = data.rows;

const { columns, rows } = data;
const dateColumn = columns.find((col) => col.name === this.dateColumn);
const timeColumn = columns.find((col) => col.name === this.timeColumn);

if (!dateColumn || !timeColumn) {
return [];
}

const getColumnValue = (
columnName: string,
value: string,
date: string,
time: string
) => {
if (columnName == dateColumn.name) return date;
if (columnName == timeColumn.name) return time;
return value;
};
if (!dateColumn || !timeColumn) return [];

const activitiesByDate = sortRows(rows, this.sort).reduce(
(acc, row) => {
const date = getCellValueForDisplay(
dateColumn,
row.cells[dateColumn.name]
);
const time = getCellValueForDisplay(
timeColumn,
row.cells[timeColumn.name]
);
const key = `${date} ${time}`;

acc[key] = acc[key] || [];
acc[key].push({
columns: columns
.filter((col) => col.visible !== false)
.map((col) => ({
title: col.title,
value: getCellValueForDisplay(
col,
row.cells[col.name]
),
columnName: col.name,
rowId: row.id,
})),
} as KupActivityTimelineActivity);

return acc;
},
{}
);

const activitiesByDate = rows.reduce((acc, row) => {
const date = getCellValueForDisplay(
dateColumn,
row.cells[dateColumn.name]
);
const time = getCellValueForDisplay(
timeColumn,
row.cells[timeColumn.name]
);

if (!acc[date]) {
acc[date] = [];
}

acc[date].push({
time,
columns: columns
.filter(
(column) => column.visible || column.visible !== false
)
.map((column) => ({
title: column.title,
value: getColumnValue(
column.name,
row.cells[column.name]!.value,
date,
time
),
columnName: column.name,
rowId: row.id,
})),
} as KupActivityTimelineActivity);

return acc;
}, {});

return Object.keys(activitiesByDate)
.sort((date1, date2) =>
this.#kupManager.dates.sortDates(date1, date2, this.sortOrder)
)
.map((date) => ({
date,
time: activitiesByDate[date][0]!.time,
activities: activitiesByDate[date].sort(
(
acc: KupActivityTimelineActivity,
activity: KupActivityTimelineActivity
) =>
this.#kupManager.dates.sortTimes(
acc.time,
activity.time
)
),
}));
return Object.entries(activitiesByDate).map(([date, activities]) => ({
date,
activities,
}));
}

getActivity(activityData: KupActivityTimelineData) {
Expand Down Expand Up @@ -362,11 +329,7 @@ export class KupActivityTimeline {
<div class="atm-content">
<div>
<h3>
<span>
{timeline.date}{' '}
{timeline.time}
</span>
<span></span>
<span>{timeline.date}</span>
</h3>
</div>
{timeline.activities.map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

## Properties

| Property | Attribute | Description | Type | Default |
| ------------ | ------------- | --------------------------------------- | ----------------------------------------- | -------------------- |
| `data` | -- | Dataset containing the activities list. | `KupDataDataset` | `undefined` |
| `dateColumn` | `date-column` | Columns containing dates. | `string` | `undefined` |
| `sortOrder` | `sort-order` | Order for sorting. | `KupDatesOrder.ASC \| KupDatesOrder.DESC` | `KupDatesOrder.DESC` |
| `timeColumn` | `time-column` | Columns containing times. | `string` | `undefined` |
| Property | Attribute | Description | Type | Default |
| ------------ | ------------- | --------------------------------------- | ---------------- | ----------- |
| `data` | -- | Dataset containing the activities list. | `KupDataDataset` | `undefined` |
| `dateColumn` | `date-column` | Columns containing dates. | `string` | `undefined` |
| `sort` | -- | Defines the current sorting options. | `SortObject[]` | `[]` |
| `timeColumn` | `time-column` | Columns containing times. | `string` | `undefined` |


## Events
Expand Down