Update workpsace settings modal for environment settings (#7585)

This commit is contained in:
James Gatz 2024-06-25 16:56:19 +02:00 committed by GitHub
parent b9883fdd14
commit 8320c4c626
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 44 additions and 25 deletions

View File

@ -1,9 +1,18 @@
import { isDesign, isMockServer, Workspace } from '../models/workspace'; import { isDesign, isEnvironment, isMockServer, Workspace } from '../models/workspace';
import { strings } from './strings'; import { strings } from './strings';
export const getWorkspaceLabel = (workspace: Workspace) => export const getWorkspaceLabel = (workspace: Workspace) => {
isDesign(workspace) if (isDesign(workspace)) {
? strings.document return strings.document;
: isMockServer(workspace) }
? strings.mock
: strings.collection; if (isMockServer(workspace)) {
return strings.mock;
}
if (isEnvironment(workspace)) {
return strings.environment;
}
return strings.collection;
};

View File

@ -12,6 +12,7 @@ type StringId =
| 'defaultProject' | 'defaultProject'
| 'localProject' | 'localProject'
| 'remoteProject' | 'remoteProject'
| 'environment'
; ;
export const strings: Record<StringId, StringInfo> = { export const strings: Record<StringId, StringInfo> = {
@ -47,4 +48,8 @@ export const strings: Record<StringId, StringInfo> = {
singular: 'Remote', singular: 'Remote',
plural: 'Remote', plural: 'Remote',
}, },
environment: {
singular: 'Environment',
plural: 'Environments',
},
}; };

View File

@ -8,7 +8,7 @@ import { getWorkspaceLabel } from '../../../common/get-workspace-label';
import * as models from '../../../models/index'; import * as models from '../../../models/index';
import { MockServer } from '../../../models/mock-server'; import { MockServer } from '../../../models/mock-server';
import { isRequest } from '../../../models/request'; import { isRequest } from '../../../models/request';
import { isScratchpad, Workspace } from '../../../models/workspace'; import { isEnvironment, isMockServer, isScratchpad, Workspace } from '../../../models/workspace';
import { OrganizationLoaderData } from '../../routes/organization'; import { OrganizationLoaderData } from '../../routes/organization';
import { Link } from '../base/link'; import { Link } from '../base/link';
import { PromptButton } from '../base/prompt-button'; import { PromptButton } from '../base/prompt-button';
@ -90,7 +90,7 @@ export const WorkspaceSettingsModal = ({ workspace, mockServer, onClose }: Props
className='p-2 w-full rounded-sm border border-solid border-[--hl-sm] bg-[--color-bg] text-[--color-font] focus:outline-none focus:ring-1 focus:ring-[--hl-md] transition-colors' className='p-2 w-full rounded-sm border border-solid border-[--hl-sm] bg-[--color-bg] text-[--color-font] focus:outline-none focus:ring-1 focus:ring-[--hl-md] transition-colors'
onChange={event => workspacePatcher(workspace._id, { name: event.target.value })} onChange={event => workspacePatcher(workspace._id, { name: event.target.value })}
/> />
{workspace.scope !== 'mock-server' && ( {!isMockServer(workspace) && (
<> <>
<Label className='text-sm text-[--hl]' aria-label='Description'> <Label className='text-sm text-[--hl]' aria-label='Description'>
Description Description
@ -102,22 +102,27 @@ export const WorkspaceSettingsModal = ({ workspace, mockServer, onClose }: Props
workspacePatcher(workspace._id, { description }); workspacePatcher(workspace._id, { description });
}} }}
/> />
<Heading>Actions</Heading> {!isEnvironment(workspace) && (
<PromptButton <>
onClick={async () => { <Heading>Actions</Heading>
const docs = await db.withDescendants(workspace, models.request.type); <PromptButton
const requests = docs.filter(isRequest); onClick={async () => {
for (const req of requests) { const docs = await db.withDescendants(workspace, models.request.type);
await models.response.removeForRequest(req._id); const requests = docs.filter(isRequest);
} for (const req of requests) {
close(); await models.response.removeForRequest(req._id);
}} }
className="width-auto btn btn--clicky inline-block space-left" close();
> }}
<i className="fa fa-trash-o" /> Clear All Responses className="width-auto btn btn--clicky inline-block space-left"
</PromptButton> >
</>)} <i className="fa fa-trash-o" /> Clear All Responses
{Boolean(workspace.scope === 'mock-server' && mockServer) && ( </PromptButton>
</>
)}
</>
)}
{Boolean(isMockServer(workspace) && mockServer) && (
<> <>
<RadioGroup <RadioGroup
name="mockServerType" name="mockServerType"