import {
AdaptableButton,
AdaptableOptions,
CustomToolbarButtonContext,
DashboardButtonContext,
DataUpdateConfig,
} from '@adaptabletools/adaptable';
import {rowData, WebFramework} from './rowData';
export function createPython(): WebFramework {
return {
id: Math.floor(Math.random() * (1000000 - 5000 + 1) + 200000),
name: 'python',
description: 'A very popular language.',
created_at: new Date().toDateString(),
updated_at: new Date().toDateString(),
pushed_at: new Date().toDateString(),
github_stars: 5000,
language: 'Python',
open_issues_count: 750,
license: 'MIT License',
github_watchers: 6671,
topics: ['duck typing', 'proxies', 'prerformance', 'solid'],
has_projects: true,
has_wiki: true,
has_pages: false,
closed_issues_count: 12326,
open_pr_count: 749,
closed_pr_count: 1708,
week_issue_change: 15,
};
}
export function createGo(): WebFramework {
return {
id: Math.floor(Math.random() * (1000000 - 5000 + 1) + 200000),
name: 'go',
description: 'A very popular language.',
created_at: new Date().toDateString(),
updated_at: new Date().toDateString(),
pushed_at: new Date().toDateString(),
github_stars: 3850,
language: 'Go',
open_issues_count: 837,
license: 'BSD 3-Clause',
github_watchers: 9852,
topics: ['open sournce', 'similar to C'],
has_projects: true,
has_wiki: true,
has_pages: false,
closed_issues_count: 10254,
open_pr_count: 985,
closed_pr_count: 2014,
week_issue_change: 65,
};
}
export const adaptableOptions: AdaptableOptions<WebFramework> = {
primaryKey: 'id',
adaptableId: 'Adding Grid Rows',
dashboardOptions: {
customToolbars: [
{
name: 'ButtonToolbar',
title: 'Buttons',
toolbarButtons: [
{
label: 'Add Python Row to Top',
onClick: (
_button: AdaptableButton<CustomToolbarButtonContext>,
context: CustomToolbarButtonContext
) => {
const python: WebFramework = createPython();
const dataUpdateConfig: DataUpdateConfig = {
runAsync: true,
addIndex: 0,
};
context.adaptableApi.gridApi.addGridData(
[python],
dataUpdateConfig
);
},
buttonStyle: {
tone: 'info',
variant: 'text',
},
disabled: () => false,
},
{
label: 'Add Go Row',
onClick: (
_button: AdaptableButton<CustomToolbarButtonContext>,
context: CustomToolbarButtonContext
) => {
const go: WebFramework = createGo();
const dataUpdateConfig: DataUpdateConfig = {
runAsync: true,
};
context.adaptableApi.gridApi.addGridData([go], dataUpdateConfig);
},
buttonStyle: {
tone: 'warning',
variant: 'text',
},
disabled: () => false,
},
],
},
],
},
initialState: {
Theme: {CurrentTheme: 'dark'},
Dashboard: {
PinnedToolbars: ['ButtonToolbar'],
},
Layout: {
CurrentLayout: 'Standard Layout',
Layouts: [
{
TableColumns: [
'name',
'language',
'github_stars',
'license',
'created_at',
'has_wiki',
'github_watchers',
'updated_at',
'pushed_at',
'description',
'open_issues_count',
'closed_issues_count',
'open_pr_count',
'closed_pr_count',
'has_projects',
'has_pages',
'week_issue_change',
],
Name: 'Standard Layout',
AutoSizeColumns: true,
},
],
},
Alert: {
AlertDefinitions: [
{
Name: 'alert-row-added',
Rule: {
ObservableExpression: 'ROW_ADDED()',
},
MessageType: 'Success',
Scope: {
All: true,
},
AlertProperties: {
HighlightRow: true,
},
},
],
},
},
};