@cccsaurora/howler-ui 2.12.0-dev.45 → 2.12.0-dev.48

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.
package/api/auth/login.js CHANGED
@@ -10,7 +10,6 @@ export const post = (body) => {
10
10
  export const get = (search) => {
11
11
  const nonce = localStorage.getItem(`${MY_LOCAL_STORAGE_PREFIX}.${StorageKey.LOGIN_NONCE}`);
12
12
  if (nonce) {
13
- console.log('Adding nonce');
14
13
  search.set('nonce', JSON.parse(nonce));
15
14
  localStorage.removeItem(`${MY_LOCAL_STORAGE_PREFIX}.${StorageKey.LOGIN_NONCE}`);
16
15
  }
@@ -1,3 +1,4 @@
1
+ /* eslint-disable import/no-cycle */
1
2
  import { hget, joinAllUri } from '@cccsaurora/howler-ui/api';
2
3
  import { uri as parentUri } from '.';
3
4
  const uri = (id) => joinAllUri(parentUri(), 'hit', id);
@@ -1,3 +1,4 @@
1
+ // eslint-disable-next-line import/no-cycle
1
2
  import { hdelete, hget, hpost, hput, joinAllUri, joinUri, uri as parentUri } from '@cccsaurora/howler-ui/api';
2
3
  import * as hit from './hit';
3
4
  export const uri = (id) => {
@@ -1,3 +1,4 @@
1
+ // eslint-disable-next-line import/no-cycle
1
2
  import { hdelete, hput, joinUri } from '@cccsaurora/howler-ui/api';
2
3
  import { uri as parentUri } from '@cccsaurora/howler-ui/api/hit/comments';
3
4
  export const uri = (hit, comment) => {
@@ -1,3 +1,3 @@
1
1
  export declare const MuiButtonColors: readonly ["inherit", "primary", "secondary", "success", "error", "info", "warning"];
2
2
  export type MuiButtonColorType = (typeof MuiButtonColors)[number];
3
- export declare function isMuiButtonColor(color: string): boolean;
3
+ export declare const isMuiButtonColor: (color: string) => boolean;
@@ -1,4 +1,4 @@
1
1
  export const MuiButtonColors = ['inherit', 'primary', 'secondary', 'success', 'error', 'info', 'warning'];
2
- export function isMuiButtonColor(color) {
2
+ export const isMuiButtonColor = (color) => {
3
3
  return MuiButtonColors.some(c => c === color);
4
- }
4
+ };
@@ -7,10 +7,11 @@ import { useTranslation } from 'react-i18next';
7
7
  import Throttler from '@cccsaurora/howler-ui/utils/Throttler';
8
8
  import { hashCode } from '@cccsaurora/howler-ui/utils/utils';
9
9
  import Markdown, {} from '../display/Markdown';
10
- import { helpers } from './handlebars/helpers';
10
+ import { useHelpers } from './handlebars/helpers';
11
11
  const THROTTLER = new Throttler(500);
12
12
  const HandlebarsMarkdown = ({ md, object = {}, disableLinks = false }) => {
13
13
  const { t } = useTranslation();
14
+ const helpers = useHelpers();
14
15
  const [rendered, setRendered] = useState('');
15
16
  const [mdComponents, setMdComponents] = useState({});
16
17
  const handlebars = useMemo(() => {
@@ -28,7 +29,7 @@ const HandlebarsMarkdown = ({ md, object = {}, disableLinks = false }) => {
28
29
  return instance;
29
30
  }, []);
30
31
  useEffect(() => {
31
- helpers().forEach(helper => {
32
+ helpers.forEach(helper => {
32
33
  if (handlebars.helpers[helper.keyword] && !helper.componentCallback) {
33
34
  return;
34
35
  }
@@ -50,7 +51,7 @@ const HandlebarsMarkdown = ({ md, object = {}, disableLinks = false }) => {
50
51
  return helper.callback(...args);
51
52
  });
52
53
  });
53
- }, [handlebars, mdComponents]);
54
+ }, [handlebars, helpers, mdComponents]);
54
55
  useEffect(() => {
55
56
  THROTTLER.debounce(async () => {
56
57
  try {
@@ -6,4 +6,4 @@ export interface HowlerHelper {
6
6
  callback?: Handlebars.HelperDelegate;
7
7
  componentCallback?: (...args: any[]) => ReactElement | Promise<ReactElement>;
8
8
  }
9
- export declare const helpers: () => HowlerHelper[];
9
+ export declare const useHelpers: () => HowlerHelper[];
@@ -8,138 +8,143 @@ import { flatten } from 'flat';
8
8
  import Handlebars from 'handlebars';
9
9
  import { capitalize, get, groupBy, isObject } from 'lodash-es';
10
10
  import howlerPluginStore from '@cccsaurora/howler-ui/plugins/store';
11
- import {} from 'react';
11
+ import { useMemo } from 'react';
12
+ import { usePluginStore } from 'react-pluggable';
12
13
  import JSONViewer from '../json/JSONViewer';
13
- export const helpers = () => [
14
- {
15
- keyword: 'equals',
16
- documentation: 'Checks the equality of the string representation of the two arguments.',
17
- callback: (arg1, arg2) => arg1?.toString() === arg2.toString()
18
- },
19
- {
20
- keyword: 'and',
21
- documentation: 'Runs the comparison `arg1 && arg2`, and returns the result.',
22
- callback: (arg1, arg2) => arg1 && arg2
23
- },
24
- {
25
- keyword: 'or',
26
- documentation: 'Runs the comparison `arg1 || arg2`, and returns the result.',
27
- callback: (arg1, arg2) => arg1 || arg2
28
- },
29
- { keyword: 'not', documentation: 'Runs the comparison `!arg`, and returns the result.', callback: arg => !arg },
30
- {
31
- keyword: 'curly',
32
- documentation: 'Wraps the given argument in curly braces.',
33
- callback: arg1 => new Handlebars.SafeString(`{{${arg1}}}`)
34
- },
35
- {
36
- keyword: 'join',
37
- documentation: 'Joins two string arguments with a given string `sep`, or the empty string as a default.',
38
- callback: (arg1, arg2, context) => [arg1?.toString() ?? '', arg2?.toString() ?? ''].join(context.hash?.sep ?? '')
39
- },
40
- {
41
- keyword: 'upper',
42
- documentation: 'Returns the uppercase representation of a string argment.',
43
- callback: (val) => val.toLocaleUpperCase()
44
- },
45
- {
46
- keyword: 'lower',
47
- documentation: 'Returns the lowercase representation of a string argment.',
48
- callback: (val) => val.toLocaleLowerCase()
49
- },
50
- {
51
- keyword: 'fetch',
52
- documentation: 'Fetches the url provided and returns the given (flattened) key from the returned JSON object. Note that the result must be JSON!',
53
- callback: async (url, key) => {
54
- try {
55
- const response = await fetch(url);
56
- const json = await response.json();
57
- return flatten(json)[key];
14
+ export const useHelpers = () => {
15
+ const pluginStore = usePluginStore();
16
+ const allHelpers = useMemo(() => [
17
+ {
18
+ keyword: 'equals',
19
+ documentation: 'Checks the equality of the string representation of the two arguments.',
20
+ callback: (arg1, arg2) => arg1?.toString() === arg2.toString()
21
+ },
22
+ {
23
+ keyword: 'and',
24
+ documentation: 'Runs the comparison `arg1 && arg2`, and returns the result.',
25
+ callback: (arg1, arg2) => arg1 && arg2
26
+ },
27
+ {
28
+ keyword: 'or',
29
+ documentation: 'Runs the comparison `arg1 || arg2`, and returns the result.',
30
+ callback: (arg1, arg2) => arg1 || arg2
31
+ },
32
+ { keyword: 'not', documentation: 'Runs the comparison `!arg`, and returns the result.', callback: arg => !arg },
33
+ {
34
+ keyword: 'curly',
35
+ documentation: 'Wraps the given argument in curly braces.',
36
+ callback: arg1 => new Handlebars.SafeString(`{{${arg1}}}`)
37
+ },
38
+ {
39
+ keyword: 'join',
40
+ documentation: 'Joins two string arguments with a given string `sep`, or the empty string as a default.',
41
+ callback: (arg1, arg2, context) => [arg1?.toString() ?? '', arg2?.toString() ?? ''].join(context.hash?.sep ?? '')
42
+ },
43
+ {
44
+ keyword: 'upper',
45
+ documentation: 'Returns the uppercase representation of a string argment.',
46
+ callback: (val) => val.toLocaleUpperCase()
47
+ },
48
+ {
49
+ keyword: 'lower',
50
+ documentation: 'Returns the lowercase representation of a string argment.',
51
+ callback: (val) => val.toLocaleLowerCase()
52
+ },
53
+ {
54
+ keyword: 'fetch',
55
+ documentation: 'Fetches the url provided and returns the given (flattened) key from the returned JSON object. Note that the result must be JSON!',
56
+ callback: async (url, key) => {
57
+ try {
58
+ const response = await fetch(url);
59
+ const json = await response.json();
60
+ return flatten(json)[key];
61
+ }
62
+ catch (e) {
63
+ return '';
64
+ }
58
65
  }
59
- catch (e) {
60
- return '';
66
+ },
67
+ {
68
+ keyword: 'howler',
69
+ documentation: 'Given a howler hit ID, this helper renders a hit card for that ID.',
70
+ componentCallback: id => {
71
+ if (!id) {
72
+ return _jsx(AppListEmpty, {});
73
+ }
74
+ return _jsx(HitCard, { id: id, layout: HitLayout.NORMAL });
61
75
  }
62
- }
63
- },
64
- {
65
- keyword: 'howler',
66
- documentation: 'Given a howler hit ID, this helper renders a hit card for that ID.',
67
- componentCallback: id => {
68
- if (!id) {
69
- return _jsx(AppListEmpty, {});
76
+ },
77
+ {
78
+ keyword: 'entries',
79
+ documentation: 'Given a dict, return an array of {key, value} objects.',
80
+ callback: obj => {
81
+ if (!isObject(obj)) {
82
+ return new Handlebars.SafeString('Invalid Object.');
83
+ }
84
+ return Object.entries(obj).map(([key, value]) => ({ key, value }));
70
85
  }
71
- return _jsx(HitCard, { id: id, layout: HitLayout.NORMAL });
72
- }
73
- },
74
- {
75
- keyword: 'entries',
76
- documentation: 'Given a dict, return an array of {key, value} objects.',
77
- callback: obj => {
78
- if (!isObject(obj)) {
79
- return new Handlebars.SafeString('Invalid Object.');
86
+ },
87
+ {
88
+ keyword: 'render_json',
89
+ documentation: 'Given a howler hit ID, this helper renders a hit card for that ID.',
90
+ componentCallback: data => {
91
+ if (!data) {
92
+ return _jsx(AppListEmpty, {});
93
+ }
94
+ return _jsx(JSONViewer, { data: data });
80
95
  }
81
- return Object.entries(obj).map(([key, value]) => ({ key, value }));
82
- }
83
- },
84
- {
85
- keyword: 'render_json',
86
- documentation: 'Given a howler hit ID, this helper renders a hit card for that ID.',
87
- componentCallback: data => {
88
- if (!data) {
89
- return _jsx(AppListEmpty, {});
96
+ },
97
+ {
98
+ keyword: 'to_json',
99
+ documentation: 'Convert any object into a JSON string.',
100
+ callback: obj => {
101
+ return new Handlebars.SafeString(JSON.stringify(obj));
90
102
  }
91
- return _jsx(JSONViewer, { data: data });
92
- }
93
- },
94
- {
95
- keyword: 'to_json',
96
- documentation: 'Convert any object into a JSON string.',
97
- callback: obj => {
98
- return new Handlebars.SafeString(JSON.stringify(obj));
99
- }
100
- },
101
- {
102
- keyword: 'parse_json',
103
- documentation: 'Convert JSON string into and object.',
104
- callback: str => {
105
- return JSON.parse(str);
106
- }
107
- },
108
- {
109
- keyword: 'get',
110
- documentation: 'Returns the given (flattened) key from the provided object.',
111
- callback: async (data, key) => {
112
- try {
113
- return get(data, key);
103
+ },
104
+ {
105
+ keyword: 'parse_json',
106
+ documentation: 'Convert JSON string into and object.',
107
+ callback: str => {
108
+ return JSON.parse(str);
114
109
  }
115
- catch (e) {
116
- return '';
110
+ },
111
+ {
112
+ keyword: 'get',
113
+ documentation: 'Returns the given (flattened) key from the provided object.',
114
+ callback: async (data, key) => {
115
+ try {
116
+ return get(data, key);
117
+ }
118
+ catch (e) {
119
+ return '';
120
+ }
117
121
  }
118
- }
119
- },
120
- {
121
- keyword: 'includes',
122
- documentation: 'Checks if field is in string',
123
- callback: (arg1, arg2) => {
124
- return !!arg2 && !!arg1?.includes(arg2);
125
- }
126
- },
127
- {
128
- keyword: 'table',
129
- documentation: 'Render a table in markdown given an array of cells',
130
- componentCallback: (cells) => {
131
- const columns = Object.keys(groupBy(cells, 'column'));
132
- const rows = groupBy(cells, 'row');
133
- return (_jsx(Paper, { sx: { width: '95%', overflowX: 'auto', m: 1 }, children: _jsxs(Table, { children: [_jsx(TableHead, { children: _jsx(TableRow, { children: columns.map(col => (_jsx(TableCell, { sx: { maxWidth: '150px' }, children: col
134
- .split(/[_-]/)
135
- .map(word => capitalize(word))
136
- .join(' ') }, col))) }) }), _jsx(TableBody, { sx: { '& td': { wordBreak: 'break-word' } }, children: Object.entries(rows).map(([rowId, _cells]) => {
137
- return (_jsx(TableRow, { children: columns.map(col => {
138
- const cell = _cells.find(row => row.column === col);
139
- return _jsx(TableCell, { children: cell?.value ?? 'N/A' }, col + cell?.value);
140
- }) }, rowId));
141
- }) })] }) }));
142
- }
143
- },
144
- ...howlerPluginStore.plugins.flatMap(plugin => howlerPluginStore.pluginStore.executeFunction(`${plugin}.helpers`))
145
- ];
122
+ },
123
+ {
124
+ keyword: 'includes',
125
+ documentation: 'Checks if field is in string',
126
+ callback: (arg1, arg2) => {
127
+ return !!arg2 && !!arg1?.includes(arg2);
128
+ }
129
+ },
130
+ {
131
+ keyword: 'table',
132
+ documentation: 'Render a table in markdown given an array of cells',
133
+ componentCallback: (cells) => {
134
+ const columns = Object.keys(groupBy(cells, 'column'));
135
+ const rows = groupBy(cells, 'row');
136
+ return (_jsx(Paper, { sx: { width: '95%', overflowX: 'auto', m: 1 }, children: _jsxs(Table, { children: [_jsx(TableHead, { children: _jsx(TableRow, { children: columns.map(col => (_jsx(TableCell, { sx: { maxWidth: '150px' }, children: col
137
+ .split(/[_-]/)
138
+ .map(word => capitalize(word))
139
+ .join(' ') }, col))) }) }), _jsx(TableBody, { sx: { '& td': { wordBreak: 'break-word' } }, children: Object.entries(rows).map(([rowId, _cells]) => {
140
+ return (_jsx(TableRow, { children: columns.map(col => {
141
+ const cell = _cells.find(row => row.column === col);
142
+ return _jsx(TableCell, { children: cell?.value ?? 'N/A' }, col + cell?.value);
143
+ }) }, rowId));
144
+ }) })] }) }));
145
+ }
146
+ },
147
+ ...howlerPluginStore.plugins.flatMap(plugin => pluginStore.executeFunction(`${plugin}.helpers`))
148
+ ], [pluginStore]);
149
+ return allHelpers;
150
+ };
@@ -1,7 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Article, Book, Code, CreateNewFolder, Dashboard, Description, Edit, EditNote, FormatListBulleted, Help, Info, Key, PersonSearch, QueryStats, SavedSearch, Search, SettingsSuggest, Shield, Storage, Terminal, Topic, Work } from '@mui/icons-material';
3
- import PersonIcon from '@mui/icons-material/Person';
4
- import SettingsIcon from '@mui/icons-material/Settings';
2
+ import { Article, Book, Code, CreateNewFolder, Dashboard, Description, Edit, EditNote, FormatListBulleted, Help, Info, Key, Person, PersonSearch, QueryStats, SavedSearch, Search, Settings, SettingsSuggest, Shield, Storage, Terminal, Topic, Work } from '@mui/icons-material';
5
3
  import { useMemo } from 'react';
6
4
  import { useTranslation } from 'react-i18next';
7
5
  // SiteMapContextProps configuration properties.
@@ -31,7 +29,7 @@ const useMySitemap = () => {
31
29
  title: t('route.admin.user.details'),
32
30
  isLeaf: true,
33
31
  breadcrumbs: ['/admin/users'],
34
- icon: _jsx(PersonIcon, {})
32
+ icon: _jsx(Person, {})
35
33
  },
36
34
  { path: '/help', title: t('route.help'), isRoot: true, icon: _jsx(Help, {}) },
37
35
  { path: '/help/api', title: t('route.help.api'), isLeaf: true, icon: _jsx(Storage, {}), breadcrumbs: ['/help'] },
@@ -209,7 +207,7 @@ const useMySitemap = () => {
209
207
  icon: _jsx(Info, {})
210
208
  },
211
209
  { path: '/home', title: t('route.home'), isRoot: true, icon: _jsx(Dashboard, {}) },
212
- { path: '/settings', title: t('page.settings.sitemap'), isRoot: true, icon: _jsx(SettingsIcon, {}) },
210
+ { path: '/settings', title: t('page.settings.sitemap'), isRoot: true, icon: _jsx(Settings, {}) },
213
211
  { path: '/advanced', title: t('route.advanced'), isRoot: true, icon: _jsx(Code, {}) }
214
212
  ]
215
213
  }), [t]);
@@ -2,12 +2,12 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import PageCenter from '@cccsaurora/howler-ui/commons/components/pages/PageCenter';
3
3
  import HandlebarsMarkdown from '@cccsaurora/howler-ui/components/elements/display/HandlebarsMarkdown';
4
4
  import { useScrollRestoration } from '@cccsaurora/howler-ui/components/hooks/useScrollRestoration';
5
- import { useMemo } from 'react';
5
+ import {} from 'react';
6
6
  import ErrorBoundary from '../ErrorBoundary';
7
- import { startingTemplate } from '../overviews/startingTemplate';
7
+ import { useStartingTemplate } from '../overviews/startingTemplate';
8
8
  const OverviewDocumentation = () => {
9
9
  useScrollRestoration();
10
- const template = useMemo(() => startingTemplate(), []);
10
+ const template = useStartingTemplate();
11
11
  return (_jsx(PageCenter, { margin: 4, width: "100%", textAlign: "left", children: _jsx(ErrorBoundary, { children: _jsx(HandlebarsMarkdown, { md: template }) }) }));
12
12
  };
13
13
  export default OverviewDocumentation;
@@ -14,7 +14,7 @@ import { useSearchParams } from 'react-router-dom';
14
14
  import hitsData from '@cccsaurora/howler-ui/utils/hit.json';
15
15
  import { sanitizeLuceneQuery } from '@cccsaurora/howler-ui/utils/stringUtils';
16
16
  import OverviewEditor from './OverviewEditor';
17
- import { startingTemplate } from './startingTemplate';
17
+ import { useStartingTemplate } from './startingTemplate';
18
18
  const OverviewViewer = () => {
19
19
  const theme = useTheme();
20
20
  const { t } = useTranslation();
@@ -34,6 +34,7 @@ const OverviewViewer = () => {
34
34
  const [x, setX] = useState(0);
35
35
  const analyticContext = useContext(AnalyticContext);
36
36
  const wrapper = useRef();
37
+ const startingTemplate = useStartingTemplate();
37
38
  useEffect(() => {
38
39
  (async () => {
39
40
  setLoading(true);
@@ -212,6 +213,6 @@ const OverviewViewer = () => {
212
213
  mt: -1,
213
214
  '& > *': { width: '100%' },
214
215
  '& > div > :first-child': { mt: 0 }
215
- }, children: _jsx(HitOverview, { content: content || startingTemplate(), hit: exampleHit }) })] }))] })] }));
216
+ }, children: _jsx(HitOverview, { content: content || startingTemplate, hit: exampleHit }) })] }))] })] }));
216
217
  };
217
218
  export default OverviewViewer;
@@ -1 +1 @@
1
- export declare const startingTemplate: () => string;
1
+ export declare const useStartingTemplate: () => string;
@@ -1,6 +1,8 @@
1
- import { helpers } from '@cccsaurora/howler-ui/components/elements/display/handlebars/helpers';
2
- export const startingTemplate = () => {
3
- const helperText = helpers()
1
+ import { useHelpers } from '@cccsaurora/howler-ui/components/elements/display/handlebars/helpers';
2
+ import { useMemo } from 'react';
3
+ export const useStartingTemplate = () => {
4
+ const helpers = useHelpers();
5
+ const helperText = useMemo(() => helpers
4
6
  .map(helper => `
5
7
  ### \`${helper.keyword}\`
6
8
 
@@ -8,8 +10,8 @@ ${helper.documentation}
8
10
 
9
11
  ---
10
12
  `.trim())
11
- .join('\n');
12
- return `
13
+ .join('\n'), [helpers]);
14
+ return useMemo(() => `
13
15
  # Creating an Overview
14
16
 
15
17
  Overviews can be used to modify the way data is presented on alerts that match the overview's settings. Overviews are, by design, easy to create and quite flexible.
@@ -177,5 +179,5 @@ You can also make basic fetch requests for, and parse, JSON data from external s
177
179
  ## Full Helper List
178
180
 
179
181
  ${helperText}
180
- `;
182
+ `, [helperText]);
181
183
  };
package/package.json CHANGED
@@ -96,7 +96,7 @@
96
96
  "internal-slot": "1.0.7"
97
97
  },
98
98
  "type": "module",
99
- "version": "2.12.0-dev.45",
99
+ "version": "2.12.0-dev.48",
100
100
  "exports": {
101
101
  "./i18n": "./i18n.js",
102
102
  "./index.css": "./index.css",
@@ -6,7 +6,7 @@ export declare class HitEvent extends Event {
6
6
  constructor(type: string, hit: Hit);
7
7
  }
8
8
  declare class HowlerPluginStore {
9
- pluginStore: import("react-pluggable").PluginStore;
9
+ private _pluginStore;
10
10
  plugins: string[];
11
11
  private _leadFormats;
12
12
  private _pivotFormats;
@@ -18,6 +18,7 @@ declare class HowlerPluginStore {
18
18
  get leadFormats(): string[];
19
19
  get pivotFormats(): string[];
20
20
  get operations(): string[];
21
+ get pluginStore(): import("react-pluggable").PluginStore;
21
22
  }
22
23
  declare const howlerPluginStore: HowlerPluginStore;
23
24
  export default howlerPluginStore;
package/plugins/store.js CHANGED
@@ -7,7 +7,7 @@ export class HitEvent extends Event {
7
7
  }
8
8
  }
9
9
  class HowlerPluginStore {
10
- pluginStore = createPluginStore();
10
+ _pluginStore = createPluginStore();
11
11
  plugins = [];
12
12
  _leadFormats = [];
13
13
  _pivotFormats = [];
@@ -47,6 +47,9 @@ class HowlerPluginStore {
47
47
  get operations() {
48
48
  return this._operations;
49
49
  }
50
+ get pluginStore() {
51
+ return this._pluginStore;
52
+ }
50
53
  }
51
54
  const howlerPluginStore = new HowlerPluginStore();
52
55
  export default howlerPluginStore;