-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to latest shlink-web-component
- Loading branch information
Showing
5 changed files
with
135 additions
and
96 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,60 @@ | ||
import { LabeledFormGroup, SimpleCard, ToggleSwitch } from '@shlinkio/shlink-frontend-kit'; | ||
import type { Settings, VisitsSettings as VisitsSettingsConfig } from '@shlinkio/shlink-web-component'; | ||
import type { FC } from 'react'; | ||
import { useCallback } from 'react'; | ||
import { FormGroup } from 'reactstrap'; | ||
import type { DateInterval } from '../utils/dates/DateIntervalSelector'; | ||
import { DateIntervalSelector } from '../utils/dates/DateIntervalSelector'; | ||
import { FormText } from '../utils/forms/FormText'; | ||
|
||
interface VisitsProps { | ||
type VisitsProps = { | ||
settings: Settings; | ||
setVisitsSettings: (settings: VisitsSettingsConfig) => void; | ||
} | ||
}; | ||
|
||
const currentDefaultInterval = (settings: Settings): DateInterval => settings.visits?.defaultInterval ?? 'last30Days'; | ||
|
||
export const VisitsSettings: FC<VisitsProps> = ({ settings, setVisitsSettings }) => ( | ||
<SimpleCard title="Visits" className="h-100"> | ||
<FormGroup> | ||
<ToggleSwitch | ||
checked={!!settings.visits?.excludeBots} | ||
onChange={(excludeBots) => setVisitsSettings( | ||
{ defaultInterval: currentDefaultInterval(settings), excludeBots }, | ||
)} | ||
> | ||
Exclude bots wherever possible (this option‘s effect might depend on Shlink server‘s version). | ||
<FormText> | ||
The visits coming from potential bots will be <b>{settings.visits?.excludeBots ? 'excluded' : 'included'}</b>. | ||
</FormText> | ||
</ToggleSwitch> | ||
</FormGroup> | ||
<LabeledFormGroup noMargin label="Default interval to load on visits sections:"> | ||
<DateIntervalSelector | ||
allText="All visits" | ||
active={currentDefaultInterval(settings)} | ||
onChange={(defaultInterval) => setVisitsSettings({ defaultInterval })} | ||
/> | ||
</LabeledFormGroup> | ||
</SimpleCard> | ||
); | ||
export const VisitsSettings: FC<VisitsProps> = ({ settings, setVisitsSettings }) => { | ||
const updateSettings = useCallback( | ||
({ defaultInterval, ...rest }: Partial<VisitsSettingsConfig>) => setVisitsSettings( | ||
{ defaultInterval: defaultInterval ?? currentDefaultInterval(settings), ...rest }, | ||
), | ||
[setVisitsSettings, settings], | ||
); | ||
|
||
return ( | ||
<SimpleCard title="Visits" className="h-100"> | ||
<FormGroup> | ||
<ToggleSwitch | ||
checked={!!settings.visits?.excludeBots} | ||
onChange={(excludeBots) => updateSettings({ excludeBots })} | ||
> | ||
Exclude bots wherever possible (this option‘s effect might depend on Shlink server‘s version). | ||
<FormText> | ||
The visits coming from potential bots will | ||
be <b>{settings.visits?.excludeBots ? 'excluded' : 'included'}</b>. | ||
</FormText> | ||
</ToggleSwitch> | ||
</FormGroup> | ||
<FormGroup> | ||
<ToggleSwitch | ||
checked={!!settings.visits?.loadPrevInterval} | ||
onChange={(loadPrevInterval) => updateSettings({ loadPrevInterval })} | ||
> | ||
Compare visits with previous period. | ||
<FormText> | ||
When loading visits, previous period <b>{settings.visits?.loadPrevInterval ? 'will' : 'won\'t'}</b> be | ||
loaded by default. | ||
</FormText> | ||
</ToggleSwitch> | ||
</FormGroup> | ||
<LabeledFormGroup noMargin label="Default interval to load on visits sections:"> | ||
<DateIntervalSelector | ||
allText="All visits" | ||
active={currentDefaultInterval(settings)} | ||
onChange={(defaultInterval) => updateSettings({ defaultInterval })} | ||
/> | ||
</LabeledFormGroup> | ||
</SimpleCard> | ||
); | ||
}; |
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