Skip to content

Commit

Permalink
fix(footer): set max-toolbar-items when mini table is used
Browse files Browse the repository at this point in the history
  • Loading branch information
micaelagoffe committed Dec 10, 2024
1 parent 4158e70 commit 0b0549d
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 81 deletions.
109 changes: 52 additions & 57 deletions lib/render-footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,61 +11,56 @@ export const renderFooter = ({
csvFilename,
xlsxFilename,
xlsxSheetname,
topPlacement
}) => {
return html`
<cosmoz-bottom-bar
id="bottomBar"
?active=${!isEmpty(selectedItems.length)}
>
<slot name="info" slot="info">
${ngettext(
'{0} selected item',
'{0} selected items',
selectedItems.length
)}
</slot>
<slot name="actions" id="actions"></slot>
<!-- These slots are needed by cosmoz-bottom-bar
topPlacement,
maxToolbarItems,
}) =>
html`<cosmoz-bottom-bar
id="bottomBar"
?active=${!isEmpty(selectedItems.length)}
?max-toolbar-items=${!isEmpty(maxToolbarItems)}
>
<slot name="info" slot="info">
${ngettext(
'{0} selected item',
'{0} selected items',
selectedItems.length,
)}
</slot>
<slot name="actions" id="actions"></slot>
<!-- These slots are needed by cosmoz-bottom-bar
as it might change the slot of the actions to distribute them in the menu -->
<slot name="bottom-bar-toolbar" slot="bottom-bar-toolbar"></slot>
<slot name="bottom-bar-menu" slot="bottom-bar-menu"></slot>
<cosmoz-dropdown-menu slot="extra" .placement=${topPlacement}>
<svg
slot="button"
width="14"
height="18"
viewBox="0 0 14 18"
fill="none"
stroke="currentColor"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M1 8.5L7.00024 14.5L13 8.5"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
<path d="M13 17L1 17" stroke-width="2" stroke-linecap="round" />
<path d="M7 1V13" stroke-width="2" stroke-linecap="round" />
</svg>
<button
@click=${() => saveAsCsvAction(columns, selectedItems, csvFilename)}
>
${_('Save as CSV')}
</button>
<button
@click=${() =>
saveAsXlsxAction(
columns,
selectedItems,
xlsxFilename,
xlsxSheetname
)}
>
${_('Save as XLSX')}
</button>
<slot name="download-menu"></slot>
</cosmoz-dropdown-menu>
</cosmoz-bottom-bar>`;
};
<slot name="bottom-bar-toolbar" slot="bottom-bar-toolbar"></slot>
<slot name="bottom-bar-menu" slot="bottom-bar-menu"></slot>
<cosmoz-dropdown-menu slot="extra" .placement=${topPlacement}>
<svg
slot="button"
width="14"
height="18"
viewBox="0 0 14 18"
fill="none"
stroke="currentColor"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M1 8.5L7.00024 14.5L13 8.5"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
<path d="M13 17L1 17" stroke-width="2" stroke-linecap="round" />
<path d="M7 1V13" stroke-width="2" stroke-linecap="round" />
</svg>
<button
@click=${() => saveAsCsvAction(columns, selectedItems, csvFilename)}
>
${_('Save as CSV')}
</button>
<button
@click=${() =>
saveAsXlsxAction(columns, selectedItems, xlsxFilename, xlsxSheetname)}
>
${_('Save as XLSX')}
</button>
<slot name="download-menu"></slot>
</cosmoz-dropdown-menu>
</cosmoz-bottom-bar>`;
8 changes: 6 additions & 2 deletions lib/use-fast-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ export const useFastLayout = ({
sortAndGroupOptions,
}) => {
const canvasWidth = useCanvasWidth(host),
{ miniColumn, miniColumns } = useMini({ host, canvasWidth, columns }),
{ isMini, miniColumn, miniColumns } = useMini({
host,
canvasWidth,
columns,
}),
{ groupOnColumn } = sortAndGroupOptions,
layout = useLayout({
canvasWidth,
Expand Down Expand Up @@ -52,5 +56,5 @@ export const useFastLayout = ({

useStyleSheet(layoutCss);

return { collapsedColumns, miniColumns };
return { isMini, collapsedColumns, miniColumns };
};
17 changes: 8 additions & 9 deletions lib/use-footer.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import { defaultPlacement } from '@neovici/cosmoz-dropdown';
const _defaultPlacement = ['top-right', ...defaultPlacement];

export const useFooter = ({
host,
...rest
}) => {
export const useFooter = ({ host, ...rest }) => {
const {
csvFilename = 'omnitable.csv',
xlsxFilename = 'omnitable.xlsx',
xlsxSheetname = 'Omnitable',
topPlacement = _defaultPlacement,
} = host;
csvFilename = 'omnitable.csv',
xlsxFilename = 'omnitable.xlsx',
xlsxSheetname = 'Omnitable',
topPlacement = _defaultPlacement,
maxToolbarItems,
} = host;

return {
csvFilename,
xlsxFilename,
xlsxSheetname,
topPlacement,
maxToolbarItems,
...rest,
};
};
25 changes: 13 additions & 12 deletions lib/use-mini.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@ export const useMini = ({ host, canvasWidth, columns: _columns }) => {
[canvasWidth, breakpoint],
);
const columns = useMemo(
() =>
isMiniSize
? _columns
?.filter((c) => c.mini != null)
.sort((a, b) => (a.mini ?? 0) - (b.mini ?? 0))
: [],
[_columns, isMiniSize],
);

const [miniColumn, ...miniColumns] = columns ?? [];
() =>
isMiniSize
? _columns
?.filter((c) => c.mini != null)
.sort((a, b) => (a.mini ?? 0) - (b.mini ?? 0))
: [],
[_columns, isMiniSize],
),
[miniColumn, ...miniColumns] = columns ?? [],
hasMiniColumn = !!miniColumn;

useEffect(() => {
host.toggleAttribute('mini', !!miniColumn);
}, [miniColumn]);
host.toggleAttribute('mini', hasMiniColumn);
}, [hasMiniColumn]);

return {
isMini: hasMiniColumn && isMiniSize,
miniColumn,
miniColumns,
};
Expand Down
4 changes: 3 additions & 1 deletion lib/use-omnitable.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ export const useOmnitable = (host) => {
noLocalSort,
noLocalFilter,
}),
{ collapsedColumns, miniColumns } = useFastLayout({
{ isMini, collapsedColumns, miniColumns } = useFastLayout({
host,
columns,
settings,
setSettings,
resizeSpeedFactor,
sortAndGroupOptions,
}),
maxToolbarItems = isMini ? '0' : undefined,
dataIsValid = data && Array.isArray(data) && data.length > 0,
[selectedItems, setSelectedItems] = useState([]);

Expand Down Expand Up @@ -94,6 +95,7 @@ export const useOmnitable = (host) => {
host,
selectedItems,
columns,
maxToolbarItems,
}),
};
};

0 comments on commit 0b0549d

Please sign in to comment.