@cccsaurora/howler-ui 2.13.0-dev.142 → 2.13.0-dev.144
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,18 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Button } from '@mui/material';
|
|
3
|
+
import api from '@cccsaurora/howler-ui/api';
|
|
4
|
+
import useMyApi from '@cccsaurora/howler-ui/components/hooks/useMyApi';
|
|
5
|
+
import useMyActionFunctions from '@cccsaurora/howler-ui/components/routes/action/useMyActionFunctions';
|
|
6
|
+
import { useEffect, useState } from 'react';
|
|
7
|
+
import { useTranslation } from 'react-i18next';
|
|
8
|
+
const ActionButton = ({ actionId, hitId, label, ...otherProps }) => {
|
|
9
|
+
const { t } = useTranslation();
|
|
10
|
+
const { dispatchApi } = useMyApi();
|
|
11
|
+
const { executeAction } = useMyActionFunctions();
|
|
12
|
+
const [action, setAction] = useState(null);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
dispatchApi(api.search.action.post({ query: `action_id:${actionId}`, rows: 1 })).then(result => setAction(result.items[0]));
|
|
15
|
+
}, [actionId, dispatchApi]);
|
|
16
|
+
return (_jsx(Button, { variant: otherProps.variant ?? 'outlined', disabled: !action, onClick: () => executeAction(actionId, `howler.id:${hitId}`), color: otherProps.color ?? 'primary', children: label ?? action?.name ?? t('loading') }));
|
|
17
|
+
};
|
|
18
|
+
export default ActionButton;
|
|
@@ -10,6 +10,7 @@ import { capitalize, get, groupBy, isObject } from 'lodash-es';
|
|
|
10
10
|
import howlerPluginStore from '@cccsaurora/howler-ui/plugins/store';
|
|
11
11
|
import { useMemo } from 'react';
|
|
12
12
|
import { usePluginStore } from 'react-pluggable';
|
|
13
|
+
import ActionButton from '../ActionButton';
|
|
13
14
|
import JSONViewer from '../json/JSONViewer';
|
|
14
15
|
const FETCH_RESULTS = {};
|
|
15
16
|
export const useHelpers = () => {
|
|
@@ -147,6 +148,17 @@ export const useHelpers = () => {
|
|
|
147
148
|
}) })] }) }));
|
|
148
149
|
}
|
|
149
150
|
},
|
|
151
|
+
{
|
|
152
|
+
keyword: 'action',
|
|
153
|
+
documentation: 'Execute a howler action given a specific action ID (from the URL when viewing the action, i.e. yaIKVqiKhWpyCsWdqsE4D)',
|
|
154
|
+
componentCallback: (actionId, hitId, context) => {
|
|
155
|
+
if (!actionId || !hitId) {
|
|
156
|
+
console.warn('Missing parameters for the action button.');
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
return _jsx(ActionButton, { actionId: actionId, hitId: hitId, ...(context.hash ?? {}) });
|
|
160
|
+
}
|
|
161
|
+
},
|
|
150
162
|
...howlerPluginStore.plugins.flatMap(plugin => pluginStore.executeFunction(`${plugin}.helpers`))
|
|
151
163
|
], [pluginStore]);
|
|
152
164
|
return allHelpers;
|