Skip to content

Commit 85543d6

Browse files
Add clickable file path to show/hide file contents in StackInfo (#827)
* add clickable file path to show/hide file contents in StackInfo Also added CopyButton due to the new functionality making the file path not selectable. * Move clicking interaction to CardHeader * Avoid sync edge cases of having toggle show function capturing showContents from outside Co-authored-by: Maxwell Becker <[email protected]> * Format previous change * Add `default_show_contents` to `handleToggleShow` --------- Co-authored-by: Maxwell Becker <[email protected]>
1 parent 6867717 commit 85543d6

File tree

1 file changed

+56
-26
lines changed
  • frontend/src/components/resources/stack

1 file changed

+56
-26
lines changed

frontend/src/components/resources/stack/info.tsx

Lines changed: 56 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { useLocalStorage, useWrite } from "@lib/hooks";
1616
import { Button } from "@ui/button";
1717
import { FilePlus, History } from "lucide-react";
1818
import { useToast } from "@ui/use-toast";
19-
import { ConfirmButton, ShowHideButton } from "@components/util";
19+
import { ConfirmButton, ShowHideButton, CopyButton } from "@components/util";
2020
import { DEFAULT_STACK_FILE_CONTENTS } from "./config";
2121
import { Types } from "komodo_client";
2222

@@ -205,50 +205,80 @@ export const StackInfo = ({
205205
latest_contents.length > 0 &&
206206
latest_contents.map((content) => {
207207
const showContents = show[content.path] ?? default_show_contents;
208+
const handleToggleShow = () => {
209+
setShow((show) => ({
210+
...show,
211+
[content.path]: !(show[content.path] ?? default_show_contents),
212+
}));
213+
};
208214
return (
209215
<Card key={content.path} className="flex flex-col gap-4">
210216
<CardHeader
211217
className={cn(
212-
"flex flex-row justify-between items-center",
218+
"flex flex-row justify-between items-center group cursor-pointer",
213219
showContents && "pb-0"
214220
)}
221+
onClick={handleToggleShow}
222+
tabIndex={0}
223+
role="button"
224+
aria-pressed={showContents}
225+
onKeyDown={(e) => {
226+
if (
227+
(e.key === "Enter" || e.key === " ") &&
228+
e.target === e.currentTarget
229+
) {
230+
if (e.key === " ") e.preventDefault();
231+
handleToggleShow();
232+
}
233+
}}
215234
>
216-
<CardTitle className="font-mono flex gap-2">
217-
<div className="text-muted-foreground">File:</div>
218-
{content.path}
235+
<CardTitle className="font-mono flex gap-2 items-center">
236+
<div className="flex gap-2 items-center">
237+
<span className="text-muted-foreground">File:</span>
238+
<span>{content.path}</span>
239+
<span onClick={(e) => e.stopPropagation()} data-copy-button>
240+
<CopyButton content={content.path} label="file path" />
241+
</span>
242+
</div>
219243
</CardTitle>
220244
<div className="flex items-center gap-2">
221245
{canEdit && (
222246
<>
223247
<Button
224248
variant="outline"
225-
onClick={() =>
226-
setEdits({ ...edits, [content.path]: undefined })
227-
}
249+
onClick={(e) => {
250+
e.stopPropagation();
251+
setEdits({ ...edits, [content.path]: undefined });
252+
}}
228253
className="flex items-center gap-2"
229254
disabled={!edits[content.path]}
230255
>
231256
<History className="w-4 h-4" />
232257
Reset
233258
</Button>
234-
<ConfirmUpdate
235-
previous={{ contents: content.contents }}
236-
content={{ contents: edits[content.path] }}
237-
onConfirm={async () => {
238-
if (stack) {
239-
return await mutateAsync({
240-
stack: stack.name,
241-
file_path: content.path,
242-
contents: edits[content.path]!,
243-
}).then(() =>
244-
setEdits({ ...edits, [content.path]: undefined })
245-
);
246-
}
247-
}}
248-
disabled={!edits[content.path]}
249-
language="yaml"
250-
loading={isPending}
251-
/>
259+
<span onClick={(e) => e.stopPropagation()}>
260+
<ConfirmUpdate
261+
previous={{ contents: content.contents }}
262+
content={{ contents: edits[content.path] }}
263+
onConfirm={async () => {
264+
if (stack) {
265+
return await mutateAsync({
266+
stack: stack.name,
267+
file_path: content.path,
268+
contents: edits[content.path]!,
269+
}).then(() =>
270+
setEdits({
271+
...edits,
272+
[content.path]: undefined,
273+
})
274+
);
275+
}
276+
}}
277+
disabled={!edits[content.path]}
278+
language="yaml"
279+
loading={isPending}
280+
/>
281+
</span>
252282
</>
253283
)}
254284
<ShowHideButton

0 commit comments

Comments
 (0)