Skip to content

Commit

Permalink
🐛 Refactor questionnaire template downloading (#1574)
Browse files Browse the repository at this point in the history
Resolves: https://issues.redhat.com/browse/MTA-1720

Refactor the questionnaire template download to follow the direct
download of the application / manage imports / download CSV template.

Summary of changes:
  - Move template files to `client/public/templates/`
  - Reconfigure webpack to copy the template folder to `dist/`
  - Update URLs for the new location
- Convert the questionnaire template download to use an `<a download>`
tag Button

Signed-off-by: Scott J Dickerson <sdickers@redhat.com>
  • Loading branch information
sjd78 committed Nov 28, 2023
1 parent ae8c567 commit 70d7db9
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 16 deletions.
6 changes: 3 additions & 3 deletions client/config/webpack.common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "path";
import { Configuration, WatchIgnorePlugin } from "webpack";
import { Configuration } from "webpack";
// import CaseSensitivePathsWebpackPlugin from "case-sensitive-paths-webpack-plugin";
import CopyPlugin from "copy-webpack-plugin";
import Dotenv from "dotenv-webpack";
Expand Down Expand Up @@ -181,8 +181,8 @@ const config: Configuration = {
to: pathTo("../dist/manifest.json"),
},
{
from: pathTo("../public/template_application_import.csv"),
to: pathTo("../dist/template_application_import.csv"),
from: pathTo("../public/templates"),
to: pathTo("../dist/templates"),
},
],
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export const ManageImports: React.FC = () => {
<a
{...props}
download
href="/template_application_import.csv"
href="/templates/template_application_import.csv"
/>
)}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ import { ExportQuestionnaireDropdownItem } from "./components/export-questionnai
import dayjs from "dayjs";
import { QuestionnaireQuestionsColumn } from "./components/questionnaire-questions-column";
import { QuestionnaireThresholdsColumn } from "./components/questionnaire-thresholds-column";
import saveAs from "file-saver";
import { load } from "js-yaml";
import questionnaireTemplateFile from "./questionnaire-template.yaml";

const AssessmentSettings: React.FC = () => {
const { t } = useTranslation();
Expand Down Expand Up @@ -157,14 +154,6 @@ const AssessmentSettings: React.FC = () => {
// TODO: Check RBAC access
const rbacWriteAccess = true; // checkAccess(userScopes, questionnaireWriteScopes);

const downloadTemplate = () => {
const parsedContent = load(questionnaireTemplateFile);
const blob = new Blob([JSON.stringify(parsedContent, null, 2)], {
type: "application/x-yaml",
});
saveAs(blob, "questionnaire-template.yaml");
};

return (
<>
<PageSection variant={PageSectionVariants.light}>
Expand Down Expand Up @@ -211,7 +200,9 @@ const AssessmentSettings: React.FC = () => {
id="download-yaml-template"
aria-label="Download questionnaire"
variant={ButtonVariant.link}
onClick={downloadTemplate}
component="a"
download
href="/templates/questionnaire-template.yaml"
>
{t("dialog.title.download", {
what: t("terms.YAMLTemplate"),
Expand Down

0 comments on commit 70d7db9

Please sign in to comment.