Skip to content

Commit bb2faa3

Browse files
committed
settings/other: add a setting to dim file extensions, false by default
1 parent 8f826f0 commit bb2faa3

File tree

15 files changed

+86
-30
lines changed

15 files changed

+86
-30
lines changed

src/packages/frontend/_colors.sass

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,4 @@ $COL_LANDING_TOP_BG: #c7d9f5
6969
$COL_TAB: #333333
7070
$COL_FILE_ICON: rgb(66, 139, 202)
7171
$COL_FILE_EXT: #999
72+
$COL_FILE_DIMMED: #959595

src/packages/frontend/account/other-settings.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,18 @@ export function OtherSettings(props: Readonly<Props>): React.JSX.Element {
210210
);
211211
}
212212

213+
function render_dim_file_extensions(): Rendered {
214+
return (
215+
<Switch
216+
checked={!!props.other_settings.get("dim_file_extensions")}
217+
onChange={(e) => on_change("dim_file_extensions", e.target.checked)}
218+
>
219+
<strong>Dim file extensions:</strong> gray out file extensions so their
220+
names stand out.
221+
</Switch>
222+
);
223+
}
224+
213225
function render_antd(): Rendered {
214226
return (
215227
<>
@@ -443,6 +455,7 @@ export function OtherSettings(props: Readonly<Props>): React.JSX.Element {
443455
</>
444456
}
445457
>
458+
{render_dim_file_extensions()}
446459
{render_mask_files()}
447460
{render_default_file_sort()}
448461
{render_page_size()}

src/packages/frontend/components/path-link.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import { COLORS } from "@cocalc/util/theme";
1313
import { handleFileEntryClick } from "../project/history/utils";
1414
import { Tip } from "./tip";
1515

16+
import React from "react";
17+
18+
const DIMMED_STYLE = { color: COLORS.FILE_DIMMED } as const;
19+
1620
interface Props {
1721
path: string;
1822
project_id: string;
@@ -22,6 +26,7 @@ interface Props {
2226
style?: React.CSSProperties;
2327
link?: boolean; // set to false to make it not be a link
2428
onOpen?: () => void; // called if link is clicked on to open it.
29+
dimExtensions?: boolean;
2530
}
2631

2732
// Component to attempt opening a cocalc path in a project
@@ -34,6 +39,7 @@ export const PathLink: React.FC<Props> = ({
3439
style = {},
3540
link = true,
3641
onOpen,
42+
dimExtensions = false,
3743
}: Props) => {
3844
function render_link(text): React.JSX.Element {
3945
let s;
@@ -43,7 +49,7 @@ export const PathLink: React.FC<Props> = ({
4349
s = (
4450
<>
4551
{name}
46-
<span style={{ color: "#999" }}>.{ext}</span>
52+
<span style={dimExtensions ? DIMMED_STYLE : undefined}>.{ext}</span>
4753
</>
4854
);
4955
} else {

src/packages/frontend/project/explorer/file-listing/file-listing.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export const FileListing: React.FC<Props> = ({
8484
configuration_main,
8585
file_search = "",
8686
isRunning,
87+
other_settings,
8788
}: Props) => {
8889
const [starting, setStarting] = useState<boolean>(false);
8990
const { starred, setStarredPath } = useStarredFilesManager(project_id);
@@ -120,6 +121,7 @@ export const FileListing: React.FC<Props> = ({
120121
}, [current_path, isRunning]);
121122

122123
const computeServerId = useTypedRedux({ project_id }, "compute_server_id");
124+
const dimFileExtensions = !!other_settings?.get?.("dim_file_extensions");
123125

124126
function render_row(
125127
name,
@@ -170,6 +172,7 @@ export const FileListing: React.FC<Props> = ({
170172
isdir && !path.endsWith("/") ? `${path}/` : path;
171173
setStarredPath(normalizedPath, starState);
172174
}}
175+
dimFileExtensions={dimFileExtensions}
173176
/>
174177
);
175178
}

src/packages/frontend/project/explorer/file-listing/file-row.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export const VIEWABLE_FILE_EXT: Readonly<string[]> = [
3535
"jpeg",
3636
] as const;
3737

38+
const DIMMED_STYLE = { color: COLORS.FILE_DIMMED } as const;
39+
3840
interface Props {
3941
isdir: boolean;
4042
name: string;
@@ -57,6 +59,7 @@ interface Props {
5759
computeServerId?: number;
5860
isStarred?: boolean;
5961
onToggleStar?: (path: string, starred: boolean) => void;
62+
dimFileExtensions?: boolean;
6063
}
6164

6265
export const FileRow: React.FC<Props> = React.memo((props) => {
@@ -68,7 +71,7 @@ export const FileRow: React.FC<Props> = React.memo((props) => {
6871

6972
function render_icon() {
7073
const style: React.CSSProperties = {
71-
color: props.mask ? "#bbbbbb" : COLORS.FILE_ICON,
74+
color: props.mask ? COLORS.FILE_DIMMED : COLORS.FILE_ICON,
7275
verticalAlign: "sub",
7376
} as const;
7477
let body: React.JSX.Element;
@@ -117,12 +120,11 @@ export const FileRow: React.FC<Props> = React.memo((props) => {
117120
}
118121

119122
function render_name_link(styles, name, ext) {
123+
const extStyle = props.dimFileExtensions ? DIMMED_STYLE : undefined;
120124
return (
121125
<a style={styles} cocalc-test="file-line">
122126
{misc.trunc_middle(name, 50)}
123-
<span style={{ color: !props.mask ? COLORS.GRAY_M : undefined }}>
124-
{ext === "" ? "" : `.${ext}`}
125-
</span>
127+
<span style={extStyle}>{ext === "" ? "" : `.${ext}`}</span>
126128
{render_link_target()}
127129
</a>
128130
);
@@ -147,7 +149,7 @@ export const FileRow: React.FC<Props> = React.memo((props) => {
147149
wordWrap: "break-word",
148150
overflowWrap: "break-word",
149151
verticalAlign: "middle",
150-
color: props.mask ? "#bbbbbb" : COLORS.TAB,
152+
color: props.mask ? COLORS.FILE_DIMMED : COLORS.TAB,
151153
};
152154

153155
if (show_tip) {

src/packages/frontend/project/history/log-entry.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ export const LogEntry: React.FC<Props> = React.memo(
146146
"customize",
147147
"software",
148148
);
149+
const otherSettings = useTypedRedux("account", "other_settings");
150+
const dimFileExtensions = !!otherSettings?.get("dim_file_extensions");
149151

150152
function render_open_file(event: OpenFile): React.JSX.Element {
151153
return (
@@ -158,6 +160,7 @@ export const LogEntry: React.FC<Props> = React.memo(
158160
style={cursor ? selected_item : undefined}
159161
trunc={TRUNC}
160162
project_id={project_id}
163+
dimExtensions={dimFileExtensions}
161164
onOpen={() =>
162165
track("open-file", {
163166
how: "project-log",
@@ -193,6 +196,7 @@ export const LogEntry: React.FC<Props> = React.memo(
193196
style={cursor ? selected_item : undefined}
194197
trunc={TRUNC}
195198
project_id={project_id}
199+
dimExtensions={dimFileExtensions}
196200
/>
197201
),
198202
event: event.disabled ? "disabled" : "enabled",
@@ -350,6 +354,7 @@ export const LogEntry: React.FC<Props> = React.memo(
350354
trunc={TRUNC}
351355
link={link}
352356
project_id={project_id != null ? project_id : props.project_id}
357+
dimExtensions={dimFileExtensions}
353358
onOpen={() =>
354359
track("open-file", {
355360
how: "project-log",
@@ -609,6 +614,7 @@ export const LogEntry: React.FC<Props> = React.memo(
609614
style={cursor ? selected_item : undefined}
610615
trunc={TRUNC}
611616
project_id={project_id}
617+
dimExtensions={dimFileExtensions}
612618
/>
613619
);
614620

@@ -670,6 +676,7 @@ export const LogEntry: React.FC<Props> = React.memo(
670676
style={cursor ? selected_item : undefined}
671677
trunc={TRUNC}
672678
project_id={project_id}
679+
dimExtensions={dimFileExtensions}
673680
/>
674681
</span>
675682
);

src/packages/frontend/project/page/file-tab.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,10 @@ export function FileTab(props: Readonly<Props>) {
215215
// alerts only work on non-docker projects (for now) -- #7077
216216
const status_alerts: string[] =
217217
!onCoCalcDocker && name === "info"
218-
? project_status
218+
? (project_status
219219
?.get("alerts")
220220
?.map((a) => a.get("type"))
221-
.toJS() ?? []
221+
.toJS() ?? [])
222222
: [];
223223

224224
const other_settings = useTypedRedux("account", "other_settings");
@@ -303,8 +303,8 @@ export function FileTab(props: Readonly<Props>) {
303303
flyout === active_flyout
304304
? COLORS.PROJECT.FIXED_LEFT_ACTIVE
305305
: active_flyout == null
306-
? COLORS.GRAY_L
307-
: COLORS.GRAY_L0;
306+
? COLORS.GRAY_L
307+
: COLORS.GRAY_L0;
308308
const bg = flyout === active_flyout ? COLORS.GRAY_L0 : undefined;
309309

310310
return (
@@ -368,7 +368,7 @@ export function FileTab(props: Readonly<Props>) {
368368

369369
const icon =
370370
path != null
371-
? file_options(path)?.icon ?? "code-o"
371+
? (file_options(path)?.icon ?? "code-o")
372372
: FIXED_PROJECT_TABS[name!].icon;
373373

374374
const tags =
@@ -545,6 +545,8 @@ const FULLPATH_LABEL_STYLE: CSS = {
545545
} as const;
546546

547547
function DisplayedLabel({ path, label, inline = true, project_id }) {
548+
const otherSettings = useTypedRedux("account", "other_settings");
549+
const dimFileExtensions = !!otherSettings?.get("dim_file_extensions");
548550
if (path == null) {
549551
// a fixed tab (not an actual file)
550552
const E = inline ? "span" : "div";
@@ -590,7 +592,11 @@ function DisplayedLabel({ path, label, inline = true, project_id }) {
590592
>
591593
<span style={{ direction: "ltr" }}>
592594
{label}
593-
<span style={{ color: COLORS.FILE_EXT }}>{ext}</span>
595+
<span
596+
style={dimFileExtensions ? { color: COLORS.FILE_DIMMED } : undefined}
597+
>
598+
{ext}
599+
</span>
594600
</span>
595601
</div>
596602
);

src/packages/frontend/project/page/flyouts/active-group.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ interface GroupProps {
2828
setStarredPath: (path: string, next: boolean) => void;
2929
showStarred: boolean;
3030
isLast?: boolean; // if group is empty, it is also the last one in the group
31+
dimFileExtensions: boolean;
3132
}
3233

3334
export function Group({
@@ -38,6 +39,7 @@ export function Group({
3839
setStarredPath,
3940
showStarred,
4041
isLast = false,
42+
dimFileExtensions,
4143
}: GroupProps): React.JSX.Element {
4244
const { project_id } = useProjectContext();
4345
const actions = useActions({ project_id });
@@ -75,7 +77,7 @@ export function Group({
7577
const fileType = file_options(`foo.${group}`);
7678
return {
7779
iconName:
78-
group === "" ? UNKNOWN_FILE_TYPE_ICON : fileType?.icon ?? "file",
80+
group === "" ? UNKNOWN_FILE_TYPE_ICON : (fileType?.icon ?? "file"),
7981
display: (group === "" ? "No extension" : fileType?.name) || group,
8082
};
8183
}
@@ -127,6 +129,7 @@ export function Group({
127129
// trailing slash indicates to open a directory
128130
handleFileEntryClick(e, `${group}/`, project_id);
129131
}}
132+
dimFileExtensions={dimFileExtensions}
130133
/>
131134
);
132135

src/packages/frontend/project/page/flyouts/active.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ export function ActiveFlyout(props: Readonly<Props>): React.JSX.Element {
133133
const openFiles = useTypedRedux({ project_id }, "open_files_order");
134134
const justClosed = useTypedRedux({ project_id }, "just_closed_files");
135135
const activeTab = useTypedRedux({ project_id }, "active_project_tab");
136+
const otherSettings = useTypedRedux("account", "other_settings");
137+
const dimFileExtensions = !!otherSettings?.get("dim_file_extensions");
136138
const [filterTerm, setFilterTerm] = useState<string>("");
137139
const [showStarred, setShowStarred] = useState<boolean>(
138140
getFlyoutActiveShowStarred(project_id),
@@ -195,7 +197,7 @@ export function ActiveFlyout(props: Readonly<Props>): React.JSX.Element {
195197
filteredFiles.forEach((path) => {
196198
const { head, tail } = path_split(path);
197199
const group =
198-
mode === "folder" ? head : filename_extension_notilde(tail) ?? "";
200+
mode === "folder" ? head : (filename_extension_notilde(tail) ?? "");
199201
if (grouped[group] == null) grouped[group] = [];
200202
grouped[group].push(path);
201203
});
@@ -317,6 +319,7 @@ export function ActiveFlyout(props: Readonly<Props>): React.JSX.Element {
317319
/>
318320
) : undefined
319321
}
322+
dimFileExtensions={dimFileExtensions}
320323
/>
321324
);
322325
}
@@ -473,6 +476,7 @@ export function ActiveFlyout(props: Readonly<Props>): React.JSX.Element {
473476
setStarredPath={setStarredPath}
474477
showStarred={showStarred}
475478
isLast={fileNames.length === 0}
479+
dimFileExtensions={dimFileExtensions}
476480
/>,
477481
);
478482

0 commit comments

Comments
 (0)