mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-28 00:06:53 +01:00
feat: Change request preview integration (#7743)
Use API to check change request evaluation
This commit is contained in:
parent
57a8b9da79
commit
43c8152515
@ -113,7 +113,12 @@ export const AdvancedPlayground: FC<{
|
|||||||
const { setToastData } = useToast();
|
const { setToastData } = useToast();
|
||||||
const [searchParams, setSearchParams] = useSearchParams();
|
const [searchParams, setSearchParams] = useSearchParams();
|
||||||
const [changeRequest, setChangeRequest] = useState<string>();
|
const [changeRequest, setChangeRequest] = useState<string>();
|
||||||
const { evaluateAdvancedPlayground, loading, errors } = usePlaygroundApi();
|
const {
|
||||||
|
evaluateAdvancedPlayground,
|
||||||
|
evaluateChangeRequestPlayground,
|
||||||
|
loading,
|
||||||
|
errors,
|
||||||
|
} = usePlaygroundApi();
|
||||||
const [hasFormBeenSubmitted, setHasFormBeenSubmitted] = useState(false);
|
const [hasFormBeenSubmitted, setHasFormBeenSubmitted] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -203,14 +208,21 @@ export const AdvancedPlayground: FC<{
|
|||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
setConfigurationError(undefined);
|
setConfigurationError(undefined);
|
||||||
const parsedContext = JSON.parse(context || '{}');
|
const parsedContext = {
|
||||||
const response = await evaluateAdvancedPlayground({
|
appName: 'playground',
|
||||||
|
...JSON.parse(context || '{}'),
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = changeRequest
|
||||||
|
? await evaluateChangeRequestPlayground(changeRequest, {
|
||||||
|
context: parsedContext,
|
||||||
|
projects: [],
|
||||||
|
environments: [],
|
||||||
|
})
|
||||||
|
: await evaluateAdvancedPlayground({
|
||||||
environments: resolveEnvironments(environments),
|
environments: resolveEnvironments(environments),
|
||||||
projects: resolveProjects(projects),
|
projects: resolveProjects(projects),
|
||||||
context: {
|
context: parsedContext,
|
||||||
appName: 'playground',
|
|
||||||
...parsedContext,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (action && typeof action === 'function') {
|
if (action && typeof action === 'function') {
|
||||||
|
@ -213,7 +213,7 @@ test('should show change request and disable other fields until removed', async
|
|||||||
const [environments, setEnvironments] = useState<string[]>([]);
|
const [environments, setEnvironments] = useState<string[]>([]);
|
||||||
const [projects, setProjects] = useState<string[]>(['test-project']);
|
const [projects, setProjects] = useState<string[]>(['test-project']);
|
||||||
const [token, setToken] = useState<string>();
|
const [token, setToken] = useState<string>();
|
||||||
const [changeRequest, setChangeRequest] = useState('CR #1');
|
const [changeRequest, setChangeRequest] = useState('1');
|
||||||
|
|
||||||
const availableEnvironments = ['development', 'production'];
|
const availableEnvironments = ['development', 'production'];
|
||||||
|
|
||||||
@ -233,14 +233,15 @@ test('should show change request and disable other fields until removed', async
|
|||||||
};
|
};
|
||||||
render(<Component />);
|
render(<Component />);
|
||||||
|
|
||||||
const changeRequestInput = await screen.findByDisplayValue('CR #1');
|
const changeRequestInput =
|
||||||
// expect(changeRequestInput).toHaveValue('CR #1');
|
await screen.findByDisplayValue('Change request #1');
|
||||||
const viewButton = await screen.findByText(/View change request/);
|
const viewButton = await screen.findByText(/View change request/);
|
||||||
expect(viewButton).toHaveProperty(
|
expect(viewButton).toHaveProperty(
|
||||||
'href',
|
'href',
|
||||||
'http://localhost:3000/projects/test-project/change-requests/CR%20#1',
|
'http://localhost:3000/projects/test-project/change-requests/1',
|
||||||
);
|
);
|
||||||
// TODO: check if other fields are disabled
|
const tokenInput = await screen.findByLabelText('API token');
|
||||||
|
expect(tokenInput).toBeDisabled();
|
||||||
|
|
||||||
const clearButton = await screen.findByLabelText(/clear change request/i);
|
const clearButton = await screen.findByLabelText(/clear change request/i);
|
||||||
|
|
||||||
|
@ -277,20 +277,17 @@ export const PlaygroundConnectionFieldset: FC<
|
|||||||
<Box sx={{ flex: 1 }}>
|
<Box sx={{ flex: 1 }}>
|
||||||
<StyledChangeRequestInput
|
<StyledChangeRequestInput
|
||||||
label='Change request'
|
label='Change request'
|
||||||
value={changeRequest || ''}
|
value={
|
||||||
|
changeRequest
|
||||||
|
? `Change request #${changeRequest}`
|
||||||
|
: ''
|
||||||
|
}
|
||||||
onChange={() => {}}
|
onChange={() => {}}
|
||||||
type={'text'}
|
type={'text'}
|
||||||
// error={Boolean(changeRequestError)}
|
|
||||||
// errorText={changeRequestError)}}
|
|
||||||
placeholder={'Enter your API token'}
|
|
||||||
data-testid={'PLAYGROUND_TOKEN_INPUT'}
|
|
||||||
disabled
|
disabled
|
||||||
InputProps={{
|
InputProps={{
|
||||||
endAdornment: (
|
endAdornment: (
|
||||||
<InputAdornment
|
<InputAdornment position='end'>
|
||||||
position='end'
|
|
||||||
data-testid='CR_INPUT_CLEAR_BTN'
|
|
||||||
>
|
|
||||||
<IconButton
|
<IconButton
|
||||||
aria-label='clear Change request results'
|
aria-label='clear Change request results'
|
||||||
onClick={
|
onClick={
|
||||||
|
@ -24,8 +24,23 @@ export const usePlaygroundApi = () => {
|
|||||||
return res.json();
|
return res.json();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const evaluateChangeRequestPlayground = async (
|
||||||
|
changeRequestId: string,
|
||||||
|
payload: AdvancedPlaygroundRequestSchema, // FIXME: type
|
||||||
|
): Promise<AdvancedPlaygroundResponseSchema> => {
|
||||||
|
const path = `${URI}/change-request/${changeRequestId}`;
|
||||||
|
const req = createRequest(path, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
});
|
||||||
|
|
||||||
|
const res = await makeRequest(req.caller, req.id);
|
||||||
|
return res.json();
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
evaluateAdvancedPlayground,
|
evaluateAdvancedPlayground,
|
||||||
|
evaluateChangeRequestPlayground,
|
||||||
errors,
|
errors,
|
||||||
loading,
|
loading,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user