import React from 'react' ; import { Router } from 'react-router' ; import { createMemoryHistory } from 'history' ; import { ContextProvider , Context } from 'teleport' ; import Audit from './Audit' ; import EventList from './EventList' ; import { events , eventsSample } from './fixtures' ; export default { title : 'Teleport/Audit' , } ; export const LoadedSample = ( ) => { const ctx = new Context ( ) ; ctx . auditService . fetchEvents = ( ) => Promise . resolve ( { events : eventsSample , startKey : '' } ) ; return render ( ctx ) ; } ; export const LoadedFetchMore = ( ) => { const ctx = new Context ( ) ; ctx . auditService . fetchEvents = ( ) => Promise . resolve ( { events , startKey : 'any-text' } ) ; return render ( ctx ) ; } ; export const Processing = ( ) => { const ctx = new Context ( ) ; ctx . auditService . fetchEvents = ( ) => new Promise ( ( ) => null ) ; return render ( ctx ) ; } ; export const Failed = ( ) => { const ctx = new Context ( ) ; ctx . auditService . fetchEvents = ( ) => Promise . reject ( new Error ( 'server error' ) ) ; return render ( ctx ) ; } ; export const AllEvents = ( ) => ( < EventList clusterId = "im-a-cluster" events = { events } fetchMore = { ( ) => null } fetchStatus = { '' } pageSize = { 100 } / > ) ; function render ( ctx ) { const history = createMemoryHistory ( { initialEntries : [ '/web/cluster/localhost/audit/events' ] , initialIndex : 0 , } ) ; return ( < ContextProvider ctx = { ctx } > < Router history = { history } > < Audit /> < /Router> < /ContextProvider>); }