Fix show and hide all buttons
This commit is contained in:
parent
594b2eb04c
commit
d2a92e2c90
|
@ -11,30 +11,20 @@
|
||||||
$: anyHidden = $columns.some(col => !col.visible)
|
$: anyHidden = $columns.some(col => !col.visible)
|
||||||
$: text = getText($columns)
|
$: text = getText($columns)
|
||||||
|
|
||||||
const toggleVisibility = async (column, visible) => {
|
const toggleColumn = async (column, visible) => {
|
||||||
datasource.actions.addSchemaMutation(column.name, { visible })
|
datasource.actions.addSchemaMutation(column.name, { visible })
|
||||||
await datasource.actions.saveSchemaMutations()
|
await datasource.actions.saveSchemaMutations()
|
||||||
dispatch(visible ? "show-column" : "hide-column")
|
dispatch(visible ? "show-column" : "hide-column")
|
||||||
}
|
}
|
||||||
|
|
||||||
const showAll = async () => {
|
const toggleAll = async visible => {
|
||||||
let mutations = {}
|
let mutations = {}
|
||||||
columns.forEach(column => {
|
$columns.forEach(column => {
|
||||||
mutations[column.name] = { visible: true }
|
mutations[column.name] = { visible }
|
||||||
})
|
})
|
||||||
datasource.actions.addSchemaMutations(mutations)
|
datasource.actions.addSchemaMutations(mutations)
|
||||||
await datasource.actions.saveSchemaMutations()
|
await datasource.actions.saveSchemaMutations()
|
||||||
dispatch("show-column")
|
dispatch(visible ? "show-column" : "hide-column")
|
||||||
}
|
|
||||||
|
|
||||||
const hideAll = async () => {
|
|
||||||
let mutations = {}
|
|
||||||
columns.forEach(column => {
|
|
||||||
mutations[column.name] = { visible: false }
|
|
||||||
})
|
|
||||||
datasource.actions.addSchemaMutations(mutations)
|
|
||||||
await datasource.actions.saveSchemaMutations()
|
|
||||||
dispatch("hide-column")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const getText = columns => {
|
const getText = columns => {
|
||||||
|
@ -74,14 +64,14 @@
|
||||||
<Toggle
|
<Toggle
|
||||||
size="S"
|
size="S"
|
||||||
value={column.visible}
|
value={column.visible}
|
||||||
on:change={e => toggleVisibility(column, e.detail)}
|
on:change={e => toggleColumn(column, e.detail)}
|
||||||
disabled={column.primaryDisplay}
|
disabled={column.primaryDisplay}
|
||||||
/>
|
/>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<ActionButton on:click={showAll}>Show all</ActionButton>
|
<ActionButton on:click={() => toggleAll(true)}>Show all</ActionButton>
|
||||||
<ActionButton on:click={hideAll}>Hide all</ActionButton>
|
<ActionButton on:click={() => toggleAll(false)}>Hide all</ActionButton>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Popover>
|
</Popover>
|
||||||
|
|
|
@ -47,7 +47,7 @@ export const deriveStores = context => {
|
||||||
// prop and user overrides
|
// prop and user overrides
|
||||||
const enrichedSchema = derived(
|
const enrichedSchema = derived(
|
||||||
[schema, schemaOverrides, schemaMutations, columnWhitelist],
|
[schema, schemaOverrides, schemaMutations, columnWhitelist],
|
||||||
([$schema, $schemaOverrides, schemaMutations, $columnWhitelist]) => {
|
([$schema, $schemaOverrides, $schemaMutations, $columnWhitelist]) => {
|
||||||
if (!$schema) {
|
if (!$schema) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ export const deriveStores = context => {
|
||||||
enrichedSchema[field] = {
|
enrichedSchema[field] = {
|
||||||
...$schema[field],
|
...$schema[field],
|
||||||
...$schemaOverrides?.[field],
|
...$schemaOverrides?.[field],
|
||||||
...schemaMutations[field],
|
...$schemaMutations[field],
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return enrichedSchema
|
return enrichedSchema
|
||||||
|
|
Loading…
Reference in New Issue