Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/app/MenuButtons/Permalink.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class MenuButtonsPermalink extends React.PureComponent<Props, State> {
<ButtonWithPanel
buttonClassName="menuButtonsButton menuButtonsButton-hasIcon menuButtonsPermalinkButtonButton"
label="Permalink"
initialOpen={this.props.isNewlyPublished}
open={this.props.isNewlyPublished}
onPanelOpen={this._shortenUrlAndFocusTextFieldOnCompletion}
onPanelClose={this._onPermalinkPanelClose}
panelClassName="menuButtonsPermalinkPanel"
Expand Down
15 changes: 11 additions & 4 deletions src/components/shared/ButtonWithPanel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ type Props = {|
+label: string,
+panelContent: React.Node,
+panelClassName?: string,
// This prop tells the panel to be open by default, but the open/close state is fully
// managed by the ButtonWithPanel component.
+initialOpen?: boolean,
// Setting this prop to true opens the panel.
+open?: boolean,
// The class name of the button input element.
+buttonClassName?: string,
+onPanelOpen?: () => mixed,
Expand All @@ -57,7 +56,7 @@ export class ButtonWithPanel extends React.PureComponent<Props, State> {

constructor(props: Props) {
super(props);
this.state = { open: !!props.initialOpen };
this.state = { open: !!props.open };
}

componentDidMount() {
Expand All @@ -70,6 +69,14 @@ export class ButtonWithPanel extends React.PureComponent<Props, State> {
}
}

componentDidUpdate(prevProps: Props) {
// Open the panel when the open prop becomes true.
if (!prevProps.open && this.props.open) {
this.setState({ open: true });
this.openPanel();
}
}

componentWillUnmount() {
window.removeEventListener('keydown', this._onKeyDown);
window.removeEventListener('click', this._onWindowClick);
Expand Down
4 changes: 2 additions & 2 deletions src/test/components/ButtonWithPanel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('shared/ButtonWithPanel', () => {
<ButtonWithPanel
className="button"
label="My Button"
initialOpen={true}
open={true}
panelClassName="panel"
panelContent={<div>Panel content</div>}
/>
Expand Down Expand Up @@ -73,7 +73,7 @@ describe('shared/ButtonWithPanel', () => {
<ButtonWithPanel
className="button"
label="My Button"
initialOpen={true}
open={true}
panelContent={<div data-testid="panel-content">Panel content</div>}
/>
);
Expand Down
27 changes: 27 additions & 0 deletions src/test/components/MenuButtonsPermalinks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,31 @@ describe('<Permalink>', function () {
);
expect(input).toHaveValue(shortUrl);
});

it('opens the permalink panel when isNewlyPublished changes to true', async function () {
const { dispatch, queryInput, shortUrl, shortUrlPromise } = setup();

// Initially the panel should not be open
expect(queryInput()).toBeFalsy();

// Simulate a profile being published/re-uploaded by dispatching PROFILE_PUBLISHED
act(() => {
dispatch({
type: 'PROFILE_PUBLISHED',
hash: 'newhash',
profileName: 'test',
prePublishedState: null,
});
});

// Wait for the async operations to complete
await act(() => shortUrlPromise);

// The input should now be visible, indicating the panel opened automatically
const input = ensureExists(
queryInput(),
'Expected the permalink panel to open automatically after publishing'
);
expect(input).toHaveValue(shortUrl);
});
});