Skip to content

Commit

Permalink
Add UI for updating default retro settings
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenWeathers committed Oct 16, 2024
1 parent 8e1f9a0 commit ff0357c
Show file tree
Hide file tree
Showing 5 changed files with 266 additions and 29 deletions.
2 changes: 1 addition & 1 deletion ui/src/components/poker/CreatePokerGame.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@
class="block text-gray-700 dark:text-gray-400 text-sm font-bold mb-2"
for="joinCode"
>
{$LL.passCode()}
{$LL.joinCodeLabelOptional()}
</label>
<div class="control">
<TextInput
Expand Down
11 changes: 6 additions & 5 deletions ui/src/components/poker/PokerSettings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { user } from '../../stores';
import BooleanDisplay from '../global/BooleanDisplay.svelte';
import UpdatePokerSettings from './UpdatePokerSettings.svelte';
import LL from '../../i18n/i18n-svelte';
export let xfetch;
export let notifications;
Expand Down Expand Up @@ -75,12 +76,12 @@
/>
<Table>
<tr slot="header">
<HeadCol>AutoFinishVoting</HeadCol>
<HeadCol>PointAverageRounding</HeadCol>
<HeadCol>HideVoterIdentity</HeadCol>
<HeadCol>{$LL.autoFinishVotingLabel()}</HeadCol>
<HeadCol>{$LL.pointAverageRounding()}</HeadCol>
<HeadCol>{$LL.hideVoterIdentity()}</HeadCol>
<!-- <HeadCol>Estimation Scale ID</HeadCol>-->
<HeadCol>Join Code</HeadCol>
<HeadCol>Facilitator Code</HeadCol>
<HeadCol>{$LL.joinCodeLabelOptional()}</HeadCol>
<HeadCol>{$LL.facilitatorCodeOptional()}</HeadCol>
</tr>
<tbody slot="body">
{#if defaultSettings.id !== ''}
Expand Down
5 changes: 2 additions & 3 deletions ui/src/components/poker/UpdatePokerSettings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import SolidButton from '../global/SolidButton.svelte';
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
export let toggleClose = () => {};
export let xfetch;
export let notifications;
Expand All @@ -29,6 +27,7 @@
facilitatorCode: '',
};
const dispatch = createEventDispatcher();
const allowedPointAverages = ['ceil', 'round', 'floor'];
// let estimationScales = []
Expand Down Expand Up @@ -134,7 +133,7 @@
class="block text-gray-700 dark:text-gray-400 text-sm font-bold mb-2"
for="joinCode"
>
{$LL.passCode()}
{$LL.joinCodeLabelOptional()}
</label>
<div class="control">
<TextInput
Expand Down
67 changes: 47 additions & 20 deletions ui/src/components/retro/RetroSettings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import { validateUserIsAdmin } from '../../validationUtils';
import { user } from '../../stores';
import BooleanDisplay from '../global/BooleanDisplay.svelte';
import UpdateRetroSettings from './UpdateRetroSettings.svelte';
import LL from '../../i18n/i18n-svelte';
export let xfetch;
export let notifications;
Expand All @@ -23,12 +25,11 @@
let defaultSettings = {
id: '',
maxVotes: 0,
allowMultipleVotes: false,
brainstormVisibility: false,
brainstormVisibility: '',
phaseTimeLimit: 0,
phaseAutoAdvance: false,
allowCumulativeVoting: false,
templateId: '',
templateId: null,
joinCode: '',
facilitatorCode: '',
};
Expand All @@ -46,12 +47,17 @@
async function getDefaultSettings() {
const response = await xfetch(`${apiPrefix}/retro-settings`);
if (response.ok) {
defaultSettings = await response.json();
const res = await response.json();
defaultSettings = res.data;
} else {
notifications.error('Failed to get default retro settings');
}
}
function handleSettingsUpdate(event) {
defaultSettings = event.detail.settings;
}
getDefaultSettings();
</script>

Expand All @@ -72,15 +78,14 @@
/>
<Table>
<tr slot="header">
<HeadCol>MaxVotes</HeadCol>
<HeadCol>AllowMultipleVotes</HeadCol>
<HeadCol>BrainstormVisibility</HeadCol>
<HeadCol>PhaseTimeLimit</HeadCol>
<HeadCol>PhaseAutoAdvance</HeadCol>
<HeadCol>AllowCumulativeVoting</HeadCol>
<HeadCol>{$LL.retroMaxVotesPerUserLabel()}</HeadCol>
<HeadCol>{$LL.brainstormPhaseFeedbackVisibility()}</HeadCol>
<HeadCol>{$LL.retroPhaseTimeLimitMinLabel()}</HeadCol>
<HeadCol>{$LL.phaseAutoAdvanceLabel()}</HeadCol>
<HeadCol>{$LL.allowCumulativeVotingLabel()}</HeadCol>
<!-- <HeadCol>TemplateId</HeadCol>-->
<HeadCol>Join Code</HeadCol>
<HeadCol>Facilitator Code</HeadCol>
<HeadCol>{$LL.joinCodeLabelOptional()}</HeadCol>
<HeadCol>{$LL.facilitatorCodeOptional()}</HeadCol>
</tr>
<tbody slot="body">
{#if defaultSettings.id !== ''}
Expand All @@ -89,14 +94,7 @@
{defaultSettings.maxVotes}
</RowCol>
<RowCol>
<BooleanDisplay
boolValue="{defaultSettings.allowMultipleVotes}"
/>
</RowCol>
<RowCol>
<BooleanDisplay
boolValue="{defaultSettings.brainstormVisibility}"
/>
{defaultSettings.brainstormVisibility}
</RowCol>
<RowCol>
{defaultSettings.phaseTimeLimit}
Expand All @@ -123,4 +121,33 @@
</tbody>
</Table>
</TableContainer>

{#if showCreateDefaultSettings}
<UpdateRetroSettings
toggleClose="{toggleCreateDefaultSettings}"
xfetch="{xfetch}"
notifications="{notifications}"
apiPrefix="{apiPrefix}"
organizationId="{organizationId}"
teamId="{teamId}"
departmentId="{departmentId}"
eventTag="{eventTag}"
on:updateRetroSettings="{handleSettingsUpdate}"
/>
{/if}

{#if showUpdateDefaultSettings}
<UpdateRetroSettings
toggleClose="{toggleUpdateDefaultSettings}"
xfetch="{xfetch}"
notifications="{notifications}"
retroSettings="{defaultSettings}"
apiPrefix="{apiPrefix}"
organizationId="{organizationId}"
teamId="{teamId}"
departmentId="{departmentId}"
eventTag="{eventTag}"
on:updateRetroSettings="{handleSettingsUpdate}"
/>
{/if}
</div>
210 changes: 210 additions & 0 deletions ui/src/components/retro/UpdateRetroSettings.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
<script lang="ts">
import Modal from '../global/Modal.svelte';
import SelectInput from '../forms/SelectInput.svelte';
import LL from '../../i18n/i18n-svelte';
import Checkbox from '../forms/Checkbox.svelte';
import { Crown, Lock } from 'lucide-svelte';
import TextInput from '../forms/TextInput.svelte';
import SolidButton from '../global/SolidButton.svelte';
import { createEventDispatcher } from 'svelte';
export let toggleClose = () => {};
export let xfetch;
export let notifications;
export let eventTag;
export let organizationId;
export let teamId;
export let departmentId;
export let apiPrefix = '/api';
export let isEntityAdmin = false;
export let retroSettings = {
id: '',
maxVotes: 3,
allowMultipleVotes: false,
brainstormVisibility: 'visible',
phaseTimeLimit: 0,
phaseAutoAdvance: true,
allowCumulativeVoting: false,
templateId: null,
joinCode: '',
facilitatorCode: '',
};
const dispatch = createEventDispatcher();
const brainstormVisibilityOptions = [
{
label: $LL.brainstormVisibilityLabelVisible(),
value: 'visible',
},
{
label: $LL.brainstormVisibilityLabelConcealed(),
value: 'concealed',
},
{
label: $LL.brainstormVisibilityLabelHidden(),
value: 'hidden',
},
];
const maxPhaseTimeLimitMin = 59;
async function handleSubmit() {
const method = retroSettings.id !== '' ? 'PUT' : 'POST';
// hack because of svelte bug where binding to dynamic number input doesn't keep type
retroSettings.maxVotes = parseInt(`${retroSettings.maxVotes}`, 10);
retroSettings.phaseTimeLimit = parseInt(
`${retroSettings.phaseTimeLimit}`,
10,
);
if (
retroSettings.phaseTimeLimit > maxPhaseTimeLimitMin ||
retroSettings.phaseTimeLimit < 0
) {
notifications.danger('Phase Time Limit minutes must be between 0-59');
return;
}
const response = await xfetch(`${apiPrefix}/retro-settings`, {
method,
body: retroSettings,
});
if (response.ok) {
const res = await response.json();
retroSettings = res.data;
dispatch('updateRetroSettings', { settings: retroSettings });
notifications.success(
`Default retro settings ${method === 'PUT' ? 'updated' : 'created'}`,
);
toggleClose();
} else {
notifications.error(
`Failed to ${
method === 'PUT' ? 'update' : 'create'
} default retro settings`,
);
}
}
</script>

<Modal closeModal="{toggleClose}">
<form on:submit|preventDefault="{handleSubmit}" class="mt-6 space-y-6">
<div>
<label
class="block text-gray-700 dark:text-gray-400 text-sm font-bold mb-2"
for="maxVotes"
>
{$LL.retroMaxVotesPerUserLabel()}
</label>
<div class="control">
<TextInput
name="maxVotes"
bind:value="{retroSettings.maxVotes}"
id="maxVotes"
type="number"
min="1"
max="10"
required
/>
</div>
</div>

<div>
<Checkbox
bind:checked="{retroSettings.allowCumulativeVoting}"
id="allowCumulativeVoting"
name="allowCumulativeVoting"
label="{$LL.allowCumulativeVotingLabel()}"
/>
</div>

<div>
<label
class="text-gray-700 dark:text-gray-400 text-sm font-bold mb-2"
for="brainstormVisibility"
>
{$LL.brainstormPhaseFeedbackVisibility()}
</label>
<SelectInput
bind:value="{retroSettings.brainstormVisibility}"
id="brainstormVisibility"
name="brainstormVisibility"
>
{#each brainstormVisibilityOptions as item}
<option value="{item.value}">
{item.label}
</option>
{/each}
</SelectInput>
</div>

<div>
<label
class="block text-gray-700 dark:text-gray-400 text-sm font-bold mb-2"
for="phaseTimeLimitMin"
>
{$LL.retroPhaseTimeLimitMinLabel()}
</label>
<div class="control">
<TextInput
name="phaseTimeLimitMin"
bind:value="{retroSettings.phaseTimeLimit}"
id="phaseTimeLimitMin"
type="number"
min="0"
max="{maxPhaseTimeLimitMin}"
required
/>
</div>
</div>

<div>
<Checkbox
bind:checked="{retroSettings.phaseAutoAdvance}"
id="phaseAutoAdvance"
name="phaseAutoAdvance"
label="{$LL.phaseAutoAdvanceLabel()}"
/>
</div>

<div>
<label
class="block text-gray-700 dark:text-gray-400 text-sm font-bold mb-2"
for="joinCode"
>
{$LL.joinCodeLabelOptional()}
</label>
<div class="control">
<TextInput
name="joinCode"
bind:value="{retroSettings.joinCode}"
placeholder="{$LL.joinCodePlaceholder()}"
id="joinCode"
icon="{Lock}"
/>
</div>
</div>

<div>
<label
class="block text-gray-700 dark:text-gray-400 text-sm font-bold mb-2"
for="leaderCode"
>
{$LL.facilitatorCodeOptional()}
</label>
<div class="control">
<TextInput
name="leaderCode"
bind:value="{retroSettings.facilitatorCode}"
placeholder="{$LL.facilitatorCodePlaceholder()}"
id="leaderCode"
icon="{Crown}"
/>
</div>
</div>

<div class="text-right">
<SolidButton type="submit">Save Settings</SolidButton>
</div>
</form>
</Modal>

0 comments on commit ff0357c

Please sign in to comment.