Skip to content

Commit ae48e44

Browse files
authored
Merge pull request #153 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents a8bb878 + 2f4081d commit ae48e44

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/components/CippComponents/CippAutocomplete.jsx

+24-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export const CippAutoComplete = (props) => {
7070
sx,
7171
removeOptions = [],
7272
sortOptions = false,
73+
preselectedValue,
7374
...other
7475
} = props;
7576

@@ -166,13 +167,35 @@ export const CippAutoComplete = (props) => {
166167
};
167168
});
168169
setUsedOptions(convertedOptions);
170+
if (preselectedValue && !defaultValue && !value && convertedOptions.length > 0) {
171+
const preselectedOption = convertedOptions.find(
172+
(option) => option.value === preselectedValue
173+
);
174+
175+
if (preselectedOption) {
176+
const newValue = multiple ? [preselectedOption] : preselectedOption;
177+
if (onChange) {
178+
onChange(newValue, newValue?.addedFields);
179+
}
180+
}
181+
}
169182
}
170183
}
171184

172185
if (actionGetRequest.isError) {
173186
setUsedOptions([{ label: getCippError(actionGetRequest.error), value: "error" }]);
174187
}
175-
}, [api, actionGetRequest.data, actionGetRequest.isSuccess, actionGetRequest.isError]);
188+
}, [
189+
api,
190+
actionGetRequest.data,
191+
actionGetRequest.isSuccess,
192+
actionGetRequest.isError,
193+
preselectedValue,
194+
defaultValue,
195+
value,
196+
multiple,
197+
onChange,
198+
]);
176199

177200
const memoizedOptions = useMemo(() => {
178201
let finalOptions = api ? usedOptions : options;

src/components/CippComponents/CippFormTenantSelector.jsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from "react";
22
import { CippFormComponent } from "./CippFormComponent";
3+
import { useSettings } from "../../hooks/use-settings";
34

45
export const CippFormTenantSelector = ({
56
formControl,
6-
componentType='autoComplete',
7+
componentType = "autoComplete",
78
allTenants = false,
89
type = "multiple",
910
name = "tenantFilter",
@@ -21,13 +22,15 @@ export const CippFormTenantSelector = ({
2122
}
2223
return {};
2324
};
24-
25+
const currentTenant = useSettings()?.currentTenant;
2526
return (
2627
<CippFormComponent
2728
type={componentType}
2829
name={name}
2930
formControl={formControl}
31+
preselectedValue={currentTenant ? currentTenant : null}
3032
placeholder="Select a tenant"
33+
//default value is: if currentTenant is not null, then FIND
3134
api={{
3235
excludeTenantFilter: true,
3336
url: allTenants ? "/api/ListTenants?AllTenantSelector=true" : "/api/ListTenants",

0 commit comments

Comments
 (0)