Skip to content

Commit

Permalink
update schema dialogBox
Browse files Browse the repository at this point in the history
  • Loading branch information
Xziy committed Apr 28, 2024
1 parent e456cec commit 4074ca3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
8 changes: 8 additions & 0 deletions interfaces/DialogBox.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ interface DialogBoxBase {
"critical";
message: string;
title: string;
/**
* Unix time seconds when dialog box was emitted
*/
emitTime?: number;
/**
* If passed;
* After this moment the dialogue will fade away
Expand All @@ -46,6 +50,9 @@ export interface DialogBoxProduct extends DialogBoxBase {
}
interface DialogOptionBase {
id: string;
/**
* @deprecated
*/
label: string;
}
interface DialogOptionProduct extends DialogOptionBase {
Expand All @@ -60,6 +67,7 @@ interface DialogOptionButton extends DialogOptionBase {
* * 1st - primary
*/
button?: {
label?: string;
type: "primary" | "secondary" | "link" | "abort";
};
}
Expand Down
10 changes: 10 additions & 0 deletions interfaces/DialogBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ interface DialogBoxBase {

message: string;
title: string;

/**
* Unix time seconds when dialog box was emitted
*/
emitTime?: number;

/**
* If passed;
* After this moment the dialogue will fade away
Expand All @@ -53,6 +59,9 @@ export interface DialogBoxProduct extends DialogBoxBase {

interface DialogOptionBase {
id: string;
/**
* @deprecated
*/
label: string;
}

Expand All @@ -69,6 +78,7 @@ interface DialogOptionButton extends DialogOptionBase {
* * 1st - primary
*/
button?: {
label?: string;
type: "primary" | "secondary" | "link" | "abort"
}
}
14 changes: 8 additions & 6 deletions libs/DialogBox.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DialogBox = void 0;
const uuid_1 = require("uuid");
const ajv_1 = __importDefault(require("ajv"));
const ajv_1 = require("ajv");
const ajv = new ajv_1.default();
let jsonSchema = require("./schemas/dialogBoxConfig.json");
const validate = ajv.compile(jsonSchema);
class DialogBox {
config;
user;
answerId = null;
askId;
deviceId;
static dialogs = {};
constructor(config, deviceId) {
this.answerId = null;
if (config.type === undefined)
config.type = "routine";
if (config.allowClosing === undefined)
Expand Down Expand Up @@ -43,6 +45,7 @@ class DialogBox {
timeout = 30 * 1000;
const startTime = Date.now();
const dialogBox = new DialogBox(dialog, deviceId);
dialogBox.config.emitTime = Math.round((startTime) / 1000);
DialogBox.dialogs[dialogBox.askId] = dialogBox;
emitter.emit("dialog-box:new", dialogBox);
while (Date.now() - startTime < timeout) {
Expand Down Expand Up @@ -70,4 +73,3 @@ class DialogBox {
}
}
exports.DialogBox = DialogBox;
DialogBox.dialogs = {};
1 change: 1 addition & 0 deletions libs/DialogBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class DialogBox {
if (!timeout) timeout = 30 * 1000;
const startTime = Date.now();
const dialogBox = new DialogBox(dialog, deviceId);
dialogBox.config.emitTime = Math.round((startTime)/1000)
DialogBox.dialogs[dialogBox.askId] = dialogBox;
emitter.emit("dialog-box:new", dialogBox);

Expand Down
13 changes: 8 additions & 5 deletions libs/schemas/dialogBoxConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,39 @@
"minItems": 2,
"items": {
"type": "object",
"additionalProperties": true,
"if": {
"properties": { "optionsType": { "const": "button" } }
},
"then": {
"properties": {
"id": { "type": "string" },
"label": { "type": "string" },
"button": {
"type": "object",
"additionalProperties": true,
"properties": {
"type": {
"type": "string",
"label": { "type": "string" },
"enum": ["primary", "secondary", "link", "abort"]
}
},
"required": ["type"]
"required": ["type", "label"]
}
},
"required": ["id", "label", "button"]
"additionalProperties": true,
"required": ["id", "button"]
},
"else": {
"properties": {
"id": { "type": "string" },
"label": { "type": "string" },
"product": {
"type": "object",
"additionalProperties": true
}
},
"required": ["id", "label", "product"]
"additionalProperties": true,
"required": ["id", "product"]
}
}
}
Expand Down

0 comments on commit 4074ca3

Please sign in to comment.