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';
export const getWorkspaceLabel = (workspace: Workspace) =>
isDesign(workspace)
? strings.document
: isMockServer(workspace)
? strings.mock
: strings.collection;
export const getWorkspaceLabel = (workspace: Workspace) => {
if (isDesign(workspace)) {
return strings.document;
}
if (isMockServer(workspace)) {
return strings.mock;
}
if (isEnvironment(workspace)) {
return strings.environment;
}
return strings.collection;
};

View File

@ -12,6 +12,7 @@ type StringId =
| 'defaultProject'
| 'localProject'
| 'remoteProject'
| 'environment'
;
export const strings: Record<StringId, StringInfo> = {
@ -47,4 +48,8 @@ export const strings: Record<StringId, StringInfo> = {
singular: '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 { MockServer } from '../../../models/mock-server';
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 { Link } from '../base/link';
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'
onChange={event => workspacePatcher(workspace._id, { name: event.target.value })}
/>
{workspace.scope !== 'mock-server' && (
{!isMockServer(workspace) && (
<>
<Label className='text-sm text-[--hl]' aria-label='Description'>
Description
@ -102,22 +102,27 @@ export const WorkspaceSettingsModal = ({ workspace, mockServer, onClose }: Props
workspacePatcher(workspace._id, { description });
}}
/>
<Heading>Actions</Heading>
<PromptButton
onClick={async () => {
const docs = await db.withDescendants(workspace, models.request.type);
const requests = docs.filter(isRequest);
for (const req of requests) {
await models.response.removeForRequest(req._id);
}
close();
}}
className="width-auto btn btn--clicky inline-block space-left"
>
<i className="fa fa-trash-o" /> Clear All Responses
</PromptButton>
</>)}
{Boolean(workspace.scope === 'mock-server' && mockServer) && (
{!isEnvironment(workspace) && (
<>
<Heading>Actions</Heading>
<PromptButton
onClick={async () => {
const docs = await db.withDescendants(workspace, models.request.type);
const requests = docs.filter(isRequest);
for (const req of requests) {
await models.response.removeForRequest(req._id);
}
close();
}}
className="width-auto btn btn--clicky inline-block space-left"
>
<i className="fa fa-trash-o" /> Clear All Responses
</PromptButton>
</>
)}
</>
)}
{Boolean(isMockServer(workspace) && mockServer) && (
<>
<RadioGroup
name="mockServerType"