2023-06-15 11:29:31 +02:00
|
|
|
import {
|
|
|
|
PlaygroundResponseSchema,
|
|
|
|
AdvancedPlaygroundResponseSchema,
|
|
|
|
} from 'openapi';
|
2022-07-22 13:15:28 +02:00
|
|
|
import { IEnvironment } from 'interfaces/environments';
|
2023-06-15 11:29:31 +02:00
|
|
|
import { ensureArray } from '@server/util/ensureArray';
|
2022-07-22 13:15:28 +02:00
|
|
|
|
|
|
|
export const resolveProjects = (
|
|
|
|
projects: string[] | string
|
2023-01-05 11:57:53 +01:00
|
|
|
): string[] | '*' => {
|
|
|
|
if (
|
|
|
|
!projects ||
|
2022-07-22 13:15:28 +02:00
|
|
|
projects.length === 0 ||
|
|
|
|
(projects.length === 1 && projects[0] === '*')
|
2023-01-05 11:57:53 +01:00
|
|
|
) {
|
|
|
|
return '*';
|
|
|
|
}
|
|
|
|
|
2023-06-15 11:29:31 +02:00
|
|
|
return ensureArray(projects);
|
|
|
|
};
|
2023-01-05 11:57:53 +01:00
|
|
|
|
2023-06-15 11:29:31 +02:00
|
|
|
export const resolveEnvironments = (
|
|
|
|
envrironments: string[] | string
|
|
|
|
): string[] => {
|
|
|
|
return ensureArray(envrironments);
|
2022-07-22 13:15:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export const resolveDefaultEnvironment = (
|
|
|
|
environmentOptions: IEnvironment[]
|
|
|
|
) => {
|
|
|
|
const options = getEnvironmentOptions(environmentOptions);
|
|
|
|
if (options.length > 0) {
|
|
|
|
return options[0];
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getEnvironmentOptions = (environments: IEnvironment[]) => {
|
|
|
|
return environments
|
|
|
|
.filter(({ enabled }) => Boolean(enabled))
|
|
|
|
.sort((a, b) => a.sortOrder - b.sortOrder)
|
|
|
|
.map(({ name }) => name);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const resolveResultsWidth = (
|
|
|
|
matches: boolean,
|
2023-06-15 11:29:31 +02:00
|
|
|
results:
|
|
|
|
| PlaygroundResponseSchema
|
|
|
|
| AdvancedPlaygroundResponseSchema
|
|
|
|
| undefined
|
2022-07-22 13:15:28 +02:00
|
|
|
) => {
|
|
|
|
if (matches) {
|
|
|
|
return '100%';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (results && !matches) {
|
2023-06-15 14:11:04 +02:00
|
|
|
return '60%';
|
2022-07-22 13:15:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return '50%';
|
|
|
|
};
|
2023-06-22 10:06:25 +02:00
|
|
|
|
|
|
|
export const isStringOrStringArray = (
|
|
|
|
value: unknown
|
|
|
|
): value is string | string[] => {
|
|
|
|
if (typeof value === 'string') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Array.isArray(value)) {
|
|
|
|
return value.every(item => typeof item === 'string');
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|