From 66c2837d2cf5f4ed0342023c46eaeee302a4fbec Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Tue, 18 Jul 2023 09:03:52 -0400 Subject: [PATCH] Fix add command in backstage (#24043) --- .../abstract_command.test.tsx.snap | 469 ++++++++++++++++++ .../integrations/abstract_command.test.tsx | 12 + .../integrations/abstract_command.tsx | 44 +- 3 files changed, 513 insertions(+), 12 deletions(-) diff --git a/webapp/channels/src/components/integrations/__snapshots__/abstract_command.test.tsx.snap b/webapp/channels/src/components/integrations/__snapshots__/abstract_command.test.tsx.snap index 82f849c5a0..3e06bac1cc 100644 --- a/webapp/channels/src/components/integrations/__snapshots__/abstract_command.test.tsx.snap +++ b/webapp/channels/src/components/integrations/__snapshots__/abstract_command.test.tsx.snap @@ -471,6 +471,475 @@ exports[`components/integrations/AbstractCommand should match snapshot 1`] = ` `; +exports[`components/integrations/AbstractCommand should match snapshot when header/footer/loading is a string 1`] = ` +
+ + + + + + Header as string + + +
+
+
+ +
+ +
+ +
+
+
+
+ +
+ +
+ +
+
+
+
+ +
+ +
+ +
+
+ +
+
+ + + , + } + } + /> +
+
+
+
+ +
+ +
+ +
+
+
+
+ +
+ +
+ +
+
+
+
+ +
+ +
+ +
+
+
+
+ +
+ +
+ +
+
+
+
+ +
+ +
+ +
+
+
+
+ +
+ +
+ +
+
+
+
+ +
+ +
+ +
+
+
+
+ + + + + + + Footer as string + + +
+ renderExtra +
+
+
+
+
+`; + exports[`components/integrations/AbstractCommand should match snapshot, displays client error 1`] = `
{ expect(wrapper).toMatchSnapshot(); }); + test('should match snapshot when header/footer/loading is a string', () => { + const wrapper = shallow( + , + ); + expect(wrapper).toMatchSnapshot(); + }); + test('should match snapshot, displays client error', () => { const newSeverError = 'server error'; const props = {...baseProps, serverError: newSeverError}; diff --git a/webapp/channels/src/components/integrations/abstract_command.tsx b/webapp/channels/src/components/integrations/abstract_command.tsx index f32f0c1751..d907f6233c 100644 --- a/webapp/channels/src/components/integrations/abstract_command.tsx +++ b/webapp/channels/src/components/integrations/abstract_command.tsx @@ -31,17 +31,17 @@ type Props = { /** * The header text to render, has id and defaultMessage */ - header: MessageDescriptor; + header: MessageDescriptor | string; /** * The footer text to render, has id and defaultMessage */ - footer: MessageDescriptor; + footer: MessageDescriptor | string; /** * The spinner loading text to render, has id and defaultMessage */ - loading: MessageDescriptor; + loading: MessageDescriptor | string; /** * Any extra component/node to render @@ -103,6 +103,32 @@ export default class AbstractCommand extends React.PureComponent { }; }; + getBackstageHeader = () => { + if (typeof this.props.header === 'string') { + return {this.props.header}; + } + + return ( + + ); + }; + + getBackstageFooter = () => { + if (typeof this.props.footer === 'string') { + return {this.props.footer}; + } + + return ( + + ); + }; + handleSubmit = (e: React.FormEvent) => { e.preventDefault(); @@ -362,10 +388,7 @@ export default class AbstractCommand extends React.PureComponent { defaultMessage='Slash Commands' /> - + {this.getBackstageHeader()}
{ className='btn btn-primary' type='submit' spinning={this.state.saving} - spinningText={Utils.localizeMessage(this.props.loading?.id ?? '', this.props.loading?.defaultMessage as string)} + spinningText={typeof this.props.loading === 'string' ? this.props.loading : Utils.localizeMessage(this.props.loading?.id ?? '', this.props.loading?.defaultMessage as string)} onClick={this.handleSubmit} id='saveCommand' > - + {this.getBackstageFooter()} {this.props.renderExtra}