Skip to content

Commit

Permalink
Disable ProjectFile checkbox when package file
Browse files Browse the repository at this point in the history
  • Loading branch information
dotNomad committed Jan 25, 2025
1 parent ac7fe4d commit ce97e9f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:checked="isIncluded"
:disabled="isDisabled"
:list-style="listStyle"
:disable-opacity="isEntrypoint"
:disable-opacity="isEntrypoint || isPackageFile"
:indent-level="file.indent + 1"
:expandable="file.isDir"
:tooltip="tooltip"
Expand Down Expand Up @@ -60,6 +60,7 @@ const isDisabled = computed((): boolean => {
const source = props.file.reason?.source;
return (
(isEntrypoint.value && isIncluded.value) ||
(isPackageFile.value && isIncluded.value) ||
source === "built-in" ||
source === "permissions"
);
Expand Down Expand Up @@ -89,6 +90,26 @@ const isEntrypoint = computed((): boolean => {
return false;
});
const isPackageFile = computed((): boolean => {
return isPythonPackageFile.value || isRPackageFile.value;
});
const isPythonPackageFile = computed((): boolean => {
const config = home.selectedConfiguration;
if (config != undefined && !isConfigurationError(config)) {
return props.file.id === config.configuration.python?.packageFile;
}
return false;
});
const isRPackageFile = computed((): boolean => {
const config = home.selectedConfiguration;
if (config != undefined && !isConfigurationError(config)) {
return props.file.id === config.configuration.r?.packageFile;
}
return false;
});
const listStyle = computed((): "emphasized" | "default" | "deemphasized" => {
return isEntrypoint.value
? "emphasized"
Expand All @@ -99,7 +120,10 @@ const listStyle = computed((): "emphasized" | "default" | "deemphasized" => {
const tooltip = computed((): string => {
return isIncluded.value
? includedFileTooltip(props.file, isEntrypoint.value)
? includedFileTooltip(props.file, {
isEntrypoint: isEntrypoint.value,
isPackageFile: isPackageFile.value,
})
: excludedFileTooltip(props.file);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,19 @@ describe("includedFileTooltip", () => {

it("should return correct tooltip for entrypoint file", () => {
const file = { rel: "src/index.ts", reason: null };
const tooltip = includedFileTooltip(file, true);
const tooltip = includedFileTooltip(file, { isEntrypoint: 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.`,
);
});

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

describe("excludedFileTooltip", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import {

export function includedFileTooltip(
file: Pick<ContentRecordFile, "rel" | "reason">,
isEntrypoint: boolean = false,
{
isEntrypoint = false,
isPackageFile = false,
}: { isEntrypoint?: boolean; isPackageFile?: boolean } = {},
) {
let tooltip = `${file.rel} will be included in the next deployment.`;
if (file.reason) {
Expand All @@ -14,6 +17,9 @@ export function includedFileTooltip(
if (isEntrypoint) {
tooltip += `\n${file.rel} is the entrypoint. Entrypoints must be included in the configuration 'files' list.`;
}
if (isPackageFile) {
tooltip += `\n${file.rel} is a package file. Package files must be included in the configuration 'files' list.`;
}
return tooltip;
}

Expand Down

0 comments on commit ce97e9f

Please sign in to comment.