Skip to content

Commit 0748359

Browse files
authored
feat: add requested copy changes (#26)
* non-repo helper * copy changes * pr feedback
1 parent 422d1dc commit 0748359

File tree

5 files changed

+63
-24
lines changed

5 files changed

+63
-24
lines changed

plugins/backstage-plugin-coder/src/components/CoderAuthWrapper/CoderAuthInputForm.tsx

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ export const CoderAuthInputForm = () => {
104104
<div>
105105
<CoderLogo className={styles.coderLogo} />
106106
<p>
107-
Your Coder session token is {mapAuthStatusToText(status)}. Please
108-
enter a new token from your{' '}
107+
Link your Coder account to create remote workspaces. Please enter a
108+
new token from your{' '}
109109
<Link
110110
to={`${appConfig.deployment.accessUrl}/cli-auth`}
111111
target="_blank"
@@ -162,20 +162,3 @@ export const CoderAuthInputForm = () => {
162162
</form>
163163
);
164164
};
165-
166-
function mapAuthStatusToText(status: CoderAuthStatus): string {
167-
switch (status) {
168-
case 'tokenMissing': {
169-
return 'missing';
170-
}
171-
172-
case 'initializing':
173-
case 'authenticating': {
174-
return status;
175-
}
176-
177-
default: {
178-
return 'invalid';
179-
}
180-
}
181-
}

plugins/backstage-plugin-coder/src/components/CoderWorkspacesCard/ExtraActionsButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export const ExtraActionsButton = ({
173173
closeMenu();
174174
}}
175175
>
176-
Refresh workspaces list
176+
Refresh
177177
</MenuItem>
178178

179179
<MenuItem
@@ -182,7 +182,7 @@ export const ExtraActionsButton = ({
182182
closeMenu();
183183
}}
184184
>
185-
Eject token
185+
Unlink Coder account
186186
</MenuItem>
187187
</Menu>
188188
</>

plugins/backstage-plugin-coder/src/components/CoderWorkspacesCard/HeaderRow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const HeaderRow = ({
6666
hgroupClassName,
6767
subheaderClassName,
6868
activeRepoFilteringText,
69-
headerText = 'Coder workspaces',
69+
headerText = 'Coder Workspaces',
7070
fullBleedLayout = true,
7171
...delegatedProps
7272
}: HeaderProps) => {

plugins/backstage-plugin-coder/src/components/CoderWorkspacesCard/Root.tsx

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React, {
44
useContext,
55
useState,
66
} from 'react';
7-
7+
import { makeStyles } from '@material-ui/core';
88
import { useId } from '../../hooks/hookPolyfills';
99
import { UseQueryResult } from '@tanstack/react-query';
1010
import {
@@ -16,6 +16,7 @@ import type { Workspace } from '../../typesConstants';
1616
import { useCoderWorkspaces } from '../../hooks/useCoderWorkspaces';
1717
import { Card } from '../Card';
1818
import { CoderAuthWrapper } from '../CoderAuthWrapper';
19+
import { VisuallyHidden } from '../VisuallyHidden';
1920
import { type CoderWorkspaceConfig, useCoderAppConfig } from '../CoderProvider';
2021

2122
type WorkspacesCardContext = Readonly<{
@@ -29,6 +30,22 @@ type WorkspacesCardContext = Readonly<{
2930

3031
const CardContext = createContext<WorkspacesCardContext | null>(null);
3132

33+
const useStyles = makeStyles(theme => ({
34+
button: {
35+
color: theme.palette.type,
36+
backgroundColor: theme.palette.background.paper,
37+
border: 'none',
38+
paddingTop: theme.spacing(2),
39+
fontSize: theme.typography.body2.fontSize,
40+
cursor: 'pointer',
41+
},
42+
43+
snippet: {
44+
backgroundColor: theme.palette.grey[100],
45+
borderRadius: '0.4em',
46+
},
47+
}));
48+
3249
export type WorkspacesCardProps = Readonly<
3350
Omit<HTMLAttributes<HTMLDivElement>, 'role' | 'aria-labelledby'> & {
3451
queryFilter?: string;
@@ -47,15 +64,23 @@ export const Root = ({
4764
readEntityData = false,
4865
...delegatedProps
4966
}: WorkspacesCardProps) => {
67+
const styles = useStyles();
5068
const hookId = useId();
5169
const appConfig = useCoderAppConfig();
5270
const [innerFilter, setInnerFilter] = useState(defaultQueryFilter);
5371
const activeFilter = outerFilter ?? innerFilter;
5472

73+
const [isExpanded, setIsExpanded] = useState(false);
74+
const toggleExpansion = () => {
75+
setIsExpanded(!isExpanded);
76+
};
77+
5578
const dynamicConfig = useDynamicEntityConfig(readEntityData);
5679
const workspacesQuery = useCoderWorkspaces(activeFilter, {
5780
repoConfig: dynamicConfig,
5881
});
82+
const showEntityDataReminder =
83+
workspacesQuery.data && dynamicConfig && !dynamicConfig.repoUrl;
5984

6085
const headerId = `${hookId}-header`;
6186
const activeConfig = {
@@ -94,6 +119,36 @@ export const Root = ({
94119
cases around keyboard input and button children that native <form>
95120
elements automatically introduce */}
96121
<div role="form">{children}</div>
122+
{showEntityDataReminder && (
123+
<div>
124+
<button
125+
onClick={toggleExpansion}
126+
type="button"
127+
className={styles.button}
128+
>
129+
{isExpanded ? '▼' : '►'}{' '}
130+
{isExpanded ? 'Hide text' : 'Why am I seeing all workspaces?'}
131+
</button>
132+
{isExpanded && (
133+
<p>
134+
This component displays all workspaces when the entity has no
135+
repo URL to filter by. Consider disabling{' '}
136+
<code className={styles.snippet}>readEntityData</code>;
137+
details in our{' '}
138+
<a
139+
href="https://github.com/coder/backstage-plugins/blob/main/plugins/backstage-plugin-coder/docs/components.md#notes-4"
140+
rel="noopener noreferrer"
141+
target="_blank"
142+
style={{ textDecoration: 'underline', color: 'inherit' }}
143+
>
144+
docs
145+
<VisuallyHidden> (link opens in new tab)</VisuallyHidden>
146+
</a>
147+
.
148+
</p>
149+
)}
150+
</div>
151+
)}
97152
</Card>
98153
</CardContext.Provider>
99154
</CoderAuthWrapper>

plugins/backstage-plugin-coder/src/hooks/useCoderWorkspaces.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ export function useCoderWorkspaces(
1818
const auth = useCoderAuth();
1919
const { baseUrl } = useBackstageEndpoints();
2020
const { repoConfig } = options ?? {};
21+
const hasRepoData = repoConfig && repoConfig.repoUrl;
2122

22-
const queryOptions = repoConfig
23+
const queryOptions = hasRepoData
2324
? workspacesByRepo({ coderQuery, auth, baseUrl, repoConfig })
2425
: workspaces({ coderQuery, auth, baseUrl });
2526

0 commit comments

Comments
 (0)