Skip to content

Commit

Permalink
Merge pull request #74 from gisce/tag-widget
Browse files Browse the repository at this point in the history
Add Tag widget
  • Loading branch information
mguellsegarra authored Apr 4, 2023
2 parents 5c3e4fb + 67fc251 commit af878d3
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gisce/ooui",
"version": "0.17.12",
"version": "0.17.13",
"main": "./dist/ooui.umd.js",
"module": "./dist/ooui.es.js",
"types": "./dist/index.d.ts",
Expand Down
12 changes: 12 additions & 0 deletions src/Tag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Selection from "./Selection";

/**
* A Tag widget
*/
class Tag extends Selection {
get colors(): any | "auto" {
return this._parsedWidgetProps.colors || {};
}
}

export default Tag;
4 changes: 4 additions & 0 deletions src/WidgetFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import FiberGrid from "./FiberGrid";
import Timeline from "./Timeline";
import Indicator from "./Indicator";
import Tags from "./Tags";
import Tag from "./Tag";
import Radio from "./Radio";
import MultiCheckbox from "./MultiCheckbox";
import Switch from "./Switch";
Expand Down Expand Up @@ -132,6 +133,9 @@ class WidgetFactory {
case "tags":
this._widgetClass = Tags;
break;
case "tag":
this._widgetClass = Tag;
break;
case "radio":
this._widgetClass = Radio;
break;
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import Indicator from "./Indicator";
import Dashboard from "./Dashboard";
import DashboardItem from "./DashboardItem";
import Tags from "./Tags";
import Tag from "./Tag";
import MultiCheckbox from "./MultiCheckbox";
import Radio from "./Radio";
import Switch from "./Switch";
Expand Down Expand Up @@ -109,6 +110,7 @@ export {
graphProcessor,
graphFieldUtils,
Tags,
Tag,
MultiCheckbox,
Radio,
Switch,
Expand Down
46 changes: 46 additions & 0 deletions src/spec/Tag.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import WidgetFactory from "../WidgetFactory";

describe("A Tag widget", () => {
it("should have an id corresponding to field name", () => {
const widgetFactory = new WidgetFactory();
const props = {
name: "status",
};

const widget = widgetFactory.createWidget("tag", props);

expect(widget.id).toBe("status");
});

describe("colors property", () => {
it("should have default colors to empty object", () => {
const widgetFactory = new WidgetFactory();
const props = {
name: "status",
};
const widget = widgetFactory.createWidget("tag", props);

expect(widget.colors).toStrictEqual({});
});
it("should parse colors property", () => {
const widgetFactory = new WidgetFactory();
const props = {
name: "status",
widget_props: '{"colors": {"draft": "blue", "open": "red"}}',
};
const widget = widgetFactory.createWidget("tag", props);

expect(widget.colors).toStrictEqual({draft: 'blue', open: 'red'});
});
it("should parse colors property and can be an string 'auto'", () => {
const widgetFactory = new WidgetFactory();
const props = {
name: "status",
widget_props: '{"colors": "auto"}',
};
const widget = widgetFactory.createWidget("tag", props);

expect(widget.colors).toStrictEqual("auto");
});
});
});

0 comments on commit af878d3

Please sign in to comment.