-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d9d2863
commit ded6316
Showing
4 changed files
with
196 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { useContext,} from "react"; | ||
import AppContext from "../AppContext"; | ||
import JSZip from "jszip"; | ||
import { saveAs } from "file-saver"; | ||
import { MenuItem } from "@mui/material"; | ||
|
||
export default function ExportArtifacts({ | ||
onClose | ||
}) { | ||
const { | ||
modifiedRule, | ||
syntaxCheck, | ||
schemaCheck, | ||
jsonCheck, | ||
loadDefineXMLCheck, | ||
loadDatasetsCheck, | ||
testCheck, | ||
} = useContext(AppContext); | ||
|
||
const exportArtifacts = async () => { | ||
const zip = new JSZip(); | ||
zip.file("Rule.yml", modifiedRule); | ||
zip.file( | ||
"Rule_spaces.json", | ||
JSON.stringify(syntaxCheck.details[0].details, null, 4) | ||
); | ||
zip.file( | ||
"Schema_Validation.json", | ||
JSON.stringify(schemaCheck.details[0].details, null, 4) | ||
); | ||
zip.file( | ||
"Rule_underscores.json", | ||
JSON.stringify(jsonCheck.details[0].details, null, 4) | ||
); | ||
zip.file("Define.xml", loadDefineXMLCheck.details[1]?.details ?? ""); | ||
zip.file("Datasets.xlsx", loadDatasetsCheck.details[0]?.details ?? ""); | ||
zip.file( | ||
"Datasets.json", | ||
JSON.stringify(loadDatasetsCheck.details[1]?.details ?? "", null, 4) | ||
); | ||
zip.file( | ||
"Request.json", | ||
JSON.stringify(testCheck.details[1]?.details ?? "", null, 4) | ||
); | ||
zip.file( | ||
"Results.json", | ||
JSON.stringify(testCheck.details[3]?.details ?? "", null, 4) | ||
); | ||
|
||
zip.generateAsync({ type: "blob" }).then((content) => { | ||
saveAs(content, "Rule.zip"); | ||
}); | ||
|
||
onClose(); | ||
}; | ||
return ( | ||
<MenuItem onClick={exportArtifacts}>Export debugging artifacts</MenuItem> | ||
); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import AppContext from "../AppContext"; | ||
import { useContext } from "react"; | ||
import { IFilter } from "../../types/IFilter"; | ||
import { saveAs } from "file-saver"; | ||
import { ColumnOption } from "csv-stringify/browser/esm/sync"; | ||
import { MenuItem } from "@mui/material"; | ||
import JSZip from "jszip"; | ||
|
||
const columns: ColumnOption[] = [ | ||
{ | ||
header: "id", | ||
key: "id", | ||
}, | ||
{ | ||
header: "ruleId", | ||
key: "json.Authorities.Standards.References.Rule Identifier.Id", | ||
}, | ||
{ | ||
header: "content", | ||
key: "content", | ||
}, | ||
]; | ||
|
||
const cast = (value) => | ||
Array.isArray(value) ? value.join(",") : JSON.stringify(value); | ||
|
||
export default function ExportRulesYAML({ onClose }) { | ||
const { dataService, orderBy, order, searchText, setAlertState } = useContext( | ||
AppContext | ||
); | ||
|
||
const exportRules = async () => { | ||
const params = { | ||
orderBy: orderBy, | ||
order: order, | ||
select: columns.map((column) => column.key), | ||
filters: Object.entries(searchText) | ||
.filter( | ||
([_, filterValue]: [string, string]) => | ||
!(filterValue == null || filterValue === "") | ||
) | ||
.map( | ||
([filterName, filterValue]: [string, string]): IFilter => ({ | ||
name: filterName, | ||
operator: "contains", | ||
value: filterValue, | ||
}) | ||
), | ||
}; | ||
const rules = []; | ||
setAlertState({ | ||
message: `Downloading Rules ${rules.length}/?...`, | ||
severity: "info", | ||
}); | ||
var currentRules = await dataService.get_rules_filter_sort(params); | ||
rules.push(...currentRules.rules); | ||
while (currentRules.next) { | ||
setAlertState({ | ||
message: `Downloading Rules ${rules.length}/?...`, | ||
severity: "info", | ||
}); | ||
currentRules = await dataService.get_rules_filter_sort(currentRules.next); | ||
rules.push(...currentRules.rules); | ||
} | ||
setAlertState({ | ||
message: `Saving ${rules.length} Rules...`, | ||
severity: "info", | ||
}); | ||
|
||
const zip = new JSZip(); | ||
for (const rule of rules) { | ||
zip.file( | ||
`${cast( | ||
rule["json.Authorities.Standards.References.Rule Identifier.Id"] | ||
)}.${rule["id"]}.yml`, | ||
rule["content"] | ||
); | ||
} | ||
zip.generateAsync({ type: "blob" }).then((content) => { | ||
saveAs(content, "Rules.zip"); | ||
}); | ||
|
||
setAlertState({ | ||
message: `Saved ${rules.length} Rules`, | ||
severity: "success", | ||
}); | ||
onClose(); | ||
}; | ||
|
||
return ( | ||
<MenuItem onClick={exportRules}>Export rules YAML (as filtered)</MenuItem> | ||
); | ||
} |