Skip to content

Commit

Permalink
fix: fixed minor typings issues
Browse files Browse the repository at this point in the history
  • Loading branch information
BetimBeja committed Apr 27, 2024
1 parent ee82ef8 commit e1625e9
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Licensed under the MIT license.
*/

import type { ShkoOnline } from '@shko.online/componentframework-mock/ShkoOnline';
import type { ShkoOnline } from '../../../ShkoOnline';
import alasql from 'alasql';

export const CREATE_TABLE_METADATA_ATTRIBUTE = `
Expand Down
2 changes: 0 additions & 2 deletions src/ComponentFramework-Mock-Generator/mockRefreshDatasets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
Licensed under the MIT license.
*/

/// <reference path="../global.d.ts" />

import type { PropertyToMock } from '../ComponentFramework-Mock';
import type { MockGenerator } from './MockGenerator';
import type { ShkoOnline } from '../ShkoOnline';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
Licensed under the MIT license.
*/

/// <reference path="../global.d.ts" />

import type { MockGenerator } from './MockGenerator';
import type { ShkoOnline } from '../ShkoOnline';
import { stub } from 'sinon';
Expand Down
6 changes: 6 additions & 0 deletions src/ComponentFramework-Mock/Context.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,9 @@ export class ContextMock<IInputs extends ShkoOnline.PropertyTypes<IInputs>>
this.webAPI = new WebApiMock(db, this.formatting);
}
}

declare global {
interface ObjectConstructor {
getOwnPropertyNames<T>(o: T): (keyof T)[];
}
}
112 changes: 112 additions & 0 deletions src/ComponentFramework-Mock/PropertyTypes/DataSet.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,115 @@ export class DataSetMock implements ComponentFramework.PropertyTypes.DataSet {
});
}
}

declare global{
namespace ComponentFramework {
namespace PropertyTypes {
/**
* The structure of a dataset property as it would be passed to a control
*/
interface DataSet {
/**
* Delete the records from data source.
* @param ids Array of IDs to be deleted.
* @todo Overloaded by Shko Online
*/
delete: (ids: string[]) => Promise<void>;

/**
* The capabilities for the dataset.
* @todo Overloaded by Shko Online
*/
getDataSetCapabilities: () => DataProviderCapabilities;

/**
* Initialize a local record object for control to set the value. The control needs to invoke the {@link ComponentFramework.PropertyHelper.DataSetApi.EntityRecord.save save()} method on the newly created record to persist the change.
* @todo Overloaded by Shko Online
*/
newRecord: () => ComponentFramework.PropertyHelper.DataSetApi.EntityRecord;
}

/**
* Provides access to all the properties of a file.
* @todo Overloaded by Shko Online
*/
interface DataProviderCapabilities {
/**
* Whether adding new records is supported or not.
*/
canCreateNewRecords: boolean;
/**
* If the dataset records can be paged.
*/
canPaginate: boolean;
/**
* Whether image info for record columns can be retrieved.
*/
hasCellImageInfo: boolean;
/**
* Whether the dataset supports record navigation for lookup and primary fields.
*/
hasRecordNavigation: boolean;
/**
* If the data provider has edit capabilities.
*/
isEditable: boolean;
/**
* If the dataset can be filtered.
*/
isFilterable: boolean;
/**
* If the dataset can be sorted.
*/
isSortable: boolean;
}
}
namespace PropertyHelper {
namespace DataSetApi {
/**
* Base interface for dataset record result. Supports value retrival by column name.
*/
interface EntityRecord {
/**
* Whether this record is dirty. Only applicable if the dataset is editable and this record has dirty values.
* @todo Overloaded by Shko Online
*/
isDirty(): boolean;

/**
* Whether this record is valid. Only applicable if the dataset is editable and this record has invalid values.
* @todo Overloaded by Shko Online
*/
isValid(): boolean;

/**
* Saves the record
* @throws You can get an error saying `Invalid snapshot with id undefined` when the incorrect column name parameter was used with {@link ComponentFramework.PropertyHelper.DataSetApi.EntityRecord.setValue setValue}. Make sure to use the logical name of the column.
* @todo Overloaded by Shko Online
*/
save(): Promise<void>;

/**
* Set value for the column.
* @param columnName The logical name of the column.
* @param value New value for the record.
* @todo Overloaded by Shko Online
*/
setValue(
columnName: string,
value:
| string
| Date
| number
| number[]
| boolean
| ComponentFramework.EntityReference
| ComponentFramework.EntityReference[]
| ComponentFramework.LookupValue
| ComponentFramework.LookupValue[],
): Promise<void>;
}
}
}
}
}
120 changes: 0 additions & 120 deletions src/global.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion storybook/stories/ComplexComponent.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default {
} as Meta<StoryArgs>;

const renderGenerator = () => {
let container: HTMLDivElement;
let container: HTMLDivElement | null;
let mockGenerator: ComponentFrameworkMockGenerator<IInputs, IOutputs>;

return function () {
Expand Down
2 changes: 1 addition & 1 deletion storybook/stories/ContainerSize.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface StoryArgs {
}

const renderGenerator = () => {
let container: HTMLDivElement;
let container: HTMLDivElement | null;
let mockGenerator: ComponentFrameworkMockGenerator<IInputs, IOutputs>;

return function () {
Expand Down
6 changes: 3 additions & 3 deletions storybook/stories/ContainerSizeVirtual.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ComponentFrameworkMockGeneratorReact, TwoOptionsPropertyMock } from '..

export default {
title: "Shko Online's ComponentFramework-Mock/ContainerSizeReact",
argTypes: {
argTypes: {
trackContainer: {
defaultValue: false,
name: 'Track Container',
Expand All @@ -28,11 +28,11 @@ interface StoryArgs {
}

const renderGenerator = () => {
let container: HTMLDivElement;
let container: HTMLDivElement | null;
let mockGenerator: ComponentFrameworkMockGeneratorReact<IInputs, IOutputs>;

return function () {
const [args] = useArgs<StoryArgs>();
const [args, updateArgs] = useArgs<StoryArgs>();
useEffect(
() => () => {
container = null;
Expand Down
10 changes: 5 additions & 5 deletions storybook/stories/MultiSelectOptionSet.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ interface StoryArgs {
}

const renderGenerator = () => {
let container: HTMLDivElement;
let container: HTMLDivElement | null;
let mockGenerator: ComponentFrameworkMockGenerator<IInputs, IOutputs>;

return function () {
Expand Down Expand Up @@ -78,8 +78,8 @@ const renderGenerator = () => {
selection: args.selection,
});

mockGenerator.onOutputChanged.callsFake(()=>{
updateArgs({selection: mockGenerator.context._parameters.selection.raw});
mockGenerator.onOutputChanged.callsFake(() => {
updateArgs({ selection: mockGenerator.context._parameters.selection.raw });
});

mockGenerator.ExecuteInit();
Expand All @@ -89,9 +89,9 @@ const renderGenerator = () => {
mockGenerator.context.mode.isVisible = args.isVisible;
mockGenerator.context.mode.isControlDisabled = args.isDisabled;
mockGenerator.UpdateValues({
selection: args.selection
selection: args.selection,
});

mockGenerator.ExecuteUpdateView();
}

Expand Down
12 changes: 5 additions & 7 deletions storybook/stories/OwnerLookup.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default {
} as Meta<StoryArgs>;

const renderGenerator = () => {
let container: HTMLDivElement;
let container: HTMLDivElement | null;
let mockGenerator: ComponentFrameworkMockGenerator<IInputs, IOutputs>;

return function () {
Expand Down Expand Up @@ -50,12 +50,10 @@ const renderGenerator = () => {
value: { entityType: 'account', id: 'my-id' },
});

mockGenerator.onOutputChanged.callsFake(({value}) => {
mockGenerator.onOutputChanged.callsFake(({ value }) => {
mockGenerator.context._parameters.value._Refresh();
updateArgs({
value: value
? value[0]
: undefined,
value: value ? value[0] : undefined,
});
});

Expand All @@ -66,9 +64,9 @@ const renderGenerator = () => {
mockGenerator.context.mode.isVisible = args.isVisible;
mockGenerator.context.mode.isControlDisabled = args.isDisabled;
mockGenerator.UpdateValues({
value: args.value
value: args.value,
});

mockGenerator.ExecuteUpdateView();
}
return container;
Expand Down
Loading

0 comments on commit e1625e9

Please sign in to comment.