Skip to content

Commit

Permalink
update flashbars
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkRoss-Eviden committed Jan 21, 2025
1 parent 0384f6e commit 3379964
Showing 1 changed file with 49 additions and 3 deletions.
52 changes: 49 additions & 3 deletions new/src/pages/models.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ interface State {
flashMessages: FlashbarProps.MessageDefinition[];
}

interface FlashbarProps {
MessageDefinition: {
id: string;
type: string;
content: string;
};
}

class Models extends React.Component<{}, State> {
fileInput: HTMLInputElement | null = null;

Expand All @@ -44,15 +52,34 @@ class Models extends React.Component<{}, State> {
};

deleteModels = async () => {
const csrfToken = this.getCsrfToken();
if (!csrfToken) {
console.error('CSRF token meta tag not found');
return;
}
try {
const response = await axios.post("/api/deleteModels", {
filenames: this.state.selectedModels.map(model => model.name)
filenames: this.state.selectedModels.map(model => model.name),
'X-CSRF-Token': csrfToken
});
if (response.data.success) {
this.getModels(); // Refresh the model list after deletion
this.setState({
flashMessages: [
...this.state.flashMessages,
{ type: "success", content: "Model deleted successfully" }
]
});
}
} catch (error) {
console.error("Error deleting models:", error);
this.getModels(); // Refresh the model list after deletion
this.setState({
flashMessages: [
...this.state.flashMessages,
{ type: "success", content: "Error deleting model" }
]
});
}
};

Expand Down Expand Up @@ -173,14 +200,33 @@ class Models extends React.Component<{}, State> {
return `${formattedDate} ${formattedTime}`;
};

removeFlashMessage = (id: string) => {
this.setState((prevState) => ({
flashMessages: prevState.flashMessages.filter(message => message.id !== id)
}));
};

renderFlashMessages() {
return (
<Flashbar
items={this.state.flashMessages.map(message => ({
content: message.content,
dismissible: true,
onDismiss: () => this.removeFlashMessage(message.id),
id: message.id
}))}
/>
);
}

render() {
const { models, selectedModels, flashMessages } = this.state;
const { models, selectedModels } = this.state;

return (
<BaseAppLayout
content={
<TextContent>
<Flashbar items={flashMessages} />
{this.renderFlashMessages()}
<h1>Models</h1>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<h2>Reinforcement learning models</h2>
Expand Down

0 comments on commit 3379964

Please sign in to comment.