Skip to content

Commit 333baf8

Browse files
authored
A new permalink should be generated and shown after using the re-upload feature. (#5547)
1 parent a148dac commit 333baf8

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

src/components/app/MenuButtons/Permalink.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class MenuButtonsPermalink extends React.PureComponent<Props, State> {
7878
<ButtonWithPanel
7979
buttonClassName="menuButtonsButton menuButtonsButton-hasIcon menuButtonsPermalinkButtonButton"
8080
label="Permalink"
81-
initialOpen={this.props.isNewlyPublished}
81+
open={this.props.isNewlyPublished}
8282
onPanelOpen={this._shortenUrlAndFocusTextFieldOnCompletion}
8383
onPanelClose={this._onPermalinkPanelClose}
8484
panelClassName="menuButtonsPermalinkPanel"

src/components/shared/ButtonWithPanel/index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ type Props = {|
3636
+label: string,
3737
+panelContent: React.Node,
3838
+panelClassName?: string,
39-
// This prop tells the panel to be open by default, but the open/close state is fully
40-
// managed by the ButtonWithPanel component.
41-
+initialOpen?: boolean,
39+
// Setting this prop to true opens the panel.
40+
+open?: boolean,
4241
// The class name of the button input element.
4342
+buttonClassName?: string,
4443
+onPanelOpen?: () => mixed,
@@ -57,7 +56,7 @@ export class ButtonWithPanel extends React.PureComponent<Props, State> {
5756

5857
constructor(props: Props) {
5958
super(props);
60-
this.state = { open: !!props.initialOpen };
59+
this.state = { open: !!props.open };
6160
}
6261

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

72+
componentDidUpdate(prevProps: Props) {
73+
// Open the panel when the open prop becomes true.
74+
if (!prevProps.open && this.props.open) {
75+
this.setState({ open: true });
76+
this.openPanel();
77+
}
78+
}
79+
7380
componentWillUnmount() {
7481
window.removeEventListener('keydown', this._onKeyDown);
7582
window.removeEventListener('click', this._onWindowClick);

src/test/components/ButtonWithPanel.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('shared/ButtonWithPanel', () => {
4444
<ButtonWithPanel
4545
className="button"
4646
label="My Button"
47-
initialOpen={true}
47+
open={true}
4848
panelClassName="panel"
4949
panelContent={<div>Panel content</div>}
5050
/>
@@ -73,7 +73,7 @@ describe('shared/ButtonWithPanel', () => {
7373
<ButtonWithPanel
7474
className="button"
7575
label="My Button"
76-
initialOpen={true}
76+
open={true}
7777
panelContent={<div data-testid="panel-content">Panel content</div>}
7878
/>
7979
);

src/test/components/MenuButtonsPermalinks.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,31 @@ describe('<Permalink>', function () {
8888
);
8989
expect(input).toHaveValue(shortUrl);
9090
});
91+
92+
it('opens the permalink panel when isNewlyPublished changes to true', async function () {
93+
const { dispatch, queryInput, shortUrl, shortUrlPromise } = setup();
94+
95+
// Initially the panel should not be open
96+
expect(queryInput()).toBeFalsy();
97+
98+
// Simulate a profile being published/re-uploaded by dispatching PROFILE_PUBLISHED
99+
act(() => {
100+
dispatch({
101+
type: 'PROFILE_PUBLISHED',
102+
hash: 'newhash',
103+
profileName: 'test',
104+
prePublishedState: null,
105+
});
106+
});
107+
108+
// Wait for the async operations to complete
109+
await act(() => shortUrlPromise);
110+
111+
// The input should now be visible, indicating the panel opened automatically
112+
const input = ensureExists(
113+
queryInput(),
114+
'Expected the permalink panel to open automatically after publishing'
115+
);
116+
expect(input).toHaveValue(shortUrl);
117+
});
91118
});

0 commit comments

Comments
 (0)