Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ npm i --save quaire
## Define quaire data

First you need to define the data (decision tree) based on the
[QuaireItem interface](https://github.com/devCrossNet/quaire/blob/main/src/interfaces.ts#L43). This can be static
[QuaireItem type](https://github.com/devCrossNet/quaire/blob/main/src/types.ts#L46). This can be static
data in a JS/TS file, a JSON file that you load on demand
or a dynamic JSON from a CMS or backend API.

Expand Down
6 changes: 5 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ export default defineConfig(
},
},
rules: {
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
'@typescript-eslint/naming-convention': [
'error',
{ selector: 'typeLike', format: ['PascalCase'], custom: { regex: '^I[A-Z]', match: false } },
],
'@typescript-eslint/no-require-imports': 0,
'no-async-promise-executor': 0,
'no-prototype-builtins': 0,
Expand Down
10 changes: 6 additions & 4 deletions examples/custom-component-types/MyQuaire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class MyQuaire extends Quaire {
}

// override default behaviour and apply new logic for MULTI_SELECT components
protected _validateSelectComponent(question: QuaireQuestion, currentAnswer: any[]) {
protected _validateSelectComponent(question: QuaireQuestion, currentAnswer: unknown[]) {
if (question.componentType === MyComponentType.MULTI_SELECT) {
const options = question.selectOptions.filter((o) => currentAnswer.includes(o.value));

Expand All @@ -46,7 +46,7 @@ export class MyQuaire extends Quaire {
}

// override default behaviour and apply new logic for MULTI_SELECT components
protected _getNextItemIdFromSelectComponents = (activeQuestion: QuaireQuestion, answer: any | any[]) => {
protected _getNextItemIdFromSelectComponents = (activeQuestion: QuaireQuestion, answer: unknown) => {
const option = activeQuestion.selectOptions.find((o) =>
Array.isArray(answer) ? answer.includes(o.value) : o.value === answer,
);
Expand All @@ -72,10 +72,12 @@ export class MyQuaire extends Quaire {
}

// override default behaviour and apply new logic for MULTI_SELECT components
protected _getNavigationValue(question: QuaireQuestion, answer: any) {
protected _getNavigationValue(question: QuaireQuestion, answer: unknown) {
if (question.componentType === MyComponentType.MULTI_SELECT) {
const answers = answer as unknown[];

return question.selectOptions
.filter((selectOption) => answer.includes(selectOption.value))
.filter((selectOption) => answers.includes(selectOption.value))
.map((selectOption) => selectOption.label);
} else {
return super._getNavigationValue(question, answer);
Expand Down
22 changes: 11 additions & 11 deletions examples/extending-data-definition/MyQuaire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ import {
QuaireRangeItemOption,
} from '../../src';

export interface MyRangeItemOption extends QuaireRangeItemOption {
export type MyRangeItemOption = QuaireRangeItemOption & {
divisor: number;
unit: string;
}
};

export interface MyItem extends QuaireItem {
export type MyItem = QuaireItem & {
progress: number;
rangeOption: MyRangeItemOption;
}
};

export interface MyQuestion extends QuaireQuestion {
export type MyQuestion = QuaireQuestion & {
progress: number;
rangeOption: MyRangeItemOption;
}
};

export interface MyNavigationItem extends QuaireNavigationItem {
export type MyNavigationItem = QuaireNavigationItem & {
progress?: number;
unit?: string;
}
};

export class MyQuaire extends Quaire<MyItem, MyQuestion, MyNavigationItem> {
protected _getQuestionObject(
Expand All @@ -35,7 +35,7 @@ export class MyQuaire extends Quaire<MyItem, MyQuestion, MyNavigationItem> {
selectOptions: QuaireItemOption[],
rangeOption: QuaireRangeItemOption,
inputOption: QuaireInputItemOption,
defaultValue: any,
defaultValue: unknown,
): MyQuestion {
return {
...super._getQuestionObject(item, dependsOnKeys, selectOptions, rangeOption, inputOption, defaultValue),
Expand All @@ -47,8 +47,8 @@ export class MyQuaire extends Quaire<MyItem, MyQuestion, MyNavigationItem> {
activeNavigationItem: MyNavigationItem,
navigationItem: MyNavigationItem,
question: MyQuestion,
answer: any,
isParent,
answer: unknown,
isParent: boolean,
): MyNavigationItem {
return {
...super._getNavigationItemObject(activeNavigationItem, navigationItem, question, answer, isParent),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NO_VALUE, Quaire } from '../../src';
import { items, navigationItems } from './data';

describe('linear-flow-skip-question', () => {
let Q;
let Q: Quaire;

beforeEach(() => {
Q = new Quaire({ items, navigationItems });
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './constants';
export * from './enums';
export * from './interfaces';
export * from './types';
export * from './quaire';
Loading
Loading