Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#66277 [atlassian-connect-js] Fix some type…
Browse files Browse the repository at this point in the history
…s and other improvements by @JoaoBrlt

* [atlassian-connect-js] Properly type the AP.navigator.getLocation() function.

* [atlassian-connect-js] Allow emitting an event without additional arguments.

* [atlassian-connect-js] Allow pushing any value to the history state.

* [atlassian-connect-js] Allow using generics to properly type macro data.

* [atlassian-connect-js] Allow using strings for the width and height of a dialog.

---------

Co-authored-by: JoĂŁo Brilhante <[email protected]>
  • Loading branch information
JoaoBrlt and jbrilhante-yogi authored Aug 4, 2023
1 parent 24b0fef commit 0c7f509
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
21 changes: 21 additions & 0 deletions types/atlassian-connect-js/atlassian-connect-js-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ AP.confluence.saveMacro({ foo: 'bar' }); // $ExpectType void
AP.confluence.closeMacroEditor(); // $ExpectType void
AP.confluence.getMacroBody(body => console.log(body)); // $ExpectType void
AP.confluence.getMacroData(data => console.log(data)); // $ExpectType void
AP.confluence.getMacroData<{ foo: string; bar: number }>(({ foo, bar }) => console.log(foo, bar)); // $ExpectType void
AP.confluence.onMacroPropertyPanelEvent({ '{event-type}.{control-key}.{macro-key}.macro.property-panel': () => null }); // $ExpectType void
AP.confluence.closeMacroPropertyPanel(); // $ExpectType void
AP.confluence.getContentProperty('propertyKey', property => console.log(property)); // $ExpectType void
Expand Down Expand Up @@ -62,7 +63,21 @@ editComponent.cancelCallback(false); // $ExpectType void
editComponent.cancelCallback(false, 'error'); // $ExpectType void

AP.dialog.create({ key: 'key', size: 'small', customData: { data: 1 } }); // $ExpectType Dialog
// $ExpectType Dialog
AP.dialog.create({
key: 'my-module-key',
width: '500px',
height: '200px',
chrome: true,
buttons: [
{
text: 'my button',
identifier: 'my_unique_identifier',
},
],
});
AP.dialog.close(); // $ExpectType void
AP.dialog.close({ foo: 'bar' }); // $ExpectType void
AP.dialog.getCustomData(data => console.log(data)); // $ExpectType void
AP.dialog.getButton('submit'); // $ExpectType {} | DialogButton
AP.dialog.disableCloseOnSubmit(); // $ExpectType void
Expand All @@ -83,7 +98,9 @@ AP.events.offAll('name'); // $ExpectType void
AP.events.offAllPublic('name'); // $ExpectType void
AP.events.offAny((name, data) => console.log(name, data)); // $ExpectType void
AP.events.offAnyPublic((name, data) => console.log(name, data)); // $ExpectType void
AP.events.emit('name'); // $ExpectType void
AP.events.emit('name', ['data']); // $ExpectType void
AP.events.emitPublic('name'); // $ExpectType void
AP.events.emitPublic('name', ['data']); // $ExpectType void

const flag = AP.flag.create({ title: 'title', body: 'body', type: 'info', actions: { test: 'text' } }); // $ExpectType Flag
Expand All @@ -93,6 +110,8 @@ AP.history.back(); // $ExpectType void
AP.history.forward(); // $ExpectType void
AP.history.go(-2); // $ExpectType void
AP.history.getState(); // $ExpectType string
AP.history.pushState(1); // $ExpectType void
AP.history.pushState('page2'); // $ExpectType void
AP.history.pushState({ state: 'state' }, 'title', 'https://example.com'); // $ExpectType void
AP.history.replaceState('https://example.com'); // $ExpectType void

Expand All @@ -110,6 +129,8 @@ AP.jira.showJQLEditor(obj => console.log(obj.jql), {}); // $ExpectType void
AP.jira.isNativeApp(isNative => console.log(isNative)); // $ExpectType void

AP.navigator.getLocation(location => console.log(location)); // $ExpectType void
AP.navigator.getLocation(location => console.log(location.target)); // $ExpectType void
AP.navigator.getLocation(location => console.log(location.context)); // $ExpectType void
AP.navigator.go('contentview', {}); // $ExpectType void
AP.navigator.go('issue', {}); // $ExpectType void
// $ExpectType void
Expand Down
28 changes: 21 additions & 7 deletions types/atlassian-connect-js/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ declare namespace AP {
* alert(data);
* });
*/
function getMacroData(callback: (data: object) => void): void;
// eslint-disable-next-line no-unnecessary-generics
function getMacroData<T extends object>(callback: (data: T) => void): void;

/**
* Get the body saved in the saveMacro method.
Expand Down Expand Up @@ -522,12 +523,12 @@ declare namespace AP {
/**
* if size is not set, define the width as a percentage (append a % to the number) or pixels.
*/
width?: number | undefined;
width?: number | string | undefined;

/**
* if size is not set, define the height as a percentage (append a % to the number) or pixels.
*/
height?: number | undefined;
height?: number | string | undefined;

/**
* (optional) opens the dialog with heading and buttons.
Expand Down Expand Up @@ -774,7 +775,7 @@ declare namespace AP {
* @param name The name of event to emit
* @param args 0 or more additional data arguments to deliver with the event
*/
function emit(name: string, args: string[]): void;
function emit(name: string, args?: string[]): void;

/**
* Emits a public event on this bus, firing listeners by name as well as all 'anyPublic' listeners.
Expand All @@ -785,7 +786,7 @@ declare namespace AP {
* @param name The name of event to emit
* @param args 0 or more additional data arguments to deliver with the event
*/
function emitPublic(name: string, args: string[]): void;
function emitPublic(name: string, args?: string[]): void;
}

/**
Expand Down Expand Up @@ -865,7 +866,7 @@ declare namespace AP {
* @param title
* @param url URL to add to history
*/
function pushState(newState: object, title: string, url: string): void;
function pushState(newState: any, title?: string, url?: string): void;

/**
* Updates the current entry in the session history. Updates the location's anchor with the specified value but does not change the session history. Does not invoke popState callback.
Expand Down Expand Up @@ -1233,6 +1234,19 @@ declare namespace AP {
*/
absoluteUrl: string;
}

interface NavigatorLocationContext {
/**
* The type of the page.
*/
target: NavigatorTargetJira | NavigatorTargetConfluence;

/**
* Specific information that identifies the page.
*/
context: Partial<NavigatorContext>;
}

/**
* Returns the context of the current page within the host application.
*
Expand All @@ -1247,7 +1261,7 @@ declare namespace AP {
* **contentedit** - the host application is currently editing a page, blog post or other content.
* @param callback
*/
function getLocation(callback: (location: string) => void): void;
function getLocation(callback: (location: NavigatorLocationContext) => void): void;

/**
* Navigates the user from the current page to the specified page. This call navigates the host product, not the iframe content.
Expand Down

0 comments on commit 0c7f509

Please sign in to comment.