Skip to content

Commit

Permalink
Add error handling to getEditableJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
AllegroFox committed Oct 30, 2024
1 parent 67303f5 commit f902127
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
5 changes: 4 additions & 1 deletion app/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ export const fxmsMessageColumns: ColumnDef<FxMSMessageInfo>[] = [
header: "",
cell: (props: any) => {
const supportedTypes = ["infobar", "spotlight"];
if (supportedTypes.includes(props.row.original.template)) {
if (
supportedTypes.includes(props.row.original.template) &&
props.row.original.editableJson
) {
return (
<button
onClick={() =>
Expand Down
31 changes: 24 additions & 7 deletions lib/messageUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,33 @@ export function maybeCreateWelcomePreview(message: any): object {
return message;
}

export function getEditableJSON(message: any): string {
export function getEditableJSON(message: any): string | undefined {
// fallbacks for important properties
if (message.template === "spotlight") {
message.content.screens.forEach((screen: any) => {
if (!screen.id) {
screen.id = message.content.id;
switch (message.template) {
case "spotlight":
try {
message.content.screens.forEach((screen: any) => {
if (!screen.id) {
screen.id = message.content.id;
}
});
return message;
} catch (e) {
console.log("Could not generate editable JSON: ", e);
}
});
break;
case "infobar":
try {
if (message.content && message.content.buttons) {
return message;
}
} catch (e) {
console.log("Could note generate editable JSON: ", e);
}
break;
default:
return undefined;
}
return message;
}

export function getPreviewLink(message: any): string {
Expand Down

0 comments on commit f902127

Please sign in to comment.