@teambit/component.ui.component-filters.env-filter 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ import { ComponentID } from '@teambit/component';
2
+ import { ComponentFilterCriteria } from '@teambit/component.ui.component-filters.component-filter-context';
3
+ declare type EnvFilterEnvState = {
4
+ active: boolean;
5
+ icon?: string;
6
+ displayName: string;
7
+ id: string;
8
+ description: string;
9
+ componentId: ComponentID;
10
+ };
11
+ export declare type EnvFilterState = {
12
+ envsState: Map<string, EnvFilterEnvState>;
13
+ dropdownState: boolean;
14
+ };
15
+ export declare type EnvsFilterCriteria = ComponentFilterCriteria<EnvFilterState>;
16
+ export declare const EnvsFilter: EnvsFilterCriteria;
17
+ export {};
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.EnvsFilter = void 0;
26
+ const react_1 = __importStar(require("react"));
27
+ const design_inputs_selectors_multi_select_1 = require("@teambit/design.inputs.selectors.multi-select");
28
+ const component_1 = require("@teambit/component");
29
+ const component_modules_component_url_1 = require("@teambit/component.modules.component-url");
30
+ const classnames_1 = __importDefault(require("classnames"));
31
+ const design_ui_styles_ellipsis_1 = require("@teambit/design.ui.styles.ellipsis");
32
+ const design_ui_tooltip_1 = require("@teambit/design.ui.tooltip");
33
+ const base_react_navigation_link_1 = require("@teambit/base-react.navigation.link");
34
+ const component_ui_component_filters_component_filter_context_1 = require("@teambit/component.ui.component-filters.component-filter-context");
35
+ const envs_filter_module_scss_1 = __importDefault(require("./envs-filter.module.scss"));
36
+ exports.EnvsFilter = {
37
+ id: 'envs',
38
+ match: (component, filter) => {
39
+ var _a;
40
+ const { envsState } = filter;
41
+ const activeEnvs = [...envsState.values()].filter((envState) => envState.active).map((envState) => envState.id);
42
+ // match everything when no envs are set
43
+ if (activeEnvs.length === 0)
44
+ return true;
45
+ const envId = component.environment && ((_a = component_1.ComponentID.tryFromString(component.environment.id)) === null || _a === void 0 ? void 0 : _a.toStringWithoutVersion());
46
+ const matches = !!envId && activeEnvs.indexOf(envId) >= 0;
47
+ return matches;
48
+ },
49
+ state: {
50
+ envsState: new Map(),
51
+ dropdownState: false,
52
+ },
53
+ order: 1,
54
+ render: envsFilter,
55
+ };
56
+ const getDefaultState = (components) => {
57
+ return (0, react_1.useMemo)(() => {
58
+ const defaultState = {
59
+ dropdownState: false,
60
+ envsState: new Map(),
61
+ };
62
+ const componentEnvSet = new Set();
63
+ const componentsEnvsWithIcons = components
64
+ .filter((component) => {
65
+ const envId = component.environment && component_1.ComponentID.tryFromString(component.environment.id);
66
+ if (!envId)
67
+ return false;
68
+ const envKey = envId.toStringWithoutVersion();
69
+ if (componentEnvSet.has(envKey))
70
+ return false;
71
+ componentEnvSet.add(envKey);
72
+ return true;
73
+ })
74
+ .map((component) => {
75
+ var _a, _b;
76
+ const envId = component_1.ComponentID.fromString((_a = component.environment) === null || _a === void 0 ? void 0 : _a.id);
77
+ return {
78
+ displayName: envId.name,
79
+ id: envId.toStringWithoutVersion(),
80
+ description: `${envId.scope}${envId.namespace ? '/'.concat(envId.namespace) : ''}`,
81
+ icon: (_b = component.environment) === null || _b === void 0 ? void 0 : _b.icon,
82
+ componentId: envId,
83
+ };
84
+ });
85
+ componentsEnvsWithIcons.forEach((componentEnvWithIcon) => {
86
+ defaultState.envsState.set(componentEnvWithIcon.id, Object.assign(Object.assign({}, componentEnvWithIcon), { active: true }));
87
+ });
88
+ return defaultState;
89
+ }, [components]);
90
+ };
91
+ function envsFilter({ components, className, }) {
92
+ const defaultState = getDefaultState(components);
93
+ const filterContext = (0, component_ui_component_filters_component_filter_context_1.useComponentFilter)(exports.EnvsFilter, defaultState);
94
+ if (!filterContext)
95
+ return null;
96
+ const [currentFilter, updateFilter] = filterContext;
97
+ const currentEnvsState = currentFilter.state.envsState;
98
+ const selectList = [];
99
+ currentFilter.state.envsState.forEach((state) => {
100
+ var _a;
101
+ selectList.push({
102
+ value: state.id,
103
+ icon: state.icon,
104
+ description: state.description,
105
+ checked: !!((_a = currentEnvsState.get(state.id)) === null || _a === void 0 ? void 0 : _a.active),
106
+ element: react_1.default.createElement(EnvsDropdownItem, Object.assign({}, state)),
107
+ });
108
+ });
109
+ const onCheck = (value, e) => {
110
+ const checked = e.target.checked;
111
+ updateFilter((currentState) => {
112
+ if (checked && !currentState.state.dropdownState) {
113
+ currentState.state.dropdownState = true;
114
+ }
115
+ const currentEnvState = currentState.state.envsState.get(value);
116
+ if (!currentEnvState)
117
+ return currentState;
118
+ currentState.state.envsState.set(value, Object.assign(Object.assign({}, currentEnvState), { active: checked }));
119
+ return currentState;
120
+ });
121
+ };
122
+ const onClear = () => {
123
+ updateFilter((currentState) => {
124
+ currentState.state.envsState.forEach((value, key) => {
125
+ currentState.state.envsState.set(key, Object.assign(Object.assign({}, value), { active: false }));
126
+ });
127
+ return currentState;
128
+ });
129
+ };
130
+ const onSubmit = () => {
131
+ updateFilter((currentState) => {
132
+ currentState.state.dropdownState = false;
133
+ return currentState;
134
+ });
135
+ };
136
+ const onDropdownToggled = (event, open) => {
137
+ updateFilter((currentState) => {
138
+ currentState.state.dropdownState = open;
139
+ return currentState;
140
+ });
141
+ };
142
+ return (react_1.default.createElement("div", { className: (0, classnames_1.default)(envs_filter_module_scss_1.default.envsFilterContainer, className) },
143
+ react_1.default.createElement(design_inputs_selectors_multi_select_1.MultiSelect, { itemsList: selectList, placeholder: react_1.default.createElement(EnvsPlaceholder, null), onSubmit: onSubmit, onCheck: onCheck, onClear: onClear, onChange: onDropdownToggled, open: currentFilter.state.dropdownState, dropdownBorder: false, className: envs_filter_module_scss_1.default.envFilterDropdownContainer, dropClass: envs_filter_module_scss_1.default.envFilterDropdown })));
144
+ }
145
+ function EnvsPlaceholder() {
146
+ return (react_1.default.createElement("div", { className: envs_filter_module_scss_1.default.filterIcon },
147
+ react_1.default.createElement("img", { src: "https://static.bit.dev/bit-icons/env.svg" }),
148
+ react_1.default.createElement("span", { className: envs_filter_module_scss_1.default.filterIconLabel }, "Environments"),
149
+ react_1.default.createElement("div", { className: envs_filter_module_scss_1.default.dropdownArrow },
150
+ react_1.default.createElement("img", { src: "https://static.bit.dev/bit-icons/fat-arrow-down.svg" }))));
151
+ }
152
+ function EnvsDropdownItem({ displayName, icon, description, componentId, id }) {
153
+ return (react_1.default.createElement(design_ui_tooltip_1.Tooltip, { placement: "right", content: react_1.default.createElement(base_react_navigation_link_1.Link, { className: envs_filter_module_scss_1.default.envLink, href: component_modules_component_url_1.ComponentUrl.toUrl(componentId, { includeVersion: false }), external: true }, id) },
154
+ react_1.default.createElement("div", { className: envs_filter_module_scss_1.default.envDropdownItemContainer },
155
+ react_1.default.createElement("div", { className: envs_filter_module_scss_1.default.envDropdownItem },
156
+ react_1.default.createElement(design_ui_styles_ellipsis_1.Ellipsis, null, displayName),
157
+ react_1.default.createElement("div", { className: envs_filter_module_scss_1.default.envDropdownItemIconContainer },
158
+ react_1.default.createElement("img", { className: envs_filter_module_scss_1.default.envDropdownItemIcon, src: icon }))),
159
+ react_1.default.createElement("div", { className: envs_filter_module_scss_1.default.description },
160
+ react_1.default.createElement(design_ui_styles_ellipsis_1.Ellipsis, { className: envs_filter_module_scss_1.default.descriptionText }, description)))));
161
+ }
162
+ //# sourceMappingURL=envs-filter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envs-filter.js","sourceRoot":"","sources":["../envs-filter.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAuC;AACvC,wGAAsF;AACtF,kDAAiE;AACjE,8FAAwE;AACxE,4DAAoC;AACpC,kFAA8D;AAC9D,kEAAqD;AACrD,oFAA2D;AAC3D,8IAG0E;AAC1E,wFAA+C;AAgBlC,QAAA,UAAU,GAAuB;IAC5C,EAAE,EAAE,MAAM;IACV,KAAK,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE;;QAC3B,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;QAC7B,MAAM,UAAU,GAAG,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAChH,wCAAwC;QACxC,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QACzC,MAAM,KAAK,GACT,SAAS,CAAC,WAAW,KAAI,MAAA,uBAAW,CAAC,aAAa,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,CAAC,0CAAE,sBAAsB,EAAE,CAAA,CAAC;QACzG,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,IAAI,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC1D,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,KAAK,EAAE;QACL,SA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AI,IAEb,EAAE,CACE;QAGT,uCAAK,SAAS,EAAE,iCAAM,CAAC,wBAAwB;YAC7C,uCAAK,SAAS,EAAE,iCAAM,CAAC,eAAe;gBACpC,8BAAC,oCAAQ,QAAE,WAAW,CAAY;gBAClC,uCAAK,SAAS,EAAE,iCAAM,CAAC,4BAA4B;oBACjD,uCAAK,SAAS,EAAE,iCAAM,CAAC,mBAAmB,EAAE,GAAG,EAAE,IAAI,GAAQ,CACzD,CACF;YACN,uCAAK,SAAS,EAAE,iCAAM,CAAC,WAAW;gBAChC,8BAAC,oCAAQ,IAAC,SAAS,EAAE,iCAAM,CAAC,eAAe,IAAG,WAAW,CAAY,CACjE,CACF,CACE,CACX,CAAC;AACJ,CAAC"}
@@ -0,0 +1,94 @@
1
+ @import '~@teambit/ui-foundation.ui.constants.z-indexes/z-indexes.module.scss';
2
+ .envsFilterContainer {
3
+ > div {
4
+ line-height: 16px;
5
+ display: flex;
6
+ }
7
+
8
+ .filterIcon {
9
+ display: flex;
10
+ padding: 8px;
11
+ border-radius: 8px;
12
+
13
+ &:hover {
14
+ background: var(--bit-bg-heavy, #f6f6f6);
15
+ cursor: pointer;
16
+ }
17
+
18
+ img {
19
+ width: 16px;
20
+ filter: invert(44%) sepia(7%) saturate(560%) hue-rotate(187deg) brightness(96%) contrast(91%);
21
+ }
22
+
23
+ .filterIconLabel {
24
+ margin: 0px 8px;
25
+ font-size: 14px;
26
+ }
27
+
28
+ .dropdownArrow {
29
+ display: flex;
30
+ }
31
+ }
32
+ }
33
+
34
+ .envFilterDropdownContainer {
35
+ width: 100%;
36
+ }
37
+
38
+ .envFilterDropdown {
39
+ width: 100%;
40
+ // otherwise when the dropdown is open it clashes with the content of the tree
41
+ // (this is bizarre, the tree has no position absolute)
42
+ z-index: $nav-z-index;
43
+ }
44
+
45
+ .envDropdownItemContainer {
46
+ display: flex;
47
+ width: calc(100% - 24px);
48
+ align-items: baseline;
49
+ flex-direction: column;
50
+ }
51
+
52
+ .envDropdownItemIconContainer {
53
+ display: flex;
54
+ height: 16px;
55
+ width: 16px;
56
+ }
57
+
58
+ .envDropdownItem {
59
+ padding-left: 8px;
60
+ display: flex;
61
+ justify-content: space-between;
62
+ width: 100%;
63
+ font-size: var(--bit-p-md, 16px);
64
+ }
65
+
66
+ .envDropdownItemLabel,
67
+ .envDropdownItemIcon {
68
+ display: flex;
69
+ justify-content: space-between;
70
+ padding-left: 8px;
71
+ }
72
+ .description {
73
+ font-size: var(--bit-p-xs, 14px);
74
+ padding-left: 8px;
75
+ padding-right: 16px;
76
+ color: var(--bit-text-color-light, #6c707c);
77
+ width: calc(100% - 24px);
78
+ }
79
+
80
+ .envDropdownItemContainerWithIcon {
81
+ display: flex;
82
+ flex-direction: row;
83
+ justify-content: space-between;
84
+ width: calc(100% - 24px);
85
+ }
86
+
87
+ .descriptionText {
88
+ width: 100%;
89
+ }
90
+
91
+ .envLink {
92
+ color: white;
93
+ text-decoration: none;
94
+ }
@@ -0,0 +1 @@
1
+ export { EnvsFilter } from './envs-filter';
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EnvsFilter = void 0;
4
+ var envs_filter_1 = require("./envs-filter");
5
+ Object.defineProperty(exports, "EnvsFilter", { enumerable: true, get: function () { return envs_filter_1.EnvsFilter; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,6CAA2C;AAAlC,yGAAA,UAAU,OAAA"}
@@ -0,0 +1,32 @@
1
+ {
2
+ "compilerOptions": {
3
+ "lib": [
4
+ "es2019",
5
+ "DOM",
6
+ "ES6",
7
+ "DOM.Iterable"
8
+ ],
9
+ "target": "es2015",
10
+ "module": "CommonJS",
11
+ "jsx": "react",
12
+ "allowJs": true,
13
+ "composite": true,
14
+ "declaration": true,
15
+ "sourceMap": true,
16
+ "skipLibCheck": true,
17
+ "experimentalDecorators": true,
18
+ "outDir": "dist",
19
+ "moduleResolution": "node",
20
+ "esModuleInterop": true,
21
+ "rootDir": ".",
22
+ "resolveJsonModule": true
23
+ },
24
+ "exclude": [
25
+ "dist",
26
+ "package.json"
27
+ ],
28
+ "include": [
29
+ "**/*",
30
+ "**/*.json"
31
+ ]
32
+ }
@@ -0,0 +1,94 @@
1
+ @import '~@teambit/ui-foundation.ui.constants.z-indexes/z-indexes.module.scss';
2
+ .envsFilterContainer {
3
+ > div {
4
+ line-height: 16px;
5
+ display: flex;
6
+ }
7
+
8
+ .filterIcon {
9
+ display: flex;
10
+ padding: 8px;
11
+ border-radius: 8px;
12
+
13
+ &:hover {
14
+ background: var(--bit-bg-heavy, #f6f6f6);
15
+ cursor: pointer;
16
+ }
17
+
18
+ img {
19
+ width: 16px;
20
+ filter: invert(44%) sepia(7%) saturate(560%) hue-rotate(187deg) brightness(96%) contrast(91%);
21
+ }
22
+
23
+ .filterIconLabel {
24
+ margin: 0px 8px;
25
+ font-size: 14px;
26
+ }
27
+
28
+ .dropdownArrow {
29
+ display: flex;
30
+ }
31
+ }
32
+ }
33
+
34
+ .envFilterDropdownContainer {
35
+ width: 100%;
36
+ }
37
+
38
+ .envFilterDropdown {
39
+ width: 100%;
40
+ // otherwise when the dropdown is open it clashes with the content of the tree
41
+ // (this is bizarre, the tree has no position absolute)
42
+ z-index: $nav-z-index;
43
+ }
44
+
45
+ .envDropdownItemContainer {
46
+ display: flex;
47
+ width: calc(100% - 24px);
48
+ align-items: baseline;
49
+ flex-direction: column;
50
+ }
51
+
52
+ .envDropdownItemIconContainer {
53
+ display: flex;
54
+ height: 16px;
55
+ width: 16px;
56
+ }
57
+
58
+ .envDropdownItem {
59
+ padding-left: 8px;
60
+ display: flex;
61
+ justify-content: space-between;
62
+ width: 100%;
63
+ font-size: var(--bit-p-md, 16px);
64
+ }
65
+
66
+ .envDropdownItemLabel,
67
+ .envDropdownItemIcon {
68
+ display: flex;
69
+ justify-content: space-between;
70
+ padding-left: 8px;
71
+ }
72
+ .description {
73
+ font-size: var(--bit-p-xs, 14px);
74
+ padding-left: 8px;
75
+ padding-right: 16px;
76
+ color: var(--bit-text-color-light, #6c707c);
77
+ width: calc(100% - 24px);
78
+ }
79
+
80
+ .envDropdownItemContainerWithIcon {
81
+ display: flex;
82
+ flex-direction: row;
83
+ justify-content: space-between;
84
+ width: calc(100% - 24px);
85
+ }
86
+
87
+ .descriptionText {
88
+ width: 100%;
89
+ }
90
+
91
+ .envLink {
92
+ color: white;
93
+ text-decoration: none;
94
+ }
@@ -0,0 +1,213 @@
1
+ import React, { useMemo } from 'react';
2
+ import { MultiSelect, ItemType } from '@teambit/design.inputs.selectors.multi-select';
3
+ import { ComponentID, ComponentModel } from '@teambit/component';
4
+ import { ComponentUrl } from '@teambit/component.modules.component-url';
5
+ import classNames from 'classnames';
6
+ import { Ellipsis } from '@teambit/design.ui.styles.ellipsis';
7
+ import { Tooltip } from '@teambit/design.ui.tooltip';
8
+ import { Link } from '@teambit/base-react.navigation.link';
9
+ import {
10
+ ComponentFilterCriteria,
11
+ useComponentFilter,
12
+ } from '@teambit/component.ui.component-filters.component-filter-context';
13
+ import styles from './envs-filter.module.scss';
14
+
15
+ type EnvFilterEnvState = {
16
+ active: boolean;
17
+ icon?: string;
18
+ displayName: string;
19
+ id: string;
20
+ description: string;
21
+ componentId: ComponentID;
22
+ };
23
+ export type EnvFilterState = {
24
+ envsState: Map<string, EnvFilterEnvState>;
25
+ dropdownState: boolean;
26
+ };
27
+ export type EnvsFilterCriteria = ComponentFilterCriteria<EnvFilterState>;
28
+
29
+ export const EnvsFilter: EnvsFilterCriteria = {
30
+ id: 'envs',
31
+ match: (component, filter) => {
32
+ const { envsState } = filter;
33
+ const activeEnvs = [...envsState.values()].filter((envState) => envState.active).map((envState) => envState.id);
34
+ // match everything when no envs are set
35
+ if (activeEnvs.length === 0) return true;
36
+ const envId =
37
+ component.environment && ComponentID.tryFromString(component.environment.id)?.toStringWithoutVersion();
38
+ const matches = !!envId && activeEnvs.indexOf(envId) >= 0;
39
+ return matches;
40
+ },
41
+ state: {
42
+ envsState: new Map<string, EnvFilterEnvState>(),
43
+ dropdownState: false,
44
+ },
45
+ order: 1,
46
+ render: envsFilter,
47
+ };
48
+
49
+ const getDefaultState = (components: ComponentModel[]) => {
50
+ return useMemo(() => {
51
+ const defaultState = {
52
+ dropdownState: false,
53
+ envsState: new Map<string, EnvFilterEnvState>(),
54
+ };
55
+
56
+ const componentEnvSet = new Set<string>();
57
+
58
+ const componentsEnvsWithIcons = components
59
+ .filter((component) => {
60
+ const envId = component.environment && ComponentID.tryFromString(component.environment.id);
61
+
62
+ if (!envId) return false;
63
+
64
+ const envKey = envId.toStringWithoutVersion();
65
+
66
+ if (componentEnvSet.has(envKey)) return false;
67
+
68
+ componentEnvSet.add(envKey);
69
+
70
+ return true;
71
+ })
72
+ .map((component) => {
73
+ const envId = ComponentID.fromString(component.environment?.id as string);
74
+ return {
75
+ displayName: envId.name,
76
+ id: envId.toStringWithoutVersion(),
77
+ description: `${envId.scope}${envId.namespace ? '/'.concat(envId.namespace) : ''}`,
78
+ icon: component.environment?.icon,
79
+ componentId: envId,
80
+ };
81
+ });
82
+
83
+ componentsEnvsWithIcons.forEach((componentEnvWithIcon) => {
84
+ defaultState.envsState.set(componentEnvWithIcon.id, { ...componentEnvWithIcon, active: true });
85
+ });
86
+
87
+ return defaultState;
88
+ }, [components]);
89
+ };
90
+
91
+ function envsFilter({
92
+ components,
93
+ className,
94
+ }: { components: ComponentModel[] } & React.HTMLAttributes<HTMLDivElement>) {
95
+ const defaultState = getDefaultState(components);
96
+ const filterContext = useComponentFilter(EnvsFilter, defaultState);
97
+
98
+ if (!filterContext) return null;
99
+
100
+ const [currentFilter, updateFilter] = filterContext;
101
+
102
+ const currentEnvsState = currentFilter.state.envsState;
103
+
104
+ const selectList: ItemType[] = [];
105
+
106
+ currentFilter.state.envsState.forEach((state) => {
107
+ selectList.push({
108
+ value: state.id,
109
+ icon: state.icon,
110
+ description: state.description,
111
+ checked: !!currentEnvsState.get(state.id)?.active,
112
+ element: <EnvsDropdownItem {...state} />,
113
+ });
114
+ });
115
+
116
+ const onCheck = (value: string, e: React.ChangeEvent<HTMLInputElement>) => {
117
+ const checked = e.target.checked;
118
+
119
+ updateFilter((currentState) => {
120
+ if (checked && !currentState.state.dropdownState) {
121
+ currentState.state.dropdownState = true;
122
+ }
123
+
124
+ const currentEnvState = currentState.state.envsState.get(value);
125
+
126
+ if (!currentEnvState) return currentState;
127
+
128
+ currentState.state.envsState.set(value, { ...currentEnvState, active: checked });
129
+ return currentState;
130
+ });
131
+ };
132
+
133
+ const onClear = () => {
134
+ updateFilter((currentState) => {
135
+ currentState.state.envsState.forEach((value, key) => {
136
+ currentState.state.envsState.set(key, { ...value, active: false });
137
+ });
138
+ return currentState;
139
+ });
140
+ };
141
+
142
+ const onSubmit = () => {
143
+ updateFilter((currentState) => {
144
+ currentState.state.dropdownState = false;
145
+ return currentState;
146
+ });
147
+ };
148
+
149
+ const onDropdownToggled = (event, open) => {
150
+ updateFilter((currentState) => {
151
+ currentState.state.dropdownState = open;
152
+ return currentState;
153
+ });
154
+ };
155
+
156
+ return (
157
+ <div className={classNames(styles.envsFilterContainer, className)}>
158
+ <MultiSelect
159
+ itemsList={selectList}
160
+ placeholder={<EnvsPlaceholder />}
161
+ onSubmit={onSubmit}
162
+ onCheck={onCheck}
163
+ onClear={onClear}
164
+ onChange={onDropdownToggled}
165
+ open={currentFilter.state.dropdownState}
166
+ dropdownBorder={false}
167
+ className={styles.envFilterDropdownContainer}
168
+ dropClass={styles.envFilterDropdown}
169
+ />
170
+ </div>
171
+ );
172
+ }
173
+
174
+ function EnvsPlaceholder() {
175
+ return (
176
+ <div className={styles.filterIcon}>
177
+ <img src="https://static.bit.dev/bit-icons/env.svg" />
178
+ <span className={styles.filterIconLabel}>Environments</span>
179
+ <div className={styles.dropdownArrow}>
180
+ <img src="https://static.bit.dev/bit-icons/fat-arrow-down.svg" />
181
+ </div>
182
+ </div>
183
+ );
184
+ }
185
+
186
+ function EnvsDropdownItem({ displayName, icon, description, componentId, id }: EnvFilterEnvState) {
187
+ return (
188
+ <Tooltip
189
+ placement="right"
190
+ content={
191
+ <Link
192
+ className={styles.envLink}
193
+ href={ComponentUrl.toUrl(componentId, { includeVersion: false })}
194
+ external={true}
195
+ >
196
+ {id}
197
+ </Link>
198
+ }
199
+ >
200
+ <div className={styles.envDropdownItemContainer}>
201
+ <div className={styles.envDropdownItem}>
202
+ <Ellipsis>{displayName}</Ellipsis>
203
+ <div className={styles.envDropdownItemIconContainer}>
204
+ <img className={styles.envDropdownItemIcon} src={icon}></img>
205
+ </div>
206
+ </div>
207
+ <div className={styles.description}>
208
+ <Ellipsis className={styles.descriptionText}>{description}</Ellipsis>
209
+ </div>
210
+ </div>
211
+ </Tooltip>
212
+ );
213
+ }
package/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { EnvsFilter } from './envs-filter';
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@teambit/component.ui.component-filters.env-filter",
3
+ "version": "0.0.1",
4
+ "main": "dist/index.js",
5
+ "componentId": {
6
+ "scope": "teambit.component",
7
+ "name": "ui/component-filters/env-filter",
8
+ "version": "0.0.1"
9
+ },
10
+ "dependencies": {
11
+ "classnames": "2.2.6",
12
+ "core-js": "^3.0.0",
13
+ "@teambit/base-react.navigation.link": "2.0.27",
14
+ "@teambit/design.inputs.selectors.multi-select": "0.0.20",
15
+ "@teambit/ui-foundation.ui.constants.z-indexes": "0.0.488",
16
+ "@teambit/component.modules.component-url": "0.0.128",
17
+ "@teambit/component.ui.component-filters.component-filter-context": "0.0.1",
18
+ "@teambit/design.ui.styles.ellipsis": "0.0.347",
19
+ "@teambit/design.ui.tooltip": "0.0.352"
20
+ },
21
+ "devDependencies": {
22
+ "@types/classnames": "2.2.11",
23
+ "@types/react": "^17.0.8",
24
+ "@types/mocha": "9.1.0",
25
+ "@types/testing-library__jest-dom": "5.9.5",
26
+ "@babel/runtime": "7.12.18",
27
+ "@types/jest": "^26.0.0",
28
+ "@types/react-dom": "^17.0.5",
29
+ "@types/node": "12.20.4"
30
+ },
31
+ "peerDependencies": {
32
+ "react-dom": "^16.8.0 || ^17.0.0",
33
+ "react": "^16.8.0 || ^17.0.0"
34
+ },
35
+ "license": "Apache-2.0",
36
+ "private": false,
37
+ "engines": {
38
+ "node": ">=12.22.0"
39
+ },
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "https://github.com/teambit/bit"
43
+ },
44
+ "keywords": [
45
+ "bit",
46
+ "components",
47
+ "collaboration",
48
+ "web",
49
+ "react",
50
+ "react-components",
51
+ "angular",
52
+ "angular-components",
53
+ "vue",
54
+ "vue-components"
55
+ ]
56
+ }
@@ -0,0 +1,5 @@
1
+ ;
2
+ ;
3
+
4
+ export const compositions = [];
5
+ export const overview = [];
package/tsconfig.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "compilerOptions": {
3
+ "lib": [
4
+ "es2019",
5
+ "DOM",
6
+ "ES6",
7
+ "DOM.Iterable"
8
+ ],
9
+ "target": "es2015",
10
+ "module": "CommonJS",
11
+ "jsx": "react",
12
+ "allowJs": true,
13
+ "composite": true,
14
+ "declaration": true,
15
+ "sourceMap": true,
16
+ "skipLibCheck": true,
17
+ "experimentalDecorators": true,
18
+ "outDir": "dist",
19
+ "moduleResolution": "node",
20
+ "esModuleInterop": true,
21
+ "rootDir": ".",
22
+ "resolveJsonModule": true
23
+ },
24
+ "exclude": [
25
+ "dist",
26
+ "package.json"
27
+ ],
28
+ "include": [
29
+ "**/*",
30
+ "**/*.json"
31
+ ]
32
+ }
@@ -0,0 +1,29 @@
1
+ declare module '*.png' {
2
+ const value: any;
3
+ export = value;
4
+ }
5
+ declare module '*.svg' {
6
+ import type { FunctionComponent, SVGProps } from 'react';
7
+
8
+ export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
9
+ const src: string;
10
+ export default src;
11
+ }
12
+
13
+ // @TODO Gilad
14
+ declare module '*.jpg' {
15
+ const value: any;
16
+ export = value;
17
+ }
18
+ declare module '*.jpeg' {
19
+ const value: any;
20
+ export = value;
21
+ }
22
+ declare module '*.gif' {
23
+ const value: any;
24
+ export = value;
25
+ }
26
+ declare module '*.bmp' {
27
+ const value: any;
28
+ export = value;
29
+ }
@@ -0,0 +1,42 @@
1
+ declare module '*.module.css' {
2
+ const classes: { readonly [key: string]: string };
3
+ export default classes;
4
+ }
5
+ declare module '*.module.scss' {
6
+ const classes: { readonly [key: string]: string };
7
+ export default classes;
8
+ }
9
+ declare module '*.module.sass' {
10
+ const classes: { readonly [key: string]: string };
11
+ export default classes;
12
+ }
13
+
14
+ declare module '*.module.less' {
15
+ const classes: { readonly [key: string]: string };
16
+ export default classes;
17
+ }
18
+
19
+ declare module '*.less' {
20
+ const classes: { readonly [key: string]: string };
21
+ export default classes;
22
+ }
23
+
24
+ declare module '*.css' {
25
+ const classes: { readonly [key: string]: string };
26
+ export default classes;
27
+ }
28
+
29
+ declare module '*.sass' {
30
+ const classes: { readonly [key: string]: string };
31
+ export default classes;
32
+ }
33
+
34
+ declare module '*.scss' {
35
+ const classes: { readonly [key: string]: string };
36
+ export default classes;
37
+ }
38
+
39
+ declare module '*.mdx' {
40
+ const component: any;
41
+ export default component;
42
+ }