Skip to content

Commit

Permalink
Merge pull request #2487 from posit-dev/dotnomad/disable-entrypoint-c…
Browse files Browse the repository at this point in the history
…heckbox

Disable entrypoint checkbox in Project Files view
  • Loading branch information
marcosnav authored Dec 23, 2024
2 parents 69048f2 + 976e62b commit f909de6
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
:checked="checked"
:disabled="disabled"
class="tree-item-checkbox"
:class="{ 'opacity-100': disableOpacity }"
@click="checked ? $emit('uncheck') : $emit('check')"
>
<span class="tree-item-title">{{ title }}</span>
Expand Down Expand Up @@ -77,13 +78,15 @@ interface Props {
indentLevel?: number;
expandable?: boolean;
virtualized?: boolean;
disableOpacity?: boolean;
}
const props = withDefaults(defineProps<Props>(), {
listStyle: "default",
indentLevel: 1,
expandable: false,
virtualized: false,
disableOpacity: false,
});
const slots = defineSlots<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
:checked="isIncluded"
:disabled="isDisabled"
:list-style="listStyle"
:disable-opacity="isEntrypoint"
:indent-level="file.indent + 1"
:expandable="file.isDir"
:tooltip="tooltip"
Expand Down Expand Up @@ -57,7 +58,11 @@ const fileStore = useFileStore();
const isDisabled = computed((): boolean => {
const source = props.file.reason?.source;
return source === "built-in" || source === "permissions";
return (
(isEntrypoint.value && isIncluded.value) ||
source === "built-in" ||
source === "permissions"
);
});
const isIncluded = computed((): boolean => {
Expand Down Expand Up @@ -94,7 +99,7 @@ const listStyle = computed((): "emphasized" | "default" | "deemphasized" => {
const tooltip = computed((): string => {
return isIncluded.value
? includedFileTooltip(props.file)
? includedFileTooltip(props.file, isEntrypoint.value)
: excludedFileTooltip(props.file);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { describe, it, expect } from "vitest";
import { includedFileTooltip, excludedFileTooltip } from "./tooltips";
import { FileMatchSource } from "../../../../../../src/api/types/files";

describe("includedFileTooltip", () => {
it("should return correct tooltip for included file without reason", () => {
const file = { rel: "src/index.ts", reason: null };
const tooltip = includedFileTooltip(file);
expect(tooltip).toBe(
"src/index.ts will be included in the next deployment.",
);
});

it("should return correct tooltip for included file with reason", () => {
const file = {
rel: "src/config.json",
reason: {
fileName: "config.json",
pattern: "*.json",
source: FileMatchSource.FILE,
filePath: "src/config.json",
exclude: false,
},
};
const tooltip = includedFileTooltip(file);
expect(tooltip).toBe(
`src/config.json will be included in the next deployment.\nThe configuration file config.json is including it with the pattern '*.json'`,
);
});

it("should return correct tooltip for entrypoint file", () => {
const file = { rel: "src/index.ts", reason: null };
const tooltip = includedFileTooltip(file, true);
expect(tooltip).toBe(
`src/index.ts will be included in the next deployment.\nsrc/index.ts is the entrypoint. Entrypoints must be included in the configuration 'files' list.`,
);
});
});

describe("excludedFileTooltip", () => {
it("should return correct tooltip for excluded file without reason", () => {
const file = { rel: "src/index.ts", reason: null };
const tooltip = excludedFileTooltip(file);
expect(tooltip).toBe(
`src/index.ts will be excluded in the next deployment.\nIt did not match any pattern in the configuration 'files' list.`,
);
});

it("should return correct tooltip for excluded file with built-in reason", () => {
const file = {
rel: "src/index.ts",
reason: {
source: FileMatchSource.BUILT_IN,
pattern: "*.ts",
fileName: "config.json",
filePath: "src/index.ts",
exclude: true,
},
};
const tooltip = excludedFileTooltip(file);
expect(tooltip).toBe(
`src/index.ts will be excluded in the next deployment.\nThis is a built-in exclusion for the pattern: '*.ts' and cannot be overridden.`,
);
});

it("should return correct tooltip for excluded file with permissions error", () => {
const file = {
rel: "src/index.ts",
reason: {
source: FileMatchSource.PERMISSIONS_ERROR,
pattern: "",
fileName: "",
filePath: "",
exclude: true,
},
};
const tooltip = excludedFileTooltip(file);
expect(tooltip).toBe(
`src/index.ts will be excluded in the next deployment.\nYou don't have permission to access this directory.`,
);
});

it("should return correct tooltip for excluded file with custom reason", () => {
const file = {
rel: "src/index.ts",
reason: {
fileName: "config.json",
pattern: "*.ts",
source: FileMatchSource.FILE,
filePath: "src/index.ts",
exclude: true,
},
};
const tooltip = excludedFileTooltip(file);
expect(tooltip).toBe(
`src/index.ts will be excluded in the next deployment.\nThe configuration file config.json is excluding it with the pattern '*.ts'`,
);
});
});
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { ContentRecordFile, FileMatchSource } from "../../../../../../src/api";
import {
ContentRecordFile,
FileMatchSource,
} from "../../../../../../src/api/types/files";

export function includedFileTooltip(
file: Pick<ContentRecordFile, "rel" | "reason">,
isEntrypoint: boolean = false,
) {
let tooltip = `${file.rel} will be included in the next deployment.`;
if (file.reason) {
tooltip += `\nThe configuration file ${file.reason?.fileName} is including it with the pattern '${file.reason?.pattern}'`;
}
if (isEntrypoint) {
tooltip += `\n${file.rel} is the entrypoint. Entrypoints must be included in the configuration 'files' list.`;
}
return tooltip;
}

Expand Down
4 changes: 4 additions & 0 deletions extensions/vscode/webviews/homeView/src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,7 @@ body {
.text-git-conflicting {
color: var(--vscode-gitDecoration-conflictingResourceForeground);
}

.opacity-100 {
opacity: 1;
}
8 changes: 4 additions & 4 deletions extensions/vscode/webviews/homeView/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ export default defineConfig({
coverage: {
enabled: true,
thresholds: {
functions: 27.77,
lines: 16.06,
branches: 37.97,
statements: 16.06,
functions: 30.13,
lines: 17.48,
branches: 44.82,
statements: 17.48,
autoUpdate: true,
},
},
Expand Down

0 comments on commit f909de6

Please sign in to comment.