mirror of
https://github.com/rowyio/rowy.git
synced 2025-12-28 16:06:41 +01:00
Merge pull request #1306 from rowyio/feature/code-editor-quick-action-get-secrets
Add code editor quick action to get secrets
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { useEffect } from "react";
|
||||
import { useAtom } from "jotai";
|
||||
import { matchSorter } from "match-sorter";
|
||||
|
||||
import {
|
||||
tableScope,
|
||||
@@ -82,8 +83,6 @@ export default function useMonacoCustomizations({
|
||||
"ts:filename/utils.d.ts"
|
||||
);
|
||||
monaco.languages.typescript.javascriptDefaults.addExtraLib(rowyUtilsDefs);
|
||||
|
||||
setLoggingReplacementActions();
|
||||
} catch (error) {
|
||||
console.error(
|
||||
"An error occurred during initialization of Monaco: ",
|
||||
@@ -124,13 +123,13 @@ export default function useMonacoCustomizations({
|
||||
}
|
||||
}, [monaco, stringifiedDiagnosticsOptions]);
|
||||
|
||||
const setLoggingReplacementActions = () => {
|
||||
const setReplacementActions = () => {
|
||||
if (!monaco) return;
|
||||
const { dispose } = monaco.languages.registerCodeActionProvider(
|
||||
"javascript",
|
||||
{
|
||||
provideCodeActions: (model, range, context, token) => {
|
||||
const actions = context.markers
|
||||
const consoleLogReplacements = context.markers
|
||||
.filter((error) => {
|
||||
return error.message.includes("Rowy Cloud Logging");
|
||||
})
|
||||
@@ -156,8 +155,63 @@ export default function useMonacoCustomizations({
|
||||
isPreferred: true,
|
||||
};
|
||||
});
|
||||
const secretNameReplacements = context.markers
|
||||
.filter((error) => {
|
||||
return error.message.includes(
|
||||
"is not assignable to parameter of type 'SecretNames'"
|
||||
);
|
||||
})
|
||||
.map((error) => {
|
||||
const typoSecretName = model
|
||||
.getLineContent(error.startLineNumber)
|
||||
.slice(error.startColumn, error.endColumn - 2);
|
||||
const similarSecretNames =
|
||||
matchSorter(secretNames.secretNames ?? [], typoSecretName) ??
|
||||
[];
|
||||
const otherSecretNames =
|
||||
secretNames.secretNames?.filter(
|
||||
(secretName) => !similarSecretNames.includes(secretName)
|
||||
) ?? [];
|
||||
return [
|
||||
...similarSecretNames.map((secretName) => ({
|
||||
title: `Replace with "${secretName}"`,
|
||||
diagnostics: [error],
|
||||
kind: "quickfix",
|
||||
edit: {
|
||||
edits: [
|
||||
{
|
||||
resource: model.uri,
|
||||
edit: {
|
||||
range: error,
|
||||
text: `"${secretName}"`,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
isPreferred: true,
|
||||
})),
|
||||
...otherSecretNames.map((secretName) => ({
|
||||
title: `Replace with "${secretName}"`,
|
||||
diagnostics: [error],
|
||||
kind: "quickfix",
|
||||
edit: {
|
||||
edits: [
|
||||
{
|
||||
resource: model.uri,
|
||||
edit: {
|
||||
range: error,
|
||||
text: `"${secretName}"`,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
isPreferred: false,
|
||||
})),
|
||||
];
|
||||
})
|
||||
.flat();
|
||||
return {
|
||||
actions: actions,
|
||||
actions: [...consoleLogReplacements, ...secretNameReplacements],
|
||||
dispose: () => {},
|
||||
};
|
||||
},
|
||||
@@ -169,7 +223,6 @@ export default function useMonacoCustomizations({
|
||||
dispose();
|
||||
});
|
||||
};
|
||||
|
||||
const addJsonFieldDefinition = async (
|
||||
columnKey: string,
|
||||
interfaceName: string
|
||||
@@ -261,14 +314,16 @@ export default function useMonacoCustomizations({
|
||||
if (!secretNames.secretNames) return;
|
||||
const secretsDef = `type SecretNames = ${secretNames.secretNames
|
||||
.map((secret: string) => `"${secret}"`)
|
||||
.join(" | ")}
|
||||
.join(" | ")} \n
|
||||
enum secrets {
|
||||
${secretNames.secretNames
|
||||
.map((secret: string) => `${secret} = "${secret}"`)
|
||||
.map((secret: string) => `"${secret}" = "${secret}"`)
|
||||
.join("\n")}
|
||||
}
|
||||
`;
|
||||
monaco?.languages.typescript.javascriptDefaults.addExtraLib(secretsDef);
|
||||
|
||||
setReplacementActions();
|
||||
}, [monaco, secretNames]);
|
||||
|
||||
let boxSx: SystemStyleObject<Theme> = {
|
||||
|
||||
Reference in New Issue
Block a user