Skip to content

Commit

Permalink
[refactor] GH-7 Incapsulate MST initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
amivanoff committed Aug 31, 2021
1 parent 2fbef86 commit 59328dc
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 107 deletions.
53 changes: 27 additions & 26 deletions stories/AntdCardCell.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
********************************************************************************/
import moment from 'moment';
import React from 'react';
import { Story, Meta } from '@storybook/react/types-6-0';
import { Story, Meta } from '@storybook/react';

import { Provider } from 'react-redux';
import { asReduxStore, connectReduxDevtools } from 'mst-middlewares';
Expand Down Expand Up @@ -293,15 +293,6 @@ const additionalColls: CollState[] = [
},
];

registerMstViewKindSchema('aldkg:VerticalLayout', MstVerticalLayout);

const client = new SparqlClientImpl('https://rdf4j.agentlab.ru/rdf4j-server');
const rootStore = createUiModelFromState('mktp', client, rootModelInitialState, additionalColls);
console.log('rootStore', rootStore);
const store: any = asReduxStore(rootStore);
// eslint-disable-next-line @typescript-eslint/no-var-requires
connectReduxDevtools(require('remotedev'), rootStore);

export default {
title: 'Several Controls/TreeAndForm Cards',
component: Form,
Expand All @@ -310,19 +301,29 @@ export default {
},
} as Meta;

export const Empty: Story<{}> = () => (
<Provider store={store}>
<MstContextProvider store={rootStore} renderers={antdRenderers} cells={antdCells}>
<div
style={{
//height: '1000px',
width: '100%',
backgroundColor: 'rgba(230, 235, 242, 0.5)',
margin: '0 auto',
padding: '5px',
}}>
<Form viewDescrId={viewDescrs[0]['@id']} viewDescrCollId={viewDescrCollConstr['@id']} />
</div>
</MstContextProvider>
</Provider>
);
export const Empty: Story<{}> = () => {
registerMstViewKindSchema('aldkg:VerticalLayout', MstVerticalLayout);

const client = new SparqlClientImpl('https://rdf4j.agentlab.ru/rdf4j-server');
const rootStore = createUiModelFromState('mktp', client, rootModelInitialState, additionalColls);
console.log('rootStore', rootStore);
const store: any = asReduxStore(rootStore);
// eslint-disable-next-line @typescript-eslint/no-var-requires
connectReduxDevtools(require('remotedev'), rootStore);
return (
<Provider store={store}>
<MstContextProvider store={rootStore} renderers={antdRenderers} cells={antdCells}>
<div
style={{
//height: '1000px',
width: '100%',
backgroundColor: 'rgba(230, 235, 242, 0.5)',
margin: '0 auto',
padding: '5px',
}}>
<Form viewDescrId={viewDescrs[0]['@id']} viewDescrCollId={viewDescrCollConstr['@id']} />
</div>
</MstContextProvider>
</Provider>
);
};
31 changes: 16 additions & 15 deletions stories/Form.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,6 @@ const additionalColls: CollState[] = [
},
];

const client = new SparqlClientImpl('https://rdf4j.agentlab.ru/rdf4j-server');
const rootStore = createUiModelFromState('reqs2', client, rootModelInitialState, additionalColls);
const store: any = asReduxStore(rootStore);
// eslint-disable-next-line @typescript-eslint/no-var-requires
connectReduxDevtools(require('remotedev'), rootStore);

export default {
title: 'Form/ArtifactForm',
component: Form,
Expand All @@ -138,15 +132,22 @@ export default {
},
} as Meta;

const Template: Story<any> = (args: any) => (
<Provider store={store}>
<MstContextProvider store={rootStore} renderers={antdRenderers} cells={antdCells}>
<div style={{ height: '1000px' }}>
<Form viewDescrId={viewDescrs[0]['@id']} viewDescrCollId={viewDescrCollConstr['@id']} />
</div>
</MstContextProvider>
</Provider>
);
const Template: Story<any> = (args: any) => {
const client = new SparqlClientImpl('https://rdf4j.agentlab.ru/rdf4j-server');
const rootStore = createUiModelFromState('reqs2', client, rootModelInitialState, additionalColls);
const store: any = asReduxStore(rootStore);
// eslint-disable-next-line @typescript-eslint/no-var-requires
connectReduxDevtools(require('remotedev'), rootStore);
return (
<Provider store={store}>
<MstContextProvider store={rootStore} renderers={antdRenderers} cells={antdCells}>
<div style={{ height: '1000px' }}>
<Form viewDescrId={viewDescrs[0]['@id']} viewDescrCollId={viewDescrCollConstr['@id']} />
</div>
</MstContextProvider>
</Provider>
);
};

export const RemoteData = Template.bind({});
RemoteData.args = {};
31 changes: 16 additions & 15 deletions stories/FormOverride.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,6 @@ const additionalColls: CollState[] = [
},
];

const client = new SparqlClientImpl('https://rdf4j.agentlab.ru/rdf4j-server');
const rootStore = createUiModelFromState('reqs2', client, rootModelInitialState, additionalColls);
const store: any = asReduxStore(rootStore);
// eslint-disable-next-line @typescript-eslint/no-var-requires
connectReduxDevtools(require('remotedev'), rootStore);

export default {
title: 'Form/ArtifactFormOverride',
component: Form,
Expand All @@ -156,15 +150,22 @@ export default {
},
} as Meta;

const Template: Story<any> = (args: any) => (
<Provider store={store}>
<MstContextProvider store={rootStore} renderers={antdRenderers} cells={antdCells}>
<div style={{ height: '1000px' }}>
<Form viewDescrId={viewDescrs[0]['@id']} viewDescrCollId={viewDescrCollConstr['@id']} />
</div>
</MstContextProvider>
</Provider>
);
const Template: Story<any> = (args: any) => {
const client = new SparqlClientImpl('https://rdf4j.agentlab.ru/rdf4j-server');
const rootStore = createUiModelFromState('reqs2', client, rootModelInitialState, additionalColls);
const store: any = asReduxStore(rootStore);
// eslint-disable-next-line @typescript-eslint/no-var-requires
connectReduxDevtools(require('remotedev'), rootStore);
return (
<Provider store={store}>
<MstContextProvider store={rootStore} renderers={antdRenderers} cells={antdCells}>
<div style={{ height: '1000px' }}>
<Form viewDescrId={viewDescrs[0]['@id']} viewDescrCollId={viewDescrCollConstr['@id']} />
</div>
</MstContextProvider>
</Provider>
);
};

export const RemoteData = Template.bind({});
RemoteData.args = {};
67 changes: 50 additions & 17 deletions stories/TreeAndForm.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@
********************************************************************************/
import moment from 'moment';
import React from 'react';
import { Story, Meta } from '@storybook/react/types-6-0';
import { Story, Meta } from '@storybook/react';

import { Provider } from 'react-redux';
import { asReduxStore, connectReduxDevtools } from 'mst-middlewares';
import { SparqlClientImpl, rootModelInitialState, CollState } from '@agentlab/sparql-jsld-client';
import {
CollState,
JsStrObj,
Results,
rootModelInitialState,
sendGet,
SparqlClientImpl,
} from '@agentlab/sparql-jsld-client';

import {
antdCells,
Expand Down Expand Up @@ -357,12 +364,6 @@ const additionalColls: CollState[] = [
},
];

const client = new SparqlClientImpl('https://rdf4j.agentlab.ru/rdf4j-server');
const rootStore = createUiModelFromState('mktp', client, rootModelInitialState, additionalColls);
const store: any = asReduxStore(rootStore);
// eslint-disable-next-line @typescript-eslint/no-var-requires
connectReduxDevtools(require('remotedev'), rootStore);

export default {
title: 'Several Controls/TreeAndForm Mktp',
component: Form,
Expand All @@ -371,12 +372,44 @@ export default {
},
} as Meta;

export const Empty: Story<{}> = () => (
<Provider store={store}>
<MstContextProvider store={rootStore} renderers={antdRenderers} cells={antdCells}>
<div style={{ height: '1000px', width: '100%' }}>
<Form viewDescrId={viewDescrs[0]['@id']} viewDescrCollId={viewDescrCollConstr['@id']} />
</div>
</MstContextProvider>
</Provider>
);
class SparqlClientImpl2 extends SparqlClientImpl {
async loadNs() {
const url = 'https://rdf4j.agentlab.ru/rdf4j-server/repositories/mktp/namespaces';
const response = await sendGet(url);
if (response.status < 200 && response.status > 204) return Promise.reject('Cannot get namespaces');
const ns: JsStrObj = {};
//console.debug('response.data', response.data);
if (response.data && response.data.results) {
let results: Results = { bindings: [] };
results = response.data.results;
if (results) {
results.bindings.forEach((b) => {
if (b.prefix && b.namespace && b.prefix.value && b.namespace.value) {
ns[b.prefix.value] = b.namespace.value;
}
});
}
}
ns['sesame'] = 'http://www.openrdf.org/schema/sesame#';
return ns;
}
}

export const Empty: Story<{}> = () => {
//const client = new SparqlClientImpl('https://rdf4j.agentlab.ru/rdf4j-server');
//const rootStore = createUiModelFromState('mktp', client, rootModelInitialState, additionalColls);
const client = new SparqlClientImpl2('https://rdf4j.agentlab.ru/rdf4j-server');
const rootStore = createUiModelFromState('mktp-fed', client, rootModelInitialState, additionalColls);
const store: any = asReduxStore(rootStore);
// eslint-disable-next-line @typescript-eslint/no-var-requires
connectReduxDevtools(require('remotedev'), rootStore);
return (
<Provider store={store}>
<MstContextProvider store={rootStore} renderers={antdRenderers} cells={antdCells}>
<div style={{ height: '1000px', width: '100%' }}>
<Form viewDescrId={viewDescrs[0]['@id']} viewDescrCollId={viewDescrCollConstr['@id']} />
</div>
</MstContextProvider>
</Provider>
);
};
35 changes: 18 additions & 17 deletions stories/TreeAndFormArtifact.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
********************************************************************************/
import moment from 'moment';
import React from 'react';
import { Story, Meta } from '@storybook/react/types-6-0';
import { Story, Meta } from '@storybook/react';

import { Provider } from 'react-redux';
import { asReduxStore, connectReduxDevtools } from 'mst-middlewares';
import { SparqlClientImpl, rootModelInitialState, CollState } from '@agentlab/sparql-jsld-client';
import { CollState, rootModelInitialState, SparqlClientImpl } from '@agentlab/sparql-jsld-client';

import {
antdCells,
Expand Down Expand Up @@ -166,12 +166,6 @@ const additionalColls: CollState[] = [
},
];

const client = new SparqlClientImpl('https://rdf4j.agentlab.ru/rdf4j-server');
const rootStore = createUiModelFromState('reqs2', client, rootModelInitialState, additionalColls);
const store: any = asReduxStore(rootStore);
// eslint-disable-next-line @typescript-eslint/no-var-requires
connectReduxDevtools(require('remotedev'), rootStore);

export default {
title: 'Several Controls/TreeAndForm Artifacts',
component: Form,
Expand All @@ -180,12 +174,19 @@ export default {
},
} as Meta;

export const Empty: Story<{}> = () => (
<Provider store={store}>
<MstContextProvider store={rootStore} renderers={antdRenderers} cells={antdCells}>
<div style={{ height: '1000px', width: '100%' }}>
<Form viewDescrId={viewDescrs[0]['@id']} viewDescrCollId={viewDescrCollConstr['@id']} />
</div>
</MstContextProvider>
</Provider>
);
export const Empty: Story<{}> = () => {
const client = new SparqlClientImpl('https://rdf4j.agentlab.ru/rdf4j-server');
const rootStore = createUiModelFromState('reqs2', client, rootModelInitialState, additionalColls);
const store: any = asReduxStore(rootStore);
// eslint-disable-next-line @typescript-eslint/no-var-requires
connectReduxDevtools(require('remotedev'), rootStore);
return (
<Provider store={store}>
<MstContextProvider store={rootStore} renderers={antdRenderers} cells={antdCells}>
<div style={{ height: '1000px', width: '100%' }}>
<Form viewDescrId={viewDescrs[0]['@id']} viewDescrCollId={viewDescrCollConstr['@id']} />
</div>
</MstContextProvider>
</Provider>
);
};
35 changes: 18 additions & 17 deletions stories/TreeAndFormColumns.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
********************************************************************************/
import moment from 'moment';
import React from 'react';
import { Story, Meta } from '@storybook/react/types-6-0';
import { Story, Meta } from '@storybook/react';

import { Provider } from 'react-redux';
import { asReduxStore, connectReduxDevtools } from 'mst-middlewares';
import { SparqlClientImpl, rootModelInitialState, CollState } from '@agentlab/sparql-jsld-client';
import { CollState, rootModelInitialState, SparqlClientImpl } from '@agentlab/sparql-jsld-client';

import {
antdCells,
Expand Down Expand Up @@ -288,12 +288,6 @@ const additionalColls: CollState[] = [
},
];

const client = new SparqlClientImpl('https://rdf4j.agentlab.ru/rdf4j-server');
const rootStore = createUiModelFromState('mktp', client, rootModelInitialState, additionalColls);
const store: any = asReduxStore(rootStore);
// eslint-disable-next-line @typescript-eslint/no-var-requires
connectReduxDevtools(require('remotedev'), rootStore);

export default {
title: 'Several Controls/Tree And Form with Columns',
component: Form,
Expand All @@ -302,12 +296,19 @@ export default {
},
} as Meta;

export const Empty: Story<{}> = () => (
<Provider store={store}>
<MstContextProvider store={rootStore} renderers={antdRenderers} cells={antdCells}>
<div style={{ height: '1000px', width: '100%' }}>
<Form viewDescrId={viewDescrs[0]['@id']} viewDescrCollId={viewDescrCollConstr['@id']} />
</div>
</MstContextProvider>
</Provider>
);
export const Empty: Story<{}> = () => {
const client = new SparqlClientImpl('https://rdf4j.agentlab.ru/rdf4j-server');
const rootStore = createUiModelFromState('mktp', client, rootModelInitialState, additionalColls);
const store: any = asReduxStore(rootStore);
// eslint-disable-next-line @typescript-eslint/no-var-requires
connectReduxDevtools(require('remotedev'), rootStore);
return (
<Provider store={store}>
<MstContextProvider store={rootStore} renderers={antdRenderers} cells={antdCells}>
<div style={{ height: '1000px', width: '100%' }}>
<Form viewDescrId={viewDescrs[0]['@id']} viewDescrCollId={viewDescrCollConstr['@id']} />
</div>
</MstContextProvider>
</Provider>
);
};

0 comments on commit 59328dc

Please sign in to comment.