@open-tender/cloud 0.1.41 → 0.1.43

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.
@@ -4,7 +4,7 @@ export interface TagsState {
4
4
  entities: Tags;
5
5
  error: RequestError;
6
6
  loading: RequestStatus;
7
- selectedTags: Tags | null;
7
+ selectedTags: Tags;
8
8
  lookup: TagLookupEnhanced | null;
9
9
  }
10
10
  export declare enum TagsActionType {
@@ -24,9 +24,9 @@ export declare const fetchTags: import("@reduxjs/toolkit").AsyncThunk<TagsPayloa
24
24
  fulfilledMeta?: unknown;
25
25
  rejectedMeta?: unknown;
26
26
  }>;
27
- export declare const resetTags: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"tags/resetTags">, setSelectedTags: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "tags/setSelectedTags">;
27
+ export declare const resetTags: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"tags/resetTags">, setSelectedTags: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "tags/setSelectedTags">, toggleTag: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "tags/toggleTag">;
28
28
  export declare const selectTags: (state: AppState) => TagsState;
29
- export declare const selectSelectedTags: (state: AppState) => Tags | null;
29
+ export declare const selectSelectedTags: (state: AppState) => Tags;
30
30
  export declare const selectSelectedTagNames: ((state: import("redux").EmptyObject & {
31
31
  alerts: import("@open-tender/types").Alerts;
32
32
  notifications: import("@open-tender/types").Notifications;
@@ -85,7 +85,7 @@ export declare const selectSelectedTagNames: ((state: import("redux").EmptyObjec
85
85
  tags: TagsState;
86
86
  }) => string[]) & import("reselect").OutputSelectorFields<(args_0: {
87
87
  tags: Tags;
88
- selectedTags: Tags | null;
88
+ selectedTags: Tags;
89
89
  }) => string[], {
90
90
  clearCache: () => void;
91
91
  }> & {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.tagsReducer = exports.selectSelectedTagNames = exports.selectSelectedTags = exports.selectTags = exports.setSelectedTags = exports.resetTags = exports.fetchTags = exports.TagsActionType = void 0;
4
+ exports.tagsReducer = exports.selectSelectedTagNames = exports.selectSelectedTags = exports.selectTags = exports.toggleTag = exports.setSelectedTags = exports.resetTags = exports.fetchTags = exports.TagsActionType = void 0;
5
5
  const tslib_1 = require("tslib");
6
6
  const toolkit_1 = require("@reduxjs/toolkit");
7
7
  const types_1 = require("./types");
@@ -18,7 +18,7 @@ const initialState = {
18
18
  entities: [],
19
19
  error: null,
20
20
  loading: 'idle',
21
- selectedTags: null,
21
+ selectedTags: [],
22
22
  lookup: {}
23
23
  };
24
24
  var TagsActionType;
@@ -43,6 +43,15 @@ const tagsSlice = (0, toolkit_1.createSlice)({
43
43
  resetTags: () => initialState,
44
44
  setSelectedTags: (state, action) => {
45
45
  state.selectedTags = action.payload;
46
+ },
47
+ toggleTag: (state, action) => {
48
+ var _a;
49
+ const tag = action.payload;
50
+ const exists = (_a = state.selectedTags) === null || _a === void 0 ? void 0 : _a.find(i => i.tag_id === tag.tag_id);
51
+ const current = state.selectedTags || [];
52
+ state.selectedTags = exists
53
+ ? current.filter(i => i.tag_id !== tag.tag_id)
54
+ : [...current, tag];
46
55
  }
47
56
  },
48
57
  extraReducers: builder => {
@@ -62,7 +71,7 @@ const tagsSlice = (0, toolkit_1.createSlice)({
62
71
  });
63
72
  }
64
73
  });
65
- _a = tagsSlice.actions, exports.resetTags = _a.resetTags, exports.setSelectedTags = _a.setSelectedTags;
74
+ _a = tagsSlice.actions, exports.resetTags = _a.resetTags, exports.setSelectedTags = _a.setSelectedTags, exports.toggleTag = _a.toggleTag;
66
75
  const selectTags = (state) => state.tags;
67
76
  exports.selectTags = selectTags;
68
77
  const selectSelectedTags = (state) => state.tags.selectedTags;
@@ -75,8 +84,8 @@ exports.selectSelectedTagNames = (0, toolkit_1.createSelector)((state) => {
75
84
  return [];
76
85
  const selected = selectedTags.map(i => {
77
86
  var _a;
78
- const allergen = tags.find(a => a.allergen_id === i.allergen_id);
79
- return allergen ? (_a = allergen.name) !== null && _a !== void 0 ? _a : '' : '';
87
+ const tag = tags.find(a => a.tag_id === i.tag_id);
88
+ return tag ? (_a = tag.name) !== null && _a !== void 0 ? _a : '' : '';
80
89
  });
81
90
  return selected;
82
91
  });
@@ -4,7 +4,7 @@ export interface TagsState {
4
4
  entities: Tags;
5
5
  error: RequestError;
6
6
  loading: RequestStatus;
7
- selectedTags: Tags | null;
7
+ selectedTags: Tags;
8
8
  lookup: TagLookupEnhanced | null;
9
9
  }
10
10
  export declare enum TagsActionType {
@@ -24,9 +24,9 @@ export declare const fetchTags: import("@reduxjs/toolkit").AsyncThunk<TagsPayloa
24
24
  fulfilledMeta?: unknown;
25
25
  rejectedMeta?: unknown;
26
26
  }>;
27
- export declare const resetTags: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"tags/resetTags">, setSelectedTags: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "tags/setSelectedTags">;
27
+ export declare const resetTags: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"tags/resetTags">, setSelectedTags: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "tags/setSelectedTags">, toggleTag: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "tags/toggleTag">;
28
28
  export declare const selectTags: (state: AppState) => TagsState;
29
- export declare const selectSelectedTags: (state: AppState) => Tags | null;
29
+ export declare const selectSelectedTags: (state: AppState) => Tags;
30
30
  export declare const selectSelectedTagNames: ((state: import("redux").EmptyObject & {
31
31
  alerts: import("@open-tender/types").Alerts;
32
32
  notifications: import("@open-tender/types").Notifications;
@@ -85,7 +85,7 @@ export declare const selectSelectedTagNames: ((state: import("redux").EmptyObjec
85
85
  tags: TagsState;
86
86
  }) => string[]) & import("reselect").OutputSelectorFields<(args_0: {
87
87
  tags: Tags;
88
- selectedTags: Tags | null;
88
+ selectedTags: Tags;
89
89
  }) => string[], {
90
90
  clearCache: () => void;
91
91
  }> & {
@@ -14,7 +14,7 @@ const initialState = {
14
14
  entities: [],
15
15
  error: null,
16
16
  loading: 'idle',
17
- selectedTags: null,
17
+ selectedTags: [],
18
18
  lookup: {}
19
19
  };
20
20
  export var TagsActionType;
@@ -39,6 +39,15 @@ const tagsSlice = createSlice({
39
39
  resetTags: () => initialState,
40
40
  setSelectedTags: (state, action) => {
41
41
  state.selectedTags = action.payload;
42
+ },
43
+ toggleTag: (state, action) => {
44
+ var _a;
45
+ const tag = action.payload;
46
+ const exists = (_a = state.selectedTags) === null || _a === void 0 ? void 0 : _a.find(i => i.tag_id === tag.tag_id);
47
+ const current = state.selectedTags || [];
48
+ state.selectedTags = exists
49
+ ? current.filter(i => i.tag_id !== tag.tag_id)
50
+ : [...current, tag];
42
51
  }
43
52
  },
44
53
  extraReducers: builder => {
@@ -58,7 +67,7 @@ const tagsSlice = createSlice({
58
67
  });
59
68
  }
60
69
  });
61
- export const { resetTags, setSelectedTags } = tagsSlice.actions;
70
+ export const { resetTags, setSelectedTags, toggleTag } = tagsSlice.actions;
62
71
  export const selectTags = (state) => state.tags;
63
72
  export const selectSelectedTags = (state) => state.tags.selectedTags;
64
73
  export const selectSelectedTagNames = createSelector((state) => {
@@ -69,8 +78,8 @@ export const selectSelectedTagNames = createSelector((state) => {
69
78
  return [];
70
79
  const selected = selectedTags.map(i => {
71
80
  var _a;
72
- const allergen = tags.find(a => a.allergen_id === i.allergen_id);
73
- return allergen ? (_a = allergen.name) !== null && _a !== void 0 ? _a : '' : '';
81
+ const tag = tags.find(a => a.tag_id === i.tag_id);
82
+ return tag ? (_a = tag.name) !== null && _a !== void 0 ? _a : '' : '';
74
83
  });
75
84
  return selected;
76
85
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/cloud",
3
- "version": "0.1.41",
3
+ "version": "0.1.43",
4
4
  "description": "A library of hooks, reducers, utility functions, and types for use with Open Tender applications that utilize our cloud-based Order API.",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -49,7 +49,7 @@
49
49
  "typescript": "^4.8.2"
50
50
  },
51
51
  "peerDependencies": {
52
- "@open-tender/types": "^0.2.38",
52
+ "@open-tender/types": "^0.2.40",
53
53
  "@open-tender/utils": "^0.1.95",
54
54
  "@reduxjs/toolkit": "^1.8.5",
55
55
  "react": "^18.2.0"