-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1571: Import stores backend #1606
Changes from 5 commits
90415fb
3de4630
12deb10
cf835cb
29e2548
5fdf28e
c527405
e1f49cc
e515ae2
63a751f
1246274
5530ca3
56521be
33c7c05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
type DimensionsType = { | ||
navigationBarHeight: number | ||
bottomBarHeight: number | ||
} | ||
|
||
const dimensions: DimensionsType = { | ||
navigationBarHeight: 50, | ||
bottomBarHeight: 70, | ||
} | ||
export default dimensions |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Checkbox } from '@blueprintjs/core' | ||
import React, { ReactElement } from 'react' | ||
import styled from 'styled-components' | ||
|
||
const StyledCheckbox = styled(Checkbox)` | ||
margin: 12px 0; | ||
align-self: center; | ||
` | ||
|
||
const CheckboxContainer = styled.div` | ||
padding: 0 12px; | ||
display: flex; | ||
` | ||
|
||
type StoreImportAlertProps = { | ||
dryRun: boolean | ||
setDryRun: (value: boolean) => void | ||
} | ||
|
||
const StoresImportAlert = ({ dryRun, setDryRun }: StoreImportAlertProps): ReactElement => { | ||
return ( | ||
<> | ||
{dryRun ? ( | ||
<span data-testid='dry-run-alert'> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general, testing with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes i'm aware of this priority.
I think this is better readable for devs. |
||
<b>Testlauf:</b> In diesem Testlauf wird nur simuliert, wie viele Stores geupdated oder gelöscht werden | ||
f1sh1918 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
würden. Es werden keine Daten in die Datenbank geschrieben. | ||
</span> | ||
) : ( | ||
<span data-testid='prod-run-alert'> | ||
<b>Achtung:</b> Akzeptanzpartner, welche aktuell in der Datenbank gespeichert, aber nicht in der Tabelle | ||
vorhanden sind, werden gelöscht! | ||
</span> | ||
)} | ||
<CheckboxContainer> | ||
<StyledCheckbox checked={dryRun} onChange={e => setDryRun(e.currentTarget.checked)} label='Testlauf' /> | ||
</CheckboxContainer> | ||
</> | ||
) | ||
} | ||
|
||
export default StoresImportAlert |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,6 +1,7 @@ | ||||||
import { NonIdealState } from '@blueprintjs/core' | ||||||
import { NonIdealState, Spinner } from '@blueprintjs/core' | ||||||
import React, { ReactElement, useContext, useState } from 'react' | ||||||
import { useNavigate } from 'react-router-dom' | ||||||
import styled from 'styled-components' | ||||||
|
||||||
import { WhoAmIContext } from '../../WhoAmIProvider' | ||||||
import getMessageFromApolloError from '../../errors/getMessageFromApolloError' | ||||||
|
@@ -11,6 +12,7 @@ import { useAppToaster } from '../AppToaster' | |||||
import { AcceptingStoreEntry } from './AcceptingStoreEntry' | ||||||
import StoresButtonBar from './StoresButtonBar' | ||||||
import StoresCSVInput from './StoresCSVInput' | ||||||
import StoresImportResult from './StoresImportResult' | ||||||
import StoresTable from './StoresTable' | ||||||
|
||||||
const StoresImportController = (): ReactElement => { | ||||||
|
@@ -29,6 +31,13 @@ const StoresImportController = (): ReactElement => { | |||||
return <StoresImport fields={storeManagement.fields} /> | ||||||
} | ||||||
|
||||||
const CenteredSpinner = styled(Spinner)` | ||||||
z-index: 999; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggest to use 500 so we could possible put something before in the future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but what should be before an loading spinner f.e ? even its shown over a modal it should be highest index |
||||||
top: 50%; | ||||||
left: 50%; | ||||||
position: fixed; | ||||||
` | ||||||
|
||||||
type StoreImportProps = { | ||||||
fields: StoreFieldConfig[] | ||||||
} | ||||||
|
@@ -37,12 +46,25 @@ export type StoreData = { | |||||
[key: string]: string | ||||||
} | ||||||
const StoresImport = ({ fields }: StoreImportProps): ReactElement => { | ||||||
const { projectId } = useContext(ProjectConfigContext) | ||||||
const navigate = useNavigate() | ||||||
const appToaster = useAppToaster() | ||||||
const [acceptingStores, setAcceptingStores] = useState<AcceptingStoreEntry[]>([]) | ||||||
const [importStores] = useImportAcceptingStoresMutation({ | ||||||
onCompleted: () => { | ||||||
appToaster?.show({ intent: 'success', message: 'Ihre Akzeptanzpartner wurden importiert.' }) | ||||||
const [dryRun, setDryRun] = useState<boolean>(false) | ||||||
const [importStores, { loading: isApplyingStoreTransaction }] = useImportAcceptingStoresMutation({ | ||||||
onCompleted: ({ result }) => { | ||||||
appToaster?.show({ | ||||||
intent: 'none', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❓ Why 'none'?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think this is more an overview that just a success message. |
||||||
timeout: 0, | ||||||
message: ( | ||||||
<StoresImportResult | ||||||
dryRun={dryRun} | ||||||
storesUntouched={result.storesUntouched} | ||||||
storesDeleted={result.storesDeleted} | ||||||
storesCreated={result.storesCreated} | ||||||
/> | ||||||
), | ||||||
}) | ||||||
setAcceptingStores([]) | ||||||
}, | ||||||
onError: error => { | ||||||
|
@@ -59,16 +81,24 @@ const StoresImport = ({ fields }: StoreImportProps): ReactElement => { | |||||
} | ||||||
} | ||||||
|
||||||
const onImportStores = () => importStores({ variables: { stores: acceptingStores.map(store => store.data) } }) | ||||||
const onImportStores = () => | ||||||
importStores({ variables: { stores: acceptingStores.map(store => store.data), project: projectId, dryRun } }) | ||||||
|
||||||
return ( | ||||||
<> | ||||||
{isApplyingStoreTransaction && <CenteredSpinner intent='primary' />} | ||||||
{acceptingStores.length === 0 ? ( | ||||||
<StoresCSVInput setAcceptingStores={setAcceptingStores} fields={fields} /> | ||||||
) : ( | ||||||
<StoresTable fields={fields} acceptingStores={acceptingStores} /> | ||||||
)} | ||||||
<StoresButtonBar goBack={goBack} acceptingStores={acceptingStores} importStores={onImportStores} /> | ||||||
<StoresButtonBar | ||||||
goBack={goBack} | ||||||
acceptingStores={acceptingStores} | ||||||
importStores={onImportStores} | ||||||
dryRun={dryRun} | ||||||
setDryRun={setDryRun} | ||||||
/> | ||||||
</> | ||||||
) | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { H5 } from '@blueprintjs/core' | ||
import React, { ReactElement } from 'react' | ||
import styled from 'styled-components' | ||
|
||
const Container = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
` | ||
|
||
type StoreImportResultProps = { | ||
storesCreated: number | ||
storesDeleted: number | ||
storesUntouched: number | ||
dryRun: boolean | ||
} | ||
|
||
const StoresImportResult = ({ | ||
storesDeleted, | ||
storesUntouched, | ||
storesCreated, | ||
dryRun, | ||
}: StoreImportResultProps): ReactElement => { | ||
return ( | ||
<Container> | ||
<H5 data-testid='import-result-headline'>{`Der ${ | ||
dryRun ? 'Testimport' : 'Import' | ||
} der Akzeptanzpartner war erfolgreich!`}</H5> | ||
<span> | ||
{dryRun | ||
? 'Folgende Änderungen würden sich ergeben:' | ||
: 'Folgende Änderungen in der Datenbank wurden vorgenommen'} | ||
f1sh1918 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</span> | ||
<br /> | ||
<div> | ||
Akzeptanzstellen erstellt: <span data-testid='storesCreated'>{storesCreated}</span> | ||
</div> | ||
<div> | ||
Akzeptanzstellen gelöscht: <span data-testid='storesDeleted'>{storesDeleted}</span> | ||
</div> | ||
<div> | ||
Akzeptanzstellen unverändert: <span data-testid='storesUntouched'>{storesUntouched}</span> | ||
</div> | ||
</Container> | ||
) | ||
} | ||
|
||
export default StoresImportResult |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved this to the jest.setup for all tests using it