parent
d627a19935
commit
aa69bb8d1e
@ -0,0 +1,25 @@
|
|||||||
|
import { createSelector } from 'redux-orm';
|
||||||
|
|
||||||
|
import orm from '../orm';
|
||||||
|
|
||||||
|
export const makeSelectLabelById = () =>
|
||||||
|
createSelector(
|
||||||
|
orm,
|
||||||
|
(_, id) => id,
|
||||||
|
({ Label }, id) => {
|
||||||
|
const labelModel = Label.withId(id);
|
||||||
|
|
||||||
|
if (!labelModel) {
|
||||||
|
return labelModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
return labelModel.ref;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export const selectLabelById = makeSelectLabelById();
|
||||||
|
|
||||||
|
export default {
|
||||||
|
makeSelectLabelById,
|
||||||
|
selectLabelById,
|
||||||
|
};
|
||||||
@ -1,44 +1,5 @@
|
|||||||
const POSITION_GAP = 65535;
|
const { addPosition, removePosition } = require('../../utils/migrations');
|
||||||
|
|
||||||
module.exports.up = async (knex) => {
|
module.exports.up = (knex) => addPosition(knex, 'task', 'card_id');
|
||||||
await knex.schema.table('task', (table) => {
|
|
||||||
/* Columns */
|
|
||||||
|
|
||||||
table.specificType('position', 'double precision');
|
module.exports.down = (knex) => removePosition(knex, 'task');
|
||||||
|
|
||||||
/* Indexes */
|
|
||||||
|
|
||||||
table.index('position');
|
|
||||||
});
|
|
||||||
|
|
||||||
const tasks = await knex('task').orderBy(['card_id', 'id']);
|
|
||||||
|
|
||||||
let prevCardId;
|
|
||||||
let position;
|
|
||||||
|
|
||||||
// eslint-disable-next-line no-restricted-syntax
|
|
||||||
for (task of tasks) {
|
|
||||||
if (task.card_id === prevCardId) {
|
|
||||||
position += POSITION_GAP;
|
|
||||||
} else {
|
|
||||||
prevCardId = task.card_id;
|
|
||||||
position = POSITION_GAP;
|
|
||||||
}
|
|
||||||
|
|
||||||
// eslint-disable-next-line no-await-in-loop
|
|
||||||
await knex('task')
|
|
||||||
.update({
|
|
||||||
position,
|
|
||||||
})
|
|
||||||
.where('id', task.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return knex.schema.table('task', (table) => {
|
|
||||||
table.dropNullable('position');
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.down = async (knex) =>
|
|
||||||
knex.schema.table('task', (table) => {
|
|
||||||
table.dropColumn('position');
|
|
||||||
});
|
|
||||||
|
|||||||
@ -0,0 +1,5 @@
|
|||||||
|
const { addPosition, removePosition } = require('../../utils/migrations');
|
||||||
|
|
||||||
|
module.exports.up = (knex) => addPosition(knex, 'label', 'board_id');
|
||||||
|
|
||||||
|
module.exports.down = (knex) => removePosition(knex, 'label');
|
||||||
@ -0,0 +1,49 @@
|
|||||||
|
const POSITION_GAP = 65535;
|
||||||
|
|
||||||
|
const addPosition = async (knex, tableName, parentFieldName) => {
|
||||||
|
await knex.schema.table(tableName, (table) => {
|
||||||
|
/* Columns */
|
||||||
|
|
||||||
|
table.specificType('position', 'double precision');
|
||||||
|
|
||||||
|
/* Indexes */
|
||||||
|
|
||||||
|
table.index('position');
|
||||||
|
});
|
||||||
|
|
||||||
|
const records = await knex(tableName).orderBy([parentFieldName, 'id']);
|
||||||
|
|
||||||
|
let prevParentId;
|
||||||
|
let position;
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-restricted-syntax
|
||||||
|
for (record of records) {
|
||||||
|
if (record[parentFieldName] === prevParentId) {
|
||||||
|
position += POSITION_GAP;
|
||||||
|
} else {
|
||||||
|
prevParentId = record[parentFieldName];
|
||||||
|
position = POSITION_GAP;
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
await knex(tableName)
|
||||||
|
.update({
|
||||||
|
position,
|
||||||
|
})
|
||||||
|
.where('id', record.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return knex.schema.table(tableName, (table) => {
|
||||||
|
table.dropNullable('position');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const removePosition = (knex, tableName) =>
|
||||||
|
knex.schema.table(tableName, (table) => {
|
||||||
|
table.dropColumn('position');
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
addPosition,
|
||||||
|
removePosition,
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue