This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/syndesisio/syndesis-react …
…into TTOOLS-616
- Loading branch information
Showing
129 changed files
with
2,404 additions
and
824 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { DataShape, FilterOptions, Op } from '@syndesis/models'; | ||
import * as React from 'react'; | ||
import { IFetchState } from './Fetch'; | ||
import { SyndesisFetch } from './SyndesisFetch'; | ||
|
||
export interface IWithFilterOptionsProps { | ||
dataShape: DataShape; | ||
children(props: IFetchState<FilterOptions>): any; | ||
} | ||
|
||
function getDefaultOps() { | ||
return [ | ||
{ | ||
label: 'equals', | ||
operator: '==', | ||
}, | ||
{ | ||
label: 'equals (ignores case)', | ||
operator: '=~', | ||
}, | ||
{ | ||
label: 'not equals', | ||
operator: '==', | ||
}, | ||
{ | ||
operator: '<', | ||
}, | ||
{ | ||
operator: '<=', | ||
}, | ||
{ | ||
operator: '>', | ||
}, | ||
{ | ||
operator: '>=', | ||
}, | ||
{ | ||
label: 'contains', | ||
operator: 'contains', | ||
}, | ||
{ | ||
label: 'contains (ignore case)', | ||
operator: '~~', | ||
}, | ||
{ | ||
label: 'not contains', | ||
operator: 'not contains', | ||
}, | ||
{ | ||
label: 'matches', | ||
operator: 'regex', | ||
}, | ||
{ | ||
label: 'not matches', | ||
operator: 'not regex', | ||
}, | ||
{ | ||
label: 'in', | ||
operator: 'in', | ||
}, | ||
{ | ||
label: 'not in', | ||
operator: 'not in', | ||
}, | ||
]; | ||
} | ||
|
||
export interface IOp { | ||
label: string; | ||
operator?: string; | ||
value?: string; | ||
} | ||
|
||
function convertOps(ops: Op[]): Op[] { | ||
const answer = []; | ||
for (const op of ops) { | ||
// guard against blank label | ||
const label = op.label || (op as IOp).value || op.operator; | ||
const newOp = { | ||
label, | ||
value: (op as IOp).value || op.operator, | ||
} as IOp; | ||
answer.push(newOp); | ||
} | ||
return answer; | ||
} | ||
|
||
export class WithFilterOptions extends React.Component< | ||
IWithFilterOptionsProps | ||
> { | ||
public render() { | ||
const defaultValue = { | ||
ops: [], | ||
paths: [], | ||
}; | ||
return ( | ||
<SyndesisFetch<FilterOptions> | ||
body={this.props.dataShape} | ||
defaultValue={defaultValue} | ||
method={'POST'} | ||
url={`/integrations/filters/options`} | ||
> | ||
{({ response }) => { | ||
const ops = response.data.ops!.length | ||
? response.data.ops! | ||
: getDefaultOps(); | ||
const data = { | ||
ops: convertOps(ops), | ||
paths: response.data.paths || [], | ||
}; | ||
return this.props.children({ | ||
...response, | ||
data, | ||
}); | ||
}} | ||
</SyndesisFetch> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import * as React from 'react'; | ||
import { ApiContext, IApiContext } from './ApiContext'; | ||
import { callFetch } from './callFetch'; | ||
|
||
export interface IWithUserHelpersChildrenProps { | ||
logout(): Promise<any>; | ||
} | ||
export interface IWithUserHelpersProps { | ||
children(props: IWithUserHelpersChildrenProps): any; | ||
} | ||
|
||
export class WithUserHelpersWrapped extends React.Component< | ||
IWithUserHelpersProps & IApiContext | ||
> { | ||
constructor(props: IWithUserHelpersProps & IApiContext) { | ||
super(props); | ||
this.logout = this.logout.bind(this); | ||
} | ||
|
||
public async logout() { | ||
const response = await callFetch({ | ||
headers: { | ||
...this.props.headers, | ||
responseType: 'arraybuffer', | ||
}, | ||
method: 'GET', | ||
url: `${process.env.PUBLIC_URL}/logout`, | ||
}); | ||
return await response.body; | ||
} | ||
|
||
public render() { | ||
return this.props.children({ | ||
logout: this.logout, | ||
}); | ||
} | ||
} | ||
|
||
export const WithUserHelpers: React.FunctionComponent< | ||
IWithUserHelpersProps | ||
> = props => { | ||
return ( | ||
<ApiContext.Consumer> | ||
{apiContext => <WithUserHelpersWrapped {...props} {...apiContext} />} | ||
</ApiContext.Consumer> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.