Skip to content

Commit

Permalink
feat(positions): build data by positions and active views #WIK-16218 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
huanhuanwa authored Aug 5, 2024
1 parent 93e28ab commit 8896808
Show file tree
Hide file tree
Showing 22 changed files with 661 additions and 529 deletions.
2 changes: 1 addition & 1 deletion packages/grid/src/grid.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import {
import { SelectOptionPipe } from './pipes/grid';
import { AITableGridEventService } from './services/event.service';
import { AI_TABLE_GRID_FIELD_SERVICE_MAP, AITableGridFieldService } from './services/field.service';
import { AITableGridSelectionService } from './services/selection.servive';
import { AITableGridSelectionService } from './services/selection.service';
import { AIFieldConfig, AITableFieldMenuItem, AITableRowHeight } from './types';
import { buildGridData } from './utils';

Expand Down
47 changes: 27 additions & 20 deletions src/app/action/view.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AITableView, AIViewAction, ViewActionName } from '../types/view';
import { AITableRecord, AITableRecords } from '@ai-table/grid';
import { AITableView, AIViewAction, Direction, ViewActionName } from '../types/view';
import { AIViewTable } from '../types/view';
import { createDraft, finishDraft } from 'immer';

Expand All @@ -23,37 +24,43 @@ export function setView(aiTable: AIViewTable, value: Partial<AITableView>, path:
path
};
aiTable.viewApply(operation);

}

export const GeneralActions = {
transform(aiTable: AIViewTable, op: AIViewAction): void {
const views = createDraft(aiTable.views());
applyView(aiTable, views, op);
const records = createDraft(aiTable.records());
applyView(aiTable, views, records, op);
aiTable.views.update(() => {
return finishDraft(views);
});
aiTable.records.update(() => {
return finishDraft(records);
});
}
};

export const applyView = (aiTable: AIViewTable, views: AITableView[], options: AIViewAction) => {
const [viewIndex] = options.path;
const targetView: AITableView = views[viewIndex]
Object.entries(options.newView).forEach(([k, value]) => {
const key = k as keyof AITableView;
if (value == null) {
delete targetView[key]
} else {
targetView[key] = value as never
}
});
Object.entries(options.view).forEach(([k, value]) => {
if (!options.newView.hasOwnProperty(k)) {
const key = k as keyof AITableView;
delete targetView[key]
export const applyView = (aiTable: AIViewTable, views: AITableView[], records: AITableRecords, options: AIViewAction) => {
switch (options.type) {
case ViewActionName.setView: {
const [viewIndex] = options.path;
if (viewIndex > -1) {
views[viewIndex] = {
...views[viewIndex],
...options.newView
};
if (options.newView.sortCondition) {
const { sortCondition } = options.newView;
const { sortBy, direction } = sortCondition.conditions[0];
records = records.sort((a: AITableRecord, b: AITableRecord) => {
return direction === Direction.ascending
? a.values[sortBy] - b.values[sortBy]
: b.values[sortBy] - a.values[sortBy];
});
}
}
}
});
return views;
}
};

export const ViewActions = {
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.component.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
app-root {
display: block;
margin: 20px;
margin: 0 20px;
margin-bottom: 0;
overflow-x: auto;
height: calc(100vh - 20px);
Expand Down
19 changes: 11 additions & 8 deletions src/app/app.routes.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { Routes } from '@angular/router';
import { BasicComponent } from './component/basic/basic.component';
import { ShareComponent } from './component/share/share.component';
import { DemoTableContent } from './component/common/content/content.component';
import { DemoTable } from './component/table.component';

export const routes: Routes = [
{
path: '',
component: BasicComponent
},
{
path: 'share',
component: ShareComponent
},
component: DemoTable,
children:[
{
path: ':viewId',
component: DemoTableContent,
}
]
}

];
14 changes: 0 additions & 14 deletions src/app/component/basic/basic.component.html

This file was deleted.

14 changes: 0 additions & 14 deletions src/app/component/basic/basic.component.ts

This file was deleted.

Loading

0 comments on commit 8896808

Please sign in to comment.