@thunderid/react 1.16.0 → 1.17.0
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/dist/cjs/components/management/FlowVariables/BaseFlowVariables.cjs +210 -0
- package/dist/cjs/components/management/FlowVariables/BaseFlowVariables.cjs.map +1 -0
- package/dist/cjs/components/management/FlowVariables/FlowVariableField.cjs +162 -0
- package/dist/cjs/components/management/FlowVariables/FlowVariableField.cjs.map +1 -0
- package/dist/cjs/components/management/FlowVariables/FlowVariables.styles.cjs +123 -0
- package/dist/cjs/components/management/FlowVariables/FlowVariables.styles.cjs.map +1 -0
- package/dist/cjs/components/management/FlowVariables/FlowVariablesForm.cjs +50 -0
- package/dist/cjs/components/management/FlowVariables/FlowVariablesForm.cjs.map +1 -0
- package/dist/cjs/components/management/SharedFlowList/BaseSharedFlowList.cjs +78 -0
- package/dist/cjs/components/management/SharedFlowList/BaseSharedFlowList.cjs.map +1 -0
- package/dist/cjs/components/management/SharedFlowList/SharedFlowList.cjs +69 -0
- package/dist/cjs/components/management/SharedFlowList/SharedFlowList.cjs.map +1 -0
- package/dist/cjs/hooks/management/useFlowVariables.cjs +107 -0
- package/dist/cjs/hooks/management/useFlowVariables.cjs.map +1 -0
- package/dist/cjs/index.cjs +48 -0
- package/dist/components/management/FlowVariables/BaseFlowVariables.d.ts +124 -0
- package/dist/components/management/FlowVariables/BaseFlowVariables.d.ts.map +1 -0
- package/dist/components/management/FlowVariables/BaseFlowVariables.js +206 -0
- package/dist/components/management/FlowVariables/BaseFlowVariables.js.map +1 -0
- package/dist/components/management/FlowVariables/FlowVariableField.d.ts +46 -0
- package/dist/components/management/FlowVariables/FlowVariableField.d.ts.map +1 -0
- package/dist/components/management/FlowVariables/FlowVariableField.js +158 -0
- package/dist/components/management/FlowVariables/FlowVariableField.js.map +1 -0
- package/dist/components/management/FlowVariables/FlowVariables.styles.d.ts +11 -0
- package/dist/components/management/FlowVariables/FlowVariables.styles.d.ts.map +1 -0
- package/dist/components/management/FlowVariables/FlowVariables.styles.js +121 -0
- package/dist/components/management/FlowVariables/FlowVariables.styles.js.map +1 -0
- package/dist/components/management/FlowVariables/FlowVariablesForm.d.ts +30 -0
- package/dist/components/management/FlowVariables/FlowVariablesForm.d.ts.map +1 -0
- package/dist/components/management/FlowVariables/FlowVariablesForm.js +47 -0
- package/dist/components/management/FlowVariables/FlowVariablesForm.js.map +1 -0
- package/dist/components/management/SharedFlowList/BaseSharedFlowList.d.ts +53 -0
- package/dist/components/management/SharedFlowList/BaseSharedFlowList.d.ts.map +1 -0
- package/dist/components/management/SharedFlowList/BaseSharedFlowList.js +76 -0
- package/dist/components/management/SharedFlowList/BaseSharedFlowList.js.map +1 -0
- package/dist/components/management/SharedFlowList/SharedFlowList.d.ts +32 -0
- package/dist/components/management/SharedFlowList/SharedFlowList.d.ts.map +1 -0
- package/dist/components/management/SharedFlowList/SharedFlowList.js +65 -0
- package/dist/components/management/SharedFlowList/SharedFlowList.js.map +1 -0
- package/dist/hooks/management/useFlowVariables.d.ts +84 -0
- package/dist/hooks/management/useFlowVariables.d.ts.map +1 -0
- package/dist/hooks/management/useFlowVariables.js +104 -0
- package/dist/hooks/management/useFlowVariables.js.map +1 -0
- package/dist/index.d.ts +14 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -2
- package/package.json +2 -2
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { FlowVariableValues } from '@thunderid/browser';
|
|
2
|
+
import { FC } from 'react';
|
|
3
|
+
import { BaseFlowVariablesProps } from './BaseFlowVariables';
|
|
4
|
+
export type FlowVariablesFormProps = Omit<BaseFlowVariablesProps, 'connections' | 'error' | 'initialValues' | 'isSubmitting' | 'onSubmit' | 'overlay' | 'variables'> & {
|
|
5
|
+
/**
|
|
6
|
+
* Identifier of the flow whose variables are configured.
|
|
7
|
+
*/
|
|
8
|
+
flowId: string;
|
|
9
|
+
/**
|
|
10
|
+
* Called with the saved overrides.
|
|
11
|
+
*/
|
|
12
|
+
onSaved?: (values: FlowVariableValues) => void;
|
|
13
|
+
/**
|
|
14
|
+
* The organization unit the overrides belong to.
|
|
15
|
+
*/
|
|
16
|
+
ouId: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Lets a delegated admin override the variables a flow declares for their organization unit. It loads the
|
|
20
|
+
* variables the flow shares with the unit and the values the unit has set, shows them as a form, and saves
|
|
21
|
+
* the values that differ from their defaults.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* <FlowVariablesForm flowId={flowId} ouId={ouId} onSaved={() => toast('Saved')} />
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare const FlowVariablesForm: FC<FlowVariablesFormProps>;
|
|
29
|
+
export default FlowVariablesForm;
|
|
30
|
+
//# sourceMappingURL=FlowVariablesForm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FlowVariablesForm.d.ts","sourceRoot":"","sources":["../../../../src/components/management/FlowVariables/FlowVariablesForm.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAC,kBAAkB,EAA2B,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAC,EAAE,EAAe,MAAM,OAAO,CAAC;AACvC,OAA0B,EAAC,sBAAsB,EAAC,MAAM,qBAAqB,CAAC;AAK9E,MAAM,MAAM,sBAAsB,GAAG,IAAI,CACvC,sBAAsB,EACtB,aAAa,GAAG,OAAO,GAAG,eAAe,GAAG,cAAc,GAAG,UAAU,GAAG,SAAS,GAAG,WAAW,CAClG,GAAG;IACF;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAC/C;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;;;;;;;;GASG;AACH,QAAA,MAAM,iBAAiB,EAAE,EAAE,CAAC,sBAAsB,CAgDjD,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import useTranslation_default from "../../../hooks/useTranslation.js";
|
|
2
|
+
import Spinner_default from "../../primitives/Spinner/Spinner.js";
|
|
3
|
+
import BaseFlowVariables_default from "./BaseFlowVariables.js";
|
|
4
|
+
import useFlowVariables_default from "../../../hooks/management/useFlowVariables.js";
|
|
5
|
+
import { toManagementErrorMessage } from "@thunderid/browser";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
|
|
8
|
+
//#region src/components/management/FlowVariables/FlowVariablesForm.tsx
|
|
9
|
+
/**
|
|
10
|
+
* Lets a delegated admin override the variables a flow declares for their organization unit. It loads the
|
|
11
|
+
* variables the flow shares with the unit and the values the unit has set, shows them as a form, and saves
|
|
12
|
+
* the values that differ from their defaults.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* <FlowVariablesForm flowId={flowId} ouId={ouId} onSaved={() => toast('Saved')} />
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
const FlowVariablesForm = ({ flowId, onSaved, ouId, preferences, title,...rest }) => {
|
|
20
|
+
const { t } = useTranslation_default(preferences?.i18n);
|
|
21
|
+
const { connections, definitions, error, isLoaded, isSaving, overlay, overrides, save, saveError } = useFlowVariables_default({
|
|
22
|
+
flowId,
|
|
23
|
+
onSaved,
|
|
24
|
+
ouId
|
|
25
|
+
});
|
|
26
|
+
const handleSubmit = (_values, changed) => {
|
|
27
|
+
save(changed);
|
|
28
|
+
};
|
|
29
|
+
if (!isLoaded && !error) return /* @__PURE__ */ jsx(Spinner_default, {});
|
|
30
|
+
return /* @__PURE__ */ jsx(BaseFlowVariables_default, {
|
|
31
|
+
title: title ?? t("admin.flowVariables.title"),
|
|
32
|
+
variables: definitions,
|
|
33
|
+
connections,
|
|
34
|
+
initialValues: overrides,
|
|
35
|
+
overlay,
|
|
36
|
+
isSubmitting: isSaving,
|
|
37
|
+
error: error ? toManagementErrorMessage(t, error, "admin.flowVariables.load_error") : toManagementErrorMessage(t, saveError, "admin.flowVariables.error"),
|
|
38
|
+
onSubmit: handleSubmit,
|
|
39
|
+
preferences,
|
|
40
|
+
...rest
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
var FlowVariablesForm_default = FlowVariablesForm;
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
export { FlowVariablesForm_default as default };
|
|
47
|
+
//# sourceMappingURL=FlowVariablesForm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FlowVariablesForm.js","names":["FlowVariablesForm: FC<FlowVariablesFormProps>","useTranslation","useFlowVariables","Spinner","BaseFlowVariables"],"sources":["../../../../src/components/management/FlowVariables/FlowVariablesForm.tsx"],"sourcesContent":["// Copyright 2026 The ThunderID Authors\n// SPDX-License-Identifier: Apache-2.0\n\nimport {FlowVariableValues, toManagementErrorMessage} from '@thunderid/browser';\nimport {FC, ReactElement} from 'react';\nimport BaseFlowVariables, {BaseFlowVariablesProps} from './BaseFlowVariables';\nimport useFlowVariables, {UseFlowVariablesResult} from '../../../hooks/management/useFlowVariables';\nimport useTranslation from '../../../hooks/useTranslation';\nimport Spinner from '../../primitives/Spinner/Spinner';\n\nexport type FlowVariablesFormProps = Omit<\n BaseFlowVariablesProps,\n 'connections' | 'error' | 'initialValues' | 'isSubmitting' | 'onSubmit' | 'overlay' | 'variables'\n> & {\n /**\n * Identifier of the flow whose variables are configured.\n */\n flowId: string;\n /**\n * Called with the saved overrides.\n */\n onSaved?: (values: FlowVariableValues) => void;\n /**\n * The organization unit the overrides belong to.\n */\n ouId: string;\n};\n\n/**\n * Lets a delegated admin override the variables a flow declares for their organization unit. It loads the\n * variables the flow shares with the unit and the values the unit has set, shows them as a form, and saves\n * the values that differ from their defaults.\n *\n * @example\n * ```tsx\n * <FlowVariablesForm flowId={flowId} ouId={ouId} onSaved={() => toast('Saved')} />\n * ```\n */\nconst FlowVariablesForm: FC<FlowVariablesFormProps> = ({\n flowId,\n onSaved,\n ouId,\n preferences,\n title,\n ...rest\n}: FlowVariablesFormProps): ReactElement => {\n const {t} = useTranslation(preferences?.i18n);\n const {\n connections,\n definitions,\n error,\n isLoaded,\n isSaving,\n overlay,\n overrides,\n save,\n saveError,\n }: UseFlowVariablesResult = useFlowVariables({flowId, onSaved, ouId});\n\n // Only what differs from the default is an override; the rest keeps following the default.\n const handleSubmit = (_values: FlowVariableValues, changed: FlowVariableValues): void => {\n void save(changed);\n };\n\n if (!isLoaded && !error) {\n return <Spinner />;\n }\n\n return (\n <BaseFlowVariables\n title={title ?? t('admin.flowVariables.title')}\n variables={definitions}\n connections={connections}\n initialValues={overrides}\n overlay={overlay}\n isSubmitting={isSaving}\n error={\n error\n ? toManagementErrorMessage(t, error, 'admin.flowVariables.load_error')\n : toManagementErrorMessage(t, saveError, 'admin.flowVariables.error')\n }\n onSubmit={handleSubmit}\n preferences={preferences}\n {...rest}\n />\n );\n};\n\nexport default FlowVariablesForm;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAsCA,MAAMA,qBAAiD,EACrD,QACA,SACA,MACA,aACA,MACA,GAAG,WACuC;CAC1C,MAAM,EAAC,MAAKC,uBAAe,aAAa,KAAK;CAC7C,MAAM,EACJ,aACA,aACA,OACA,UACA,UACA,SACA,WACA,MACA,cAC0BC,yBAAiB;EAAC;EAAQ;EAAS;EAAK,CAAC;CAGrE,MAAM,gBAAgB,SAA6B,YAAsC;AACvF,EAAK,KAAK,QAAQ;;AAGpB,KAAI,CAAC,YAAY,CAAC,MAChB,QAAO,oBAACC,oBAAU;AAGpB,QACE,oBAACC;EACC,OAAO,SAAS,EAAE,4BAA4B;EAC9C,WAAW;EACE;EACb,eAAe;EACN;EACT,cAAc;EACd,OACE,QACI,yBAAyB,GAAG,OAAO,iCAAiC,GACpE,yBAAyB,GAAG,WAAW,4BAA4B;EAEzE,UAAU;EACG;EACb,GAAI;GACJ;;AAIN,gCAAe"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ManagedFlow, Preferences } from '@thunderid/browser';
|
|
2
|
+
import { FC, ReactNode } from 'react';
|
|
3
|
+
import { AdminListRenderProps } from '../shared/AdminListRenderProps';
|
|
4
|
+
/**
|
|
5
|
+
* What {@link BaseSharedFlowList} hands its `children` render function. `flows` and `rows` are the same array.
|
|
6
|
+
*/
|
|
7
|
+
export type BaseSharedFlowListRenderProps = AdminListRenderProps<ManagedFlow> & {
|
|
8
|
+
flows: ManagedFlow[];
|
|
9
|
+
};
|
|
10
|
+
export interface BaseSharedFlowListProps {
|
|
11
|
+
/**
|
|
12
|
+
* Controls rendered next to the title.
|
|
13
|
+
*/
|
|
14
|
+
actions?: ReactNode;
|
|
15
|
+
/**
|
|
16
|
+
* Renders custom UI in place of the default table. Receives the flows, the default columns, the loading and
|
|
17
|
+
* error state, and the pagination and selection handlers.
|
|
18
|
+
*/
|
|
19
|
+
children?: (props: BaseSharedFlowListRenderProps) => ReactNode;
|
|
20
|
+
className?: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
error?: string | null;
|
|
23
|
+
flows: ManagedFlow[];
|
|
24
|
+
isLoading?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Page size.
|
|
27
|
+
* @default 20
|
|
28
|
+
*/
|
|
29
|
+
limit?: number;
|
|
30
|
+
offset?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Called with the offset of the page to show. Pagination is hidden when omitted.
|
|
33
|
+
*/
|
|
34
|
+
onPageChange?: (offset: number) => void;
|
|
35
|
+
/**
|
|
36
|
+
* Called when a flow is chosen. Rows are selectable only when set.
|
|
37
|
+
*/
|
|
38
|
+
onSelect?: (flow: ManagedFlow) => void;
|
|
39
|
+
preferences?: Preferences;
|
|
40
|
+
selectedFlowId?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Heading of the list. Pass an empty string to hide it.
|
|
43
|
+
*/
|
|
44
|
+
title?: string;
|
|
45
|
+
totalResults?: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Lists flows with their handle and type. Holds no data of its own: pass the page of flows and handle selection
|
|
49
|
+
* and pagination.
|
|
50
|
+
*/
|
|
51
|
+
declare const BaseSharedFlowList: FC<BaseSharedFlowListProps>;
|
|
52
|
+
export default BaseSharedFlowList;
|
|
53
|
+
//# sourceMappingURL=BaseSharedFlowList.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseSharedFlowList.d.ts","sourceRoot":"","sources":["../../../../src/components/management/SharedFlowList/BaseSharedFlowList.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAC,WAAW,EAAE,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAC,EAAE,EAAgB,SAAS,EAAC,MAAM,OAAO,CAAC;AAGlD,OAAO,EAAC,oBAAoB,EAAC,MAAM,gCAAgC,CAAC;AAGpE;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG,oBAAoB,CAAC,WAAW,CAAC,GAAG;IAC9E,KAAK,EAAE,WAAW,EAAE,CAAC;CACtB,CAAC;AAEF,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,6BAA6B,KAAK,SAAS,CAAC;IAC/D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,KAAK,EAAE,WAAW,EAAE,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,CAAC;IACvC,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,QAAA,MAAM,kBAAkB,EAAE,EAAE,CAAC,uBAAuB,CAkFnD,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import useTranslation_default from "../../../hooks/useTranslation.js";
|
|
2
|
+
import DataTable_default from "../../primitives/DataTable/DataTable.js";
|
|
3
|
+
import AdminSection_default from "../shared/AdminSection.js";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
|
|
6
|
+
//#region src/components/management/SharedFlowList/BaseSharedFlowList.tsx
|
|
7
|
+
/**
|
|
8
|
+
* Lists flows with their handle and type. Holds no data of its own: pass the page of flows and handle selection
|
|
9
|
+
* and pagination.
|
|
10
|
+
*/
|
|
11
|
+
const BaseSharedFlowList = ({ actions, children, className, description, error = null, flows, isLoading = false, limit = 20, offset = 0, onPageChange, onSelect, preferences, selectedFlowId, title, totalResults }) => {
|
|
12
|
+
const { t } = useTranslation_default(preferences?.i18n);
|
|
13
|
+
const columns = [
|
|
14
|
+
{
|
|
15
|
+
header: t("admin.flows.list.columns.name"),
|
|
16
|
+
id: "name",
|
|
17
|
+
render: (flow) => flow.name
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
header: t("admin.flows.list.columns.handle"),
|
|
21
|
+
id: "handle",
|
|
22
|
+
render: (flow) => flow.handle ? /* @__PURE__ */ jsx("code", { children: flow.handle }) : null
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
header: t("admin.flows.list.columns.type"),
|
|
26
|
+
id: "type",
|
|
27
|
+
render: (flow) => flow.flowType
|
|
28
|
+
}
|
|
29
|
+
];
|
|
30
|
+
if (children) return /* @__PURE__ */ jsx("div", {
|
|
31
|
+
className,
|
|
32
|
+
children: children({
|
|
33
|
+
columns,
|
|
34
|
+
error,
|
|
35
|
+
flows,
|
|
36
|
+
isLoading,
|
|
37
|
+
limit,
|
|
38
|
+
offset,
|
|
39
|
+
onPageChange,
|
|
40
|
+
onSelect,
|
|
41
|
+
rows: flows,
|
|
42
|
+
selectedRowId: selectedFlowId,
|
|
43
|
+
totalResults: totalResults ?? flows.length
|
|
44
|
+
})
|
|
45
|
+
});
|
|
46
|
+
return /* @__PURE__ */ jsx(AdminSection_default, {
|
|
47
|
+
block: "shared-flow-list",
|
|
48
|
+
className,
|
|
49
|
+
title: title ?? t("admin.flows.list.title"),
|
|
50
|
+
description,
|
|
51
|
+
actions,
|
|
52
|
+
preferences,
|
|
53
|
+
children: /* @__PURE__ */ jsx(DataTable_default, {
|
|
54
|
+
caption: title?.length ? title : t("admin.flows.list.title"),
|
|
55
|
+
columns,
|
|
56
|
+
rows: flows,
|
|
57
|
+
getRowId: (flow) => flow.id,
|
|
58
|
+
isLoading,
|
|
59
|
+
error,
|
|
60
|
+
emptyText: t("admin.flows.list.empty"),
|
|
61
|
+
onRowClick: onSelect,
|
|
62
|
+
selectedRowId: selectedFlowId,
|
|
63
|
+
pagination: onPageChange ? {
|
|
64
|
+
limit,
|
|
65
|
+
offset,
|
|
66
|
+
onChange: onPageChange,
|
|
67
|
+
total: totalResults ?? flows.length
|
|
68
|
+
} : void 0
|
|
69
|
+
})
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
var BaseSharedFlowList_default = BaseSharedFlowList;
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
export { BaseSharedFlowList_default as default };
|
|
76
|
+
//# sourceMappingURL=BaseSharedFlowList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseSharedFlowList.js","names":["BaseSharedFlowList: FC<BaseSharedFlowListProps>","useTranslation","columns: DataTableColumn<ManagedFlow>[]","AdminSection","DataTable"],"sources":["../../../../src/components/management/SharedFlowList/BaseSharedFlowList.tsx"],"sourcesContent":["// Copyright 2026 The ThunderID Authors\n// SPDX-License-Identifier: Apache-2.0\n\nimport {ManagedFlow, Preferences} from '@thunderid/browser';\nimport {FC, ReactElement, ReactNode} from 'react';\nimport useTranslation from '../../../hooks/useTranslation';\nimport DataTable, {DataTableColumn} from '../../primitives/DataTable/DataTable';\nimport {AdminListRenderProps} from '../shared/AdminListRenderProps';\nimport AdminSection from '../shared/AdminSection';\n\n/**\n * What {@link BaseSharedFlowList} hands its `children` render function. `flows` and `rows` are the same array.\n */\nexport type BaseSharedFlowListRenderProps = AdminListRenderProps<ManagedFlow> & {\n flows: ManagedFlow[];\n};\n\nexport interface BaseSharedFlowListProps {\n /**\n * Controls rendered next to the title.\n */\n actions?: ReactNode;\n /**\n * Renders custom UI in place of the default table. Receives the flows, the default columns, the loading and\n * error state, and the pagination and selection handlers.\n */\n children?: (props: BaseSharedFlowListRenderProps) => ReactNode;\n className?: string;\n description?: string;\n error?: string | null;\n flows: ManagedFlow[];\n isLoading?: boolean;\n /**\n * Page size.\n * @default 20\n */\n limit?: number;\n offset?: number;\n /**\n * Called with the offset of the page to show. Pagination is hidden when omitted.\n */\n onPageChange?: (offset: number) => void;\n /**\n * Called when a flow is chosen. Rows are selectable only when set.\n */\n onSelect?: (flow: ManagedFlow) => void;\n preferences?: Preferences;\n selectedFlowId?: string;\n /**\n * Heading of the list. Pass an empty string to hide it.\n */\n title?: string;\n totalResults?: number;\n}\n\n/**\n * Lists flows with their handle and type. Holds no data of its own: pass the page of flows and handle selection\n * and pagination.\n */\nconst BaseSharedFlowList: FC<BaseSharedFlowListProps> = ({\n actions,\n children,\n className,\n description,\n error = null,\n flows,\n isLoading = false,\n limit = 20,\n offset = 0,\n onPageChange,\n onSelect,\n preferences,\n selectedFlowId,\n title,\n totalResults,\n}: BaseSharedFlowListProps): ReactElement => {\n const {t} = useTranslation(preferences?.i18n);\n\n const columns: DataTableColumn<ManagedFlow>[] = [\n {\n header: t('admin.flows.list.columns.name'),\n id: 'name',\n render: (flow: ManagedFlow): ReactNode => flow.name,\n },\n {\n header: t('admin.flows.list.columns.handle'),\n id: 'handle',\n render: (flow: ManagedFlow): ReactNode => (flow.handle ? <code>{flow.handle}</code> : null),\n },\n {\n header: t('admin.flows.list.columns.type'),\n id: 'type',\n render: (flow: ManagedFlow): ReactNode => flow.flowType,\n },\n ];\n\n if (children) {\n return (\n <div className={className}>\n {children({\n columns,\n error,\n flows,\n isLoading,\n limit,\n offset,\n onPageChange,\n onSelect,\n rows: flows,\n selectedRowId: selectedFlowId,\n totalResults: totalResults ?? flows.length,\n })}\n </div>\n );\n }\n\n return (\n <AdminSection\n block=\"shared-flow-list\"\n className={className}\n title={title ?? t('admin.flows.list.title')}\n description={description}\n actions={actions}\n preferences={preferences}\n >\n <DataTable\n caption={title?.length ? title : t('admin.flows.list.title')}\n columns={columns}\n rows={flows}\n getRowId={(flow: ManagedFlow): string => flow.id}\n isLoading={isLoading}\n error={error}\n emptyText={t('admin.flows.list.empty')}\n onRowClick={onSelect}\n selectedRowId={selectedFlowId}\n pagination={\n onPageChange ? {limit, offset, onChange: onPageChange, total: totalResults ?? flows.length} : undefined\n }\n />\n </AdminSection>\n );\n};\n\nexport default BaseSharedFlowList;\n"],"mappings":";;;;;;;;;;AA2DA,MAAMA,sBAAmD,EACvD,SACA,UACA,WACA,aACA,QAAQ,MACR,OACA,YAAY,OACZ,QAAQ,IACR,SAAS,GACT,cACA,UACA,aACA,gBACA,OACA,mBAC2C;CAC3C,MAAM,EAAC,MAAKC,uBAAe,aAAa,KAAK;CAE7C,MAAMC,UAA0C;EAC9C;GACE,QAAQ,EAAE,gCAAgC;GAC1C,IAAI;GACJ,SAAS,SAAiC,KAAK;GAChD;EACD;GACE,QAAQ,EAAE,kCAAkC;GAC5C,IAAI;GACJ,SAAS,SAAkC,KAAK,SAAS,oBAAC,oBAAM,KAAK,SAAc,GAAG;GACvF;EACD;GACE,QAAQ,EAAE,gCAAgC;GAC1C,IAAI;GACJ,SAAS,SAAiC,KAAK;GAChD;EACF;AAED,KAAI,SACF,QACE,oBAAC;EAAe;YACb,SAAS;GACR;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA,MAAM;GACN,eAAe;GACf,cAAc,gBAAgB,MAAM;GACrC,CAAC;GACE;AAIV,QACE,oBAACC;EACC,OAAM;EACK;EACX,OAAO,SAAS,EAAE,yBAAyB;EAC9B;EACJ;EACI;YAEb,oBAACC;GACC,SAAS,OAAO,SAAS,QAAQ,EAAE,yBAAyB;GACnD;GACT,MAAM;GACN,WAAW,SAA8B,KAAK;GACnC;GACJ;GACP,WAAW,EAAE,yBAAyB;GACtC,YAAY;GACZ,eAAe;GACf,YACE,eAAe;IAAC;IAAO;IAAQ,UAAU;IAAc,OAAO,gBAAgB,MAAM;IAAO,GAAG;IAEhG;GACW;;AAInB,iCAAe"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { BaseSharedFlowListProps } from './BaseSharedFlowList';
|
|
3
|
+
export type SharedFlowListProps = Omit<BaseSharedFlowListProps, 'error' | 'flows' | 'isLoading' | 'offset' | 'onPageChange' | 'totalResults'> & {
|
|
4
|
+
/**
|
|
5
|
+
* Restricts the list to one flow type, for example `AUTHENTICATION`.
|
|
6
|
+
*/
|
|
7
|
+
flowType?: string;
|
|
8
|
+
/**
|
|
9
|
+
* The organization unit to list the flows of: the ones it owns and the ones shared with it.
|
|
10
|
+
*/
|
|
11
|
+
ouId: string;
|
|
12
|
+
/**
|
|
13
|
+
* Which of those flows to list: the ones shared with the unit, the ones it owns, or both. The server reports
|
|
14
|
+
* the ownership of each flow, and the list narrows to it, so a narrowed list reads the first page of at most
|
|
15
|
+
* 100 flows and pages through the matches.
|
|
16
|
+
* @default 'shared'
|
|
17
|
+
*/
|
|
18
|
+
ownership?: 'all' | 'owned' | 'shared';
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Lists the flows shared with an organization unit, or the ones it owns, or both, a page at a time. Choosing a flow reports it
|
|
22
|
+
* through `onSelect`, so the application decides what to open, for example `FlowVariablesForm` for that flow.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```tsx
|
|
26
|
+
* <SharedFlowList ouId={ouId} onSelect={(flow) => setSelectedFlowId(flow.id)} />
|
|
27
|
+
* {selectedFlowId && <FlowVariablesForm flowId={selectedFlowId} ouId={ouId} />}
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare const SharedFlowList: FC<SharedFlowListProps>;
|
|
31
|
+
export default SharedFlowList;
|
|
32
|
+
//# sourceMappingURL=SharedFlowList.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SharedFlowList.d.ts","sourceRoot":"","sources":["../../../../src/components/management/SharedFlowList/SharedFlowList.tsx"],"names":[],"mappings":"AAUA,OAAO,EAAC,EAAE,EAAkC,MAAM,OAAO,CAAC;AAC1D,OAA2B,EAAC,uBAAuB,EAAC,MAAM,sBAAsB,CAAC;AAKjF,MAAM,MAAM,mBAAmB,GAAG,IAAI,CACpC,uBAAuB,EACvB,OAAO,GAAG,OAAO,GAAG,WAAW,GAAG,QAAQ,GAAG,cAAc,GAAG,cAAc,CAC7E,GAAG;IACF;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,SAAS,CAAC,EAAE,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;CACxC,CAAC;AAIF;;;;;;;;;GASG;AACH,QAAA,MAAM,cAAc,EAAE,EAAE,CAAC,mBAAmB,CA4C3C,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import useTranslation_default from "../../../hooks/useTranslation.js";
|
|
2
|
+
import useManagementEndpoint_default from "../../../hooks/management/useManagementEndpoint.js";
|
|
3
|
+
import useResourceQuery_default from "../../../hooks/management/useResourceQuery.js";
|
|
4
|
+
import BaseSharedFlowList_default from "./BaseSharedFlowList.js";
|
|
5
|
+
import { FlowQueryKeys, getFlows, toManagementErrorMessage } from "@thunderid/browser";
|
|
6
|
+
import { useMemo, useState } from "react";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
|
|
9
|
+
//#region src/components/management/SharedFlowList/SharedFlowList.tsx
|
|
10
|
+
const MAX_FETCH = 100;
|
|
11
|
+
/**
|
|
12
|
+
* Lists the flows shared with an organization unit, or the ones it owns, or both, a page at a time. Choosing a flow reports it
|
|
13
|
+
* through `onSelect`, so the application decides what to open, for example `FlowVariablesForm` for that flow.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* <SharedFlowList ouId={ouId} onSelect={(flow) => setSelectedFlowId(flow.id)} />
|
|
18
|
+
* {selectedFlowId && <FlowVariablesForm flowId={selectedFlowId} ouId={ouId} />}
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
const SharedFlowList = ({ flowType, limit = 20, ouId, ownership = "shared", preferences,...rest }) => {
|
|
22
|
+
const { t } = useTranslation_default(preferences?.i18n);
|
|
23
|
+
const [offset, setOffset] = useState(0);
|
|
24
|
+
const endpoint = useManagementEndpoint_default("flows");
|
|
25
|
+
const narrowed = ownership !== "all";
|
|
26
|
+
const { data, error, isLoading } = useResourceQuery_default([FlowQueryKeys.FLOWS, narrowed ? {
|
|
27
|
+
flowType,
|
|
28
|
+
ouId,
|
|
29
|
+
ownership
|
|
30
|
+
} : {
|
|
31
|
+
flowType,
|
|
32
|
+
limit,
|
|
33
|
+
offset,
|
|
34
|
+
ouId
|
|
35
|
+
}], (fetcher) => getFlows({
|
|
36
|
+
...endpoint,
|
|
37
|
+
fetcher,
|
|
38
|
+
flowType,
|
|
39
|
+
ouId,
|
|
40
|
+
...narrowed ? {
|
|
41
|
+
limit: MAX_FETCH,
|
|
42
|
+
offset: 0
|
|
43
|
+
} : {
|
|
44
|
+
limit,
|
|
45
|
+
offset
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
48
|
+
const matching = useMemo(() => (data?.flows ?? []).filter((flow) => ownership === "all" || flow.isOwnedByOU === (ownership === "owned")), [data, ownership]);
|
|
49
|
+
return /* @__PURE__ */ jsx(BaseSharedFlowList_default, {
|
|
50
|
+
flows: narrowed ? matching.slice(offset, offset + limit) : matching,
|
|
51
|
+
totalResults: narrowed ? matching.length : data?.totalResults,
|
|
52
|
+
isLoading,
|
|
53
|
+
error: toManagementErrorMessage(t, error, "admin.flows.list.error"),
|
|
54
|
+
limit,
|
|
55
|
+
offset,
|
|
56
|
+
onPageChange: setOffset,
|
|
57
|
+
preferences,
|
|
58
|
+
...rest
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
var SharedFlowList_default = SharedFlowList;
|
|
62
|
+
|
|
63
|
+
//#endregion
|
|
64
|
+
export { SharedFlowList_default as default };
|
|
65
|
+
//# sourceMappingURL=SharedFlowList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SharedFlowList.js","names":["SharedFlowList: FC<SharedFlowListProps>","useTranslation","endpoint: ManagementEndpoint","useManagementEndpoint","narrowed: boolean","useResourceQuery","matching: ManagedFlow[]","BaseSharedFlowList"],"sources":["../../../../src/components/management/SharedFlowList/SharedFlowList.tsx"],"sourcesContent":["// Copyright 2026 The ThunderID Authors\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n FlowQueryKeys,\n ManagedFlow,\n ManagedFlowListResponse,\n getFlows,\n toManagementErrorMessage,\n} from '@thunderid/browser';\nimport {FC, ReactElement, useMemo, useState} from 'react';\nimport BaseSharedFlowList, {BaseSharedFlowListProps} from './BaseSharedFlowList';\nimport useManagementEndpoint, {ManagementEndpoint} from '../../../hooks/management/useManagementEndpoint';\nimport useResourceQuery, {ResourceQueryResult} from '../../../hooks/management/useResourceQuery';\nimport useTranslation from '../../../hooks/useTranslation';\n\nexport type SharedFlowListProps = Omit<\n BaseSharedFlowListProps,\n 'error' | 'flows' | 'isLoading' | 'offset' | 'onPageChange' | 'totalResults'\n> & {\n /**\n * Restricts the list to one flow type, for example `AUTHENTICATION`.\n */\n flowType?: string;\n /**\n * The organization unit to list the flows of: the ones it owns and the ones shared with it.\n */\n ouId: string;\n /**\n * Which of those flows to list: the ones shared with the unit, the ones it owns, or both. The server reports\n * the ownership of each flow, and the list narrows to it, so a narrowed list reads the first page of at most\n * 100 flows and pages through the matches.\n * @default 'shared'\n */\n ownership?: 'all' | 'owned' | 'shared';\n};\n\nconst MAX_FETCH = 100;\n\n/**\n * Lists the flows shared with an organization unit, or the ones it owns, or both, a page at a time. Choosing a flow reports it\n * through `onSelect`, so the application decides what to open, for example `FlowVariablesForm` for that flow.\n *\n * @example\n * ```tsx\n * <SharedFlowList ouId={ouId} onSelect={(flow) => setSelectedFlowId(flow.id)} />\n * {selectedFlowId && <FlowVariablesForm flowId={selectedFlowId} ouId={ouId} />}\n * ```\n */\nconst SharedFlowList: FC<SharedFlowListProps> = ({\n flowType,\n limit = 20,\n ouId,\n ownership = 'shared',\n preferences,\n ...rest\n}: SharedFlowListProps): ReactElement => {\n const {t} = useTranslation(preferences?.i18n);\n const [offset, setOffset] = useState<number>(0);\n const endpoint: ManagementEndpoint = useManagementEndpoint('flows');\n const narrowed: boolean = ownership !== 'all';\n const {data, error, isLoading}: ResourceQueryResult<ManagedFlowListResponse> = useResourceQuery(\n [FlowQueryKeys.FLOWS, narrowed ? {flowType, ouId, ownership} : {flowType, limit, offset, ouId}],\n (fetcher) =>\n getFlows({\n ...endpoint,\n fetcher,\n flowType,\n ouId,\n ...(narrowed ? {limit: MAX_FETCH, offset: 0} : {limit, offset}),\n }),\n );\n const matching: ManagedFlow[] = useMemo(\n () =>\n (data?.flows ?? []).filter(\n (flow: ManagedFlow) => ownership === 'all' || flow.isOwnedByOU === (ownership === 'owned'),\n ),\n [data, ownership],\n );\n\n return (\n <BaseSharedFlowList\n flows={narrowed ? matching.slice(offset, offset + limit) : matching}\n totalResults={narrowed ? matching.length : data?.totalResults}\n isLoading={isLoading}\n error={toManagementErrorMessage(t, error, 'admin.flows.list.error')}\n limit={limit}\n offset={offset}\n onPageChange={setOffset}\n preferences={preferences}\n {...rest}\n />\n );\n};\n\nexport default SharedFlowList;\n"],"mappings":";;;;;;;;;AAqCA,MAAM,YAAY;;;;;;;;;;;AAYlB,MAAMA,kBAA2C,EAC/C,UACA,QAAQ,IACR,MACA,YAAY,UACZ,YACA,GAAG,WACoC;CACvC,MAAM,EAAC,MAAKC,uBAAe,aAAa,KAAK;CAC7C,MAAM,CAAC,QAAQ,aAAa,SAAiB,EAAE;CAC/C,MAAMC,WAA+BC,8BAAsB,QAAQ;CACnE,MAAMC,WAAoB,cAAc;CACxC,MAAM,EAAC,MAAM,OAAO,cAA2DC,yBAC7E,CAAC,cAAc,OAAO,WAAW;EAAC;EAAU;EAAM;EAAU,GAAG;EAAC;EAAU;EAAO;EAAQ;EAAK,CAAC,GAC9F,YACC,SAAS;EACP,GAAG;EACH;EACA;EACA;EACA,GAAI,WAAW;GAAC,OAAO;GAAW,QAAQ;GAAE,GAAG;GAAC;GAAO;GAAO;EAC/D,CAAC,CACL;CACD,MAAMC,WAA0B,eAE3B,MAAM,SAAS,EAAE,EAAE,QACjB,SAAsB,cAAc,SAAS,KAAK,iBAAiB,cAAc,SACnF,EACH,CAAC,MAAM,UAAU,CAClB;AAED,QACE,oBAACC;EACC,OAAO,WAAW,SAAS,MAAM,QAAQ,SAAS,MAAM,GAAG;EAC3D,cAAc,WAAW,SAAS,SAAS,MAAM;EACtC;EACX,OAAO,yBAAyB,GAAG,OAAO,yBAAyB;EAC5D;EACC;EACR,cAAc;EACD;EACb,GAAI;GACJ;;AAIN,6BAAe"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { ApiFetcher, ConnectionInstance, FlowVariableDefinition, FlowVariableValues, FlowVariables, ManagedFlowDefinition, ResolvedOverlay } from '@thunderid/browser';
|
|
2
|
+
/**
|
|
3
|
+
* Options of {@link useFlowVariables}.
|
|
4
|
+
*/
|
|
5
|
+
export interface UseFlowVariablesOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Set to `false` to skip fetching, for example until the identifiers are known.
|
|
8
|
+
* @default true
|
|
9
|
+
*/
|
|
10
|
+
enabled?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Transport for this hook only. Takes precedence over `ThunderIDProvider`'s `http.fetcher`.
|
|
13
|
+
*/
|
|
14
|
+
fetcher?: ApiFetcher;
|
|
15
|
+
/**
|
|
16
|
+
* Identifier of the flow.
|
|
17
|
+
*/
|
|
18
|
+
flowId: string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Called with the saved overrides.
|
|
21
|
+
*/
|
|
22
|
+
onSaved?: (values: FlowVariableValues) => void;
|
|
23
|
+
/**
|
|
24
|
+
* The organization unit whose overrides are read and saved.
|
|
25
|
+
*/
|
|
26
|
+
ouId: string | undefined;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* What {@link useFlowVariables} returns.
|
|
30
|
+
*/
|
|
31
|
+
export interface UseFlowVariablesResult {
|
|
32
|
+
/**
|
|
33
|
+
* The connections a `CONNECTION_SELECT` variable can take: the ones the organization unit owns and the ones shared
|
|
34
|
+
* into it. Empty until loaded, and when no variable needs them.
|
|
35
|
+
*/
|
|
36
|
+
connections: ConnectionInstance[];
|
|
37
|
+
/**
|
|
38
|
+
* The variables the flow declares for the organization unit.
|
|
39
|
+
*/
|
|
40
|
+
definitions: FlowVariableDefinition[];
|
|
41
|
+
/**
|
|
42
|
+
* Why the variables could not be loaded.
|
|
43
|
+
*/
|
|
44
|
+
error: Error | null;
|
|
45
|
+
/**
|
|
46
|
+
* The flow as the organization unit sees it.
|
|
47
|
+
*/
|
|
48
|
+
flow: ManagedFlowDefinition | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Whether the variables, the unit's values and its rules have all arrived. A form built before then would be reset when
|
|
51
|
+
* the values land.
|
|
52
|
+
*/
|
|
53
|
+
isLoaded: boolean;
|
|
54
|
+
isLoading: boolean;
|
|
55
|
+
isSaving: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* What the organization unit may do with each variable: set its own value, or only see the owner's.
|
|
58
|
+
*/
|
|
59
|
+
overlay: ResolvedOverlay | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* The values the organization unit has set. A variable it has not set is absent, and its default applies.
|
|
62
|
+
*/
|
|
63
|
+
overrides: FlowVariableValues;
|
|
64
|
+
/**
|
|
65
|
+
* Replaces the unit's overrides. A variable left out returns to its default. Never rejects: read `saveError`.
|
|
66
|
+
*/
|
|
67
|
+
save: (values: FlowVariableValues) => Promise<FlowVariables | undefined>;
|
|
68
|
+
/**
|
|
69
|
+
* Why the last save failed.
|
|
70
|
+
*/
|
|
71
|
+
saveError: Error | null;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Loads the variables a flow declares for an organization unit and the values the unit has set, and saves
|
|
75
|
+
* them. The data behind {@link FlowVariablesForm}, for building the form with any UI.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```tsx
|
|
79
|
+
* const {definitions, overrides, save} = useFlowVariables({flowId, ouId});
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
declare const useFlowVariables: ({ enabled, fetcher, flowId, onSaved, ouId, }: UseFlowVariablesOptions) => UseFlowVariablesResult;
|
|
83
|
+
export default useFlowVariables;
|
|
84
|
+
//# sourceMappingURL=useFlowVariables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFlowVariables.d.ts","sourceRoot":"","sources":["../../../src/hooks/management/useFlowVariables.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,sBAAsB,EAEtB,kBAAkB,EAClB,aAAa,EACb,qBAAqB,EACrB,eAAe,EAOhB,MAAM,oBAAoB,CAAC;AAM5B;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB;;OAEG;IACH,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAC/C;;OAEG;IACH,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,WAAW,EAAE,kBAAkB,EAAE,CAAC;IAClC;;OAEG;IACH,WAAW,EAAE,sBAAsB,EAAE,CAAC;IACtC;;OAEG;IACH,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB;;OAEG;IACH,IAAI,EAAE,qBAAqB,GAAG,SAAS,CAAC;IACxC;;;OAGG;IACH,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,OAAO,EAAE,eAAe,GAAG,SAAS,CAAC;IACrC;;OAEG;IACH,SAAS,EAAE,kBAAkB,CAAC;IAC9B;;OAEG;IACH,IAAI,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAAC;IACzE;;OAEG;IACH,SAAS,EAAE,KAAK,GAAG,IAAI,CAAC;CACzB;AAED;;;;;;;;GAQG;AACH,QAAA,MAAM,gBAAgB,GAAI,8CAMvB,uBAAuB,KAAG,sBAwD5B,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import useManagementEndpoint_default from "./useManagementEndpoint.js";
|
|
2
|
+
import useResourceQuery_default from "./useResourceQuery.js";
|
|
3
|
+
import useResourceMutation_default from "./useResourceMutation.js";
|
|
4
|
+
import { FlowVariableQueryKeys, getConnections, getFlow, getFlowOverlayRules, getFlowVariableDefinitions, getFlowVariables, updateFlowVariables } from "@thunderid/browser";
|
|
5
|
+
import { useMemo } from "react";
|
|
6
|
+
|
|
7
|
+
//#region src/hooks/management/useFlowVariables.ts
|
|
8
|
+
/**
|
|
9
|
+
* Loads the variables a flow declares for an organization unit and the values the unit has set, and saves
|
|
10
|
+
* them. The data behind {@link FlowVariablesForm}, for building the form with any UI.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* const {definitions, overrides, save} = useFlowVariables({flowId, ouId});
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
const useFlowVariables = ({ enabled = true, fetcher, flowId, onSaved, ouId }) => {
|
|
18
|
+
const flowsEndpoint = useManagementEndpoint_default("flows");
|
|
19
|
+
const connectionsEndpoint = useManagementEndpoint_default("connections");
|
|
20
|
+
const ready = enabled && Boolean(flowId) && Boolean(ouId);
|
|
21
|
+
const flowQuery = useResourceQuery_default([
|
|
22
|
+
FlowVariableQueryKeys.DEFINITIONS,
|
|
23
|
+
flowId ?? "",
|
|
24
|
+
ouId ?? ""
|
|
25
|
+
], (resolved) => getFlow({
|
|
26
|
+
...flowsEndpoint,
|
|
27
|
+
fetcher: resolved,
|
|
28
|
+
flowId,
|
|
29
|
+
ouId
|
|
30
|
+
}), {
|
|
31
|
+
enabled: ready,
|
|
32
|
+
fetcher
|
|
33
|
+
});
|
|
34
|
+
const valuesQuery = useResourceQuery_default([
|
|
35
|
+
FlowVariableQueryKeys.VALUES,
|
|
36
|
+
flowId ?? "",
|
|
37
|
+
ouId ?? ""
|
|
38
|
+
], (resolved) => getFlowVariables({
|
|
39
|
+
...flowsEndpoint,
|
|
40
|
+
fetcher: resolved,
|
|
41
|
+
flowId,
|
|
42
|
+
ouId
|
|
43
|
+
}), {
|
|
44
|
+
enabled: ready,
|
|
45
|
+
fetcher
|
|
46
|
+
});
|
|
47
|
+
const overlayQuery = useResourceQuery_default([
|
|
48
|
+
FlowVariableQueryKeys.DEFINITIONS,
|
|
49
|
+
"overlay",
|
|
50
|
+
flowId ?? "",
|
|
51
|
+
ouId ?? ""
|
|
52
|
+
], (resolved) => getFlowOverlayRules({
|
|
53
|
+
...flowsEndpoint,
|
|
54
|
+
fetcher: resolved,
|
|
55
|
+
flowId,
|
|
56
|
+
ouId
|
|
57
|
+
}), {
|
|
58
|
+
enabled: ready,
|
|
59
|
+
fetcher
|
|
60
|
+
});
|
|
61
|
+
const definitions = useMemo(() => getFlowVariableDefinitions(flowQuery.data), [flowQuery.data]);
|
|
62
|
+
const needsConnections = definitions.some((definition) => definition.type === "CONNECTION_SELECT");
|
|
63
|
+
const connectionsQuery = useResourceQuery_default([
|
|
64
|
+
FlowVariableQueryKeys.DEFINITIONS,
|
|
65
|
+
"connections",
|
|
66
|
+
ouId ?? ""
|
|
67
|
+
], (resolved) => getConnections({
|
|
68
|
+
...connectionsEndpoint,
|
|
69
|
+
fetcher: resolved,
|
|
70
|
+
limit: 100,
|
|
71
|
+
ouId
|
|
72
|
+
}), {
|
|
73
|
+
enabled: ready && needsConnections,
|
|
74
|
+
fetcher
|
|
75
|
+
});
|
|
76
|
+
const mutation = useResourceMutation_default((values, resolved) => updateFlowVariables({
|
|
77
|
+
...flowsEndpoint,
|
|
78
|
+
fetcher: resolved,
|
|
79
|
+
flowId,
|
|
80
|
+
ouId,
|
|
81
|
+
variables: values
|
|
82
|
+
}), () => [[FlowVariableQueryKeys.VALUES]], {
|
|
83
|
+
fetcher,
|
|
84
|
+
onSuccess: (response) => onSaved?.(response.values)
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
connections: connectionsQuery.data?.connections ?? [],
|
|
88
|
+
definitions,
|
|
89
|
+
error: flowQuery.error ?? valuesQuery.error ?? overlayQuery.error ?? connectionsQuery.error,
|
|
90
|
+
flow: flowQuery.data,
|
|
91
|
+
isLoaded: Boolean(flowQuery.data) && Boolean(valuesQuery.data) && Boolean(overlayQuery.data),
|
|
92
|
+
isLoading: flowQuery.isLoading || valuesQuery.isLoading || overlayQuery.isLoading || connectionsQuery.isLoading,
|
|
93
|
+
isSaving: mutation.isLoading,
|
|
94
|
+
overlay: overlayQuery.data,
|
|
95
|
+
overrides: valuesQuery.data?.values ?? {},
|
|
96
|
+
save: mutation.mutate,
|
|
97
|
+
saveError: mutation.error
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
var useFlowVariables_default = useFlowVariables;
|
|
101
|
+
|
|
102
|
+
//#endregion
|
|
103
|
+
export { useFlowVariables_default as default };
|
|
104
|
+
//# sourceMappingURL=useFlowVariables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFlowVariables.js","names":["flowsEndpoint: ManagementEndpoint","useManagementEndpoint","connectionsEndpoint: ManagementEndpoint","ready: boolean","flowQuery: ResourceQueryResult<ManagedFlowDefinition>","useResourceQuery","valuesQuery: ResourceQueryResult<FlowVariables>","overlayQuery: ResourceQueryResult<ResolvedOverlay>","definitions: FlowVariableDefinition[]","needsConnections: boolean","connectionsQuery: ResourceQueryResult<{connections: ConnectionInstance[]}>","mutation: ResourceMutationResult<FlowVariables, FlowVariableValues>","useResourceMutation"],"sources":["../../../src/hooks/management/useFlowVariables.ts"],"sourcesContent":["// Copyright 2026 The ThunderID Authors\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n ApiFetcher,\n ConnectionInstance,\n FlowVariableDefinition,\n FlowVariableQueryKeys,\n FlowVariableValues,\n FlowVariables,\n ManagedFlowDefinition,\n ResolvedOverlay,\n getConnections,\n getFlowOverlayRules,\n getFlow,\n getFlowVariableDefinitions,\n getFlowVariables,\n updateFlowVariables,\n} from '@thunderid/browser';\nimport {useMemo} from 'react';\nimport useManagementEndpoint, {ManagementEndpoint} from './useManagementEndpoint';\nimport useResourceMutation, {ResourceMutationResult} from './useResourceMutation';\nimport useResourceQuery, {ResourceQueryResult} from './useResourceQuery';\n\n/**\n * Options of {@link useFlowVariables}.\n */\nexport interface UseFlowVariablesOptions {\n /**\n * Set to `false` to skip fetching, for example until the identifiers are known.\n * @default true\n */\n enabled?: boolean;\n /**\n * Transport for this hook only. Takes precedence over `ThunderIDProvider`'s `http.fetcher`.\n */\n fetcher?: ApiFetcher;\n /**\n * Identifier of the flow.\n */\n flowId: string | undefined;\n /**\n * Called with the saved overrides.\n */\n onSaved?: (values: FlowVariableValues) => void;\n /**\n * The organization unit whose overrides are read and saved.\n */\n ouId: string | undefined;\n}\n\n/**\n * What {@link useFlowVariables} returns.\n */\nexport interface UseFlowVariablesResult {\n /**\n * The connections a `CONNECTION_SELECT` variable can take: the ones the organization unit owns and the ones shared\n * into it. Empty until loaded, and when no variable needs them.\n */\n connections: ConnectionInstance[];\n /**\n * The variables the flow declares for the organization unit.\n */\n definitions: FlowVariableDefinition[];\n /**\n * Why the variables could not be loaded.\n */\n error: Error | null;\n /**\n * The flow as the organization unit sees it.\n */\n flow: ManagedFlowDefinition | undefined;\n /**\n * Whether the variables, the unit's values and its rules have all arrived. A form built before then would be reset when\n * the values land.\n */\n isLoaded: boolean;\n isLoading: boolean;\n isSaving: boolean;\n /**\n * What the organization unit may do with each variable: set its own value, or only see the owner's.\n */\n overlay: ResolvedOverlay | undefined;\n /**\n * The values the organization unit has set. A variable it has not set is absent, and its default applies.\n */\n overrides: FlowVariableValues;\n /**\n * Replaces the unit's overrides. A variable left out returns to its default. Never rejects: read `saveError`.\n */\n save: (values: FlowVariableValues) => Promise<FlowVariables | undefined>;\n /**\n * Why the last save failed.\n */\n saveError: Error | null;\n}\n\n/**\n * Loads the variables a flow declares for an organization unit and the values the unit has set, and saves\n * them. The data behind {@link FlowVariablesForm}, for building the form with any UI.\n *\n * @example\n * ```tsx\n * const {definitions, overrides, save} = useFlowVariables({flowId, ouId});\n * ```\n */\nconst useFlowVariables = ({\n enabled = true,\n fetcher,\n flowId,\n onSaved,\n ouId,\n}: UseFlowVariablesOptions): UseFlowVariablesResult => {\n const flowsEndpoint: ManagementEndpoint = useManagementEndpoint('flows');\n const connectionsEndpoint: ManagementEndpoint = useManagementEndpoint('connections');\n const ready: boolean = enabled && Boolean(flowId) && Boolean(ouId);\n\n const flowQuery: ResourceQueryResult<ManagedFlowDefinition> = useResourceQuery(\n [FlowVariableQueryKeys.DEFINITIONS, flowId ?? '', ouId ?? ''],\n (resolved: ApiFetcher) => getFlow({...flowsEndpoint, fetcher: resolved, flowId: flowId!, ouId}),\n {enabled: ready, fetcher},\n );\n const valuesQuery: ResourceQueryResult<FlowVariables> = useResourceQuery(\n [FlowVariableQueryKeys.VALUES, flowId ?? '', ouId ?? ''],\n (resolved: ApiFetcher) => getFlowVariables({...flowsEndpoint, fetcher: resolved, flowId: flowId!, ouId: ouId!}),\n {enabled: ready, fetcher},\n );\n\n const overlayQuery: ResourceQueryResult<ResolvedOverlay> = useResourceQuery(\n [FlowVariableQueryKeys.DEFINITIONS, 'overlay', flowId ?? '', ouId ?? ''],\n (resolved: ApiFetcher) => getFlowOverlayRules({...flowsEndpoint, fetcher: resolved, flowId: flowId!, ouId: ouId!}),\n {enabled: ready, fetcher},\n );\n\n const definitions: FlowVariableDefinition[] = useMemo(\n () => getFlowVariableDefinitions(flowQuery.data),\n [flowQuery.data],\n );\n const needsConnections: boolean = definitions.some(\n (definition: FlowVariableDefinition) => definition.type === 'CONNECTION_SELECT',\n );\n\n const connectionsQuery: ResourceQueryResult<{connections: ConnectionInstance[]}> = useResourceQuery(\n [FlowVariableQueryKeys.DEFINITIONS, 'connections', ouId ?? ''],\n (resolved: ApiFetcher) => getConnections({...connectionsEndpoint, fetcher: resolved, limit: 100, ouId}),\n {enabled: ready && needsConnections, fetcher},\n );\n\n const mutation: ResourceMutationResult<FlowVariables, FlowVariableValues> = useResourceMutation(\n (values: FlowVariableValues, resolved: ApiFetcher) =>\n updateFlowVariables({...flowsEndpoint, fetcher: resolved, flowId: flowId!, ouId: ouId!, variables: values}),\n () => [[FlowVariableQueryKeys.VALUES]],\n {fetcher, onSuccess: (response: FlowVariables) => onSaved?.(response.values)},\n );\n\n return {\n connections: connectionsQuery.data?.connections ?? [],\n definitions,\n error: flowQuery.error ?? valuesQuery.error ?? overlayQuery.error ?? connectionsQuery.error,\n flow: flowQuery.data,\n isLoaded: Boolean(flowQuery.data) && Boolean(valuesQuery.data) && Boolean(overlayQuery.data),\n isLoading: flowQuery.isLoading || valuesQuery.isLoading || overlayQuery.isLoading || connectionsQuery.isLoading,\n isSaving: mutation.isLoading,\n overlay: overlayQuery.data,\n overrides: valuesQuery.data?.values ?? {},\n save: mutation.mutate,\n saveError: mutation.error,\n };\n};\n\nexport default useFlowVariables;\n"],"mappings":";;;;;;;;;;;;;;;;AA0GA,MAAM,oBAAoB,EACxB,UAAU,MACV,SACA,QACA,SACA,WACqD;CACrD,MAAMA,gBAAoCC,8BAAsB,QAAQ;CACxE,MAAMC,sBAA0CD,8BAAsB,cAAc;CACpF,MAAME,QAAiB,WAAW,QAAQ,OAAO,IAAI,QAAQ,KAAK;CAElE,MAAMC,YAAwDC,yBAC5D;EAAC,sBAAsB;EAAa,UAAU;EAAI,QAAQ;EAAG,GAC5D,aAAyB,QAAQ;EAAC,GAAG;EAAe,SAAS;EAAkB;EAAS;EAAK,CAAC,EAC/F;EAAC,SAAS;EAAO;EAAQ,CAC1B;CACD,MAAMC,cAAkDD,yBACtD;EAAC,sBAAsB;EAAQ,UAAU;EAAI,QAAQ;EAAG,GACvD,aAAyB,iBAAiB;EAAC,GAAG;EAAe,SAAS;EAAkB;EAAe;EAAM,CAAC,EAC/G;EAAC,SAAS;EAAO;EAAQ,CAC1B;CAED,MAAME,eAAqDF,yBACzD;EAAC,sBAAsB;EAAa;EAAW,UAAU;EAAI,QAAQ;EAAG,GACvE,aAAyB,oBAAoB;EAAC,GAAG;EAAe,SAAS;EAAkB;EAAe;EAAM,CAAC,EAClH;EAAC,SAAS;EAAO;EAAQ,CAC1B;CAED,MAAMG,cAAwC,cACtC,2BAA2B,UAAU,KAAK,EAChD,CAAC,UAAU,KAAK,CACjB;CACD,MAAMC,mBAA4B,YAAY,MAC3C,eAAuC,WAAW,SAAS,oBAC7D;CAED,MAAMC,mBAA6EL,yBACjF;EAAC,sBAAsB;EAAa;EAAe,QAAQ;EAAG,GAC7D,aAAyB,eAAe;EAAC,GAAG;EAAqB,SAAS;EAAU,OAAO;EAAK;EAAK,CAAC,EACvG;EAAC,SAAS,SAAS;EAAkB;EAAQ,CAC9C;CAED,MAAMM,WAAsEC,6BACzE,QAA4B,aAC3B,oBAAoB;EAAC,GAAG;EAAe,SAAS;EAAkB;EAAe;EAAO,WAAW;EAAO,CAAC,QACvG,CAAC,CAAC,sBAAsB,OAAO,CAAC,EACtC;EAAC;EAAS,YAAY,aAA4B,UAAU,SAAS,OAAO;EAAC,CAC9E;AAED,QAAO;EACL,aAAa,iBAAiB,MAAM,eAAe,EAAE;EACrD;EACA,OAAO,UAAU,SAAS,YAAY,SAAS,aAAa,SAAS,iBAAiB;EACtF,MAAM,UAAU;EAChB,UAAU,QAAQ,UAAU,KAAK,IAAI,QAAQ,YAAY,KAAK,IAAI,QAAQ,aAAa,KAAK;EAC5F,WAAW,UAAU,aAAa,YAAY,aAAa,aAAa,aAAa,iBAAiB;EACtG,UAAU,SAAS;EACnB,SAAS,aAAa;EACtB,WAAW,YAAY,MAAM,UAAU,EAAE;EACzC,MAAM,SAAS;EACf,WAAW,SAAS;EACrB;;AAGH,+BAAe"}
|