Skip to content
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

Add column functionality to EditDashboard component #2097

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
441e881
feat: Add column functionality to EditDashboard component
Terdious Jun 3, 2024
13230cc
fix: i18n, prettier and eslint
Terdious Jun 3, 2024
d977bc6
chore: Update EditDashboard component state handling and fix boxNotEm…
Terdious Jun 4, 2024
bdda5f7
fix: prettier
Terdious Jun 4, 2024
fc8bc79
fix: Fix bug in EditBoxColumns component
Terdious Jun 4, 2024
c8cf074
fix: Remove delete column button from translation files
Terdious Jun 4, 2024
31ade93
fix: Update German translation file
Terdious Jun 4, 2024
df8c3ad
Merge branch 'master' into add-choice-number-columns-dashboard
Terdious Jun 4, 2024
e240059
fix: Improve accessibility and styling of EditBoxColumns component
Terdious Jun 7, 2024
161e4c4
fix: Improve German translation for "Add a column on dashboard"
Terdious Jun 7, 2024
f59e389
fix: Improve column layout in EditBoxColumns component
Terdious Jun 7, 2024
146dd19
fix: Improve column layout and accessibility in EditBoxColumns component
Terdious Jun 9, 2024
9df1bff
fix: prettier+eslint
Terdious Jun 10, 2024
b2e5663
fix: prettier
Terdious Jun 10, 2024
c6b55c9
refactor: reordered styles
Terdious Jun 10, 2024
7cda77a
fix: review non-useful code
Terdious Jun 10, 2024
ec5fd5a
Improve column layout and accessibility in EditBoxColumns component
Terdious Jun 12, 2024
a0bf86d
Merge branch 'master' into add-choice-number-columns-dashboard
Terdious Jun 12, 2024
89d1200
Merge branch 'master' into add-choice-number-columns-dashboard
Terdious Jun 13, 2024
513a316
Merge branch 'master' into add-choice-number-columns-dashboard
Terdious Jun 13, 2024
68a7eec
fix: review
Terdious Jun 13, 2024
e170399
fix: review
Terdious Jun 13, 2024
0809b3b
fix: review delete mutationObserver and resizeObserver
Terdious Jun 13, 2024
57ca61d
refactor: review - EditBoxColumns component - delete position sticky
Terdious Jun 13, 2024
678ee43
refactor: remove position sticky from EditBoxColumns component and an…
Terdious Jun 17, 2024
786a4a9
fix: prettier
Terdious Jun 17, 2024
4bf2dea
update columns
Terdious Aug 29, 2024
c12f95a
Merge branch 'GladysAssistant:master' into add-choice-number-columns-…
Terdious Aug 29, 2024
2d61715
style: Remove unnecessary CSS properties in edit-dashboard style.css
Terdious Aug 30, 2024
925614c
style: Update EditBoxColumns class to include 'align-items-start'
Terdious Aug 30, 2024
815af8f
style: Update media query breakpoints in edit-dashboard style.css
Terdious Aug 30, 2024
9e30e4c
style: Add min-width to columnBoxHeader in edit-dashboard style.css
Terdious Aug 30, 2024
710f469
Merge branch 'master' into add-choice-number-columns-dashboard
Terdious Sep 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions front/src/config/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@
"private": "privat",
"public": "öffentlich"
},
"editDashboardAddColumnButton": "Eine Spalte zum Dashboard hinzufügen",
"editDashboardBoxNotEmpty": "Sie können diese Spalte nicht löschen, da sie Widgets enthält.",
"editDashboardMyDashboards": "Meine Dashboards",
"editDashboardExplanation": "Jedes Dashboard hat 3 Spalten, die du nach Belieben füllen kannst. Klicke auf \"+\", um ein neues Widget hinzuzufügen. Du kannst dieses Widget bewegen, indem du es greifst und verschiebst.",
"reorderDashboardButton": "Dashboards neu anordnen",
Expand Down
2 changes: 2 additions & 0 deletions front/src/config/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@
"private": "private",
"public": "public"
},
"editDashboardAddColumnButton": "Add a column on dashboard",
"editDashboardBoxNotEmpty": "You cannot delete this column as it contains widgets.",
"editDashboardMyDashboards": "My dashboards",
"editDashboardExplanation": "Each dashboard has 3 columns, which you can fill in according to your preferences. Click on the + button to add a new widget. You can move this widget by grabbing it and moving it around.",
"reorderDashboardButton": "Re-order dashboards",
Expand Down
2 changes: 2 additions & 0 deletions front/src/config/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@
"private": "privé",
"public": "public"
},
"editDashboardAddColumnButton": "Ajouter une colonne au tableau de bord",
"editDashboardBoxNotEmpty": "Vous ne pouvez pas supprimer cette colonne car elle contient des widgets.",
"editDashboardMyDashboards": "Mes tableaux de bords",
"editDashboardExplanation": "Chaque tableau de bord comporte 3 colonnes, que vous pouvez remplir selon vos préférences. Cliquez sur le bouton + pour ajouter un nouveau widget. Vous pouvez déplacer ce widget en l'attrapant et en le déplaçant.",
"reorderDashboardButton": "Re-ordonner",
Expand Down
41 changes: 23 additions & 18 deletions front/src/routes/dashboard/BoxColumns.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,28 @@ import Box from './Box';
import cx from 'classnames';
import style from './style.css';

const BoxColumns = ({ children, ...props }) => (
<div class="d-flex flex-row flex-wrap justify-content-center">
{props.homeDashboard &&
props.homeDashboard.boxes.map((column, x) => (
<div
class={cx('d-flex flex-column col-lg-4', {
[style.removePaddingFirstCol]: x === 0,
[style.removePaddingLastCol]: x === 2,
[style.removePadding]: true // it will remove padding when in mobile view
})}
>
{column.map((box, y) => (
<Box key={`${props.homeDashboard.id}-${x}-${y}`} box={box} x={x} y={y} />
))}
</div>
))}
</div>
);
const BoxColumns = ({ children, ...props }) => {
const boxesLength = props.homeDashboard.boxes.length;
const columnClass = `col-lg-${12 / boxesLength}`;

return (
<div class="d-flex flex-row flex-wrap justify-content-center">
{props.homeDashboard &&
props.homeDashboard.boxes.map((column, x) => (
<div
class={cx('d-flex flex-column', columnClass, style.removePadding, {
[style.removePaddingFirstCol]: x === 0,
[style.removePaddingLastCol]: x === boxesLength - 1,
[style.removePadding]: true // it will remove padding when in mobile view
})}
>
{column.map((box, y) => (
<Box key={`${props.homeDashboard.id}-${x}-${y}`} box={box} x={x} y={y} />
))}
</div>
))}
</div>
);
};

export default BoxColumns;
92 changes: 65 additions & 27 deletions front/src/routes/dashboard/edit-dashboard/EditBoxColumns.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ import EditBox from './EditBox';
import EmptyColumnDropZone from './EmptyColumnDropZone';
import BottomDropZone from './BottomDropZone';
import AutoScrollMobile from '../../../components/drag-and-drop/AutoScrollMobile';
import style from '../style.css';
import style from './style.css';
import stylePrimary from '../style.css';
import { DASHBOARD_VISIBILITY_LIST } from '../../../../../server/utils/constants';

const DASHBOARD_EDIT_BOX_TYPE = 'DASHBOARD_EDIT_BOX';
const maxBoxes = 3;
const getBoxesLength = props => {
return props.homeDashboard.boxes.length;
};

const EditBoxColumns = ({ children, ...props }) => (
<div class="pb-6">
Expand Down Expand Up @@ -89,7 +94,7 @@ const EditBoxColumns = ({ children, ...props }) => (
<Text id="dashboard.editDashboardExplanation" />
</div>
</div>
<div class="row mb-6">
<div class="row mb-4">
<div class="col-md-4 d-lg-none d-xl-none">
<button
class={cx('btn', {
Expand All @@ -106,44 +111,77 @@ const EditBoxColumns = ({ children, ...props }) => (
</div>
<DndProvider backend={props.isTouchDevice ? TouchBackend : HTML5Backend}>
{props.isMobileReordering && <AutoScrollMobile position="top" box_type={DASHBOARD_EDIT_BOX_TYPE} />}
<div class="d-flex flex-row flex-wrap justify-content-center">
<div class={cx('d-flex align-items-start', style.columnsCard)}>
{props.homeDashboard &&
props.homeDashboard.boxes &&
props.homeDashboard.boxes.map((column, x) => (
<div
class={cx('d-flex flex-column col-lg-4', style.removePadding, {
[style.removePaddingFirstCol]: x === 0,
[style.removePaddingLastCol]: x === 2
class={cx('d-flex flex-column', style.column, stylePrimary.removePadding, {
[stylePrimary.removePaddingFirstCol]: x === 0,
[stylePrimary.removePaddingLastCol]: x === maxBoxes - 1
})}
>
<h3 class="text-center">
<Text id="dashboard.boxes.column" fields={{ index: x + 1 }} />
</h3>

{column.length > 0 && (
<div>
{column.map((box, y) => (
<EditBox {...props} box={box} x={x} y={y} isMobileReordering={props.isMobileReordering} />
))}
<BottomDropZone
moveCard={props.moveCard}
x={x}
y={column.length}
isMobileReordering={props.isMobileReordering}
/>
<div class={cx('d-flex', 'justify-content-center', style.columnBoxHeader)}>
<h3 class="d-flex justify-content-center text-center">
<Text id="dashboard.boxes.column" fields={{ index: x + 1 }} />
{getBoxesLength(props) > 1 && (
<button
class={cx('btn p-0 ml-2', style.btnLinkDelete)}
onClick={() => props.deleteCurrentColumn(x)}
>
<i class="fe fe-trash" />
</button>
)}
</h3>
</div>
{props.boxNotEmptyError && props.columnBoxNotEmptyError === x && (
<div class="alert alert-danger d-flex justify-content-center mb-4">
<Text id="dashboard.editDashboardBoxNotEmpty" />
</div>
)}
<div>
{column.length > 0 && (
<div>
{column.map((box, y) => (
<EditBox {...props} box={box} x={x} y={y} isMobileReordering={props.isMobileReordering} />
))}
<BottomDropZone
moveCard={props.moveCard}
x={x}
y={column.length}
isMobileReordering={props.isMobileReordering}
/>
</div>
)}

{column.length === 0 && <EmptyColumnDropZone moveCard={props.moveCard} x={x} />}
{column.length === 0 && <EmptyColumnDropZone moveCard={props.moveCard} x={x} />}

{props.isMobileReordering && <AutoScrollMobile position="bottom" box_type={DASHBOARD_EDIT_BOX_TYPE} />}
<div class="d-flex justify-content-center mb-4">
<button class="btn btn-primary" onClick={() => props.addBox(x)}>
<Text id="dashboard.addBoxButton" /> <i class="fe fe-plus" />
</button>
{props.isMobileReordering && <AutoScrollMobile position="bottom" box_type={DASHBOARD_EDIT_BOX_TYPE} />}
<div class="d-flex justify-content-center mb-4">
<button class="btn btn-primary" onClick={() => props.addBox(x)}>
<Text id="dashboard.addBoxButton" /> <i class="fe fe-plus" />
</button>
</div>
</div>
</div>
))}
{getBoxesLength(props) < maxBoxes && (
<div class={cx('d-flex flex-column', style.columnAddButton)}>
<div class={cx(style.columnBoxHeader)} />
<Localizer>
<button
class={cx('btn btn-outline-primary', style.btnAddColumn)}
onClick={() => props.addColumn(getBoxesLength(props))}
data-title={<Text id="dashboard.editDashboardAddColumnButton" />}
>
<i class="fe fe-plus" />
<div class={cx('d-none', style.displayTextMobile)}>
<Text id="dashboard.editDashboardAddColumnButton" />
</div>
</button>
</Localizer>
</div>
)}
</div>
</DndProvider>
</div>
Expand Down
4 changes: 4 additions & 0 deletions front/src/routes/dashboard/edit-dashboard/EditDashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ const EditDashboard = ({ children, ...props }) => (
savingNewDashboardList={props.savingNewDashboardList}
isMobileReordering={props.isMobileReordering}
toggleMobileReorder={props.toggleMobileReorder}
deleteCurrentColumn={props.deleteCurrentColumn}
addColumn={props.addColumn}
boxNotEmptyError={props.boxNotEmptyError}
columnBoxNotEmptyError={props.columnBoxNotEmptyError}
/>
)}
</div>
Expand Down
44 changes: 41 additions & 3 deletions front/src/routes/dashboard/edit-dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class EditDashboard extends Component {
}
}
});
await this.setState(newState);
await this.setState({ ...newState, boxNotEmptyError: false });
};

addBox = x => {
Expand All @@ -127,7 +127,7 @@ class EditDashboard extends Component {
}
}
});
await this.setState(newState);
await this.setState({ ...newState, boxNotEmptyError: false });
};

updateCurrentDashboardName = e => {
Expand Down Expand Up @@ -164,7 +164,7 @@ class EditDashboard extends Component {
}
}
});
this.setState(newState);
this.setState({ ...newState, boxNotEmptyError: false });
};

updateNewSelectedBox = (x, y, type) => {
Expand Down Expand Up @@ -252,6 +252,36 @@ class EditDashboard extends Component {
}
};

addColumn = () => {
const newState = update(this.state, {
currentDashboard: {
boxes: {
$push: [[]]
}
}
});
this.setState({ ...newState, boxNotEmptyError: false });
};

deleteCurrentColumn = async x => {
const { boxes } = this.state.currentDashboard;
if (boxes[x].length === 0) {
const newState = update(this.state, {
currentDashboard: {
boxes: {
$splice: [[x, 1]]
}
}
});
await this.setState({ ...newState, boxNotEmptyError: false });
} else {
this.setState({
boxNotEmptyError: true,
columnBoxNotEmptyError: x
});
}
};

askDeleteCurrentDashboard = async () => {
await this.setState({
askDeleteDashboard: true
Expand Down Expand Up @@ -313,6 +343,8 @@ class EditDashboard extends Component {
dashboards: [],
newSelectedBoxType: {},
askDeleteDashboard: false,
boxNotEmptyError: false,
columnBoxNotEmptyError: null,
isMobileReordering: false
};
}
Expand All @@ -337,6 +369,8 @@ class EditDashboard extends Component {
dashboardAlreadyExistError,
unknownError,
askDeleteDashboard,
boxNotEmptyError,
columnBoxNotEmptyError,
savingNewDashboardList,
isMobileReordering
}
Expand Down Expand Up @@ -373,6 +407,10 @@ class EditDashboard extends Component {
savingNewDashboardList={savingNewDashboardList}
toggleMobileReorder={this.toggleMobileReorder}
isMobileReordering={isMobileReordering}
addColumn={this.addColumn}
deleteCurrentColumn={this.deleteCurrentColumn}
boxNotEmptyError={boxNotEmptyError}
columnBoxNotEmptyError={columnBoxNotEmptyError}
/>
);
}
Expand Down
Loading
Loading